From be0a68f0d10af97a22972d4d415076aef3b45b57 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 24 Aug 2022 20:45:10 +1000 Subject: 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. --- source/blender/blenlib/intern/math_rotation.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source/blender/blenlib/intern') 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]; -- cgit v1.2.3