Exemplo n.º 1
0
def test_commutativity(multipolygons_pair: MultipolygonsPair) -> None:
    left_multipolygon, right_multipolygon = multipolygons_pair

    result = symmetric_subtract_multipolygons(left_multipolygon,
                                              right_multipolygon)

    assert result == symmetric_subtract_multipolygons(right_multipolygon,
                                                      left_multipolygon)
Exemplo n.º 2
0
def test_equivalents(multipolygons_pair: MultipolygonsPair) -> None:
    left_multipolygon, right_multipolygon = multipolygons_pair

    result = unite_multipolygons(left_multipolygon, right_multipolygon)

    assert result == symmetric_subtract_multipolygons(
            symmetric_subtract_multipolygons(left_multipolygon,
                                             right_multipolygon),
            intersect_multipolygons(left_multipolygon, right_multipolygon))
Exemplo n.º 3
0
def test_repeated(multipolygons_triplet: MultipolygonsTriplet) -> None:
    (left_multipolygon, mid_multipolygon,
     right_multipolygon) = multipolygons_triplet

    result = symmetric_subtract_multipolygons(
        symmetric_subtract_multipolygons(left_multipolygon, mid_multipolygon),
        symmetric_subtract_multipolygons(mid_multipolygon, right_multipolygon))

    assert are_multipolygons_similar(
        result,
        symmetric_subtract_multipolygons(left_multipolygon,
                                         right_multipolygon))
Exemplo n.º 4
0
def test_associativity(multipolygons_triplet: MultipolygonsTriplet) -> None:
    (left_multipolygon, mid_multipolygon,
     right_multipolygon) = multipolygons_triplet

    result = symmetric_subtract_multipolygons(
        symmetric_subtract_multipolygons(left_multipolygon, mid_multipolygon),
        right_multipolygon)

    assert are_multipolygons_similar(
        result,
        symmetric_subtract_multipolygons(
            left_multipolygon,
            symmetric_subtract_multipolygons(mid_multipolygon,
                                             right_multipolygon)))
Exemplo n.º 5
0
def test_right_neutral_element(
        empty_multipolygon_with_multipolygon: MultipolygonsPair) -> None:
    empty_multipolygon, multipolygon = empty_multipolygon_with_multipolygon

    result = symmetric_subtract_multipolygons(multipolygon, empty_multipolygon)

    assert are_multipolygons_similar(result, multipolygon)
Exemplo n.º 6
0
def test_basic(multipolygons_pair: MultipolygonsPair) -> None:
    left_multipolygon, right_multipolygon = multipolygons_pair

    result = symmetric_subtract_multipolygons(left_multipolygon,
                                              right_multipolygon)

    assert is_multipolygon(result)
Exemplo n.º 7
0
def test_reversals(multipolygons_pair: MultipolygonsPair) -> None:
    left_multipolygon, right_multipolygon = multipolygons_pair

    result = symmetric_subtract_multipolygons(left_multipolygon,
                                              right_multipolygon)

    assert are_multipolygons_similar(
        result,
        symmetric_subtract_multipolygons(
            reverse_multipolygon(left_multipolygon), right_multipolygon))
    assert are_multipolygons_similar(
        result,
        symmetric_subtract_multipolygons(
            left_multipolygon, reverse_multipolygon(right_multipolygon)))
    assert are_multipolygons_similar(
        result,
        symmetric_subtract_multipolygons(
            reverse_multipolygon_borders(left_multipolygon),
            right_multipolygon))
    assert are_multipolygons_similar(
        result,
        symmetric_subtract_multipolygons(
            left_multipolygon,
            reverse_multipolygon_borders(right_multipolygon)))
    assert are_multipolygons_similar(
        result,
        symmetric_subtract_multipolygons(
            reverse_multipolygon_holes(left_multipolygon), right_multipolygon))
    assert are_multipolygons_similar(
        result,
        symmetric_subtract_multipolygons(
            left_multipolygon, reverse_multipolygon_holes(right_multipolygon)))
    assert are_multipolygons_similar(
        result,
        symmetric_subtract_multipolygons(
            reverse_multipolygon_holes_contours(left_multipolygon),
            right_multipolygon))
    assert are_multipolygons_similar(
        result,
        symmetric_subtract_multipolygons(
            left_multipolygon,
            reverse_multipolygon_holes_contours(right_multipolygon)))
Exemplo n.º 8
0
    def __xor__(self, other: Compound[Coordinate]) -> Compound[Coordinate]:
        """
        Returns symmetric difference of the multipolygon
        with the other geometry.

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

        where
            
            .. code-block:: python

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

        >>> from gon.base import EMPTY, Contour, Multipolygon, Point, Polygon
        >>> multipolygon = Multipolygon(
        ...         [Polygon(Contour([Point(0, 0), Point(14, 0), Point(14, 14),
        ...                           Point(0, 14)]),
        ...                  [Contour([Point(2, 2), Point(2, 12),
        ...                            Point(12, 12), Point(12, 2)])]),
        ...          Polygon(Contour([Point(4, 4), Point(10, 4), Point(10, 10),
        ...                           Point(4, 10)]),
        ...                  [Contour([Point(6, 6), Point(6, 8), Point(8, 8),
        ...                            Point(8, 6)])])])
        >>> multipolygon ^ multipolygon is EMPTY
        True
        """
        return (self._unite_with_multipoint(other) if isinstance(
            other, Multipoint) else
                (symmetric_subtract_multipolygon_from_segment(
                    other, self, context=self._context) if isinstance(
                        other, Segment) else
                 (symmetric_subtract_multipolygon_from_multisegment(
                     other, self, context=self._context) if isinstance(
                         other, Linear) else
                  (symmetric_subtract_multipolygon_from_polygon(
                      other, self, context=self._context
                  ) if isinstance(other, Polygon) else
                   (symmetric_subtract_multipolygons(
                       self, other, context=self._context) if isinstance(
                           other, Multipolygon) else NotImplemented)))))
Exemplo n.º 9
0
def test_self_inverse(multipolygon: Multipolygon) -> None:
    result = symmetric_subtract_multipolygons(multipolygon, multipolygon)

    assert not result.polygons