Ejemplo n.º 1
0
def test_commutativity(segments_pair: SegmentsPair) -> None:
    first, second = segments_pair

    result = symmetric_subtract_segments(first, second)

    assert are_compounds_similar(result,
                                 symmetric_subtract_segments(second, first))
Ejemplo n.º 2
0
def test_reversals(segments_pair: SegmentsPair) -> None:
    first, second = segments_pair

    result = symmetric_subtract_segments(first, second)

    assert are_compounds_similar(
        result, symmetric_subtract_segments(first, reverse_segment(second)))
    assert are_compounds_similar(
        result,
        reverse_compound_coordinates(
            symmetric_subtract_segments(reverse_segment_coordinates(first),
                                        reverse_segment_coordinates(second))))
Ejemplo n.º 3
0
def test_repeated(segments_triplet: SegmentsTriplet) -> None:
    first, second, third = segments_triplet

    first_second_symmetric_difference = symmetric_subtract_segments(
        first, second)
    second_third_symmetric_difference = symmetric_subtract_segments(
        second, third)
    assert (not is_segment(first_second_symmetric_difference)
            or not is_segment(second_third_symmetric_difference)
            or are_compounds_similar(
                symmetric_subtract_segments(first_second_symmetric_difference,
                                            second_third_symmetric_difference),
                symmetric_subtract_segments(first, third)))
Ejemplo n.º 4
0
def test_equivalents(segments_pair: SegmentsPair) -> None:
    first, second = segments_pair

    result = unite_segments(first, second)

    first_second_symmetric_difference = symmetric_subtract_segments(
        first, second)
    first_second_intersection = intersect_segments(first, second)
    assert (not is_segment(first_second_symmetric_difference)
            or not is_segment(first_second_intersection)
            or are_compounds_similar(
                result,
                symmetric_subtract_segments(first_second_symmetric_difference,
                                            first_second_intersection)))
Ejemplo n.º 5
0
    def __xor__(self, other: Compound[Coordinate]) -> Compound[Coordinate]:
        """
        Returns symmetric 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
        """
        context = self._context
        return (pack_mix(other - self, self, context.empty, context.empty,
                         context.mix_cls) if isinstance(other, Multipoint) else
                (symmetric_subtract_segments(self, other, context=context)
                 if isinstance(other, Segment) else NotImplemented))
Ejemplo n.º 6
0
def test_self_inverse(segment: Segment) -> None:
    result = symmetric_subtract_segments(segment, segment)

    assert is_empty(result)
Ejemplo n.º 7
0
def test_basic(segments_pair: SegmentsPair) -> None:
    first, second = segments_pair

    result = symmetric_subtract_segments(first, second)

    assert is_maybe_linear(result)