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
Change-Id: I8f0616e74590dd6cfee0ce913d214c8e280c4df4
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
(cherry picked from commit de9e978532ef5a3c212426f0e46de9059377968d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Paul Olav Tvete 2023-06-06 13:43:34 +02:00 committed by Qt Cherry-pick Bot
parent 7c32220284
commit f2fc341c54

View File

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