Exemplo n.º 1
0
def test_associativity(polygons_triplet: PolygonsTriplet) -> None:
    first, second, third = polygons_triplet

    first_second_union = unite_polygons(first, second)
    second_third_union = unite_polygons(second, third)
    assert (not is_polygon(first_second_union)
            or not is_polygon(second_third_union) or are_compounds_similar(
                unite_polygons(first_second_union, third),
                unite_polygons(first, second_third_union)))
Exemplo n.º 2
0
def test_distribution_over_intersection(
        polygons_triplet: PolygonsTriplet) -> None:
    first, second, third = polygons_triplet

    second_third_intersection = intersect_polygons(second, third)
    first_second_union = unite_polygons(first, second)
    first_third_union = unite_polygons(first, third)
    assert (not is_polygon(second_third_intersection)
            or not is_polygon(first_second_union)
            or not is_polygon(first_third_union) or are_compounds_similar(
                unite_polygons(first, second_third_intersection),
                intersect_polygons(first_second_union, first_third_union)))
Exemplo n.º 3
0
def test_difference_operand(polygons_triplet: PolygonsTriplet) -> None:
    first, second, third = polygons_triplet

    first_second_difference = subtract_polygons(first, second)
    first_third_union = unite_polygons(first, third)
    second_third_difference = subtract_polygons(second, third)
    assert (not is_polygon(first_second_difference)
            or not is_polygon(first_third_union)
            or not is_polygon(second_third_difference)
            or are_compounds_similar(
                unite_polygons(first_second_difference, third),
                subtract_polygons(first_third_union, second_third_difference)))
Exemplo n.º 4
0
def test_reversals(polygons_pair: PolygonsPair) -> None:
    first, second = polygons_pair

    result = unite_polygons(first, second)

    assert are_compounds_similar(
        result, unite_polygons(first, reverse_polygon_border(second)))
    assert are_compounds_similar(
        result, unite_polygons(first, reverse_polygon_holes(second)))
    assert are_compounds_similar(
        result, unite_polygons(first, reverse_polygon_holes_contours(second)))
    assert are_compounds_similar(
        result,
        reverse_compound_coordinates(
            unite_polygons(reverse_polygon_coordinates(first),
                           reverse_polygon_coordinates(second))))
def test_absorption_identity(polygons_pair: PolygonsPair) -> None:
    first, second = polygons_pair

    first_second_union = unite_polygons(first, second)
    assert (not is_polygon(first_second_union)
            or are_compounds_similar(
                    intersect_polygons(first_second_union, first), first))
Exemplo n.º 6
0
def test_equivalents(polygons_pair: PolygonsPair) -> None:
    first, second = polygons_pair

    result = symmetric_subtract_polygons(first, second)

    first_second_difference = subtract_polygons(first, second)
    first_second_union = unite_polygons(first, second)
    second_first_difference = subtract_polygons(second, first)
    second_first_intersection = intersect_polygons(second, first)
    assert (not is_polygon(first_second_difference)
            or not is_polygon(second_first_difference)
            or result == unite_polygons(first_second_difference,
                                        second_first_difference))
    assert (not is_polygon(first_second_union)
            or not is_polygon(second_first_intersection)
            or result == subtract_polygons(first_second_union,
                                           second_first_intersection))
Exemplo n.º 7
0
    def __or__(self, other: Compound) -> Compound:
        """
        Returns union 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 Multipolygon
        >>> from gon.base import 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 == polygon
        True
        """
        return (self._unite_with_multipoint(other)
                if isinstance(other, Multipoint)
                else (unite_segment_with_polygon(other, self,
                                                 context=self._context)
                      if isinstance(other, Segment)
                      else
                      (unite_multisegment_with_polygon(other, self,
                                                       context=self._context)
                       if isinstance(other, Linear)
                       else (unite_polygons(self, other,
                                            context=self._context)
                             if isinstance(other, Polygon)
                             else NotImplemented))))
Exemplo n.º 8
0
def test_commutativity(polygons_pair: PolygonsPair) -> None:
    first, second = polygons_pair

    result = unite_polygons(first, second)

    assert result == unite_polygons(second, first)
Exemplo n.º 9
0
def test_idempotence(polygon: Polygon) -> None:
    result = unite_polygons(polygon, polygon)

    assert are_compounds_similar(result, polygon)
Exemplo n.º 10
0
def test_basic(polygons_pair: PolygonsPair) -> None:
    first, second = polygons_pair

    result = unite_polygons(first, second)

    assert is_shaped(result)