From 515e802ae20c045e5c47b400ee6ef6e92349c978 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 14 Jan 2015 11:17:47 +0100 Subject: Use C++ instead of Including math.h can pollute the default namespace, and break some compilers if cmath versions of the method are declared as using. Switching to C++ math functions also greatly simplifies handling of float qreal as C++ automatically chooses the right method. [ChangeLog][QtCore][QtMath] qmath.h no longer includes math.h, so any sources depending on that indirect inclusion may fail to build. Change-Id: I4d0e331dafba354ec05dc5052e61ef4ff8d387fe Reviewed-by: Rafael Roquetto --- examples/widgets/graphicsview/boxes/qtbox.cpp | 10 +++++----- examples/widgets/graphicsview/boxes/scene.cpp | 5 +++-- examples/widgets/graphicsview/boxes/trackball.cpp | 7 ++++--- 3 files changed, 12 insertions(+), 10 deletions(-) (limited to 'examples/widgets/graphicsview/boxes') diff --git a/examples/widgets/graphicsview/boxes/qtbox.cpp b/examples/widgets/graphicsview/boxes/qtbox.cpp index e368ddb307..5e142832e0 100644 --- a/examples/widgets/graphicsview/boxes/qtbox.cpp +++ b/examples/widgets/graphicsview/boxes/qtbox.cpp @@ -242,7 +242,7 @@ void ItemBase::keyPressEvent(QKeyEvent *event) void ItemBase::wheelEvent(QGraphicsSceneWheelEvent *event) { prepareGeometryChange(); - m_size = int(m_size * exp(-event->delta() / 600.0)); + m_size = int(m_size * qExp(-event->delta() / 600.0)); if (m_size > MAX_ITEM_SIZE) m_size = MAX_ITEM_SIZE; else if (m_size < MIN_ITEM_SIZE) @@ -404,10 +404,10 @@ void CircleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option { int dt = m_startTime.msecsTo(QTime::currentTime()); - qreal r0 = 0.5 * m_size * (1.0 - exp(-0.001 * ((dt + 3800) % 4000))); - qreal r1 = 0.5 * m_size * (1.0 - exp(-0.001 * ((dt + 0) % 4000))); - qreal r2 = 0.5 * m_size * (1.0 - exp(-0.001 * ((dt + 1800) % 4000))); - qreal r3 = 0.5 * m_size * (1.0 - exp(-0.001 * ((dt + 2000) % 4000))); + qreal r0 = 0.5 * m_size * (1.0 - qExp(-0.001 * ((dt + 3800) % 4000))); + qreal r1 = 0.5 * m_size * (1.0 - qExp(-0.001 * ((dt + 0) % 4000))); + qreal r2 = 0.5 * m_size * (1.0 - qExp(-0.001 * ((dt + 1800) % 4000))); + qreal r3 = 0.5 * m_size * (1.0 - qExp(-0.001 * ((dt + 2000) % 4000))); if (r0 > r1) r0 = 0.0; diff --git a/examples/widgets/graphicsview/boxes/scene.cpp b/examples/widgets/graphicsview/boxes/scene.cpp index 2ca061a43a..48bdcb9d93 100644 --- a/examples/widgets/graphicsview/boxes/scene.cpp +++ b/examples/widgets/graphicsview/boxes/scene.cpp @@ -35,6 +35,7 @@ #include "scene.h" #include #include +#include #include "3rdparty/fbm.h" @@ -856,7 +857,7 @@ void Scene::renderCubemaps() float angle = 2.0f * PI * i / m_cubemaps.size(); - center = m_trackBalls[1].rotation().rotatedVector(QVector3D(cos(angle), sin(angle), 0.0f)); + center = m_trackBalls[1].rotation().rotatedVector(QVector3D(std::cos(angle), std::sin(angle), 0.0f)); for (int face = 0; face < 6; ++face) { m_cubemaps[i]->begin(face); @@ -910,7 +911,7 @@ void Scene::drawBackground(QPainter *painter, const QRectF &) QMatrix4x4 view; view.rotate(m_trackBalls[2].rotation()); - view(2, 3) -= 2.0f * exp(m_distExp / 1200.0f); + view(2, 3) -= 2.0f * std::exp(m_distExp / 1200.0f); renderBoxes(view); defaultStates(); diff --git a/examples/widgets/graphicsview/boxes/trackball.cpp b/examples/widgets/graphicsview/boxes/trackball.cpp index 2267636fa4..b1159b4989 100644 --- a/examples/widgets/graphicsview/boxes/trackball.cpp +++ b/examples/widgets/graphicsview/boxes/trackball.cpp @@ -33,6 +33,7 @@ #include "trackball.h" #include "scene.h" +#include //============================================================================// // TrackBall // @@ -94,19 +95,19 @@ void TrackBall::move(const QPointF& p, const QQuaternion &transformation) QVector3D lastPos3D = QVector3D(m_lastPos.x(), m_lastPos.y(), 0.0f); float sqrZ = 1 - QVector3D::dotProduct(lastPos3D, lastPos3D); if (sqrZ > 0) - lastPos3D.setZ(sqrt(sqrZ)); + lastPos3D.setZ(std::sqrt(sqrZ)); else lastPos3D.normalize(); QVector3D currentPos3D = QVector3D(p.x(), p.y(), 0.0f); sqrZ = 1 - QVector3D::dotProduct(currentPos3D, currentPos3D); if (sqrZ > 0) - currentPos3D.setZ(sqrt(sqrZ)); + currentPos3D.setZ(std::sqrt(sqrZ)); else currentPos3D.normalize(); m_axis = QVector3D::crossProduct(lastPos3D, currentPos3D); - float angle = 180 / PI * asin(sqrt(QVector3D::dotProduct(m_axis, m_axis))); + float angle = 180 / PI * std::asin(std::sqrt(QVector3D::dotProduct(m_axis, m_axis))); m_angularVelocity = angle / msecs; m_axis.normalize(); -- cgit v1.2.3