Exemplo n.º 1
0
def test_commutativity(multisegments_pair: MultisegmentsPair) -> None:
    left_multisegment, right_multisegment = multisegments_pair

    result = symmetric_subtract_multisegments(left_multisegment,
                                              right_multisegment)

    assert result == symmetric_subtract_multisegments(right_multisegment,
                                                      left_multisegment)
Exemplo n.º 2
0
def test_equivalents(multisegments_pair: MultisegmentsPair) -> None:
    left_multisegment, right_multisegment = multisegments_pair

    result = unite_multisegments(left_multisegment, right_multisegment)

    assert result == symmetric_subtract_multisegments(
        symmetric_subtract_multisegments(left_multisegment,
                                         right_multisegment),
        intersect_multisegments(left_multisegment, right_multisegment))
Exemplo n.º 3
0
def test_repeated(multisegments_triplet: MultisegmentsTriplet) -> None:
    (left_multisegment, mid_multisegment,
     right_multisegment) = multisegments_triplet

    result = symmetric_subtract_multisegments(
        symmetric_subtract_multisegments(left_multisegment, mid_multisegment),
        symmetric_subtract_multisegments(mid_multisegment, right_multisegment))

    assert are_multisegments_equivalent(
        result,
        symmetric_subtract_multisegments(left_multisegment,
                                         right_multisegment))
def test_equivalents(multisegments_pair: MultisegmentsPair) -> None:
    first, second = multisegments_pair

    result = unite_multisegments(first, second)

    first_second_symmetric_difference = symmetric_subtract_multisegments(
        first, second)
    first_second_intersection = intersect_multisegments(first, second)
    assert (not is_multisegment(first_second_symmetric_difference)
            or not is_multisegment(first_second_intersection)
            or result == symmetric_subtract_multisegments(
                first_second_symmetric_difference, first_second_intersection))
def test_reversals(multisegments_pair: MultisegmentsPair) -> None:
    first, second = multisegments_pair

    result = symmetric_subtract_multisegments(first, second)

    assert are_compounds_similar(
        result,
        symmetric_subtract_multisegments(first, reverse_multisegment(second)))
    assert are_compounds_similar(
        result,
        reverse_compound_coordinates(
            symmetric_subtract_multisegments(
                reverse_multisegment_coordinates(first),
                reverse_multisegment_coordinates(second))))
def test_repeated(multisegments_triplet: MultisegmentsTriplet) -> None:
    first, second, third = multisegments_triplet

    first_second_symmetric_difference = symmetric_subtract_multisegments(
        first, second)
    second_third_symmetric_difference = symmetric_subtract_multisegments(
        second, third)
    assert (not is_multisegment(first_second_symmetric_difference)
            or not is_multisegment(second_third_symmetric_difference)
            or are_multisegments_equivalent(
                symmetric_subtract_multisegments(
                    first_second_symmetric_difference,
                    second_third_symmetric_difference),
                symmetric_subtract_multisegments(first, third)))
Exemplo n.º 7
0
def test_reversals(multisegments_pair: MultisegmentsPair) -> None:
    left_multisegment, right_multisegment = multisegments_pair

    result = symmetric_subtract_multisegments(left_multisegment,
                                              right_multisegment)

    assert are_multisegments_similar(
        result,
        symmetric_subtract_multisegments(
            reverse_multisegment(left_multisegment), right_multisegment))
    assert are_multisegments_similar(
        result,
        symmetric_subtract_multisegments(
            left_multisegment, reverse_multisegment(right_multisegment)))
Exemplo n.º 8
0
def test_right_neutral_element(
        empty_multisegment_with_multisegment: MultisegmentsPair) -> None:
    empty_multisegment, multisegment = empty_multisegment_with_multisegment

    result = symmetric_subtract_multisegments(multisegment, empty_multisegment)

    assert are_multisegments_similar(result, multisegment)
Exemplo n.º 9
0
def test_basic(multisegments_pair: MultisegmentsPair) -> None:
    left_multisegment, right_multisegment = multisegments_pair

    result = symmetric_subtract_multisegments(left_multisegment,
                                              right_multisegment)

    assert is_multisegment(result)
Exemplo n.º 10
0
    def __xor__(self, other: Compound[Coordinate]) -> Compound[Coordinate]:
        """
        Returns symmetric difference of the multisegment
        with the other geometry.

        Time complexity:
            ``O(segments_count * log segments_count)``
        Memory complexity:
            ``O(segments_count)``

        where ``segments_count = len(self.segments)``.

        >>> from gon.base import EMPTY, Multisegment, Point, Segment
        >>> multisegment = Multisegment([Segment(Point(0, 0), Point(1, 0)),
        ...                              Segment(Point(0, 1), Point(1, 1))])
        >>> multisegment ^ multisegment is EMPTY
        True
        """
        return (self._unite_with_multipoint(other)
                if isinstance(other, Multipoint)
                else
                (symmetric_subtract_multisegment_from_segment(
                        other, self,
                        context=self._context)
                 if isinstance(other, Segment)
                 else (symmetric_subtract_multisegments(self, other,
                                                        context=self._context)
                       if isinstance(other, Multisegment)
                       else NotImplemented)))
Exemplo n.º 11
0
    def __xor__(self, other: Compound[Coordinate]) -> Compound[Coordinate]:
        """
        Returns symmetric difference of the contour with the other geometry.

        Time complexity:
            ``O(vertices_count * log vertices_count)``
        Memory complexity:
            ``O(vertices_count)``

        where ``vertices_count = len(self.vertices)``.

        >>> from gon.base import EMPTY, Contour, Point
        >>> contour = Contour([Point(0, 0), Point(1, 0), Point(0, 1)])
        >>> contour ^ contour is EMPTY
        True
        """
        return (self._unite_with_multipoint(other) if isinstance(
            other, Multipoint) else
                (symmetric_subtract_multisegment_from_segment(
                    other, self, context=self._context) if isinstance(
                        other, Segment) else (symmetric_subtract_multisegments(
                            self, other, context=self._context) if isinstance(
                                other, Linear) else NotImplemented)))
def test_commutativity(multisegments_pair: MultisegmentsPair) -> None:
    first, second = multisegments_pair

    result = symmetric_subtract_multisegments(first, second)

    assert result == symmetric_subtract_multisegments(second, first)
def test_self_inverse(multisegment: Multisegment) -> None:
    result = symmetric_subtract_multisegments(multisegment, multisegment)

    assert is_empty(result)
def test_basic(multisegments_pair: MultisegmentsPair) -> None:
    first, second = multisegments_pair

    result = symmetric_subtract_multisegments(first, second)

    assert is_maybe_linear(result)