예제 #1
0
def test_connection_with_point_in_polygon(polygon_with_segment
                                          : Tuple[Polygon, Segment]) -> None:
    polygon, segment = polygon_with_segment

    result = segment_in_polygon(segment, polygon)

    assert implication(result is Relation.DISJOINT,
                       point_in_polygon(segment.start, polygon)
                       is point_in_polygon(segment.end, polygon)
                       is Location.EXTERIOR)
예제 #2
0
def test_reversals(polygon_with_point: Tuple[Polygon, Point]) -> None:
    polygon, point = polygon_with_point

    result = point_in_polygon(point, polygon)

    assert result is point_in_polygon(point, reverse_polygon_border(polygon))
    assert result is point_in_polygon(point, reverse_polygon_holes(polygon))
    assert result is point_in_polygon(point,
                                      reverse_polygon_holes_contours(polygon))
    assert result is point_in_polygon(reverse_point_coordinates(point),
                                      reverse_polygon_coordinates(polygon))
예제 #3
0
def test_without_holes(polygon_with_point: Tuple[Polygon, Point]) -> None:
    polygon, point = polygon_with_point

    result = point_in_polygon(point, polygon)

    polygon_without_holes = to_solid_polygon(polygon)
    assert implication(
        result is Location.INTERIOR,
        point_in_polygon(point, polygon_without_holes) is Location.INTERIOR)
    assert implication(
        point_in_polygon(point, polygon_without_holes) is Location.EXTERIOR,
        result is Location.EXTERIOR)
    assert implication(
        point_in_polygon(point, polygon_without_holes) is Location.BOUNDARY,
        result is Location.BOUNDARY)
예제 #4
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))
예제 #5
0
def test_locate(context: Context, polygon_with_point: Tuple[Polygon,
                                                            Point]) -> None:
    polygon, point = polygon_with_point

    result = Graph.from_polygon(polygon, context=context)

    assert result.locate(point) is point_in_polygon(point, polygon)
예제 #6
0
def test_basic(polygon_with_point: Tuple[Polygon, Point]) -> None:
    polygon, point = polygon_with_point

    result = point_in_polygon(point, polygon)

    assert isinstance(result, Location)
    assert result in SHAPED_LOCATIONS
예제 #7
0
def test_contains(polygon_with_point: Tuple[Polygon, Point]) -> None:
    polygon, point = polygon_with_point
    border, holes = polygon

    result = polygon_trapezoidal(border, holes)

    assert ((point in result) is
            (point_in_polygon(point, polygon) is not Relation.DISJOINT))
예제 #8
0
def test_contains(context: Context, polygon_with_point: Tuple[Polygon,
                                                              Point]) -> None:
    polygon, point = polygon_with_point

    result = Graph.from_polygon(polygon, context=context)

    assert ((point in result) is
            (point_in_polygon(point, polygon) is not Location.EXTERIOR))
예제 #9
0
파일: polygon.py 프로젝트: lycantropos/gon
def _locate_point(polygon: Polygon,
                  point: Point,
                  context: Context) -> Location:
    relation = point_in_polygon(point, polygon,
                                context=context)
    return (Location.EXTERIOR
            if relation is Relation.DISJOINT
            else (Location.BOUNDARY
                  if relation is Relation.COMPONENT
                  else Location.INTERIOR))
예제 #10
0
def test_locate(polygon_with_point: Tuple[Polygon, Point]) -> None:
    polygon, point = polygon_with_point
    border, holes = polygon

    result = polygon_trapezoidal(border, holes)

    location = result.locate(point)
    relation = point_in_polygon(point, polygon)
    assert (location is Location.EXTERIOR) is (relation is Relation.DISJOINT)
    assert (location is Location.BOUNDARY) is (relation is Relation.COMPONENT)
    assert (location is Location.INTERIOR) is (relation is Relation.WITHIN)
예제 #11
0
def test_connection_with_point_in_polygon(
        polygons_pair: Tuple[Polygon, Polygon]) -> None:
    left, right = polygons_pair

    assert implication(
        polygon_in_polygon(left, right)
        in (Relation.EQUAL, Relation.COMPONENT, Relation.ENCLOSED,
            Relation.WITHIN),
        all(
            point_in_polygon(vertex, right) is not Location.EXTERIOR
            for vertex in to_polygon_vertices(left)))
def test_step(multipolygon_with_polygon: Tuple[Multipolygon, Point]) -> None:
    multipolygon, point = multipolygon_with_polygon
    first_polygon, rest_multipolygon = multipolygon_pop_left(multipolygon)

    result = point_in_multipolygon(point, rest_multipolygon)
    next_result = point_in_multipolygon(point, multipolygon)

    relation_with_first_polygon = point_in_polygon(point, first_polygon)
    assert equivalence(
        next_result is Location.EXTERIOR, result is Location.EXTERIOR
        and relation_with_first_polygon is Location.EXTERIOR)
    assert equivalence(
        next_result is Location.INTERIOR, result is Location.INTERIOR
        or relation_with_first_polygon is Location.INTERIOR)
    assert equivalence(
        next_result is Location.BOUNDARY, result is Location.BOUNDARY
        or relation_with_first_polygon is Location.BOUNDARY)
예제 #13
0
def test_connection_with_point_in_polygon(
        polygon_with_contour: Tuple[Polygon, Contour]) -> None:
    polygon, contour = polygon_with_contour

    result = contour_in_polygon(contour, polygon)

    vertices_relations = [
        point_in_polygon(vertex, polygon) for vertex in contour.vertices
    ]
    assert implication(
        result is Relation.DISJOINT,
        all(vertex_location is Location.EXTERIOR
            for vertex_location in vertices_relations))
    assert implication(
        result is Relation.TOUCH,
        all(vertex_location is not Location.INTERIOR
            for vertex_location in vertices_relations))
    assert implication(
        result is Relation.COMPONENT,
        all(vertex_location is Location.BOUNDARY
            for vertex_location in vertices_relations))
    assert implication(
        result is Relation.ENCLOSED,
        all(vertex_location is not Location.EXTERIOR
            for vertex_location in vertices_relations))
    assert implication(
        result is Relation.WITHIN,
        all(vertex_location is Location.INTERIOR
            for vertex_location in vertices_relations))
    assert implication(
        all(vertex_location is Location.EXTERIOR
            for vertex_location in vertices_relations),
        result is Relation.DISJOINT or result is Relation.TOUCH
        or result is Relation.CROSS)
    assert implication(
        all(vertex_location is Location.INTERIOR
            for vertex_location in vertices_relations),
        result is Relation.CROSS or result is Relation.ENCLOSED
        or result is Relation.WITHIN)
    assert implication(
        any(vertex_location is Location.EXTERIOR
            for vertex_location in vertices_relations)
        and any(vertex_location is Location.INTERIOR
                for vertex_location in vertices_relations),
        result is Relation.CROSS)
예제 #14
0
def test_self(polygon: Polygon) -> None:
    assert all(
        point_in_polygon(vertex, polygon) is Location.BOUNDARY
        for vertex in to_polygon_vertices(polygon))