예제 #1
0
def test_associativity(segments_triplet: SegmentsTriplet) -> None:
    first, second, third = segments_triplet

    first_second_union = unite_segments(first, second)
    second_third_union = unite_segments(second, third)
    assert (not is_segment(first_second_union)
            or not is_segment(second_third_union) or are_compounds_similar(
                unite_segments(first_second_union, third),
                unite_segments(first, second_third_union)))
예제 #2
0
def test_difference_operand(segments_triplet: SegmentsTriplet) -> None:
    first, second, third = segments_triplet

    first_second_difference = subtract_segments(first, second)
    first_third_union = unite_segments(first, third)
    second_third_difference = subtract_segments(second, third)
    assert (not is_segment(first_second_difference)
            or not is_segment(first_third_union)
            or not is_segment(second_third_difference)
            or are_compounds_similar(
                unite_segments(first_second_difference, third),
                subtract_segments(first_third_union, second_third_difference)))
예제 #3
0
def test_reversals(segments_pair: SegmentsPair) -> None:
    first, second = segments_pair

    result = unite_segments(first, second)

    assert are_compounds_similar(
        result, unite_segments(first, reverse_segment(second)))
    assert are_compounds_similar(
        result,
        reverse_compound_coordinates(
            unite_segments(reverse_segment_coordinates(first),
                           reverse_segment_coordinates(second))))
예제 #4
0
def test_distribution_over_intersection(
        segments_triplet: SegmentsTriplet) -> None:
    first, second, third = segments_triplet

    first_second_union = unite_segments(first, second)
    first_third_union = unite_segments(first, third)
    second_third_intersection = intersect_segments(second, third)
    assert (not is_segment(first_second_union)
            or not is_segment(first_third_union)
            or not is_segment(second_third_intersection)
            or are_compounds_similar(
                unite_segments(first, second_third_intersection),
                intersect_segments(first_second_union, first_third_union)))
예제 #5
0
def test_equivalents(segments_pair: SegmentsPair) -> None:
    first, second = segments_pair

    result = symmetric_subtract_segments(first, second)

    first_second_difference = subtract_segments(first, second)
    first_second_union = unite_segments(first, second)
    second_first_difference = subtract_segments(second, first)
    second_first_intersection = intersect_segments(second, first)
    assert (not is_segment(second_first_intersection)
            or not is_segment(first_second_union) or are_compounds_similar(
                result,
                subtract_segments(first_second_union,
                                  second_first_intersection)))
    assert (not is_segment(first_second_difference)
            or not is_segment(second_first_difference)
            or are_compounds_similar(
                result,
                unite_segments(first_second_difference,
                               second_first_difference)))
def test_intersection_subtrahend(segments_triplet: SegmentsTriplet) -> None:
    first, second, third = segments_triplet

    first_second_difference = subtract_segments(first, second)
    first_third_difference = subtract_segments(first, third)
    second_third_intersection = intersect_segments(second, third)
    assert (not is_segment(first_second_difference)
            or not is_segment(first_third_difference)
            or not is_segment(second_third_intersection)
            or are_compounds_similar(
                subtract_segments(first, second_third_intersection),
                unite_segments(first_second_difference,
                               first_third_difference)))
예제 #7
0
    def __or__(self, other: Compound) -> Compound:
        """
        Returns union of the segment with the other geometry.

        Time complexity:
            ``O(1)``
        Memory complexity:
            ``O(1)``

        >>> from gon.base import Point, Segment
        >>> segment = Segment(Point(0, 0), Point(2, 0))
        >>> segment | segment == segment
        True
        """
        context = self._context
        return (pack_mix(other - self, self, context.empty, context.empty,
                         context.mix_cls) if isinstance(other, Multipoint) else
                (unite_segments(self, other, context=context) if isinstance(
                    other, Segment) else NotImplemented))
def test_absorption_identity(segments_pair: SegmentsPair) -> None:
    first, second = segments_pair

    first_second_union = unite_segments(first, second)
    assert (not is_segment(first_second_union)
            or intersect_segments(first, first_second_union) == first)
예제 #9
0
def test_commutativity(segments_pair: SegmentsPair) -> None:
    first, second = segments_pair

    result = unite_segments(first, second)

    assert are_compounds_similar(result, unite_segments(second, first))
예제 #10
0
def test_idempotence(segment: Segment) -> None:
    result = unite_segments(segment, segment)

    assert result == segment
예제 #11
0
def test_basic(segments_pair: SegmentsPair) -> None:
    first, second = segments_pair

    result = unite_segments(first, second)

    assert is_homogeneous_non_shaped(result)