Beispiel #1
0
 def test_rotations(self):
     v = Vec2(1, 0)
     assert simeq(v.rotated_by(pi / 2), Vec2(0, 1))
     assert simeq(v.rotated_axis(pi / 2, Vec2(1, 0)), v)
Beispiel #2
0
 def test_polar(self):
     r, t = Vec2(1, 1).polar()
     assert simeq(r, sqrt(2))
     assert simeq(t, pi / 4)
 def test_middle(self, unitary, null):
     assert simeq(unitary.middle(null), null.middle(unitary))
     assert simeq(unitary.middle(null), unitary / 2)
 def test_scalar_division(self, obj, scalar, smul):
     value = 1 / scalar
     assert simeq(obj / value, smul)
Beispiel #5
0
 def test_pairwise_multiplication(self, a, b, mul):
     assert simeq(a * b, mul)
Beispiel #6
0
 def test_scalar_division(self, obj, scalar, smul):
     value = 1 / scalar
     assert simeq(obj / value, smul)
 def test_clamp_to_value(self, unitary):
     assert simeq(unitary.clamp(2), 2 * unitary)
     assert simeq(unitary.clamp(0.5), 0.5 * unitary)
 def test_inplace_displacement_using_pos(self, mutable):
     newpos = mutable.pos + (10, 5)
     mutable.pos += (10, 5)
     assert simeq(mutable.pos, newpos)
 def test_rotations(self):
     v = Vec(1, 0)
     assert simeq(v.rotate(pi / 2), Vec(0, 1))
     assert simeq(v.rotate_at(pi / 2, Vec(1, 0)), v)
 def test_polar(self):
     r, t = Vec(1, 1).polar()
     assert simeq(r, sqrt(2))
     assert simeq(t, pi / 4)
 def test_vector_norm_defaults_to_euclidean(self, cls, args):
     vec = cls(*(1 for _ in args))
     assert simeq(vec.norm(), sqrt(len(args)))
     assert simeq(abs(vec), sqrt(len(args)))
 def test_angle(self, unitary):
     assert simeq(unitary.angle(unitary), 0)
     assert simeq(unitary.angle(-unitary), pi)
 def test_distance(self, unitary, null):
     assert simeq(unitary.distance(unitary), 0)
     assert simeq(unitary.distance(null), 1)
     assert simeq(unitary.distance(-unitary), 2)
Beispiel #14
0
 def test_rotated_keeps_norm(self, u):
     for t in range(5):
         Z1 = u.norm()
         Z2 = u.rotated_by(6.28 * t / 5).norm()
         assert simeq(Z1, Z2)
 def test_clamp_missing_interval(self, unitary):
     assert simeq(unitary.clamp(2, 3), 2 * unitary)
     assert simeq(unitary.clamp(0.1, 0.5), 0.5 * unitary)
Beispiel #16
0
 def test_displaced(self, obj):
     new = obj.move(10, 5)
     newpos = obj.pos + (10, 5)
     assert simeq(new.pos, newpos)
 def test_direction_is_always_unitary(self):
     u = Direction2(1, 1)
     assert simeq(u.x, 1 / sqrt(2))
     assert simeq(u.y, 1 / sqrt(2))
 def test_default_object_is_on_origin(self, obj):
     assert simeq(obj.pos, (0, 0))
Beispiel #19
0
 def test_pairwise_multiplication(self, a, b, mul):
     assert simeq(a * b, mul)
Beispiel #20
0
 def test_scalar_multiplication(self, obj, scalar, smul):
     assert simeq(obj * scalar, smul)
     assert simeq(scalar * obj, smul)
Beispiel #21
0
 def test_scalar_multiplication(self, obj, scalar, smul):
     assert simeq(obj * scalar, smul)
     assert simeq(scalar * obj, smul)
 def test_spherical_coordinates(self):
     r, phi, theta = Vec3(1, 1, 0).spherical()
     assert simeq(r, sqrt(2))
     assert simeq(phi, pi / 2)
     assert simeq(theta, pi / 4)
 def test_lerp(self, u, v):
     assert simeq(u.lerp(v), v.lerp(u))
     assert simeq(u.middle(v), u.lerp(v))
     assert simeq(u.lerp(v, 0), u)
     assert simeq(u.lerp(v, 1), v)