From 373ce8878321aa561b55131bada78ad4a2ce8427 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 13 Feb 2015 12:02:19 +0100 Subject: Cleanup math function includes and usage Use std::math on floats and doubles, and qMath on qreals, and only include the math headers actually needed. Change-Id: I1d511d7b1bac0050eaa947c7baee760b736858bf Reviewed-by: Sean Harmer --- src/particles/qquickangledirection.cpp | 10 ++++------ src/particles/qquickellipseextruder.cpp | 10 +++------- src/particles/qquickfriction.cpp | 12 ++++++------ src/particles/qquickv4particledata.cpp | 2 +- 4 files changed, 14 insertions(+), 20 deletions(-) (limited to 'src/particles') diff --git a/src/particles/qquickangledirection.cpp b/src/particles/qquickangledirection.cpp index 81c92f8bfa..3fa5d21108 100644 --- a/src/particles/qquickangledirection.cpp +++ b/src/particles/qquickangledirection.cpp @@ -33,10 +33,8 @@ #include "qquickangledirection_p.h" #include -#include -#ifdef Q_OS_QNX -#include -#endif +#include + QT_BEGIN_NAMESPACE const qreal CONV = 0.017453292519943295; /*! @@ -106,8 +104,8 @@ const QPointF QQuickAngleDirection::sample(const QPointF &from) QPointF ret; qreal theta = m_angle*CONV - m_angleVariation*CONV + rand()/float(RAND_MAX) * m_angleVariation*CONV * 2; qreal mag = m_magnitude- m_magnitudeVariation + rand()/float(RAND_MAX) * m_magnitudeVariation * 2; - ret.setX(mag * cos(theta)); - ret.setY(mag * sin(theta)); + ret.setX(mag * qCos(theta)); + ret.setY(mag * qSin(theta)); return ret; } diff --git a/src/particles/qquickellipseextruder.cpp b/src/particles/qquickellipseextruder.cpp index cc854b8362..6d4e25197f 100644 --- a/src/particles/qquickellipseextruder.cpp +++ b/src/particles/qquickellipseextruder.cpp @@ -32,12 +32,8 @@ ****************************************************************************/ #include "qquickellipseextruder_p.h" +#include #include -#include - -#ifdef Q_OS_QNX -#include -#endif QT_BEGIN_NAMESPACE /*! @@ -68,8 +64,8 @@ QPointF QQuickEllipseExtruder::extrude(const QRectF & r) { qreal theta = ((qreal)rand()/RAND_MAX) * 6.2831853071795862; qreal mag = m_fill ? ((qreal)rand()/RAND_MAX) : 1; - return QPointF(r.x() + r.width()/2 + mag * (r.width()/2) * cos(theta), - r.y() + r.height()/2 + mag * (r.height()/2) * sin(theta)); + return QPointF(r.x() + r.width()/2 + mag * (r.width()/2) * qCos(theta), + r.y() + r.height()/2 + mag * (r.height()/2) * qSin(theta)); } bool QQuickEllipseExtruder::contains(const QRectF &bounds, const QPointF &point) diff --git a/src/particles/qquickfriction.cpp b/src/particles/qquickfriction.cpp index 84f6d5a80d..8f46575e1c 100644 --- a/src/particles/qquickfriction.cpp +++ b/src/particles/qquickfriction.cpp @@ -32,7 +32,7 @@ ****************************************************************************/ #include "qquickfriction_p.h" -#include +#include QT_BEGIN_NAMESPACE /*! @@ -87,16 +87,16 @@ bool QQuickFrictionAffector::affectParticle(QQuickParticleData *d, qreal dt) if (sign(curVY) != sign(newVY)) newVY = 0; } else { - qreal curMag = sqrt(curVX*curVX + curVY*curVY); + qreal curMag = qSqrt(curVX*curVX + curVY*curVY); if (curMag <= m_threshold + epsilon) return false; - qreal newMag = sqrt(newVX*newVX + newVY*newVY); + qreal newMag = qSqrt(newVX*newVX + newVY*newVY); if (newMag <= m_threshold + epsilon || //went past the threshold, stop there instead sign(curVX) != sign(newVX) || //went so far past maybe it came out the other side! sign(curVY) != sign(newVY)) { - qreal theta = atan2(curVY, curVX); - newVX = m_threshold * cos(theta); - newVY = m_threshold * sin(theta); + qreal theta = qAtan2(curVY, curVX); + newVX = m_threshold * qCos(theta); + newVY = m_threshold * qSin(theta); } } diff --git a/src/particles/qquickv4particledata.cpp b/src/particles/qquickv4particledata.cpp index 08953fd490..fcab455cce 100644 --- a/src/particles/qquickv4particledata.cpp +++ b/src/particles/qquickv4particledata.cpp @@ -338,7 +338,7 @@ static QV4::ReturnedValue particleData_set_ ## NAME (QV4::CallContext *ctx)\ ctx->engine()->throwError(QStringLiteral("Not a valid ParticleData object"));\ \ double d = ctx->argc() ? ctx->args()[0].toNumber() : 0; \ - r->d()->datum->color. VAR = qMin(255, qMax(0, (int)floor(d * 255.0)));\ + r->d()->datum->color. VAR = qMin(255, qMax(0, (int)::floor(d * 255.0)));\ return QV4::Encode::undefined(); \ } -- cgit v1.2.3