aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-02-13 12:02:19 +0100
committerSean Harmer <sean.harmer@kdab.com>2015-02-19 10:49:03 +0000
commit373ce8878321aa561b55131bada78ad4a2ce8427 (patch)
tree0b64429ea79163f1f13b4073bbe60040047d0540 /src/quick/items
parent6f264b755501fd322d1e357187b42120210a7ba3 (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/quick/items')
-rw-r--r--src/quick/items/context2d/qquickcontext2d.cpp40
-rw-r--r--src/quick/items/qquickanimatedsprite.cpp2
-rw-r--r--src/quick/items/qquickflickable.cpp4
-rw-r--r--src/quick/items/qquickgridview.cpp5
-rw-r--r--src/quick/items/qquickimage.cpp2
-rw-r--r--src/quick/items/qquickitemanimation.cpp8
-rw-r--r--src/quick/items/qquicklistview.cpp2
-rw-r--r--src/quick/items/qquickmultipointtoucharea.cpp1
-rw-r--r--src/quick/items/qquickpathview.cpp10
-rw-r--r--src/quick/items/qquickpincharea.cpp4
-rw-r--r--src/quick/items/qquickpositioners.cpp1
-rw-r--r--src/quick/items/qquickspritesequence.cpp2
-rw-r--r--src/quick/items/qquickstateoperations.cpp2
-rw-r--r--src/quick/items/qquicktextedit.cpp6
-rw-r--r--src/quick/items/qquicktextnode.cpp1
-rw-r--r--src/quick/items/qquicktranslate.cpp2
16 files changed, 41 insertions, 51 deletions
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