Ejemplo n.º 1
0
def test_rectangle_bounding_box():
    r1 = Rectangle(Point(0, 1), Point(2, 3))
    r2 = Rectangle(Point(0, 0), Point(4, 2))

    assert Rectangle.bounding_box([r1,
                                   r2]) == Rectangle(Point(0, 0), Point(4, 3))
Ejemplo n.º 2
0
def test_rectangle_sub():
    r_large = Rectangle.from_list([0, 0, 5, 5])
    r_moved = r_large - Point(1, 2)
    assert r_moved.bounds == (-1, -2, 4, 3)
Ejemplo n.º 3
0
def test_rectangle_add():
    r_large = Rectangle.from_list([0, 0, 5, 5])
    r_moved = r_large + Point(1, 2)
    assert r_moved.bounds == (1, 2, 6, 7)
def test_rectangle_unpacking():
    x, y, w, h = Rectangle(Point(3, 4), Point(5, 7))
    assert x == 3
    assert y == 4
    assert w == 2
    assert h == 3
def test_rectangle_clip(src, clip_by, dst):
    assert Rectangle.from_list(src).clip(
        Rectangle.from_list(clip_by)) == Rectangle.from_list(dst)
def test_rectangle_intersection():
    r_large = Rectangle.from_list([0, 0, 5, 5])
    r_small = Rectangle.from_list([1, 1, 2, 2])
    r_touching = Rectangle.from_list([0, 0, 4, 5])
    r_other = Rectangle.from_list([-3, -3, -1, -1])

    assert Rectangle.intersection([r_other, r_touching]) == Rectangle.empty()

    assert Rectangle.intersection([r_large, r_small]) == r_small
    assert Rectangle.intersection([r_large, r_large]) == r_large

    int1 = Rectangle.intersection(
        [Rectangle.from_list([0, 0, 2, 2]),
         Rectangle.from_list([0, 2, 1, 3])])

    assert int1 == Rectangle.from_list([0, 2, 1, 2])
    assert int1 != Rectangle.empty()

    assert Rectangle.intersection([r_other,
                                   Rectangle.empty()]) == Rectangle.empty()

    with pytest.raises(ValueError):
        Rectangle.intersection([])
    with pytest.raises(ValueError):
        Rectangle.intersection([Rectangle.empty()])