[Bf-blender-cvs] [be0a68f0d10] master: BLI_math: assert mat3_normalized_to_quat doesn't use a negative matrix

Campbell Barton noreply at git.blender.org
Wed Aug 24 12:46:22 CEST 2022


Commit: be0a68f0d10af97a22972d4d415076aef3b45b57
Author: Campbell Barton
Date:   Wed Aug 24 20:45:10 2022 +1000
Branches: master
https://developer.blender.org/rBbe0a68f0d10af97a22972d4d415076aef3b45b57

BLI_math: assert mat3_normalized_to_quat doesn't use a negative matrix

Add an assert to ensure callers don't pass in negative matrices as the
resulting quaternion is invalid.

===================================================================

M	source/blender/blenlib/intern/math_rotation.c

===================================================================

diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c
index 2cf0e1b41ae..7ecc271fa2a 100644
--- a/source/blender/blenlib/intern/math_rotation.c
+++ b/source/blender/blenlib/intern/math_rotation.c
@@ -272,6 +272,10 @@ void quat_to_mat4(float m[4][4], const float q[4])
 void mat3_normalized_to_quat(float q[4], const float mat[3][3])
 {
   BLI_ASSERT_UNIT_M3(mat);
+  /* Callers must ensure matrices have a positive determinant for valid results, see: T94231. */
+  BLI_assert_msg(!is_negative_m3(mat),
+                 "Matrix 'mat' must not be negative, the resulting quaternion will be invalid. "
+                 "The caller should call negate_m3(mat) if is_negative_m3(mat) returns true.");
 
   /* Check the trace of the matrix - bad precision if close to -1. */
   const float trace = mat[0][0] + mat[1][1] + mat[2][2];



More information about the Bf-blender-cvs mailing list