Пример #1
0
 def test_distance(self):
     v1 = Vec(1, 0, 0)
     v2 = Vec(0, 1, 0)
     
     dist = v1.distance(v2)
     correct = sqrt(2)
     self.assertEqual(dist, correct)
Пример #2
0
 def test_coordinate_system_2d(self):
     v = Vec(1, 0)
     mat = v.coordinate_system()
     
     correct = Mat(
         [1, 0],
         [0, 1],
     )
     self.assertEqual(mat, correct)
Пример #3
0
 def test_rotated_around(self):
     vec = Vec(1, 0, 0)
     axis = Vec(0, 0, 1)
     
     res = vec.rotated_around(axis, pi/4)
     self.assertEqual(res, Vec(1, 1, 0).normalized())
     
     axis = Vec(1, 1, 1).normalized()
     res = vec.rotated_around(axis, pi/4)
     
     # for the sake of this comparison, let's lower the equality threshold
     res.set_comparison_accuracy(0.00001)
     self.assertEqual(res, Vec(0.804738, 0.505879, -0.310617))
Пример #4
0
 def test_mat_from_vecs(self):
     v1 = Vec(1, 2, 3)
     v2 = Vec(4, 5, 6)
     
     mat = Mat(v1, v2)
     
     correct = Mat([
         [1, 2, 3],
         [4, 5, 6]
     ])
     self.assertEqual(mat, correct)
     
     v1.z = 39
     v2.y = 25
     correct = Mat([
         [1, 2, 39],
         [4, 25, 6]
     ])
     self.assertEqual(mat, correct)
Пример #5
0
 def test_to_list(self):
     v = Vec(1, 2, 3)
     self.assertEqual(v.to_list(), [1, 2, 3])
Пример #6
0
 def test_normalize_in_place(self):
     vec = Vec(2, 0, 0)
     vec.normalize_in_place()
     self.assertEqual(vec, Vec(1, 0, 0))
Пример #7
0
 def test_normalized(self):
     vec = Vec(2, 0, 0)
     self.assertEqual(vec.normalized(), Vec(1, 0, 0))
     self.assertTrue(isinstance(vec.normalized(), Vec))
Пример #8
0
 def test_magnitude(self):
     vec = Vec(1, 2, 3)
     correct = 3.7416573867739413
     self.assertTrue(abs(vec.magnitude() - correct) < 0.00001)
Пример #9
0
 def test_write_access(self):
     vec = Vec(1, 2, 3)
     vec.y = 49
     self.assertEqual(vec[1], 49)
     self.assertEqual(vec.y, 49)
Пример #10
0
 def test_rotated_2d(self):
     vec = Vec(1, 0)
     res = vec.rotated(pi/2)
     self.assertEqual(res, Vec(0, 1))
     self.assertTrue(isinstance(res, Vec))
Пример #11
0
 def test_scaled_2d(self):
     vec = Vec(4, 1)
     res = vec.scaled(0.5, 2.0)
     self.assertEqual(res, Vec(2, 2))
     self.assertTrue(isinstance(res, Vec))
Пример #12
0
 def test_translated_3d(self):
     vec = Vec(1, 0, 0)
     res = vec.translated(1, 2, 3)
     self.assertEqual(res, Vec(2, 2, 3))
     self.assertTrue(isinstance(res, Vec))
Пример #13
0
 def test_appended(self):
     v = Vec(1, 2, 3)
     v = v.appended(4)
     self.assertEqual(v, Vec(1, 2, 3, 4))