Example #1
0
def test_Rect_as_np():
    for i in range(1000):
        args = np.random.uniform(-100, 100, 4)
        r = Rect(*args)
        assert [
            min(args[[0, 2]]),
            min(args[[1, 3]]),
            max(args[[0, 2]]),
            max(args[[1, 3]])
        ] == approx(r.as_np())
Example #2
0
def test_Rect_unpack1():
    for i in range(1000):
        args = np.random.uniform(-100, 100, 4)
        r = Rect(*args)
        x1, y1, x2, y2 = r
        assert min(args[[0, 2]]) == approx(x1)
        assert min(args[[1, 3]]) == approx(y1)
        assert max(args[[0, 2]]) == approx(x2)
        assert max(args[[1, 3]]) == approx(y2)
Example #3
0
def test_Rect_unpack2():
    def foo(**kwargs):
        return kwargs

    for i in range(1000):
        args = np.random.uniform(-100, 100, 4)
        r = Rect(*args)
        d = foo(**r)
        assert min(args[[0, 2]]) == approx(d['x1'])
        assert min(args[[1, 3]]) == approx(d['y1'])
        assert max(args[[0, 2]]) == approx(d['x2'])
        assert max(args[[1, 3]]) == approx(d['y2'])
Example #4
0
def test_Rect_is_null():
    r = Rect.null()
    assert r.is_null()
Example #5
0
def test_Rect_area():
    for i in range(1000):
        args = np.random.uniform(-100, 100, 4)
        r = Rect(*args)
        assert r.area() >= 0
Example #6
0
def test_Rect_perimeter():
    for i in range(1000):
        args = np.random.uniform(-100, 100, 4)
        r = Rect(*args)
        assert r.perimeter() >= 0
Example #7
0
def test_Rect_union2():
    r1 = Rect(0, 0, 3, 3)
    assert r1 + (-1, -3) == Rect(-1, -3, 3, 3)
Example #8
0
def test_Rect_init3():
    for i in range(1000):
        args1 = np.random.uniform(-100, 100, 4)
        r = Rect(args1)
        assert r is not None
Example #9
0
def test_Rect_copy():
    for i in range(1000):
        args = np.random.uniform(-100, 100, 4)
        r = Rect(*args)
        r2 = r.copy()
        assert r == r2
Example #10
0
def test_Rect_intersect5():
    r = Rect(1, 1, 3, 3)
    point = r.intersect((0, 2), (10, 2))
    assert point == (1, 2)
Example #11
0
def test_Rect_intersect3():
    r1 = Rect(0, 0, 3, 3)
    r2 = Rect(-1, -3, 2, 2)
    assert r1 * r2 == Rect(0, 0, 2, 2)
Example #12
0
def test_Rect_intersect2():
    r1 = Rect(0, 0, 3, 3)
    r2 = Rect(-1, -3, -2, -3)
    assert r1.intersect(r2).is_null()
Example #13
0
def test_Rect_intersect1():
    r1 = Rect(0, 0, 3, 3)
    r2 = Rect(-1, -3, 2, 2)
    assert r1.intersect(r2) == Rect(0, 0, 2, 2)
Example #14
0
def test_Rect_union4():
    r1 = Rect(0, 0, 3, 3)
    assert r1 + [-1, -3] == Rect(-1, -3, 3, 3)
Example #15
0
def test_Rect_union3():
    r1 = Rect(0, 0, 3, 3)
    assert r1 + Vec2(-1, -3) == Rect(-1, -3, 3, 3)
Example #16
0
def test_Rect_intersect6():
    r = Rect(1, 1, 3, 3)
    point = r.intersect((0, 0), (4, 4))
    assert point == (1, 1)
Example #17
0
def test_Rect_intersect7():
    r = Rect(1, 1, 3, 3)
    point = r.intersect((0, 3), (4, 3))
    assert point == (1, 3)
Example #18
0
def test_Rect_init2():
    for i in range(1000):
        args1 = np.random.uniform(-100, 100, 2)
        args2 = np.random.uniform(-100, 100, 2)
        r = Rect(args1, args2)
        assert r is not None
Example #19
0
def test_Rect_intersect9():
    r = Rect(1, 1, 3, 3)
    point = r.intersect(r=((0, 4), (4, 0)))
    assert point == (1, 3)
Example #20
0
def test_rect_is_in():
    r = Rect(0, 0, 3, 2)
    assert r.is_in(Vec2(1, 1))
Example #21
0
def test_Rect_union1():
    r1 = Rect(0, 0, 3, 3)
    r2 = Rect(-1, -3, 2, 2)
    assert r1 + r2 == Rect(-1, -3, 3, 3)