From dfa1c7e554fcc3ddd40780fb8555cdd6e90eaba3 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sat, 21 Nov 2020 16:06:02 +0300 Subject: Split and extend unit tests for vec_roll_to_mat3_normalized. Separate the huge test into huge logical parts and add more cases to check. Also add a utility to check that the matrix is orthogonal, with arbitrary epsilon values and calculations in double. A couple of tests deliberately fail, to be fixed in following commits. Ref D9551 --- source/blender/blenlib/BLI_math_matrix.h | 2 ++ source/blender/blenlib/intern/math_matrix.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) (limited to 'source/blender/blenlib') diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h index 2b0c3db21ee..241acebffa3 100644 --- a/source/blender/blenlib/BLI_math_matrix.h +++ b/source/blender/blenlib/BLI_math_matrix.h @@ -57,6 +57,7 @@ void copy_m4_m4_db(double m1[4][4], const double m2[4][4]); void copy_m3_m3d(float m1[3][3], const double m2[3][3]); /* float->double */ +void copy_m3d_m3(double m1[3][3], const float m2[3][3]); void copy_m4d_m4(double m1[4][4], const float m2[4][4]); void swap_m3m3(float m1[3][3], float m2[3][3]); @@ -291,6 +292,7 @@ float determinant_m3( float a1, float a2, float a3, float b1, float b2, float b3, float c1, float c2, float c3); float determinant_m3_array(const float m[3][3]); float determinant_m4_mat3_array(const float m[4][4]); +double determinant_m3_array_db(const double m[3][3]); float determinant_m4(const float m[4][4]); #define PSEUDOINVERSE_EPSILON 1e-8f diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c index 554506e90e7..b6d80d76be1 100644 --- a/source/blender/blenlib/intern/math_matrix.c +++ b/source/blender/blenlib/intern/math_matrix.c @@ -180,6 +180,21 @@ void copy_m4_m2(float m1[4][4], const float m2[2][2]) m1[3][3] = 1.0f; } +void copy_m3d_m3(double m1[3][3], const float m2[3][3]) +{ + m1[0][0] = m2[0][0]; + m1[0][1] = m2[0][1]; + m1[0][2] = m2[0][2]; + + m1[1][0] = m2[1][0]; + m1[1][1] = m2[1][1]; + m1[1][2] = m2[1][2]; + + m1[2][0] = m2[2][0]; + m1[2][1] = m2[2][1]; + m1[2][2] = m2[2][2]; +} + void copy_m4d_m4(double m1[4][4], const float m2[4][4]) { m1[0][0] = m2[0][0]; @@ -1113,6 +1128,13 @@ float determinant_m4_mat3_array(const float m[4][4]) m[2][0] * (m[0][1] * m[1][2] - m[0][2] * m[1][1])); } +double determinant_m3_array_db(const double m[3][3]) +{ + return (m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1]) - + m[1][0] * (m[0][1] * m[2][2] - m[0][2] * m[2][1]) + + m[2][0] * (m[0][1] * m[1][2] - m[0][2] * m[1][1])); +} + bool invert_m3_ex(float m[3][3], const float epsilon) { float tmp[3][3]; -- cgit v1.2.3