Пример #1
0
def test_cross_product():
    u = Vec3(2, 3, 4)
    v = Vec3(5, 6, 7)
    cross = u.cross(v)
    assert cross.x == -3
    assert cross.y == 6
    assert cross.z == -3
Пример #2
0
def test_element_wise_division():
    v = Vec3(4, 8, 12)
    w = Vec3(2, 4, 3)
    u = v / w
    assert u.x == 2
    assert u.y == 2
    assert u.z == 4
Пример #3
0
def test_inplace_subtract():
    v = Vec3(-3, 11, -5.5)

    v -= Vec3(1, 1, 1)

    assert v.x == -4
    assert v.y == 10
    assert v.z == -6.5
Пример #4
0
def test_inplace_add():
    v = Vec3(-3, 11, -5.5)

    v += Vec3(1, 1, 1)

    assert v.x == -2
    assert v.y == 12
    assert v.z == -4.5
Пример #5
0
def test_element_wise_multiplication():
    a = Vec3(1, 2, 3)
    b = Vec3(4, 5, 7)
    c = a * b

    assert c.x == 4
    assert c.y == 10
    assert c.z == 21
Пример #6
0
def test_subtract():
    a = Vec3(1, 2, 3)
    b = Vec3(3, 2, 1)
    c = a - b
    assert c != a
    assert c != b
    assert c.x == -2
    assert c.y == 0
    assert c.z == 2
Пример #7
0
def test_add():
    a = Vec3(1, 2, 3)
    b = Vec3(3, 2, 1)
    c = a + b
    assert c != a
    assert c != b
    assert c.x == 4
    assert c.y == 4
    assert c.z == 4
Пример #8
0
def test_scaling():
    v = Vec3(2, 5, 7)
    u = v * 5

    assert u.x == 10
    assert u.y == 25
    assert u.z == 35
Пример #9
0
def test_inplace_division():
    v = Vec3(-3, 11, -2)

    v /= 2

    assert v.x == -1.5
    assert v.y == 5.5
    assert v.z == -1
Пример #10
0
def test_inplace_multiplication():
    v = Vec3(-3, 11, -2)

    v *= 2

    assert v.x == -6
    assert v.y == 22
    assert v.z == -4
Пример #11
0
def test_negation():
    v = Vec3(1, 3, 7)
    neg_v = -v
    assert neg_v.x == -1
    assert neg_v.y == -3
    assert neg_v.z == -7

    neg_neg_v = -neg_v
    assert neg_neg_v.x == 1
    assert neg_neg_v.y == 3
    assert neg_neg_v.z == 7
Пример #12
0
def test_subscript():
    v = Vec3(-5, 7, 1)

    assert v[0] == v.x
    assert v[1] == v.y
    assert v[2] == v.z
Пример #13
0
def test_division():
    v = Vec3(3, 6, 9)
    u = v / 3
    assert u.x == 1
    assert u.y == 2
    assert u.z == 3
Пример #14
0
def test_length():
    v = Vec3(1, 1, 1)
    assert v.length() == sqrt(3)
Пример #15
0
def test_unit_vector():
    u = Vec3(2, 4, 7)
    n = u.unit_vector()
    assert abs(n.x - 0.24077171) < 0.0000001
    assert abs(n.y - 0.48154341) < 0.0000001
    assert abs(n.z - 0.84270097) < 0.0000001
Пример #16
0
def test_dot_product():
    v = Vec3(1, 2, 3)
    assert v.dot(v) == (1 * 1) + (2 * 2) + (3 * 3)