From 24ec3b3e7fa09900d791dcaedb0820a0b1890336 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 6 Mar 2017 17:25:45 +0100 Subject: Prefer qHypot() over sqrt(a sum of squares) It's apt to be more accurate and may even be optimised. Comment on a benchmark where we could use Math.hypot(), but that would break comparison with Qt 5 results. Change-Id: I7c37dd3df82fdef18e7ebb0e1548198afd256faa Reviewed-by: Ulf Hermann --- src/particles/qquicktargetdirection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/particles') diff --git a/src/particles/qquicktargetdirection.cpp b/src/particles/qquicktargetdirection.cpp index 0a0eeb4a24..5aa813be6f 100644 --- a/src/particles/qquicktargetdirection.cpp +++ b/src/particles/qquicktargetdirection.cpp @@ -123,7 +123,7 @@ QPointF QQuickTargetDirection::sample(const QPointF &from) qreal theta = std::atan2(targetY, targetX); qreal mag = m_magnitude + QRandomGenerator::global()->generateDouble() * m_magnitudeVariation * 2 - m_magnitudeVariation; if (m_proportionalMagnitude) - mag *= std::sqrt(targetX * targetX + targetY * targetY); + mag *= qHypot(targetX, targetY); ret.setX(mag * std::cos(theta)); ret.setY(mag * std::sin(theta)); return ret; -- cgit v1.2.3