Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.2.8, 6.5.1
-
Windows 10 22H2, MSVC 2019 x64
-
de9e97853 (dev), 20da75212 (6.5), 06b5d1d33 (dev), c425e5374 (6.5.2), 5adf5c1fc (6.5), f2fc341c5 (6.6), 615e4d9b0 (6.6), 820eff05f (dev)
Description
getAxisAndAngle() calls std::acos() on the value of scalar() as-is, which would obviously produce NaN if scalar() > 1: https://github.com/qt/qtbase/blob/v6.5.1/src/gui/math3d/qquaternion.cpp#L365-L396
But we would at least expect normalize() to produce a valid value.
#include <QQuaternion> static void report (const QQuaternion& q, const QString& description) { float x, y, z, angle; q.getAxisAndAngle(&x, &y, &z, &angle); qDebug().noquote() << "###" << description; qDebug().noquote() << QString("Axis: (%1, %2, %3)").arg(x).arg(y).arg(z) << '\t' << QString("Angle: %1").arg(angle) << '\n'; } int main() { QQuaternion q; q.setScalar(1.0f + std::numeric_limits<float>::epsilon()); q.setVector(0.0025f, 0.0025f, 0.0025f); report(q, "Original"); report(q.normalized(), "Used QQuaternion::normalized()"); report(q/q.length(), "Forced manual normalization"); report((q * 2).normalized(), "Scaled first, then QQuaternion::normalized()"); }
Output on Qt 5.15.14
### Original Axis: (0.57735, 0.57735, 0.57735) Angle: nan ### Used QQuaternion::normalized() Axis: (0.57735, 0.57735, 0.57735) Angle: 0.497321 ### Forced manual normalization Axis: (0.57735, 0.57735, 0.57735) Angle: 0.494163 ### Scaled first, then QQuaternion::normalized() Axis: (0.57735, 0.57735, 0.57735) Angle: 0.497321
Output on Qt 6.2.8/6.5.1
### Original Axis: (0.57735, 0.57735, 0.57735) Angle: nan ### Used QQuaternion::normalized() Axis: (0.57735, 0.57735, 0.57735) Angle: nan ### Forced manual normalization Axis: (0.57735, 0.57735, 0.57735) Angle: 0.494163 ### Scaled first, then QQuaternion::normalized() Axis: (0.57735, 0.57735, 0.57735) Angle: 0.494163
Attachments
For Gerrit Dashboard: QTBUG-114313 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
484275,1 | Fix for QQuaternion normalize when length > 1 | 6.6 | qt/qtbase | Status: NEW | 0 | 0 |
484280,1 | Fix for QQuaternion normalize when length > 1 | 6.6 | qt/qtbase | Status: NEW | 0 | 0 |
484305,1 | Fix for QQuaternion normalize when length > 1 | 6.6 | qt/qtbase | Status: NEW | 0 | 0 |