diff options
author | Campbell Barton <campbell@blender.org> | 2022-08-24 13:45:10 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-08-24 13:45:17 +0300 |
commit | be0a68f0d10af97a22972d4d415076aef3b45b57 (patch) | |
tree | d0cda499ca391c907d03cda8bff55ebf4a6b3cc9 | |
parent | 489aeda034130d84674b82368d083ad9ab87fa0a (diff) |
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.
-rw-r--r-- | source/blender/blenlib/intern/math_rotation.c | 4 |
1 files changed, 4 insertions, 0 deletions
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]; |