def __generate_visivility_graph(self):
def extend_line(line):
return np.append(line, [line[0], line[1]], axis=0)
H = self.__H
join_style = JOIN_STYLE.mitre
is_ccw = LinearRing(self.borders_points).is_ccw
map_po = LineString(extend_line(self.borders_points)).parallel_offset(
H,
'left' if is_ccw else 'right',
join_style=join_style
)
if map_po.geom_type == 'MultiLineString':
geoms = list(map_po.geoms)
map_po = list(chain(geoms[0].coords, geoms[1].coords))
self.__support_points = np.array(map_po)
self.__holes = []
for item in self.items_border_points:
if item.size > 0:
is_ccw = LinearRing(item).is_ccw
item_po = LineString(extend_line(item)).parallel_offset(
H,
'right' if is_ccw else 'left',
join_style=join_style
)
if item_po.geom_type == 'MultiLineString':
geoms = list(item_po.geoms)
item_po = list(chain(geoms[0].coords, geoms[1].coords))
support_item_points = np.array(item_po)
self.__holes.append(support_item_points)
all_points = self.__support_points
for hole in self.__holes:
all_points = np.append(all_points, hole, axis=0)
holes_p = [Polygon(h) for h in self.__holes]
border_p = Polygon(self.__support_points)
points_len = len(all_points)
visibility_graph = np.zeros(shape=(points_len, points_len))
for i in range(all_points.shape[0]):
for j in range(all_points.shape[0]):
line = np.array((all_points[i], all_points[j]))
if self.is_valid(LineString(line), border_p, holes_p):
visibility_graph[i, j] = True
return all_points, visibility_graph