def test_basic(polygon_with_multisegment: PolygonWithMultisegment) -> None: polygon, multisegment = polygon_with_multisegment result = complete_intersect_multisegment_with_polygon( multisegment, polygon) assert is_non_shaped(result)
def test_connection_with_intersect( polygon_with_multisegment: PolygonWithMultisegment) -> None: polygon, multisegment = polygon_with_multisegment result = complete_intersect_multisegment_with_polygon( multisegment, polygon) assert (compound_to_linear(result) == intersect_multisegment_with_polygon( multisegment, polygon))
def test_properties( polygon_with_multisegment: PolygonWithMultisegment) -> None: polygon, multisegment = polygon_with_multisegment result = complete_intersect_multisegment_with_polygon( multisegment, polygon) result_points, result_segments = pack_non_shaped(result) assert all( point_in_multisegment(point, multisegment) is Location.BOUNDARY for point in result_points) assert all( point_in_polygon(point, polygon) is Location.BOUNDARY for point in result_points) assert all( any( point_in_segment(point, segment) is Location.BOUNDARY for point in result_points) or any( segments_relation(segment, result_segment) is Relation.TOUCH for result_segment in result_segments) for segment in multisegment.segments if (segment_in_polygon(segment, polygon) is Relation.TOUCH and all( segments_relation(segment, contour_segment) in (Relation.CROSS, Relation.DISJOINT, Relation.TOUCH) for contour in to_polygon_contours(polygon) for contour_segment in to_contour_segments(contour)))) assert all( segment_in_multisegment(result_segment, multisegment) in ( Relation.EQUAL, Relation.COMPONENT) for result_segment in result_segments) assert all( segment_in_polygon(result_segment, polygon) in (Relation.COMPONENT, Relation.ENCLOSED, Relation.WITHIN) for result_segment in result_segments) assert all( to_sorted_segment(segment) in result_segments # in case of cross or any( segment_in_segment(result_segment, segment) is Relation.COMPONENT for result_segment in result_segments) for segment in multisegment.segments if (segment_in_polygon(segment, polygon) in (Relation.CROSS, Relation.COMPONENT, Relation.ENCLOSED, Relation.WITHIN)))
def __and__(self, other: Compound) -> Compound: """ Returns intersection of the polygon with the other geometry. Time complexity: ``O(vertices_count * log vertices_count)`` Memory complexity: ``O(vertices_count)`` where .. code-block:: python vertices_count = (len(self.border.vertices) + sum(len(hole.vertices)\ for hole in self.holes)) >>> from gon.base import Contour, Point, Polygon >>> polygon = Polygon(Contour([Point(0, 0), Point(6, 0), Point(6, 6), ... Point(0, 6)]), ... [Contour([Point(2, 2), Point(2, 4), Point(4, 4), ... Point(4, 2)])]) >>> polygon & polygon == polygon True """ return (complete_intersect_segment_with_polygon(other, self, context=self._context) if isinstance(other, Segment) else (complete_intersect_multisegment_with_polygon( other, self, context=self._context) if isinstance(other, Linear) else ((complete_intersect_polygons(self, other, context=self._context) if self.holes or other.holes else complete_intersect_regions(self.border, other.border, context=self._context)) if isinstance(other, Polygon) else NotImplemented)))
def test_reversals(polygon_with_multisegment: PolygonWithMultisegment) -> None: polygon, multisegment = polygon_with_multisegment result = complete_intersect_multisegment_with_polygon( multisegment, polygon) assert result == complete_intersect_multisegment_with_polygon( multisegment, reverse_polygon_border(polygon)) assert result == complete_intersect_multisegment_with_polygon( multisegment, reverse_polygon_holes(polygon)) assert result == complete_intersect_multisegment_with_polygon( multisegment, reverse_polygon_holes_contours(polygon)) assert result == complete_intersect_multisegment_with_polygon( reverse_multisegment(multisegment), polygon) assert result == complete_intersect_multisegment_with_polygon( reverse_multisegment_endpoints(multisegment), polygon) assert are_compounds_similar( result, reverse_compound_coordinates( complete_intersect_multisegment_with_polygon( reverse_multisegment_coordinates(multisegment), reverse_polygon_coordinates(polygon))))