コード例 #1
0
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)
コード例 #2
0
def test_intersection_minuend(segments_triplet: SegmentsTriplet) -> None:
    first, second, third = segments_triplet

    first_second_intersection = intersect_segments(first, second)
    second_third_difference = subtract_segments(second, third)
    assert (not is_segment(first_second_intersection)
            or not is_segment(second_third_difference)
            or are_compounds_similar(
                subtract_segments(first_second_intersection, third),
                intersect_segments(first, second_third_difference)))
コード例 #3
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)))
コード例 #4
0
def test_reversals(segments_pair: SegmentsPair) -> None:
    first, second = segments_pair

    result = subtract_segments(first, second)

    assert are_compounds_similar(
        result, subtract_segments(reverse_segment(first), second))
    assert result == subtract_segments(first, reverse_segment(second))
    assert are_compounds_similar(
        result,
        reverse_compound_coordinates(
            subtract_segments(reverse_segment_coordinates(first),
                              reverse_segment_coordinates(second))))
コード例 #5
0
def test_difference_subtrahend(segments_triplet: SegmentsTriplet) -> None:
    first, second, third = segments_triplet

    first_second_difference = subtract_segments(first, second)
    first_third_difference = intersect_segments(first, third)
    second_third_difference = subtract_segments(second, third)
    assert (not is_segment(first_second_difference)
            or not is_segment(first_third_difference)
            or not is_segment(second_third_difference)
            or are_compounds_similar(
                subtract_segments(first, second_third_difference),
                unite_segments(first_second_difference,
                               first_third_difference)))
コード例 #6
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)))
コード例 #7
0
    def __sub__(self, other: Compound[Coordinate]) -> Compound[Coordinate]:
        """
        Returns difference of the segment with the other geometry.

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

        >>> from gon.base import EMPTY, Point, Segment
        >>> segment = Segment(Point(0, 0), Point(2, 0))
        >>> segment - segment is EMPTY
        True
        """
        return (self if isinstance(other, Multipoint) else
                (subtract_segments(self, other, context=self._context)
                 if isinstance(other, Segment) else NotImplemented))
コード例 #8
0
def test_basic(segments_pair: SegmentsPair) -> None:
    first, second = segments_pair

    result = subtract_segments(first, second)

    assert is_maybe_linear(result)