Example #1
0
    def __and__(self, other: Compound[Coordinate]) -> Compound[Coordinate]:
        """
        Returns intersection 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 Multisegment, Point, Segment
        >>> multisegment = Multisegment([Segment(Point(0, 0), Point(1, 0)),
        ...                              Segment(Point(0, 1), Point(1, 1))])
        >>> multisegment & multisegment == multisegment
        True
        """
        return (complete_intersect_segment_with_multisegment(
                other, self,
                context=self._context)
                if isinstance(other, Segment)
                else (complete_intersect_multisegments(self, other,
                                                       context=self._context)
                      if isinstance(other, Multisegment)
                      else NotImplemented))
Example #2
0
def test_validity(multisegment_with_segment: MultisegmentWithSegment) -> None:
    multisegment, segment = multisegment_with_segment

    result = complete_intersect_segment_with_multisegment(segment,
                                                          multisegment)

    assert is_non_shaped_valid(result)
Example #3
0
def test_reversals(multisegment_with_segment: MultisegmentWithSegment) -> None:
    multisegment, segment = multisegment_with_segment

    result = complete_intersect_segment_with_multisegment(segment,
                                                          multisegment)

    assert are_compounds_similar(
            result, complete_intersect_segment_with_multisegment(
                    segment, reverse_multisegment(multisegment)))
    assert are_compounds_similar(
            result, complete_intersect_segment_with_multisegment(
                    segment, reverse_multisegment_endpoints(multisegment)))
    assert are_compounds_similar(
            result,
            complete_intersect_segment_with_multisegment(
                reverse_segment(segment),
                multisegment))
    assert are_compounds_similar(
            result, reverse_compound_coordinates(
                    complete_intersect_segment_with_multisegment(
                            reverse_segment_coordinates(segment),
                            reverse_multisegment_coordinates(multisegment))))
Example #4
0
    def __and__(self, other: Compound[Coordinate]) -> Compound[Coordinate]:
        """
        Returns intersection 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 Contour, Multisegment, Point, Segment
        >>> contour = Contour([Point(0, 0), Point(1, 0), Point(0, 1)])
        >>> (contour & contour
        ...  == Multisegment([Segment(Point(0, 0), Point(1, 0)),
        ...                   Segment(Point(1, 0), Point(0, 1)),
        ...                   Segment(Point(0, 1), Point(0, 0))]))
        True
        """
        return (complete_intersect_segment_with_multisegment(
            other, self, context=self._context) if isinstance(other, Segment)
                else (complete_intersect_multisegments(
                    self, other, context=self._context) if isinstance(
                        other, Linear) else NotImplemented))