def test_associativity(segments_triplet: SegmentsTriplet) -> None: first, second, third = segments_triplet first_second_union = unite_segments(first, second) second_third_union = unite_segments(second, third) assert (not is_segment(first_second_union) or not is_segment(second_third_union) or are_compounds_similar( unite_segments(first_second_union, third), unite_segments(first, second_third_union)))
def test_difference_operand(segments_triplet: SegmentsTriplet) -> None: first, second, third = segments_triplet first_second_difference = subtract_segments(first, second) first_third_union = unite_segments(first, third) second_third_difference = subtract_segments(second, third) assert (not is_segment(first_second_difference) or not is_segment(first_third_union) or not is_segment(second_third_difference) or are_compounds_similar( unite_segments(first_second_difference, third), subtract_segments(first_third_union, second_third_difference)))
def test_reversals(segments_pair: SegmentsPair) -> None: first, second = segments_pair result = unite_segments(first, second) assert are_compounds_similar( result, unite_segments(first, reverse_segment(second))) assert are_compounds_similar( result, reverse_compound_coordinates( unite_segments(reverse_segment_coordinates(first), reverse_segment_coordinates(second))))
def test_distribution_over_intersection( segments_triplet: SegmentsTriplet) -> None: first, second, third = segments_triplet first_second_union = unite_segments(first, second) first_third_union = unite_segments(first, third) second_third_intersection = intersect_segments(second, third) assert (not is_segment(first_second_union) or not is_segment(first_third_union) or not is_segment(second_third_intersection) or are_compounds_similar( unite_segments(first, second_third_intersection), intersect_segments(first_second_union, first_third_union)))
def test_equivalents(segments_pair: SegmentsPair) -> None: first, second = segments_pair result = symmetric_subtract_segments(first, second) first_second_difference = subtract_segments(first, second) first_second_union = unite_segments(first, second) second_first_difference = subtract_segments(second, first) second_first_intersection = intersect_segments(second, first) assert (not is_segment(second_first_intersection) or not is_segment(first_second_union) or are_compounds_similar( result, subtract_segments(first_second_union, second_first_intersection))) assert (not is_segment(first_second_difference) or not is_segment(second_first_difference) or are_compounds_similar( result, unite_segments(first_second_difference, second_first_difference)))
def test_intersection_subtrahend(segments_triplet: SegmentsTriplet) -> None: first, second, third = segments_triplet first_second_difference = subtract_segments(first, second) first_third_difference = subtract_segments(first, third) second_third_intersection = intersect_segments(second, third) assert (not is_segment(first_second_difference) or not is_segment(first_third_difference) or not is_segment(second_third_intersection) or are_compounds_similar( subtract_segments(first, second_third_intersection), unite_segments(first_second_difference, first_third_difference)))
def __or__(self, other: Compound) -> Compound: """ Returns union of the segment with the other geometry. Time complexity: ``O(1)`` Memory complexity: ``O(1)`` >>> from gon.base import Point, Segment >>> segment = Segment(Point(0, 0), Point(2, 0)) >>> segment | segment == segment True """ context = self._context return (pack_mix(other - self, self, context.empty, context.empty, context.mix_cls) if isinstance(other, Multipoint) else (unite_segments(self, other, context=context) if isinstance( other, Segment) else NotImplemented))
def test_absorption_identity(segments_pair: SegmentsPair) -> None: first, second = segments_pair first_second_union = unite_segments(first, second) assert (not is_segment(first_second_union) or intersect_segments(first, first_second_union) == first)
def test_commutativity(segments_pair: SegmentsPair) -> None: first, second = segments_pair result = unite_segments(first, second) assert are_compounds_similar(result, unite_segments(second, first))
def test_idempotence(segment: Segment) -> None: result = unite_segments(segment, segment) assert result == segment
def test_basic(segments_pair: SegmentsPair) -> None: first, second = segments_pair result = unite_segments(first, second) assert is_homogeneous_non_shaped(result)