def test_reversals(regions_pair: Tuple[Region, Region]) -> None:
    left, right = regions_pair

    result = region_in_region(left, right)

    assert result is region_in_region(reverse_contour(left), right)
    assert result is region_in_region(left, reverse_contour(right))
    assert result is region_in_region(reverse_contour_coordinates(left),
                                      reverse_contour_coordinates(right))
def test_rotations(regions_pair: Tuple[Region, Region]) -> None:
    left, right = regions_pair

    result = region_in_region(left, right)

    assert all(result is region_in_region(rotated, right)
               for rotated in region_rotations(left))
    assert all(result is region_in_region(left, rotated)
               for rotated in region_rotations(right))
def test_relations(regions_pair: Tuple[Region, Region]) -> None:
    left_region, right_region = regions_pair

    result = region_in_region(left_region, right_region)

    complement = region_in_region(right_region, left_region)
    assert equivalence(result is complement,
                       result in SYMMETRIC_COMPOUND_RELATIONS)
    assert equivalence(result is not complement,
                       result.complement is complement
                       and result in ASYMMETRIC_UNIFORM_COMPOUND_RELATIONS
                       and complement in ASYMMETRIC_UNIFORM_COMPOUND_RELATIONS)
def test_basic(regions_pair: Tuple[Region, Region]) -> None:
    left_region, right_region = regions_pair

    result = region_in_region(left_region, right_region)

    assert isinstance(result, Relation)
    assert result in UNIFORM_COMPOUND_RELATIONS
def test_connection_with_point_in_region(regions_pair: Tuple[Region, Region]
                                         ) -> None:
    left_region, right_region = regions_pair

    assert implication(region_in_region(left_region, right_region)
                       in (Relation.EQUAL, Relation.COMPONENT,
                           Relation.ENCLOSED, Relation.WITHIN),
                       all(point_in_region(vertex, right_region)
                           is not Location.EXTERIOR
                           for vertex in left_region.vertices))
Example #6
0
def test_step(multiregion_with_region: Tuple[Multiregion, Region]) -> None:
    multiregion, region = multiregion_with_region
    first_region, *rest_multiregion = multiregion

    result = region_in_multiregion(region, rest_multiregion)
    next_result = region_in_multiregion(region, multiregion)

    relation_with_first_region = region_in_region(region, 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 in (Relation.DISJOINT, Relation.TOUCH))
    assert equivalence(
        next_result is Relation.COMPONENT, result is Relation.COMPONENT
        or bool(rest_multiregion)
        and relation_with_first_region is Relation.EQUAL)
    assert equivalence(
        next_result is Relation.OVERLAP, result is Relation.OVERLAP
        or relation_with_first_region is Relation.OVERLAP
        or (bool(rest_multiregion) and result is Relation.DISJOINT
            or result is Relation.TOUCH)
        and relation_with_first_region in (Relation.COVER, Relation.ENCLOSES)
        or result in (Relation.COVER, Relation.ENCLOSES)
        and relation_with_first_region is Relation.DISJOINT)
    assert equivalence(next_result is Relation.COVER,
                       (not rest_multiregion or result is Relation.COVER)
                       and relation_with_first_region is Relation.COVER)
    assert equivalence(
        next_result is Relation.ENCLOSES, result is Relation.ENCLOSES
        and relation_with_first_region in (Relation.ENCLOSES, Relation.COVER)
        or (not rest_multiregion or result is Relation.COVER)
        and relation_with_first_region is Relation.ENCLOSES)
    assert equivalence(
        next_result is Relation.EQUAL, not rest_multiregion
        and relation_with_first_region is Relation.EQUAL)
    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)
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)
def test_convex_hull(region: Region) -> None:
    assert (region_in_region(region, to_region_convex_hull(region))
            in (Relation.EQUAL, Relation.ENCLOSED))
def test_self(region: Region) -> None:
    assert region_in_region(region, region) is Relation.EQUAL