Exemplo n.º 1
0
def test_reversals(polygons_pair: PolygonsPair) -> None:
    first, second = polygons_pair

    result = complete_intersect_polygons(first, second)

    assert result == complete_intersect_polygons(
        first, reverse_polygon_border(second))
    assert result == complete_intersect_polygons(first,
                                                 reverse_polygon_holes(second))
    assert result == complete_intersect_polygons(
        first, reverse_polygon_holes_contours(second))
    assert are_compounds_similar(
        result,
        reverse_compound_coordinates(
            complete_intersect_polygons(reverse_polygon_coordinates(first),
                                        reverse_polygon_coordinates(second))))
Exemplo n.º 2
0
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(
        first, complete_intersect_polygons(first_second_union, first)))
Exemplo n.º 3
0
    def __and__(self, other: Compound) -> Compound:
        """
        Returns intersection 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 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 (complete_intersect_segment_with_polygon(other, self,
                                                        context=self._context)
                if isinstance(other, Segment)
                else
                (complete_intersect_multisegment_with_polygon(
                        other, self,
                        context=self._context)
                 if isinstance(other, Linear)
                 else ((complete_intersect_polygons(self, other,
                                                    context=self._context)
                        if self.holes or other.holes
                        else complete_intersect_regions(self.border,
                                                        other.border,
                                                        context=self._context))
                       if isinstance(other, Polygon)
                       else NotImplemented)))
Exemplo n.º 4
0
def test_connection_with_intersect(polygons_pair: PolygonsPair) -> None:
    first, second = polygons_pair

    result = complete_intersect_polygons(first, second)

    assert compound_to_shaped(result) == intersect_polygons(first, second)
Exemplo n.º 5
0
def test_commutativity(polygons_pair: PolygonsPair) -> None:
    first, second = polygons_pair

    result = complete_intersect_polygons(first, second)

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

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

    result = complete_intersect_polygons(first, second)

    assert is_compound(result)