def pred_poly_by_line(self, polygon: Polygon, splitter: Segment) -> PolygonsSet: pred_poly_by_edges = self._pred_poly_by_edges(polygon) vertices_in_interval = cut(polygon.border, splitter.start, splitter.end) edges_in_interval = Multisegment(*map(Segment, vertices_in_interval[:-1], vertices_in_interval[1:])) return PolygonsSet({part for edge, pred_poly in pred_poly_by_edges.items() for part in pred_poly if isinstance(edge & edges_in_interval, Segment)})
def plr(self, polygon: Polygon, splitter: Segment) -> RootedPolygons: """ Portion of the current polygon to the right of the splitter plus all immediate ancestors accessible through the polygon edges that lie on the right of the splitter """ vertices_in_interval = cut(polygon.border, splitter.start, splitter.end) if len(vertices_in_interval) < 3: current_polygon_part = EMPTY else: contour = Contour(shrink_collinear_vertices( Contour(vertices_in_interval))) current_polygon_part = Polygon(contour) pred_poly_by_line = self.pred_poly_by_line(polygon, splitter=splitter) return RootedPolygons(root=current_polygon_part, predecessors=pred_poly_by_line)
def test_both_directions( contour_and_points: Tuple[Contour, Point, Point]) -> None: contour, start, end = contour_and_points right_vertices = cut(contour, start, end) left_vertices = cut(contour, end, start) assert {*right_vertices, *left_vertices} == {*contour.vertices, start, end}
def test_duplicates(contour_and_points: Tuple[Contour, Point, Point]) -> None: contour, start, end = contour_and_points vertices = cut(contour, start, end) assert len(set(vertices)) == len(vertices)
def test_segments(contour_and_points: Tuple[Contour, Point, Point]) -> None: contour, start, end = contour_and_points vertices = cut(contour, start, end) segments = map(Segment, vertices[:-1], vertices[1:]) assert all(segment < contour for segment in segments)
def test_vertices(contour_and_points: Tuple[Contour, Point, Point]) -> None: contour, start, end = contour_and_points assert all(point in contour for point in cut(contour, start, end))