From 3a9e135d5561ddbc8b6664f5aadf58fd07b02ec1 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 22 Mar 2017 14:18:02 +0100 Subject: 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 --- examples/widgets/graphicsview/boxes/trackball.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/widgets/graphicsview') diff --git a/examples/widgets/graphicsview/boxes/trackball.cpp b/examples/widgets/graphicsview/boxes/trackball.cpp index c350f6adee..794ce7ac37 100644 --- a/examples/widgets/graphicsview/boxes/trackball.cpp +++ b/examples/widgets/graphicsview/boxes/trackball.cpp @@ -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(); -- cgit v1.2.3