From a47137a2dbee17a58bce71d4761264a157078db6 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 18 Mar 2014 00:37:43 +1100 Subject: Python API: add Vector.orthogonal() method --- source/tests/bl_pyapi_mathutils.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'source/tests') diff --git a/source/tests/bl_pyapi_mathutils.py b/source/tests/bl_pyapi_mathutils.py index bbb4d7f355f..45d68257559 100644 --- a/source/tests/bl_pyapi_mathutils.py +++ b/source/tests/bl_pyapi_mathutils.py @@ -3,6 +3,32 @@ import unittest from test import support from mathutils import Matrix, Vector from mathutils import kdtree +import math + +# keep globals immutable +vector_data = ( + (1.0, 0.0, 0.0), + (0.0, 1.0, 0.0), + (0.0, 0.0, 1.0), + + (1.0, 1.0, 1.0), + + (0.33783, 0.715698, -0.611206), + (-0.944031, -0.326599, -0.045624), + (-0.101074, -0.416443, -0.903503), + (0.799286, 0.49411, -0.341949), + (-0.854645, 0.518036, 0.033936), + (0.42514, -0.437866, -0.792114), + (-0.358948, 0.597046, 0.717377), + (-0.985413,0.144714, 0.089294), + ) + +# get data at different scales +vector_data = sum( + (tuple(tuple(a * scale for a in v) for v in vector_data) + for scale in (s * sign for s in (0.0001, 0.1, -1.0, 10.0, 1000.0, 100000.0) + for sign in (1.0, -1.0))), ()) + ((0.0, 0.0, 0.0),) + class MatrixTesting(unittest.TestCase): def test_matrix_column_access(self): @@ -149,6 +175,17 @@ class MatrixTesting(unittest.TestCase): self.assertEqual(mat * mat, prod_mat) +class VectorTesting(unittest.TestCase): + + def test_orthogonal(self): + + angle_90d = math.pi / 2.0 + for v in vector_data: + v = Vector(v) + if v.length_squared != 0.0: + self.assertAlmostEqual(v.angle(v.orthogonal()), angle_90d) + + class KDTreeTesting(unittest.TestCase): @staticmethod @@ -256,6 +293,7 @@ class KDTreeTesting(unittest.TestCase): def test_main(): try: support.run_unittest(MatrixTesting) + support.run_unittest(VectorTesting) support.run_unittest(KDTreeTesting) except: import traceback -- cgit v1.2.3