def test_rotations(multisegment_with_point: Tuple[Multisegment, Point] ) -> None: multisegment, point = multisegment_with_point result = point_in_multisegment(point, multisegment) assert all(result is point_in_multisegment(point, rotated) for rotated in multisegment_rotations(multisegment))
def test_connection_with_point_in_multisegment( multisegment_with_segment: Tuple[Multisegment, Segment]) -> None: multisegment, segment = multisegment_with_segment result = segment_in_multisegment(segment, multisegment) assert implication( result is Relation.DISJOINT, point_in_multisegment(segment.start, multisegment) is point_in_multisegment(segment.end, multisegment) is Location.EXTERIOR)
def test_reversals(multisegment_with_point: Tuple[Multisegment, Point] ) -> None: multisegment, point = multisegment_with_point result = point_in_multisegment(point, multisegment) assert result is point_in_multisegment(point, reverse_multisegment(multisegment)) assert result is point_in_multisegment( reverse_point_coordinates(point), reverse_multisegment_coordinates(multisegment))
def _locate_point(multisegment: Multisegment[Coordinate], point: Point[Coordinate], context: Context) -> Location: return (Location.EXTERIOR if point_in_multisegment(point, multisegment, context=context) is Relation.DISJOINT else Location.BOUNDARY)
def test_basic(multisegment_with_point: Tuple[Multisegment, Point]) -> None: multisegment, point = multisegment_with_point result = point_in_multisegment(point, multisegment) assert isinstance(result, Location) assert result in LINEAR_LOCATIONS
def test_locate(context: Context, multisegment_with_point: Tuple[Multisegment, Point]) -> None: multisegment, point = multisegment_with_point result = Graph.from_multisegment(multisegment, context=context) assert result.locate(point) is point_in_multisegment(point, multisegment)
def test_contains(context: Context, multisegment_with_point: Tuple[Multisegment, Point]) -> None: multisegment, point = multisegment_with_point result = Graph.from_multisegment(multisegment, context=context) assert (point in result) is (point_in_multisegment(point, multisegment) is not Location.EXTERIOR)
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))
def test_properties(multisegments_pair: MultisegmentsPair) -> None: first, second = multisegments_pair result = complete_intersect_multisegments(first, second) result_points, result_segments = pack_non_shaped(result) assert all( point_in_multisegment(point, first) is point_in_multisegment( point, second) is Location.BOUNDARY for point in result_points) assert (multisegment_in_multisegment(first, second) is not Relation.TOUCH or bool(result_points)) assert all( all(point in result_points or any( point == result_segment.start or point == result_segment.end for result_segment in result_segments) for second_segment in second.segments for point in segments_intersections(first_segment, second_segment)) for first_segment in first.segments if (segment_in_multisegment(first_segment, second) in ( Relation.TOUCH, Relation.CROSS))) assert all( segment_in_multisegment(result_segment, first) in (Relation.EQUAL, Relation.COMPONENT) for result_segment in result_segments) assert all( segment_in_multisegment(result_segment, second) in (Relation.EQUAL, Relation.COMPONENT) for result_segment in result_segments) assert all( to_sorted_segment(first_segment) in result_segments or any( segment_in_segment(result_segment, first_segment) is Relation.COMPONENT for result_segment in result_segments) for first_segment in first.segments if any( segments_relation(first_segment, second_segment) not in ( Relation.CROSS, Relation.DISJOINT, Relation.TOUCH) for second_segment in second.segments))
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( 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 _locate_point(contour: Contour[Coordinate], point: Point[Coordinate], context: Context) -> Location: return (Location.BOUNDARY if point_in_multisegment( point, contour, context=context) else Location.EXTERIOR)