Exploit QVector3D::length() instead of duplicating its work

Calling the class-method dotProduct(x, x) in order to then take its
square root is a clumsy way to obfuscate x.length() - and lacks its
efforts (clumsy though they are) to limit rounding issues.

Change-Id: I1dc1f38764651bc70c0620e286cb5625f505ddbf
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Edward Welbourne 2017-03-22 14:18:02 +01:00
parent fcb423d1f2
commit 3a9e135d55

View File

@ -126,7 +126,7 @@ void TrackBall::move(const QPointF& p, const QQuaternion &transformation)
currentPos3D.normalize();
m_axis = QVector3D::crossProduct(lastPos3D, currentPos3D);
float angle = qRadiansToDegrees(std::asin(std::sqrt(QVector3D::dotProduct(m_axis, m_axis))));
float angle = qRadiansToDegrees(std::asin(m_axis.length()));
m_angularVelocity = angle / msecs;
m_axis.normalize();