diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-02-13 12:02:19 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2015-02-19 10:49:03 +0000 |
commit | 373ce8878321aa561b55131bada78ad4a2ce8427 (patch) | |
tree | 0b64429ea79163f1f13b4073bbe60040047d0540 /src | |
parent | 6f264b755501fd322d1e357187b42120210a7ba3 (diff) |
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 <sean.harmer@kdab.com>
Diffstat (limited to 'src')
35 files changed, 115 insertions, 149 deletions
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 <stdlib.h> -#include <cmath> -#ifdef Q_OS_QNX -#include <math.h> -#endif +#include <qmath.h> + 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 <qmath.h> #include <stdlib.h> -#include <cmath> - -#ifdef Q_OS_QNX -#include <math.h> -#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 <math.h> +#include <qmath.h> 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(); \ } diff --git a/src/qml/jsruntime/qv4dateobject.cpp b/src/qml/jsruntime/qv4dateobject.cpp index c74995faee..28f0f2e044 100644 --- a/src/qml/jsruntime/qv4dateobject.cpp +++ b/src/qml/jsruntime/qv4dateobject.cpp @@ -37,14 +37,10 @@ #include "qv4scopedvalue_p.h" #include "qv4runtime_p.h" -#include <QtCore/qnumeric.h> -#include <QtCore/qmath.h> +#include <QtCore/QDebug> #include <QtCore/QDateTime> #include <QtCore/QStringList> -#include <QtCore/QDebug> -#include <cmath> -#include <qmath.h> -#include <qnumeric.h> + #include <time.h> #include <private/qqmljsengine_p.h> diff --git a/src/qml/jsruntime/qv4errorobject.cpp b/src/qml/jsruntime/qv4errorobject.cpp index be9f1e8df7..119ad93e63 100644 --- a/src/qml/jsruntime/qv4errorobject.cpp +++ b/src/qml/jsruntime/qv4errorobject.cpp @@ -34,14 +34,9 @@ #include "qv4errorobject_p.h" #include "qv4mm_p.h" -#include <QtCore/qnumeric.h> -#include <QtCore/qmath.h> #include <QtCore/QDateTime> #include <QtCore/QStringList> #include <QtCore/QDebug> -#include <cmath> -#include <qmath.h> -#include <qnumeric.h> #include <private/qqmljsengine_p.h> #include <private/qqmljslexer_p.h> diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index 303e654fe3..5be638e909 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -52,7 +52,6 @@ #include "private/qlocale_tools_p.h" #include "private/qqmlbuiltinfunctions_p.h" -#include <QtCore/qmath.h> #include <QtCore/QDebug> #include <algorithm> #include "qv4alloca_p.h" diff --git a/src/qml/jsruntime/qv4mathobject.cpp b/src/qml/jsruntime/qv4mathobject.cpp index 9d2c496bd0..473e05bf88 100644 --- a/src/qml/jsruntime/qv4mathobject.cpp +++ b/src/qml/jsruntime/qv4mathobject.cpp @@ -34,13 +34,13 @@ #include "qv4mathobject_p.h" #include "qv4objectproto_p.h" -#include <cmath> -#include <qmath.h> -#include <qnumeric.h> - #include <QtCore/qdatetime.h> +#include <QtCore/qmath.h> +#include <QtCore/qnumeric.h> #include <QtCore/qthreadstorage.h> +#include <cmath> + using namespace QV4; DEFINE_OBJECT_VTABLE(MathObject); @@ -53,14 +53,14 @@ Heap::MathObject::MathObject(ExecutionEngine *e) Scope scope(e); ScopedObject m(scope, this); - m->defineReadonlyProperty(QStringLiteral("E"), Primitive::fromDouble(::exp(1.0))); - m->defineReadonlyProperty(QStringLiteral("LN2"), Primitive::fromDouble(::log(2.0))); - m->defineReadonlyProperty(QStringLiteral("LN10"), Primitive::fromDouble(::log(10.0))); - m->defineReadonlyProperty(QStringLiteral("LOG2E"), Primitive::fromDouble(1.0/::log(2.0))); - m->defineReadonlyProperty(QStringLiteral("LOG10E"), Primitive::fromDouble(1.0/::log(10.0))); - m->defineReadonlyProperty(QStringLiteral("PI"), Primitive::fromDouble(qt_PI)); - m->defineReadonlyProperty(QStringLiteral("SQRT1_2"), Primitive::fromDouble(::sqrt(0.5))); - m->defineReadonlyProperty(QStringLiteral("SQRT2"), Primitive::fromDouble(::sqrt(2.0))); + m->defineReadonlyProperty(QStringLiteral("E"), Primitive::fromDouble(M_E)); + m->defineReadonlyProperty(QStringLiteral("LN2"), Primitive::fromDouble(M_LN2)); + m->defineReadonlyProperty(QStringLiteral("LN10"), Primitive::fromDouble(M_LN10)); + m->defineReadonlyProperty(QStringLiteral("LOG2E"), Primitive::fromDouble(M_LOG2E)); + m->defineReadonlyProperty(QStringLiteral("LOG10E"), Primitive::fromDouble(M_LOG10E)); + m->defineReadonlyProperty(QStringLiteral("PI"), Primitive::fromDouble(M_PI)); + m->defineReadonlyProperty(QStringLiteral("SQRT1_2"), Primitive::fromDouble(M_SQRT1_2)); + m->defineReadonlyProperty(QStringLiteral("SQRT2"), Primitive::fromDouble(M_SQRT2)); m->defineDefaultProperty(QStringLiteral("abs"), QV4::MathObject::method_abs, 1); m->defineDefaultProperty(QStringLiteral("acos"), QV4::MathObject::method_acos, 1); @@ -117,7 +117,7 @@ ReturnedValue MathObject::method_acos(CallContext *context) if (v > 1) return Encode(qSNaN()); - return Encode(::acos(v)); + return Encode(std::acos(v)); } ReturnedValue MathObject::method_asin(CallContext *context) @@ -126,7 +126,7 @@ ReturnedValue MathObject::method_asin(CallContext *context) if (v > 1) return Encode(qSNaN()); else - return Encode(::asin(v)); + return Encode(std::asin(v)); } ReturnedValue MathObject::method_atan(CallContext *context) @@ -135,7 +135,7 @@ ReturnedValue MathObject::method_atan(CallContext *context) if (v == 0.0) return Encode(v); else - return Encode(::atan(v)); + return Encode(std::atan(v)); } ReturnedValue MathObject::method_atan2(CallContext *context) @@ -148,12 +148,12 @@ ReturnedValue MathObject::method_atan2(CallContext *context) if ((v1 == 0.0) && (v2 == 0.0)) { if ((copySign(1.0, v1) == 1.0) && (copySign(1.0, v2) == -1.0)) { - return Encode(qt_PI); + return Encode(M_PI); } else if ((copySign(1.0, v1) == -1.0) && (copySign(1.0, v2) == -1.0)) { - return Encode(-qt_PI); + return Encode(-M_PI); } } - return Encode(::atan2(v1, v2)); + return Encode(std::atan2(v1, v2)); } ReturnedValue MathObject::method_ceil(CallContext *context) @@ -162,13 +162,13 @@ ReturnedValue MathObject::method_ceil(CallContext *context) if (v < 0.0 && v > -1.0) return Encode(copySign(0, -1.0)); else - return Encode(::ceil(v)); + return Encode(std::ceil(v)); } ReturnedValue MathObject::method_cos(CallContext *context) { double v = context->argc() ? context->args()[0].toNumber() : qSNaN(); - return Encode(::cos(v)); + return Encode(std::cos(v)); } ReturnedValue MathObject::method_exp(CallContext *context) @@ -180,14 +180,14 @@ ReturnedValue MathObject::method_exp(CallContext *context) else return Encode(qInf()); } else { - return Encode(::exp(v)); + return Encode(std::exp(v)); } } ReturnedValue MathObject::method_floor(CallContext *context) { double v = context->argc() ? context->args()[0].toNumber() : qSNaN(); - return Encode(::floor(v)); + return Encode(std::floor(v)); } ReturnedValue MathObject::method_log(CallContext *context) @@ -196,7 +196,7 @@ ReturnedValue MathObject::method_log(CallContext *context) if (v < 0) return Encode(qSNaN()); else - return Encode(::log(v)); + return Encode(std::log(v)); } ReturnedValue MathObject::method_max(CallContext *context) @@ -239,12 +239,12 @@ ReturnedValue MathObject::method_pow(CallContext *context) return Encode(qInf()); } else if ((x == 0) && copySign(1.0, x) == -1.0) { if (y < 0) { - if (::fmod(-y, 2.0) == 1.0) + if (std::fmod(-y, 2.0) == 1.0) return Encode(-qInf()); else return Encode(qInf()); } else if (y > 0) { - if (::fmod(y, 2.0) == 1.0) + if (std::fmod(y, 2.0) == 1.0) return Encode(copySign(0, -1.0)); else return Encode(0); @@ -254,12 +254,12 @@ ReturnedValue MathObject::method_pow(CallContext *context) #ifdef Q_OS_AIX else if (qIsInf(x) && copySign(1.0, x) == -1.0) { if (y > 0) { - if (::fmod(y, 2.0) == 1.0) + if (std::fmod(y, 2.0) == 1.0) return Encode(-qInf()); else return Encode(qInf()); } else if (y < 0) { - if (::fmod(-y, 2.0) == 1.0) + if (std::fmod(-y, 2.0) == 1.0) return Encode(copySign(0, -1.0)); else return Encode(0); @@ -267,7 +267,7 @@ ReturnedValue MathObject::method_pow(CallContext *context) } #endif else { - return Encode(::pow(x, y)); + return Encode(std::pow(x, y)); } // ### return Encode(qSNaN()); @@ -287,20 +287,20 @@ ReturnedValue MathObject::method_random(CallContext *context) ReturnedValue MathObject::method_round(CallContext *context) { double v = context->argc() ? context->args()[0].toNumber() : qSNaN(); - v = copySign(::floor(v + 0.5), v); + v = copySign(std::floor(v + 0.5), v); return Encode(v); } ReturnedValue MathObject::method_sin(CallContext *context) { double v = context->argc() ? context->args()[0].toNumber() : qSNaN(); - return Encode(::sin(v)); + return Encode(std::sin(v)); } ReturnedValue MathObject::method_sqrt(CallContext *context) { double v = context->argc() ? context->args()[0].toNumber() : qSNaN(); - return Encode(::sqrt(v)); + return Encode(std::sqrt(v)); } ReturnedValue MathObject::method_tan(CallContext *context) @@ -309,6 +309,6 @@ ReturnedValue MathObject::method_tan(CallContext *context) if (v == 0.0) return Encode(v); else - return Encode(::tan(v)); + return Encode(std::tan(v)); } diff --git a/src/qml/jsruntime/qv4numberobject.cpp b/src/qml/jsruntime/qv4numberobject.cpp index 4135ab064b..d8c9d89369 100644 --- a/src/qml/jsruntime/qv4numberobject.cpp +++ b/src/qml/jsruntime/qv4numberobject.cpp @@ -139,22 +139,22 @@ ReturnedValue NumberPrototype::method_toString(CallContext *ctx) negative = true; num = -num; } - double frac = num - ::floor(num); + double frac = num - std::floor(num); num = Primitive::toInteger(num); do { - char c = (char)::fmod(num, radix); + char c = (char)std::fmod(num, radix); c = (c < 10) ? (c + '0') : (c - 10 + 'a'); str.prepend(QLatin1Char(c)); - num = ::floor(num / radix); + num = std::floor(num / radix); } while (num != 0); if (frac != 0) { str.append(QLatin1Char('.')); do { frac = frac * radix; - char c = (char)::floor(frac); + char c = (char)std::floor(frac); c = (c < 10) ? (c + '0') : (c - 10 + 'a'); str.append(QLatin1Char(c)); - frac = frac - ::floor(frac); + frac = frac - std::floor(frac); } while (frac != 0); } if (negative) diff --git a/src/qml/jsruntime/qv4objectproto.cpp b/src/qml/jsruntime/qv4objectproto.cpp index a74ebafc8d..9356ea434e 100644 --- a/src/qml/jsruntime/qv4objectproto.cpp +++ b/src/qml/jsruntime/qv4objectproto.cpp @@ -39,8 +39,6 @@ #include "qv4runtime_p.h" #include "qv4objectiterator_p.h" -#include <QtCore/qnumeric.h> -#include <QtCore/qmath.h> #include <QtCore/QDateTime> #include <QtCore/QStringList> diff --git a/src/qml/jsruntime/qv4regexpobject.cpp b/src/qml/jsruntime/qv4regexpobject.cpp index dccd3ee1a8..f6e88e62b7 100644 --- a/src/qml/jsruntime/qv4regexpobject.cpp +++ b/src/qml/jsruntime/qv4regexpobject.cpp @@ -48,7 +48,6 @@ #include <qv4codegen_p.h> #include "private/qlocale_tools_p.h" -#include <QtCore/qmath.h> #include <QtCore/QDebug> #include <QtCore/qregexp.h> #include <cassert> diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index 607a68831f..20707d073b 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -50,14 +50,13 @@ #include <private/qv8engine_p.h> #endif -#include <QtCore/qmath.h> -#include <QtCore/qnumeric.h> #include <QtCore/QDebug> -#include <cstdio> #include <cassert> -#include <typeinfo> +#include <cstdio> #include <stdlib.h> +#include <wtf/MathExtras.h> + #include "../../3rdparty/double-conversion/double-conversion.h" #ifdef QV4_COUNT_RUNTIME_FUNCTIONS diff --git a/src/qml/jsruntime/qv4stringobject.cpp b/src/qml/jsruntime/qv4stringobject.cpp index 82a7080fc1..a589ae94c3 100644 --- a/src/qml/jsruntime/qv4stringobject.cpp +++ b/src/qml/jsruntime/qv4stringobject.cpp @@ -38,15 +38,10 @@ #include "qv4objectproto_p.h" #include "qv4mm_p.h" #include "qv4scopedvalue_p.h" -#include <QtCore/qnumeric.h> -#include <QtCore/qmath.h> + #include <QtCore/QDateTime> -#include <QtCore/QStringList> #include <QtCore/QDebug> -#include <cmath> -#include <qmath.h> -#include <qnumeric.h> -#include <cassert> +#include <QtCore/QStringList> #include <private/qqmljsengine_p.h> #include <private/qqmljslexer_p.h> @@ -55,6 +50,8 @@ #include <qv4jsir_p.h> #include <qv4codegen_p.h> +#include <cassert> + #ifndef Q_OS_WIN # include <time.h> # ifndef Q_OS_VXWORKS diff --git a/src/qml/jsruntime/qv4typedarray.cpp b/src/qml/jsruntime/qv4typedarray.cpp index a590b0df07..429ec96f0b 100644 --- a/src/qml/jsruntime/qv4typedarray.cpp +++ b/src/qml/jsruntime/qv4typedarray.cpp @@ -33,6 +33,8 @@ #include "qv4typedarray_p.h" #include "qv4arraybuffer_p.h" +#include <cmath> + using namespace QV4; DEFINE_OBJECT_VTABLE(TypedArrayCtor); @@ -85,7 +87,7 @@ void UInt8ClampedArrayWrite(ExecutionEngine *e, char *data, int index, const Val data[index] = (unsigned char)(255); return; } - double f = floor(d); + double f = std::floor(d); if (f + 0.5 < d) { data[index] = (unsigned char)(f + 1); return; diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp index 0fcf35a543..d45f3ac19b 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -55,8 +55,6 @@ #include <private/qmetaobject_p.h> #include <QtCore/qdebug.h> -#include <math.h> - Q_DECLARE_METATYPE(QList<int>) Q_DECLARE_METATYPE(QList<qreal>) Q_DECLARE_METATYPE(QList<bool>) diff --git a/src/quick/items/context2d/qquickcontext2d.cpp b/src/quick/items/context2d/qquickcontext2d.cpp index b079a3aca0..4aa3b1c8d0 100644 --- a/src/quick/items/context2d/qquickcontext2d.cpp +++ b/src/quick/items/context2d/qquickcontext2d.cpp @@ -37,7 +37,6 @@ #include <private/qquickcontext2dtexture_p.h> #include <private/qquickitem_p.h> #include <QtQuick/private/qquickshadereffectsource_p.h> -#include <QtGui/qopenglframebufferobject.h> #include <QtQuick/private/qsgcontext_p.h> #include <private/qquicksvgparser_p.h> @@ -45,16 +44,13 @@ #include <private/qquickimage_p_p.h> -#include <QtGui/qguiapplication.h> #include <qqmlinfo.h> -#include <QtCore/qmath.h> #include <private/qv8engine_p.h> #include <qqmlengine.h> #include <private/qv4domerrors_p.h> #include <private/qv4engine_p.h> #include <private/qv4object_p.h> -#include <QtCore/qnumeric.h> #include <private/qquickwindow_p.h> #include <private/qv4value_inl_p.h> @@ -62,11 +58,15 @@ #include <private/qv4objectproto_p.h> #include <private/qv4scopedvalue_p.h> +#include <QtCore/qmath.h> +#include <QtCore/qnumeric.h> +#include <QtCore/QRunnable> +#include <QtGui/qguiapplication.h> +#include <QtGui/qopenglframebufferobject.h> #include <private/qguiapplication_p.h> #include <qpa/qplatformintegration.h> -#include <QtCore/QRunnable> - +#include <cmath> #if defined(Q_OS_QNX) || defined(Q_OS_ANDROID) #include <ctype.h> #endif @@ -113,9 +113,7 @@ QT_BEGIN_NAMESPACE Q_CORE_EXPORT double qstrtod(const char *s00, char const **se, bool *ok); -static const double Q_PI = 3.14159265358979323846; // pi - -#define DEGREES(t) ((t) * 180.0 / Q_PI) +#define DEGREES(t) ((t) * 180.0 / M_PI) #define CHECK_CONTEXT(r) if (!r || !r->d()->context || !r->d()->context->bufferValid()) \ V4THROW_ERROR("Not a Context2D object"); @@ -3662,25 +3660,25 @@ void QQuickContext2D::addArcTo(const QPointF& p1, const QPointF& p2, float radiu QPointF p1p0((p0.x() - p1.x()), (p0.y() - p1.y())); QPointF p1p2((p2.x() - p1.x()), (p2.y() - p1.y())); - float p1p0_length = qSqrt(p1p0.x() * p1p0.x() + p1p0.y() * p1p0.y()); - float p1p2_length = qSqrt(p1p2.x() * p1p2.x() + p1p2.y() * p1p2.y()); + float p1p0_length = std::sqrt(p1p0.x() * p1p0.x() + p1p0.y() * p1p0.y()); + float p1p2_length = std::sqrt(p1p2.x() * p1p2.x() + p1p2.y() * p1p2.y()); double cos_phi = (p1p0.x() * p1p2.x() + p1p0.y() * p1p2.y()) / (p1p0_length * p1p2_length); // The points p0, p1, and p2 are on the same straight line (HTML5, 4.8.11.1.8) // We could have used areCollinear() here, but since we're reusing // the variables computed above later on we keep this logic. - if (qFuzzyCompare(qAbs(cos_phi), 1.0)) { + if (qFuzzyCompare(std::abs(cos_phi), 1.0)) { m_path.lineTo(p1); return; } - float tangent = radius / tan(acos(cos_phi) / 2); + float tangent = radius / std::tan(std::acos(cos_phi) / 2); float factor_p1p0 = tangent / p1p0_length; QPointF t_p1p0((p1.x() + factor_p1p0 * p1p0.x()), (p1.y() + factor_p1p0 * p1p0.y())); QPointF orth_p1p0(p1p0.y(), -p1p0.x()); - float orth_p1p0_length = sqrt(orth_p1p0.x() * orth_p1p0.x() + orth_p1p0.y() * orth_p1p0.y()); + float orth_p1p0_length = std::sqrt(orth_p1p0.x() * orth_p1p0.x() + orth_p1p0.y() * orth_p1p0.y()); float factor_ra = radius / orth_p1p0_length; // angle between orth_p1p0 and p1p2 to get the right vector orthographic to p1p0 @@ -3692,9 +3690,9 @@ void QQuickContext2D::addArcTo(const QPointF& p1, const QPointF& p2, float radiu // calculate angles for addArc orth_p1p0 = QPointF(-orth_p1p0.x(), -orth_p1p0.y()); - float sa = acos(orth_p1p0.x() / orth_p1p0_length); + float sa = std::acos(orth_p1p0.x() / orth_p1p0_length); if (orth_p1p0.y() < 0.f) - sa = 2 * Q_PI - sa; + sa = 2 * M_PI - sa; // anticlockwise logic bool anticlockwise = false; @@ -3702,13 +3700,13 @@ void QQuickContext2D::addArcTo(const QPointF& p1, const QPointF& p2, float radiu float factor_p1p2 = tangent / p1p2_length; QPointF t_p1p2((p1.x() + factor_p1p2 * p1p2.x()), (p1.y() + factor_p1p2 * p1p2.y())); QPointF orth_p1p2((t_p1p2.x() - p.x()), (t_p1p2.y() - p.y())); - float orth_p1p2_length = sqrtf(orth_p1p2.x() * orth_p1p2.x() + orth_p1p2.y() * orth_p1p2.y()); - float ea = acos(orth_p1p2.x() / orth_p1p2_length); + float orth_p1p2_length = std::sqrt(orth_p1p2.x() * orth_p1p2.x() + orth_p1p2.y() * orth_p1p2.y()); + float ea = std::acos(orth_p1p2.x() / orth_p1p2_length); if (orth_p1p2.y() < 0) - ea = 2 * Q_PI - ea; - if ((sa > ea) && ((sa - ea) < Q_PI)) + ea = 2 * M_PI - ea; + if ((sa > ea) && ((sa - ea) < M_PI)) anticlockwise = true; - if ((sa < ea) && ((ea - sa) > Q_PI)) + if ((sa < ea) && ((ea - sa) > M_PI)) anticlockwise = true; arc(p.x(), p.y(), radius, sa, ea, anticlockwise); diff --git a/src/quick/items/qquickanimatedsprite.cpp b/src/quick/items/qquickanimatedsprite.cpp index 7b8b611383..5e653e426c 100644 --- a/src/quick/items/qquickanimatedsprite.cpp +++ b/src/quick/items/qquickanimatedsprite.cpp @@ -592,7 +592,7 @@ void QQuickAnimatedSprite::prepareNextFrame() const int max = lastLoop ? frameCountInRow - 1 : frameCountInRow; frame = qBound(qreal(0.0), frame, qreal(max)); double intpart; - progress = modf(frame,&intpart); + progress = std::modf(frame,&intpart); frameAt = (int)intpart; const int rowIndex = m_spriteEngine->spriteY()/frameHeight(); const int newFrame = rowIndex * nColumns + frameAt; diff --git a/src/quick/items/qquickflickable.cpp b/src/quick/items/qquickflickable.cpp index acdcb6d343..9c03a6db28 100644 --- a/src/quick/items/qquickflickable.cpp +++ b/src/quick/items/qquickflickable.cpp @@ -2105,7 +2105,7 @@ bool QQuickFlickable::xflick() const { Q_D(const QQuickFlickable); if (d->flickableDirection == QQuickFlickable::AutoFlickDirection) - return floor(qAbs(vWidth() - width())); + return std::floor(qAbs(vWidth() - width())); return d->flickableDirection & QQuickFlickable::HorizontalFlick; } @@ -2113,7 +2113,7 @@ bool QQuickFlickable::yflick() const { Q_D(const QQuickFlickable); if (d->flickableDirection == QQuickFlickable::AutoFlickDirection) - return floor(qAbs(vHeight() - height())); + return std::floor(qAbs(vHeight() - height())); return d->flickableDirection & QQuickFlickable::VerticalFlick; } diff --git a/src/quick/items/qquickgridview.cpp b/src/quick/items/qquickgridview.cpp index f3e2e9338f..3cc0a28b87 100644 --- a/src/quick/items/qquickgridview.cpp +++ b/src/quick/items/qquickgridview.cpp @@ -41,9 +41,10 @@ #include <QtGui/qevent.h> #include <QtCore/qmath.h> #include <QtCore/qcoreapplication.h> -#include <math.h> #include "qplatformdefs.h" +#include <cmath> + QT_BEGIN_NAMESPACE #ifndef QML_FLICK_SNAPONETHRESHOLD @@ -349,7 +350,7 @@ qreal QQuickGridViewPrivate::snapPosAt(qreal pos) const pos += highlightStart; pos += rowSize()/2; snapPos = static_cast<FxGridItemSG*>(visibleItems.first())->rowPos() - visibleIndex / columns * rowSize(); - snapPos = pos - fmodf(pos - snapPos, qreal(rowSize())); + snapPos = pos - std::fmod(pos - snapPos, qreal(rowSize())); snapPos -= highlightStart; qreal maxExtent; qreal minExtent; diff --git a/src/quick/items/qquickimage.cpp b/src/quick/items/qquickimage.cpp index 3a3a5654cc..a278fb72a2 100644 --- a/src/quick/items/qquickimage.cpp +++ b/src/quick/items/qquickimage.cpp @@ -39,8 +39,8 @@ #include <QtQuick/private/qsgcontext_p.h> #include <private/qsgadaptationlayer_p.h> +#include <QtCore/qmath.h> #include <QtGui/qpainter.h> -#include <qmath.h> #include <QtCore/QRunnable> QT_BEGIN_NAMESPACE diff --git a/src/quick/items/qquickitemanimation.cpp b/src/quick/items/qquickitemanimation.cpp index 400350f48e..dadef6a0c3 100644 --- a/src/quick/items/qquickitemanimation.cpp +++ b/src/quick/items/qquickitemanimation.cpp @@ -37,12 +37,12 @@ #include <private/qqmlproperty_p.h> #include <private/qquickpath_p.h> +#include "private/qparallelanimationgroupjob_p.h" +#include "private/qsequentialanimationgroupjob_p.h" -#include <QtQml/qqmlinfo.h> #include <QtCore/qmath.h> -#include "private/qsequentialanimationgroupjob_p.h" -#include "private/qparallelanimationgroupjob_p.h" #include <QtGui/qtransform.h> +#include <QtQml/qqmlinfo.h> QT_BEGIN_NAMESPACE @@ -319,7 +319,7 @@ QAbstractAnimationJob* QQuickParentAnimation::transition(QQuickStateActions &act } if (scale != 0) - rotation = atan2(transform.m12()/scale, transform.m11()/scale) * 180/M_PI; + rotation = qAtan2(transform.m12()/scale, transform.m11()/scale) * 180/M_PI; else { qmlInfo(this) << QQuickParentAnimation::tr("Unable to preserve appearance under scale of 0"); ok = false; diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp index fc01417620..ab8e9a7854 100644 --- a/src/quick/items/qquicklistview.cpp +++ b/src/quick/items/qquicklistview.cpp @@ -39,8 +39,8 @@ #include <QtQml/qqmlengine.h> #include <QtQml/qqmlinfo.h> #include <QtGui/qevent.h> -#include <QtCore/qmath.h> #include <QtCore/qcoreapplication.h> +#include <QtCore/qmath.h> #include <private/qquicksmoothedanimation_p_p.h> #include "qplatformdefs.h" diff --git a/src/quick/items/qquickmultipointtoucharea.cpp b/src/quick/items/qquickmultipointtoucharea.cpp index 0d77607168..dcc07300e4 100644 --- a/src/quick/items/qquickmultipointtoucharea.cpp +++ b/src/quick/items/qquickmultipointtoucharea.cpp @@ -38,7 +38,6 @@ #include <private/qguiapplication_p.h> #include <QEvent> #include <QMouseEvent> -#include <math.h> #include <QDebug> #include <qpa/qplatformnativeinterface.h> diff --git a/src/quick/items/qquickpathview.cpp b/src/quick/items/qquickpathview.cpp index 0f3b24bbec..66b0e5c292 100644 --- a/src/quick/items/qquickpathview.cpp +++ b/src/quick/items/qquickpathview.cpp @@ -47,8 +47,8 @@ #include <QtGui/qguiapplication.h> #include <QtGui/qstylehints.h> #include <QtCore/qmath.h> -#include <math.h> +#include <cmath> QT_BEGIN_NAMESPACE @@ -56,12 +56,8 @@ const qreal MinimumFlickVelocity = 75.0; inline qreal qmlMod(qreal x, qreal y) { -#ifdef QT_USE_MATH_H_FLOATS - if (sizeof(qreal) == sizeof(float)) - return fmodf(float(x), float(y)); - else -#endif - return fmod(x, y); + using std::fmod; + return fmod(x, y); } static QQmlOpenMetaObjectType *qPathViewAttachedType = 0; diff --git a/src/quick/items/qquickpincharea.cpp b/src/quick/items/qquickpincharea.cpp index 5c3916cfc4..33f4bade3a 100644 --- a/src/quick/items/qquickpincharea.cpp +++ b/src/quick/items/qquickpincharea.cpp @@ -34,6 +34,7 @@ #include "qquickpincharea_p_p.h" #include "qquickwindow.h" +#include <QtCore/qmath.h> #include <QtGui/qevent.h> #include <QtGui/qguiapplication.h> #include <QtGui/qstylehints.h> @@ -43,7 +44,6 @@ #include <QVariant> #include <float.h> -#include <math.h> QT_BEGIN_NAMESPACE @@ -455,7 +455,7 @@ void QQuickPinchArea::updatePinch() QPointF p2 = touchPoint2.scenePos(); qreal dx = p1.x() - p2.x(); qreal dy = p1.y() - p2.y(); - qreal dist = sqrt(dx*dx + dy*dy); + qreal dist = qSqrt(dx*dx + dy*dy); QPointF sceneCenter = (p1 + p2)/2; qreal angle = QLineF(p1, p2).angle(); if (d->touchPoints.count() == 1) { diff --git a/src/quick/items/qquickpositioners.cpp b/src/quick/items/qquickpositioners.cpp index ce54d4355a..887d317069 100644 --- a/src/quick/items/qquickpositioners.cpp +++ b/src/quick/items/qquickpositioners.cpp @@ -36,7 +36,6 @@ #include <QtQml/qqml.h> #include <QtQml/qqmlinfo.h> -#include <QtCore/qmath.h> #include <QtCore/qcoreapplication.h> #include <QtQuick/private/qquickstate_p.h> diff --git a/src/quick/items/qquickspritesequence.cpp b/src/quick/items/qquickspritesequence.cpp index eb62dfb013..854582e58e 100644 --- a/src/quick/items/qquickspritesequence.cpp +++ b/src/quick/items/qquickspritesequence.cpp @@ -424,7 +424,7 @@ void QQuickSpriteSequence::prepareNextFrame() if (frameDuration > 0) { qreal frame = (time - animT)/(frameDuration / 1000.0); frame = qBound(qreal(0.0), frame, frameCount - qreal(1.0));//Stop at count-1 frames until we have between anim interpolation - progress = modf(frame,&frameAt); + progress = std::modf(frame,&frameAt); } else { m_curFrame++; if (m_curFrame >= frameCount){ diff --git a/src/quick/items/qquickstateoperations.cpp b/src/quick/items/qquickstateoperations.cpp index d4d99bdc5e..579919db27 100644 --- a/src/quick/items/qquickstateoperations.cpp +++ b/src/quick/items/qquickstateoperations.cpp @@ -95,7 +95,7 @@ void QQuickParentChangePrivate::doChange(QQuickItem *targetParent, QQuickItem *s } if (scale != 0) - rotation = atan2(transform.m12()/scale, transform.m11()/scale) * 180/M_PI; + rotation = qAtan2(transform.m12()/scale, transform.m11()/scale) * 180/M_PI; else { qmlInfo(q) << QQuickParentChange::tr("Unable to preserve appearance under scale of 0"); ok = false; diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp index f2f44dc8a0..20416da69a 100644 --- a/src/quick/items/qquicktextedit.cpp +++ b/src/quick/items/qquicktextedit.cpp @@ -40,15 +40,15 @@ #include "qquicktextnode_p.h" #include "qquicktextnodeengine_p.h" #include "qquicktextutil_p.h" -#include <QtQuick/qsgsimplerectnode.h> -#include <QtQml/qqmlinfo.h> +#include <QtCore/qmath.h> #include <QtGui/qguiapplication.h> #include <QtGui/qevent.h> #include <QtGui/qpainter.h> #include <QtGui/qtextobject.h> #include <QtGui/qtexttable.h> -#include <QtCore/qmath.h> +#include <QtQml/qqmlinfo.h> +#include <QtQuick/qsgsimplerectnode.h> #include <private/qqmlglobal_p.h> #include <private/qqmlproperty_p.h> diff --git a/src/quick/items/qquicktextnode.cpp b/src/quick/items/qquicktextnode.cpp index 61eb31dead..010a443d18 100644 --- a/src/quick/items/qquicktextnode.cpp +++ b/src/quick/items/qquicktextnode.cpp @@ -42,7 +42,6 @@ #include <QtQuick/private/qsgcontext_p.h> #include <QtCore/qpoint.h> -#include <qmath.h> #include <qtextdocument.h> #include <qtextlayout.h> #include <qabstracttextdocumentlayout.h> diff --git a/src/quick/items/qquicktranslate.cpp b/src/quick/items/qquicktranslate.cpp index ce66d6490f..2550432bba 100644 --- a/src/quick/items/qquicktranslate.cpp +++ b/src/quick/items/qquicktranslate.cpp @@ -34,8 +34,6 @@ #include "qquicktranslate_p.h" #include "qquickitem_p.h" -#include <QtCore/qmath.h> - QT_BEGIN_NAMESPACE class QQuickTranslatePrivate : public QQuickTransformPrivate diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp index 2bd5b6e5d2..8f94a86026 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp @@ -2971,7 +2971,7 @@ void Renderer::visualizeOverdraw() step += static_cast<float>(M_PI * 2 / 1000.); if (step > M_PI * 2) step = 0; - float angle = 80.0 * sin(step); + float angle = 80.0 * std::sin(step); QMatrix4x4 xrot; xrot.rotate(20, 1, 0, 0); QMatrix4x4 zrot; zrot.rotate(angle, 0, 0, 1); diff --git a/src/quick/util/qquicksmoothedanimation.cpp b/src/quick/util/qquicksmoothedanimation.cpp index a94ddbfada..55011f5a46 100644 --- a/src/quick/util/qquicksmoothedanimation.cpp +++ b/src/quick/util/qquicksmoothedanimation.cpp @@ -37,6 +37,7 @@ #include "qquickanimation_p_p.h" #include "private/qcontinuinganimationgroupjob_p.h" +#include <qmath.h> #include <qqmlproperty.h> #include <private/qqmlproperty_p.h> @@ -44,7 +45,6 @@ #include <QtCore/qdebug.h> -#include <math.h> #define DELAY_STOP_TIMER_INTERVAL 32 @@ -157,7 +157,7 @@ bool QSmoothedAnimation::recalc() return false; } - finalDuration = ceil(tf * 1000.0); + finalDuration = qCeil(tf * 1000.0); if (maximumEasingTime == 0) { a = 0; @@ -191,7 +191,7 @@ bool QSmoothedAnimation::recalc() qreal c2 = 0.5 * vi * tf - s; qreal c3 = -0.25 * vi * vi; - qreal a1 = (-c2 + sqrt(c2 * c2 - 4 * c1 * c3)) / (2. * c1); + qreal a1 = (-c2 + qSqrt(c2 * c2 - 4 * c1 * c3)) / (2. * c1); qreal tp1 = 0.5 * tf - 0.5 * vi / a1; qreal vp1 = a1 * tp1 + vi; diff --git a/src/quick/util/qquickspringanimation.cpp b/src/quick/util/qquickspringanimation.cpp index f4c888b943..f2eee6a802 100644 --- a/src/quick/util/qquickspringanimation.cpp +++ b/src/quick/util/qquickspringanimation.cpp @@ -41,8 +41,7 @@ #include <private/qobject_p.h> -#include <limits.h> -#include <math.h> +#include <cmath> #define DELAY_STOP_TIMER_INTERVAL 32 @@ -282,11 +281,11 @@ void QSpringAnimation::updateCurrentTime(int time) if (diff > 0) { currentValue += moveBy; if (haveModulus) - currentValue = fmod(currentValue, modulus); + currentValue = std::fmod(currentValue, modulus); } else { currentValue -= moveBy; if (haveModulus && currentValue < 0.0) - currentValue = fmod(currentValue, modulus) + modulus; + currentValue = std::fmod(currentValue, modulus) + modulus; } if (lastTime - startTime >= dura) { currentValue = to; diff --git a/src/quick/util/qquicksvgparser.cpp b/src/quick/util/qquicksvgparser.cpp index 73f7170aa1..587f4ac972 100644 --- a/src/quick/util/qquicksvgparser.cpp +++ b/src/quick/util/qquicksvgparser.cpp @@ -159,8 +159,8 @@ static void pathArcSegment(QPainterPath &path, qreal t; qreal thHalf; - sinTh = qSin(xAxisRotation * (Q_PI / 180.0)); - cosTh = qCos(xAxisRotation * (Q_PI / 180.0)); + sinTh = qSin(qDegreesToRadians(xAxisRotation)); + cosTh = qCos(qDegreesToRadians(xAxisRotation)); a00 = cosTh * rx; a01 = -sinTh * ry; @@ -202,8 +202,8 @@ void QQuickSvgParser::pathArc(QPainterPath &path, rx = qAbs(rx); ry = qAbs(ry); - sin_th = qSin(x_axis_rotation * (Q_PI / 180.0)); - cos_th = qCos(x_axis_rotation * (Q_PI / 180.0)); + sin_th = qSin(qDegreesToRadians(x_axis_rotation)); + cos_th = qCos(qDegreesToRadians(x_axis_rotation)); dx = (curx - x) / 2.0; dy = (cury - y) / 2.0; |