Ejemplo n.º 1
0
def _get_straight_line_intersection(x, other_y1, other_y2, self_y1, self_y2):
    """Get the intersection point of two straight vertical lines."""
    self_y = Interval(left=min(self_y1, self_y2), right=max(self_y1, self_y2))
    other_y = Interval(left=min(other_y1, other_y2),
                       right=max(other_y1, other_y2))

    intersection = self_y.intersection(other_y)
    if intersection.left == intersection.right:
        return Point(x, intersection.left)
    else:
        return LineSegment(Point(x, intersection.left),
                           Point(x, intersection.right))
Ejemplo n.º 2
0
def test_interval_intersection():
    i42 = Interval(42, 1337)
    assert Interval(None, None).intersection(i42) == Interval(None, None)
    assert i42.intersection(Interval(None, None)) == Interval(None, None)
    assert Interval(0, 1).intersection(Interval(1, 3)) == Interval(1, 1)
    assert Interval(0, 1).intersection(Interval(2, 4)) == Interval(None, None)
    assert Interval(0, 1).intersection(Interval(3, 5)) == Interval(None, None)
    assert Interval(0, 1).intersection(Interval(-1, 6)) == Interval(0, 1)
    assert Interval(1, 3).intersection(Interval(2, 4)) == Interval(2, 3)
    assert Interval(1, 3).intersection(Interval(3, 5)) == Interval(3, 3)
    assert Interval(1, 3).intersection(Interval(-1, 6)) == Interval(1, 3)
    assert Interval(2, 4).intersection(Interval(3, 5)) == Interval(3, 4)
    assert Interval(2, 4).intersection(Interval(-1, 6)) == Interval(2, 4)
    assert Interval(3, 5).intersection(Interval(-1, 6)) == Interval(3, 5)
    assert Interval(1, 10).intersection(Interval(-1, 12)) == Interval(1, 10)
Ejemplo n.º 3
0
def test_interval_intersection_non_interval():
    i1 = Interval(0, 10)
    iu1 = IntervalUnion([[0, 1], [2, 3]])
    i1.intersection(iu1) == iu1