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))
Exemplo n.º 2
0
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))
Exemplo n.º 3
0
def test_reversals(segment_with_point: Tuple[Segment, Point]) -> None:
    segment, point = segment_with_point

    result = point_in_segment(point, segment)

    assert result is point_in_segment(point, reverse_segment(segment))
    assert result is point_in_segment(reverse_point_coordinates(point),
                                      reverse_segment_coordinates(segment))
Exemplo n.º 4
0
def test_basic(segment_with_point: Tuple[Segment, Point]) -> None:
    segment, point = segment_with_point

    result = point_in_segment(point, segment)

    assert isinstance(result, Location)
    assert result in LINEAR_LOCATIONS
Exemplo n.º 5
0
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)))
Exemplo n.º 6
0
def test_orientation(segment_with_point: Tuple[Segment, Point]) -> None:
    segment, point = segment_with_point

    assert implication(point_in_segment(point, segment) is Location.BOUNDARY,
                       orientation(segment.start, segment.end, point)
                       is Orientation.COLLINEAR)
Exemplo n.º 7
0
def test_self(segment: Segment) -> None:
    assert point_in_segment(segment.start, segment) is Location.BOUNDARY
    assert point_in_segment(segment.end, segment) is Location.BOUNDARY
Exemplo n.º 8
0
def point_in_multisegment(point: Point,
                          multisegment: Multisegment) -> Relation:
    return (Relation.COMPONENT
            if any(point_in_segment(point, segment) is Relation.COMPONENT
                   for segment in multisegment)
            else Relation.DISJOINT)