Fix for QQuaternion normalize when length > 1

If the length of the quaternion was slightly larger than 1,
the resulting quaternion would be invalid, causing
getAxisAndAngle() to fail.

Fixes: QTBUG-114313
Pick-to: 6.5 6.6
Change-Id: I8f0616e74590dd6cfee0ce913d214c8e280c4df4
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
This commit is contained in:
Paul Olav Tvete 2023-06-06 13:43:34 +02:00
parent 4c18ebbc1c
commit de9e978532

View File

@ -227,8 +227,6 @@ float QQuaternion::lengthSquared() const
QQuaternion QQuaternion::normalized() const QQuaternion QQuaternion::normalized() const
{ {
const float scale = length(); const float scale = length();
if (qFuzzyCompare(scale, 1.0f))
return *this;
if (qFuzzyIsNull(scale)) if (qFuzzyIsNull(scale))
return QQuaternion(0.0f, 0.0f, 0.0f, 0.0f); return QQuaternion(0.0f, 0.0f, 0.0f, 0.0f);
return *this / scale; return *this / scale;
@ -243,7 +241,7 @@ QQuaternion QQuaternion::normalized() const
void QQuaternion::normalize() void QQuaternion::normalize()
{ {
const float len = length(); const float len = length();
if (qFuzzyCompare(len, 1.0f) || qFuzzyIsNull(len)) if (qFuzzyIsNull(len))
return; return;
xp /= len; xp /= len;