def test_equivalents(polygons_pair: PolygonsPair) -> None:
    first, second = polygons_pair

    result = unite_polygons(first, second)

    first_second_symmetric_difference = symmetric_subtract_polygons(
        first, second)
    first_second_intersection = intersect_polygons(first, second)
    assert (not is_polygon(first_second_symmetric_difference)
            or not is_polygon(first_second_intersection)
            or result == symmetric_subtract_polygons(
                first_second_symmetric_difference, first_second_intersection))
Esempio n. 2
0
def test_repeated(polygons_triplet: PolygonsTriplet) -> None:
    first, second, third = polygons_triplet

    first_second_symmetric_difference = symmetric_subtract_polygons(
        first, second)
    second_third_symmetric_difference = symmetric_subtract_polygons(
        second, third)
    assert (not is_polygon(first_second_symmetric_difference)
            or not is_polygon(second_third_symmetric_difference)
            or are_compounds_similar(
                symmetric_subtract_polygons(first_second_symmetric_difference,
                                            second_third_symmetric_difference),
                symmetric_subtract_polygons(first, third)))
Esempio n. 3
0
def test_reversals(polygons_pair: PolygonsPair) -> None:
    first, second = polygons_pair

    result = symmetric_subtract_polygons(first, second)

    assert are_compounds_similar(
        result,
        symmetric_subtract_polygons(first, reverse_polygon_border(second)))
    assert are_compounds_similar(
        result,
        symmetric_subtract_polygons(first, reverse_polygon_holes(second)))
    assert are_compounds_similar(
        result,
        symmetric_subtract_polygons(first,
                                    reverse_polygon_holes_contours(second)))
    assert are_compounds_similar(
        result,
        reverse_compound_coordinates(
            symmetric_subtract_polygons(reverse_polygon_coordinates(first),
                                        reverse_polygon_coordinates(second))))
Esempio n. 4
0
    def __xor__(self, other: Compound) -> Compound:
        """
        Returns symmetric difference of the polygon with the other geometry.

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

        where

            .. code-block:: python

                vertices_count = (len(self.border.vertices)
                                  + sum(len(hole.vertices)\
 for hole in self.holes))

        >>> from gon.base import EMPTY, Contour, Point, Polygon
        >>> polygon = Polygon(Contour([Point(0, 0), Point(6, 0), Point(6, 6),
        ...                            Point(0, 6)]),
        ...                   [Contour([Point(2, 2), Point(2, 4), Point(4, 4),
        ...                             Point(4, 2)])])
        >>> polygon ^ polygon is EMPTY
        True
        """
        return (self._unite_with_multipoint(other)
                if isinstance(other, Multipoint)
                else
                (symmetric_subtract_polygon_from_segment(other, self,
                                                         context=self._context)
                 if isinstance(other, Segment)
                 else
                 (symmetric_subtract_polygon_from_multisegment(
                         other, self,
                         context=self._context)
                  if isinstance(other, Linear)
                  else (symmetric_subtract_polygons(self, other,
                                                    context=self._context)
                        if isinstance(other, Polygon)
                        else NotImplemented))))
Esempio n. 5
0
def test_commutativity(polygons_pair: PolygonsPair) -> None:
    first, second = polygons_pair

    result = symmetric_subtract_polygons(first, second)

    assert result == symmetric_subtract_polygons(second, first)
Esempio n. 6
0
def test_self_inverse(polygon: Polygon) -> None:
    result = symmetric_subtract_polygons(polygon, polygon)

    assert is_empty(result)
Esempio n. 7
0
def test_basic(polygons_pair: PolygonsPair) -> None:
    first, second = polygons_pair

    result = symmetric_subtract_polygons(first, second)

    assert is_maybe_shaped(result)