示例#1
0
def test_step(multiregion_with_region: Tuple[Multiregion, Segment]) -> None:
    multiregion, segment = multiregion_with_region
    first_region, *rest_multiregion = multiregion

    result = segment_in_multiregion(segment, rest_multiregion)
    next_result = segment_in_multiregion(segment, multiregion)

    relation_with_first_region = segment_in_region(segment, first_region)
    assert equivalence(
        next_result is Relation.DISJOINT, result is Relation.DISJOINT
        and relation_with_first_region is Relation.DISJOINT)
    assert equivalence(
        next_result is Relation.WITHIN, result is Relation.WITHIN
        or relation_with_first_region is Relation.WITHIN)
    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.TOUCH, result is Relation.TOUCH and
        (relation_with_first_region is Relation.DISJOINT
         or relation_with_first_region is Relation.TOUCH)
        or result is Relation.DISJOINT
        and relation_with_first_region is Relation.TOUCH)
def test_connection_with_contour_in_multipolygon(
        multipolygon_with_region: Tuple[Multipolygon, Region]) -> None:
    multipolygon, region = multipolygon_with_region

    result = region_in_multipolygon(region, multipolygon)

    contour_relation = contour_in_multipolygon(region, multipolygon)
    assert implication(result is Relation.DISJOINT or result is Relation.COVER,
                       contour_relation is Relation.DISJOINT)
    assert implication(
        contour_relation is Relation.DISJOINT, result is Relation.DISJOINT
        or result is Relation.OVERLAP or result is Relation.COVER)
    assert implication(
        result is Relation.TOUCH or result is Relation.ENCLOSES
        or result is Relation.COMPOSITE, contour_relation is Relation.TOUCH)
    assert implication(
        contour_relation is Relation.TOUCH, result is Relation.TOUCH
        or result is Relation.ENCLOSES or result is Relation.OVERLAP
        or result is Relation.COMPOSITE)
    assert implication(
        result is Relation.OVERLAP, contour_relation is Relation.DISJOINT
        or contour_relation is Relation.CROSS
        or contour_relation is Relation.TOUCH)
    assert implication(contour_relation is Relation.CROSS,
                       result is Relation.OVERLAP)
    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)
示例#3
0
def test_equivalents(first: Expression,
                     second: Expression) -> None:
    result = first < second

    assert equivalence(result, second > first)
    assert equivalence(result, second >= first != second)
    assert equivalence(result, first <= second != first)
def test_connection_with_segment_in_contour(
        region_with_segment: Tuple[Region, Segment]) -> None:
    region, segment = region_with_segment

    result = segment_in_region(segment, region)

    relation_with_contour = segment_in_contour(segment, region)
    assert implication(result is Relation.DISJOINT,
                       relation_with_contour is Relation.DISJOINT)
    assert implication(
        result is Relation.TOUCH, relation_with_contour is Relation.TOUCH
        or relation_with_contour is Relation.OVERLAP)
    assert equivalence(result is Relation.CROSS,
                       relation_with_contour is Relation.CROSS)
    assert equivalence(result is Relation.COMPONENT,
                       relation_with_contour is Relation.COMPONENT)
    assert implication(
        result is Relation.ENCLOSED, relation_with_contour is Relation.TOUCH
        or relation_with_contour is Relation.OVERLAP)
    assert implication(result is Relation.WITHIN,
                       relation_with_contour is Relation.DISJOINT)
    assert implication(
        relation_with_contour is Relation.DISJOINT, result is Relation.DISJOINT
        or result is Relation.WITHIN)
    assert implication(relation_with_contour is Relation.TOUCH,
                       result is Relation.TOUCH or result is Relation.ENCLOSED)
    assert implication(relation_with_contour is Relation.OVERLAP,
                       result is Relation.TOUCH or result is Relation.ENCLOSED)
示例#5
0
def test_mixes_relations(mixes_pair: Tuple[Mix, Mix]) -> None:
    left_mix, right_mix = mixes_pair

    result = left_mix.relate(right_mix)

    assert equivalence(
        result is Relation.DISJOINT,
        all(
            left_component.relate(right_component) is Relation.DISJOINT
            for left_component, right_component in product(
                mix_to_components(left_mix), mix_to_components(right_mix))))
    assert implication(
        result is Relation.OVERLAP,
        left_mix.shaped is right_mix.shaped is EMPTY
        or left_mix.shaped is not EMPTY and right_mix.shaped is not EMPTY)
    assert implication(result in (Relation.COVER, Relation.ENCLOSES),
                       right_mix.shaped is not EMPTY)
    assert implication(
        result is Relation.COMPOSITE,
        all(component is EMPTY
            or right_mix.relate(component) is Relation.COMPONENT
            for component in mix_to_components(left_mix)))
    assert equivalence(
        result is Relation.EQUAL,
        all(left_component is right_component is EMPTY or (
            left_component.relate(right_component) is Relation.EQUAL)
            for left_component, right_component in zip(
                mix_to_components(left_mix), mix_to_components(right_mix))))
    assert implication(
        result is Relation.COMPONENT,
        all(component is EMPTY
            or left_mix.relate(component) is Relation.COMPONENT
            for component in mix_to_components(right_mix)))
    assert implication(result in (Relation.ENCLOSED, Relation.WITHIN),
                       left_mix.shaped is not EMPTY)
示例#6
0
def test_convexity(polygon: Polygon) -> None:
    result = polygon.perimeter

    is_polygon_convex = polygon.is_convex
    convex_hull_perimeter = polygon.convex_hull.perimeter
    assert equivalence(not is_polygon_convex, result > convex_hull_perimeter)
    assert equivalence(is_polygon_convex, result == convex_hull_perimeter)
示例#7
0
def test_equivalents(compounds_pair: Tuple[Compound, Compound]) -> None:
    first_compound, second_compound = compounds_pair

    result = first_compound < second_compound

    assert equivalence(result, second_compound > first_compound)
    assert equivalence(result,
                       first_compound <= second_compound != first_compound)
    assert equivalence(result,
                       second_compound >= first_compound != second_compound)
def test_step(multipolygon_with_multisegment: Tuple[Multipolygon, Multisegment]
              ) -> None:
    multipolygon, multisegment = multipolygon_with_multisegment
    first_segment, rest_multisegment = multisegment_pop_left(multisegment)

    result = multisegment_in_multipolygon(rest_multisegment, multipolygon)
    next_result = multisegment_in_multipolygon(multisegment, multipolygon)

    relation_with_first_segment = segment_in_multipolygon(first_segment,
                                                          multipolygon)
    assert equivalence(next_result is Relation.DISJOINT,
                       result is relation_with_first_segment
                       is Relation.DISJOINT)
    assert implication(next_result is Relation.TOUCH,
                       result is Relation.TOUCH
                       and relation_with_first_segment is not Relation.CROSS
                       or result is Relation.DISJOINT
                       and relation_with_first_segment is Relation.TOUCH)
    assert implication(result is Relation.DISJOINT
                       and relation_with_first_segment is Relation.TOUCH
                       or result is Relation.TOUCH
                       and relation_with_first_segment is Relation.DISJOINT,
                       next_result is Relation.TOUCH)
    assert equivalence(next_result is Relation.CROSS,
                       result is Relation.CROSS
                       or relation_with_first_segment is Relation.CROSS
                       or (bool(rest_multisegment.segments)
                           and result is Relation.DISJOINT
                           or result is Relation.TOUCH)
                       and (relation_with_first_segment is Relation.ENCLOSED
                            or relation_with_first_segment is Relation.WITHIN)
                       or (result is Relation.ENCLOSED
                           or result is Relation.WITHIN)
                       and (relation_with_first_segment is Relation.DISJOINT
                            or relation_with_first_segment is Relation.TOUCH))
    assert equivalence(next_result is Relation.COMPONENT,
                       (not rest_multisegment.segments
                        or result is Relation.COMPONENT)
                       and relation_with_first_segment is Relation.COMPONENT)
    assert equivalence(next_result is Relation.ENCLOSED,
                       not rest_multisegment.segments
                       and relation_with_first_segment is Relation.ENCLOSED
                       or (result is Relation.COMPONENT
                           or result is Relation.ENCLOSED)
                       and (relation_with_first_segment is Relation.ENCLOSED
                            or relation_with_first_segment is Relation.WITHIN)
                       or (result is Relation.ENCLOSED
                           or result is Relation.WITHIN)
                       and relation_with_first_segment is Relation.COMPONENT
                       or result is Relation.WITHIN
                       and relation_with_first_segment is Relation.ENCLOSED)
    assert equivalence(next_result is Relation.WITHIN,
                       (not rest_multisegment.segments
                        or result is Relation.WITHIN)
                       and relation_with_first_segment is Relation.WITHIN)
def test_self(multipolygon: Multipolygon) -> None:
    has_holes = any(polygon.holes for polygon in multipolygon.polygons)
    assert equivalence(
        all(
            region_in_multipolygon(polygon.border, multipolygon) is
            Relation.COMPONENT
            for polygon in multipolygon.polygons), not has_holes)
    assert equivalence(
        any(
            region_in_multipolygon(polygon.border, multipolygon) is
            Relation.OVERLAP for polygon in multipolygon.polygons), has_holes)
def test_relations(polygons_pair: Tuple[Polygon, Polygon]) -> None:
    left, right = polygons_pair

    result = polygon_in_polygon(left, right)

    complement = polygon_in_polygon(right, left)
    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_relations(contours_pair: Tuple[Contour, Contour]) -> None:
    left_contour, right_contour = contours_pair

    result = contour_in_contour(left_contour, right_contour)

    complement = contour_in_contour(right_contour, left_contour)
    assert equivalence(result is complement, result
                       in SYMMETRIC_SAME_LINEAR_RELATIONS)
    assert equivalence(
        result is not complement, result.complement is complement
        and result in ASYMMETRIC_LINEAR_RELATIONS
        and complement in ASYMMETRIC_LINEAR_RELATIONS)
def test_relations(segments_pair: Tuple[Segment, Segment]) -> None:
    left_segment, right_segment = segments_pair

    result = segment_in_segment(left_segment, right_segment)

    complement = segment_in_segment(right_segment, left_segment)
    assert equivalence(result is complement, result
                       in SYMMETRIC_SAME_LINEAR_RELATIONS)
    assert equivalence(
        result is not complement, result.complement is complement
        and result in ASYMMETRIC_LINEAR_RELATIONS
        and complement in ASYMMETRIC_LINEAR_RELATIONS)
示例#13
0
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_commutativity(context_with_segments_pair
                       : Tuple[Context, Tuple[Segment, Segment]]) -> None:
    context, (first, second) = context_with_segments_pair

    result = context.segments_relation(first, second)

    complement = context.segments_relation(second, first)
    assert equivalence(result is complement,
                       result in SYMMETRIC_LINEAR_RELATIONS)
    assert equivalence(result is not complement,
                       result.complement is complement
                       and result in ASYMMETRIC_LINEAR_RELATIONS
                       and complement in ASYMMETRIC_LINEAR_RELATIONS)
示例#15
0
def test_relations(multiregions_pair: Tuple[Multiregion, Multiregion]) -> None:
    left_multiregion, right_multiregion = multiregions_pair

    result = multiregion_in_multiregion(left_multiregion, right_multiregion)

    complement = multiregion_in_multiregion(right_multiregion,
                                            left_multiregion)
    assert equivalence(result is complement, result
                       in SYMMETRIC_COMPOUND_RELATIONS)
    assert equivalence(
        result is not complement, result.complement is complement
        and result in ASYMMETRIC_MULTIPART_COMPOUND_RELATIONS
        and complement in ASYMMETRIC_MULTIPART_COMPOUND_RELATIONS)
示例#16
0
def test_properties(multisegment_with_segment: MultisegmentWithSegment
                    ) -> None:
    multisegment, segment = multisegment_with_segment

    result = unite_segment_with_multisegment(segment, multisegment)

    relation = segment_in_multisegment(segment, multisegment)
    assert equivalence(is_multisegment(result),
                       relation in (Relation.DISJOINT, Relation.TOUCH,
                                    Relation.CROSS, Relation.OVERLAP,
                                    Relation.COMPONENT))
    assert equivalence(is_segment(result),
                       relation is Relation.EQUAL
                       or relation is Relation.COMPOSITE)
示例#17
0
def test_connection_with_contains(
        compound_with_point: Tuple[Compound, Point]) -> None:
    compound, point = compound_with_point

    result = compound.distance_to(point)

    assert equivalence(not result, point in compound)
示例#18
0
def test_basic(first_pair: BoundPortedBeachLineKeysPair,
               second_pair: BoundPortedBeachLineKeysPair) -> None:
    first_bound, first_ported = first_pair
    second_bound, second_ported = second_pair

    assert equivalence(first_bound < second_bound,
                       first_ported < second_ported)
示例#19
0
def test_basic(first_pair: BoundPortedSetsPair,
               second_pair: BoundPortedSetsPair) -> None:
    first_bound, first_ported = first_pair
    second_bound, second_ported = second_pair

    assert equivalence(first_bound <= second_bound,
                       first_ported <= second_ported)
示例#20
0
def test_basic(first_pair: BoundPortedCharClassBuildersPair,
               second_pair: BoundPortedCharClassBuildersPair) -> None:
    first_bound, first_ported = first_pair
    second_bound, second_ported = second_pair

    assert equivalence(first_bound == second_bound,
                       first_ported == second_ported)
示例#21
0
def test_basic(pair: BoundPortedSourceCategoriesPair,
               geometry_categories: BoundPortedGeometryCategoriesPair) -> None:
    bound, ported = pair
    bound_geometry_category, ported_geometry_category = geometry_categories

    assert equivalence(bound.belongs(bound_geometry_category),
                       ported.belongs(ported_geometry_category))
示例#22
0
def test_basic(first_edges_pair: BoundPortedEdgesPair,
               second_edges_pair: BoundPortedEdgesPair) -> None:
    first_bound, first_ported = first_edges_pair
    second_bound, second_ported = second_edges_pair

    assert equivalence(first_bound == second_bound,
                       first_ported == second_ported)
示例#23
0
def test_defaults(pair: AlternativeNativeSetsPair) -> None:
    alternative, native = pair

    alternative_result, native_result = alternative.pop(), native.pop()

    assert equivalence(alternative_result not in alternative, native_result
                       not in native)
示例#24
0
def test_basic(first_pair: BoundPortedBoxesPair,
               second_pair: BoundPortedBoxesPair) -> None:
    first_bound, first_ported = first_pair
    second_bound, second_ported = second_pair

    assert equivalence(first_bound.inside_of(second_bound),
                       first_ported.inside_of(second_ported))
示例#25
0
def test_basic(first_pair: BoundPortedRingManagersPair,
               second_pair: BoundPortedRingManagersPair) -> None:
    first_bound, first_ported = first_pair
    second_bound, second_ported = second_pair

    assert equivalence(first_bound == second_bound,
                       first_ported == second_ported)
示例#26
0
def test_basic(first_trapezoids_pair: BoundPortedTrapezoidsPair,
               second_trapezoids_pair: BoundPortedTrapezoidsPair) -> None:
    first_bound, first_ported = first_trapezoids_pair
    second_bound, second_ported = second_trapezoids_pair

    assert equivalence(first_bound == second_bound,
                       first_ported == second_ported)
示例#27
0
def test_connection_with_disjoint(
        compounds_pair: Tuple[Compound, Compound]) -> None:
    left_compound, right_compound = compounds_pair

    result = left_compound.distance_to(right_compound)

    assert equivalence(bool(result), left_compound.disjoint(right_compound))
示例#28
0
def test_basic(first_pair: BoundPortedBoundsPair,
               second_pair: BoundPortedBoundsPair) -> None:
    first_bound, first_ported = first_pair
    second_bound, second_ported = second_pair

    assert equivalence(bound(first_bound, second_bound),
                       ported(first_ported, second_ported))
示例#29
0
def test_basic(first_pair: AlternativeNativeIntsPair,
               second_pair: AlternativeNativeIntsPair) -> None:
    alternative_first, native_first = first_pair
    alternative_second, native_second = second_pair

    assert equivalence(alternative_first == alternative_second,
                       native_first == native_second)
def test_commutative_case(segments_pair: SegmentsPair) -> None:
    first, second = segments_pair

    result = subtract_segments(first, second)

    assert equivalence(result == subtract_segments(second, first),
                       first == second)