diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2014-09-06 16:54:08 +0400 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2014-09-06 16:58:38 +0400 |
commit | e44c49d89d67038657cdcbd373e64b9a17b6c993 (patch) | |
tree | 1a4d64bdbaca13948bb5927dd83c5477638aa55a /tests | |
parent | f670a8aeaa9ac63f3245bed1ba9bd84c0b575aa3 (diff) |
Py Mathutils: add `invert_safe()` and `inverted_safe()` to `Matrix`.
Those two mimic our BLI invert_m4_m4_safe - they add a small offset to diagonal values,
in case org matrix is degenerated, and if still non-invertible, return identity matrix.
Org patch by me, final enhanced version by ideasman42, many thanks!
Diffstat (limited to 'tests')
-rw-r--r-- | tests/python/bl_pyapi_mathutils.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/python/bl_pyapi_mathutils.py b/tests/python/bl_pyapi_mathutils.py index 7354f559b95..85232e465d7 100644 --- a/tests/python/bl_pyapi_mathutils.py +++ b/tests/python/bl_pyapi_mathutils.py @@ -162,6 +162,29 @@ class MatrixTesting(unittest.TestCase): self.assertEqual(mat.inverted(), inv_mat) + def test_matrix_inverse_safe(self): + mat = Matrix(((1, 4, 0, -1), + (2, -1, 0, -2), + (0, 3, 0, 3), + (-2, 9, 0, 0))) + + # Warning, if we change epsilon in py api we have to update this!!! + epsilon = 1e-8 + inv_mat_safe = mat.copy() + inv_mat_safe[0][0] += epsilon + inv_mat_safe[1][1] += epsilon + inv_mat_safe[2][2] += epsilon + inv_mat_safe[3][3] += epsilon + inv_mat_safe.invert() + ''' + inv_mat_safe = Matrix(((1.0, -0.5, 0.0, -0.5), + (0.222222, -0.111111, -0.0, 0.0), + (-333333344.0, 316666656.0, 100000000.0, 150000000.0), + (0.888888, -0.9444444, 0.0, -0.5))) + ''' + + self.assertEqual(mat.inverted_safe(), inv_mat_safe) + def test_matrix_mult(self): mat = Matrix(((1, 4, 0, -1), (2, -1, 2, -2), |