예제 #1
0
def test_rotations(region_with_contour: Tuple[Region, Contour]) -> None:
    region, contour = region_with_contour

    result = contour_in_region(contour, region)

    assert all(result is contour_in_region(rotated, region)
               for rotated in contour_rotations(contour))
    assert all(result is contour_in_region(contour, rotated)
               for rotated in contour_rotations(region))
예제 #2
0
def test_reversals(region_with_contour: Tuple[Region, Contour]) -> None:
    region, contour = region_with_contour

    result = contour_in_region(contour, region)

    assert result is contour_in_region(reverse_contour(contour), region)
    assert result is contour_in_region(contour, reverse_contour(region))
    assert result is contour_in_region(reverse_contour_coordinates(contour),
                                       reverse_contour_coordinates(region))
예제 #3
0
def test_step(multiregion_with_contour: Tuple[Multiregion, Contour]) -> None:
    multiregion, contour = multiregion_with_contour
    first_region, *rest_multiregion = multiregion

    result = contour_in_multiregion(contour, rest_multiregion)
    next_result = contour_in_multiregion(contour, multiregion)

    relation_with_first_region = contour_in_region(contour, first_region)
    assert equivalence(
        next_result is Relation.DISJOINT,
        result is relation_with_first_region is Relation.DISJOINT)
    assert equivalence(
        next_result is Relation.TOUCH, result is Relation.DISJOINT
        and relation_with_first_region is Relation.TOUCH
        or result is Relation.TOUCH and
        (relation_with_first_region is Relation.DISJOINT
         or relation_with_first_region is Relation.TOUCH))
    assert equivalence(
        next_result is Relation.COMPONENT, result is Relation.COMPONENT
        or relation_with_first_region is Relation.COMPONENT)
    assert equivalence(
        next_result is Relation.CROSS, result is Relation.CROSS
        or relation_with_first_region is Relation.CROSS)
    assert equivalence(
        next_result is Relation.ENCLOSED, result is Relation.ENCLOSED
        or relation_with_first_region is Relation.ENCLOSED)
    assert equivalence(
        next_result is Relation.WITHIN, result is Relation.WITHIN
        or relation_with_first_region is Relation.WITHIN)
예제 #4
0
def test_basic(contour_with_region: Tuple[Contour, Region]) -> None:
    contour, region = contour_with_region

    result = contour_in_region(contour, region)

    assert isinstance(result, Relation)
    assert result in LINEAR_COMPOUND_RELATIONS
예제 #5
0
def test_connection_with_segment_in_region(
        region_with_contour: Tuple[Region, Contour]) -> None:
    region, contour = region_with_contour

    result = contour_in_region(contour, region)

    contour_segments_relations = [
        segment_in_region(segment, region)
        for segment in to_contour_segments(contour)
    ]
    assert equivalence(
        result is Relation.DISJOINT,
        all(relation is Relation.DISJOINT
            for relation in contour_segments_relations))
    assert equivalence(
        result is Relation.TOUCH,
        all(relation is not Relation.CROSS and relation
            is not Relation.ENCLOSED and relation is not Relation.WITHIN
            for relation in contour_segments_relations)
        and any(relation is Relation.TOUCH
                for relation in contour_segments_relations))
    assert equivalence(
        result is Relation.CROSS,
        any(relation is Relation.CROSS
            for relation in contour_segments_relations)
        or any(relation is Relation.TOUCH or relation is Relation.DISJOINT
               for relation in contour_segments_relations)
        and any(relation is Relation.ENCLOSED or relation is Relation.WITHIN
                for relation in contour_segments_relations))
    assert equivalence(
        result is Relation.COMPONENT,
        all(relation is Relation.COMPONENT
            for relation in contour_segments_relations))
    assert equivalence(
        result is Relation.ENCLOSED,
        all(relation is Relation.COMPONENT or relation is Relation.ENCLOSED
            or relation is Relation.WITHIN
            for relation in contour_segments_relations)
        and any(relation is Relation.COMPONENT or relation is Relation.ENCLOSED
                for relation in contour_segments_relations)
        and any(relation is Relation.ENCLOSED or relation is Relation.WITHIN
                for relation in contour_segments_relations))
    assert equivalence(
        result is Relation.WITHIN,
        all(relation is Relation.WITHIN
            for relation in contour_segments_relations))
예제 #6
0
def test_connection_with_point_in_region(
        region_with_contour: Tuple[Region, Contour]) -> None:
    region, contour = region_with_contour

    result = contour_in_region(contour, region)

    vertices_relations = [
        point_in_region(vertex, region) 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)
예제 #7
0
def test_connection_with_contour_in_region(regions_pair: Tuple[Region, Region]
                                           ) -> None:
    left_region, right_region = regions_pair

    result = region_in_region(left_region, right_region)

    contour_relation = contour_in_region(left_region, right_region)
    assert equivalence(result is Relation.DISJOINT
                       or result is Relation.COVER,
                       contour_relation is Relation.DISJOINT)
    assert equivalence(result is Relation.TOUCH
                       or result is Relation.ENCLOSES
                       or result is Relation.COMPOSITE,
                       contour_relation is Relation.TOUCH)
    assert equivalence(result is Relation.OVERLAP,
                       contour_relation is Relation.CROSS)
    assert equivalence(result is Relation.COMPONENT
                       or result is Relation.EQUAL,
                       contour_relation is Relation.COMPONENT)
    assert equivalence(result is Relation.ENCLOSED,
                       contour_relation is Relation.ENCLOSED)
    assert equivalence(result is Relation.WITHIN,
                       contour_relation is Relation.WITHIN)
예제 #8
0
def test_self(contour: Contour) -> None:
    assert contour_in_region(contour, contour) is Relation.COMPONENT