Exemple #1
0
def test_commutativity(multisegments_pair: MultisegmentsPair) -> None:
    left_multisegment, right_multisegment = multisegments_pair

    result = complete_intersect_multisegments(left_multisegment,
                                              right_multisegment)

    assert result == complete_intersect_multisegments(right_multisegment,
                                                      left_multisegment)
Exemple #2
0
def test_reversals(multisegments_pair: MultisegmentsPair) -> None:
    left_multisegment, right_multisegment = multisegments_pair

    result = complete_intersect_multisegments(left_multisegment,
                                              right_multisegment)
    assert result == complete_intersect_multisegments(
        reverse_multisegment(left_multisegment), right_multisegment)
    assert result == complete_intersect_multisegments(
        left_multisegment, reverse_multisegment(right_multisegment))
Exemple #3
0
def test_reversals(multisegments_pair: MultisegmentsPair) -> None:
    first, second = multisegments_pair

    result = complete_intersect_multisegments(first, second)
    assert result == complete_intersect_multisegments(
        first, reverse_multisegment(second))
    assert are_compounds_similar(
        result,
        reverse_compound_coordinates(
            complete_intersect_multisegments(
                reverse_multisegment_coordinates(first),
                reverse_multisegment_coordinates(second))))
Exemple #4
0
def test_basic(multisegments_pair: MultisegmentsPair) -> None:
    left_multisegment, right_multisegment = multisegments_pair

    result = complete_intersect_multisegments(left_multisegment,
                                              right_multisegment)

    assert is_linear_mix(result)
Exemple #5
0
def test_connection_with_intersect(
        multisegments_pair: MultisegmentsPair) -> None:
    first, second = multisegments_pair

    result = complete_intersect_multisegments(first, second)

    assert compound_to_linear(result) == intersect_multisegments(first, second)
Exemple #6
0
def test_absorption_identity(multisegments_pair: MultisegmentsPair) -> None:
    first, second = multisegments_pair

    assert are_multisegments_equivalent(
        complete_intersect_multisegments(first,
                                         unite_multisegments(first, second)),
        first)
Exemple #7
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))
Exemple #8
0
def test_right_absorbing_element(
        empty_multisegment_with_multisegment: MultisegmentsPair) -> None:
    empty_multisegment, multisegment = empty_multisegment_with_multisegment

    result = complete_intersect_multisegments(multisegment, empty_multisegment)

    assert is_linear_mix_empty(result)
Exemple #9
0
def test_absorption_identity(multisegments_pair: MultisegmentsPair) -> None:
    left_multisegment, right_multisegment = multisegments_pair

    result = complete_intersect_multisegments(
        left_multisegment,
        unite_multisegments(left_multisegment, right_multisegment))

    assert linear_mix_equivalent_to_multisegment(result, left_multisegment)
Exemple #10
0
def test_connection_with_intersect(
        multisegments_pair: MultisegmentsPair) -> None:
    left_multisegment, right_multisegment = multisegments_pair

    result = complete_intersect_multisegments(left_multisegment,
                                              right_multisegment)

    _, multisegment = result
    assert multisegment == intersect_multisegments(left_multisegment,
                                                   right_multisegment)
Exemple #11
0
def test_properties(multisegments_pair: MultisegmentsPair) -> None:
    left_multisegment, right_multisegment = multisegments_pair

    result = complete_intersect_multisegments(left_multisegment,
                                              right_multisegment)

    result_multipoint, result_multisegment = result
    assert all(
        point_in_multisegment(point, left_multisegment) is
        point_in_multisegment(point, right_multisegment) is Relation.COMPONENT
        for point in result_multipoint.points)
    assert (multisegment_in_multisegment(left_multisegment, right_multisegment)
            is not Relation.TOUCH or bool(result_multipoint))
    assert all(
        all(point in result_multipoint or any(
            point in segment for segment in result_multisegment.segments)
            for right_segment in right_multisegment.segments
            for point in segments_intersections(left_segment, right_segment))
        for left_segment in left_multisegment.segments
        if (segment_in_multisegment(left_segment, right_multisegment) in (
            Relation.TOUCH, Relation.CROSS)))
    assert all(
        segment_in_multisegment(segment, left_multisegment) in (
            Relation.EQUAL, Relation.COMPONENT)
        for segment in result_multisegment.segments)
    assert all(
        segment_in_multisegment(segment, right_multisegment) in (
            Relation.EQUAL, Relation.COMPONENT)
        for segment in result_multisegment.segments)
    assert all(
        to_sorted_segment(left_segment) in result_multisegment.segments or any(
            segment_in_segment(segment, left_segment) is Relation.COMPONENT
            for segment in result_multisegment.segments)
        for left_segment in left_multisegment.segments if any(
            segments_relation(left_segment.start, left_segment.end,
                              right_segment.start, right_segment.end) not in (
                                  Relation.CROSS, Relation.DISJOINT,
                                  Relation.TOUCH)
            for right_segment in right_multisegment.segments))
Exemple #12
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))
Exemple #13
0
def test_properties(multisegments_pair: MultisegmentsPair) -> None:
    first, second = multisegments_pair

    result = complete_intersect_multisegments(first, second)

    result_points, result_segments = pack_non_shaped(result)
    assert all(
        point_in_multisegment(point, first) is point_in_multisegment(
            point, second) is Location.BOUNDARY for point in result_points)
    assert (multisegment_in_multisegment(first, second) is not Relation.TOUCH
            or bool(result_points))
    assert all(
        all(point in result_points or any(
            point == result_segment.start or point == result_segment.end
            for result_segment in result_segments)
            for second_segment in second.segments
            for point in segments_intersections(first_segment, second_segment))
        for first_segment in first.segments
        if (segment_in_multisegment(first_segment, second) in (
            Relation.TOUCH, Relation.CROSS)))
    assert all(
        segment_in_multisegment(result_segment, first) in (Relation.EQUAL,
                                                           Relation.COMPONENT)
        for result_segment in result_segments)
    assert all(
        segment_in_multisegment(result_segment, second) in (Relation.EQUAL,
                                                            Relation.COMPONENT)
        for result_segment in result_segments)
    assert all(
        to_sorted_segment(first_segment) in result_segments or any(
            segment_in_segment(result_segment, first_segment) is
            Relation.COMPONENT for result_segment in result_segments)
        for first_segment in first.segments if any(
            segments_relation(first_segment, second_segment) not in (
                Relation.CROSS, Relation.DISJOINT, Relation.TOUCH)
            for second_segment in second.segments))
Exemple #14
0
def test_commutativity(multisegments_pair: MultisegmentsPair) -> None:
    first, second = multisegments_pair

    result = complete_intersect_multisegments(first, second)

    assert result == complete_intersect_multisegments(second, first)
Exemple #15
0
def test_idempotence(multisegment: Multisegment) -> None:
    result = complete_intersect_multisegments(multisegment, multisegment)

    assert are_compounds_similar(result, multisegment)
Exemple #16
0
def test_basic(multisegments_pair: MultisegmentsPair) -> None:
    first, second = multisegments_pair

    result = complete_intersect_multisegments(first, second)

    assert is_non_shaped(result)
Exemple #17
0
def test_idempotence(multisegment: Multisegment) -> None:
    result = complete_intersect_multisegments(multisegment, multisegment)

    assert linear_mix_equivalent_to_multisegment(result, multisegment)