def test_properties(segments_pair: SegmentsPair) -> None: first, second = segments_pair result = intersect_segments(first, second) result_points, result_segments = pack_non_shaped(result) assert all( point_in_segment(point, first) is point_in_segment(point, second) is Location.BOUNDARY for point in result_points) assert (segment_in_segment(first, second) is not Relation.TOUCH or bool(result_points)) assert (segment_in_segment(first, second) not in (Relation.TOUCH, Relation.CROSS) or all(point in result_points or any( point == result_segment.start or point == result_segment.end for result_segment in result_segments) for point in segments_intersections(first, second))) assert all( segment_in_segment(result_segment, first) in (Relation.EQUAL, Relation.COMPONENT) for result_segment in result_segments) assert all( segment_in_segment(result_segment, second) in (Relation.EQUAL, Relation.COMPONENT) for result_segment in result_segments) assert (segments_relation( first, second) in (Relation.CROSS, Relation.DISJOINT, Relation.TOUCH) or to_sorted_segment(first) in result_segments or any( segment_in_segment(result_segment, first) is Relation.COMPONENT for result_segment in result_segments))
def test_properties(polygon_with_segment: PolygonWithSegment ) -> None: polygon, segment = polygon_with_segment result = complete_intersect_segment_with_polygon(segment, polygon) result_points, result_segments = pack_non_shaped(result) assert all(point_in_segment(point, segment) is Location.BOUNDARY for point in result_points) assert all(point_in_polygon(point, polygon) is Location.BOUNDARY for point in result_points) assert (not (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))) or 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)) assert all(segment_in_segment(result_segment, segment) 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 (segment_in_polygon(segment, polygon) not in (Relation.CROSS, Relation.COMPONENT, Relation.ENCLOSED, Relation.WITHIN) or 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))
def test_properties( polygon_with_multisegment: PolygonWithMultisegment) -> None: polygon, multisegment = polygon_with_multisegment result = intersect_multisegment_with_polygon(multisegment, polygon) result_points, result_segments = pack_non_shaped(result) assert not result_points 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 test_properties( multipolygon_with_multisegment: MultipolygonWithMultisegment) -> None: multipolygon, multisegment = multipolygon_with_multisegment result = intersect_multisegment_with_multipolygon(multisegment, multipolygon) assert all( segment_in_multisegment(segment, multisegment) in (Relation.EQUAL, Relation.COMPONENT) for segment in result.segments) assert all( segment_in_multipolygon(segment, multipolygon) in (Relation.COMPONENT, Relation.ENCLOSED, Relation.WITHIN) for 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_multipolygon(segment, multipolygon) in ( Relation.CROSS, Relation.COMPONENT, Relation.ENCLOSED, Relation.WITHIN)))
def test_properties( multipolygon_with_multisegment: MultipolygonWithMultisegment) -> None: multipolygon, multisegment = multipolygon_with_multisegment result = complete_intersect_multisegment_with_multipolygon( multisegment, multipolygon) result_multipoint, result_multisegment = result assert all( point_in_multisegment(point, multisegment) is Relation.COMPONENT for point in result_multipoint.points) assert all( point_in_multipolygon(point, multipolygon) is Relation.COMPONENT for point in result_multipoint.points) assert all( any( point_in_segment(point, segment) is Relation.COMPONENT for point in result_multipoint.points) or any( segments_relation(segment.start, segment.end, result_segment. start, result_segment.end) is Relation.TOUCH for result_segment in result_multisegment.segments) for segment in multisegment.segments if (segment_in_multipolygon(segment, multipolygon) is Relation.TOUCH and all( segments_relation(segment.start, segment.end, edge_start, edge_end) in (Relation.CROSS, Relation.DISJOINT, Relation.TOUCH) for contour in to_multipolygon_contours(multipolygon) for edge_start, edge_end in contour_to_edges_endpoints(contour)))) assert all( segment_in_multisegment(segment, multisegment) in (Relation.EQUAL, Relation.COMPONENT) for segment in result_multisegment.segments) assert all( segment_in_multipolygon(segment, multipolygon) in (Relation.COMPONENT, Relation.ENCLOSED, Relation.WITHIN) for segment in result_multisegment.segments) assert all( to_sorted_segment(segment) in result_multisegment.segments # in case of cross or any( segment_in_segment(result_segment, segment) is Relation.COMPONENT for result_segment in result_multisegment.segments) for segment in multisegment.segments if (segment_in_multipolygon(segment, multipolygon) in ( Relation.CROSS, Relation.COMPONENT, Relation.ENCLOSED, Relation.WITHIN)))
def test_properties(multisegments_pair: MultisegmentsPair) -> None: left_multisegment, right_multisegment = multisegments_pair result = complete_intersect_multisegments(left_multisegment, right_multisegment) result_multipoint, result_multisegment = result assert all( point_in_multisegment(point, left_multisegment) is point_in_multisegment(point, right_multisegment) is Relation.COMPONENT for point in result_multipoint.points) assert (multisegment_in_multisegment(left_multisegment, right_multisegment) is not Relation.TOUCH or bool(result_multipoint)) assert all( all(point in result_multipoint or any( point in segment for segment in result_multisegment.segments) for right_segment in right_multisegment.segments for point in segments_intersections(left_segment, right_segment)) for left_segment in left_multisegment.segments if (segment_in_multisegment(left_segment, right_multisegment) in ( Relation.TOUCH, Relation.CROSS))) assert all( segment_in_multisegment(segment, left_multisegment) in ( Relation.EQUAL, Relation.COMPONENT) for segment in result_multisegment.segments) assert all( segment_in_multisegment(segment, right_multisegment) in ( Relation.EQUAL, Relation.COMPONENT) for segment in result_multisegment.segments) assert all( to_sorted_segment(left_segment) in result_multisegment.segments or any( segment_in_segment(segment, left_segment) is Relation.COMPONENT for segment in result_multisegment.segments) for left_segment in left_multisegment.segments if any( segments_relation(left_segment.start, left_segment.end, right_segment.start, right_segment.end) not in ( Relation.CROSS, Relation.DISJOINT, Relation.TOUCH) for right_segment in right_multisegment.segments))