diff options
23 files changed, 120 insertions, 166 deletions
diff --git a/examples/embedded/lightmaps/lightmaps.cpp b/examples/embedded/lightmaps/lightmaps.cpp index a8bc13beaf..6334530c3a 100644 --- a/examples/embedded/lightmaps/lightmaps.cpp +++ b/examples/embedded/lightmaps/lightmaps.cpp @@ -52,15 +52,9 @@ #include <QtWidgets> #include <QtNetwork> -#include <math.h> - #include "lightmaps.h" #include "slippymap.h" -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - // how long (milliseconds) the user need to hold (after a tap on the screen) // before triggering the magnifying glass feature // 701, a prime number, is the sum of 229, 233, 239 diff --git a/examples/embedded/raycasting/raycasting.cpp b/examples/embedded/raycasting/raycasting.cpp index 992c383db1..d37b9f5d2e 100644 --- a/examples/embedded/raycasting/raycasting.cpp +++ b/examples/embedded/raycasting/raycasting.cpp @@ -50,12 +50,7 @@ #include <QtCore> #include <QtWidgets> - -#include <math.h> - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif +#include <qmath.h> #define WORLD_SIZE 8 int world_map[WORLD_SIZE][WORLD_SIZE] = { diff --git a/examples/opengl/hellowindow/hellowindow.cpp b/examples/opengl/hellowindow/hellowindow.cpp index dc48cc4b76..235775f09a 100644 --- a/examples/opengl/hellowindow/hellowindow.cpp +++ b/examples/opengl/hellowindow/hellowindow.cpp @@ -276,21 +276,20 @@ void Renderer::createGeometry() extrude(x4, y4, y4, x4); extrude(y4, x4, y3, x3); - const qreal Pi = 3.14159f; const int NumSectors = 100; - + const qreal sectorAngle = 2 * qreal(M_PI) / NumSectors; for (int i = 0; i < NumSectors; ++i) { - qreal angle1 = (i * 2 * Pi) / NumSectors; - qreal x5 = 0.30 * qSin(angle1); - qreal y5 = 0.30 * qCos(angle1); - qreal x6 = 0.20 * qSin(angle1); - qreal y6 = 0.20 * qCos(angle1); - - qreal angle2 = ((i + 1) * 2 * Pi) / NumSectors; - qreal x7 = 0.20 * qSin(angle2); - qreal y7 = 0.20 * qCos(angle2); - qreal x8 = 0.30 * qSin(angle2); - qreal y8 = 0.30 * qCos(angle2); + qreal angle = i * sectorAngle; + qreal x5 = 0.30 * qSin(angle); + qreal y5 = 0.30 * qCos(angle); + qreal x6 = 0.20 * qSin(angle); + qreal y6 = 0.20 * qCos(angle); + + angle += sectorAngle; + qreal x7 = 0.20 * qSin(angle); + qreal y7 = 0.20 * qCos(angle); + qreal x8 = 0.30 * qSin(angle); + qreal y8 = 0.30 * qCos(angle); quad(x5, y5, x6, y6, x7, y7, x8, y8); diff --git a/examples/opengl/legacy/framebufferobject2/glwidget.cpp b/examples/opengl/legacy/framebufferobject2/glwidget.cpp index ac8deddd1f..f14d31aff6 100644 --- a/examples/opengl/legacy/framebufferobject2/glwidget.cpp +++ b/examples/opengl/legacy/framebufferobject2/glwidget.cpp @@ -50,8 +50,7 @@ #include "glwidget.h" #include <QtGui/QImage> - -#include <math.h> +#include <qmath.h> static GLint cubeArray[][3] = { {0, 0, 0}, {0, 1, 0}, {1, 1, 0}, {1, 0, 0}, @@ -253,6 +252,6 @@ void GLWidget::drawCube(int i, GLfloat z, GLfloat rotation, GLfloat jmp, GLfloat xOffs[i] = xOffs[i] > 1.0f ? 1.0f : -1.0f; } xOffs[i] += xInc[i]; - yOffs[i] = qAbs(cos((-3.141592f * jmp) * xOffs[i]) * amp) - 1; + yOffs[i] = qAbs(cos((-GLfloat(M_PI) * jmp) * xOffs[i]) * amp) - 1; rot[i] += rotation; } diff --git a/examples/opengl/legacy/grabber/glwidget.cpp b/examples/opengl/legacy/grabber/glwidget.cpp index 958b8055cd..6be4d30597 100644 --- a/examples/opengl/legacy/grabber/glwidget.cpp +++ b/examples/opengl/legacy/grabber/glwidget.cpp @@ -52,8 +52,7 @@ #include <QMouseEvent> #include <QTimer> - -#include <math.h> +#include <qmath.h> GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent) @@ -190,8 +189,6 @@ GLuint GLWidget::makeGear(const GLfloat *reflectance, GLdouble innerRadius, GLdouble outerRadius, GLdouble thickness, GLdouble toothSize, GLint toothCount) { - const double Pi = 3.14159265358979323846; - GLuint list = glGenLists(1); glNewList(list, GL_COMPILE); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, reflectance); @@ -199,7 +196,8 @@ GLuint GLWidget::makeGear(const GLfloat *reflectance, GLdouble innerRadius, GLdouble r0 = innerRadius; GLdouble r1 = outerRadius - toothSize / 2.0; GLdouble r2 = outerRadius + toothSize / 2.0; - GLdouble delta = (2.0 * Pi / toothCount) / 4.0; + GLdouble toothAngle = 2 * M_PI / toothCount; + GLdouble delta = toothAngle / 4.0; GLdouble z = thickness / 2.0; glShadeModel(GL_FLAT); @@ -211,7 +209,7 @@ GLuint GLWidget::makeGear(const GLfloat *reflectance, GLdouble innerRadius, glBegin(GL_QUAD_STRIP); for (int j = 0; j <= toothCount; ++j) { - GLdouble angle = 2.0 * Pi * j / toothCount; + GLdouble angle = j * toothAngle; glVertex3d(r0 * cos(angle), r0 * sin(angle), sign * z); glVertex3d(r1 * cos(angle), r1 * sin(angle), sign * z); glVertex3d(r0 * cos(angle), r0 * sin(angle), sign * z); @@ -221,7 +219,7 @@ GLuint GLWidget::makeGear(const GLfloat *reflectance, GLdouble innerRadius, glBegin(GL_QUADS); for (int j = 0; j < toothCount; ++j) { - GLdouble angle = 2.0 * Pi * j / toothCount; + GLdouble angle = j * toothAngle; glVertex3d(r1 * cos(angle), r1 * sin(angle), sign * z); glVertex3d(r2 * cos(angle + delta), r2 * sin(angle + delta), sign * z); glVertex3d(r2 * cos(angle + 2 * delta), r2 * sin(angle + 2 * delta), sign * z); @@ -233,7 +231,7 @@ GLuint GLWidget::makeGear(const GLfloat *reflectance, GLdouble innerRadius, glBegin(GL_QUAD_STRIP); for (int i = 0; i < toothCount; ++i) { for (int j = 0; j < 2; ++j) { - GLdouble angle = 2.0 * Pi * (i + j / 2.0) / toothCount; + GLdouble angle = (i + j / 2.0) * toothAngle; GLdouble s1 = r1; GLdouble s2 = r2; if (j == 1) @@ -257,7 +255,7 @@ GLuint GLWidget::makeGear(const GLfloat *reflectance, GLdouble innerRadius, glBegin(GL_QUAD_STRIP); for (int i = 0; i <= toothCount; ++i) { - GLdouble angle = i * 2.0 * Pi / toothCount; + GLdouble angle = i * toothAngle; glNormal3d(-cos(angle), -sin(angle), 0.0); glVertex3d(r0 * cos(angle), r0 * sin(angle), +z); glVertex3d(r0 * cos(angle), r0 * sin(angle), -z); diff --git a/examples/opengl/legacy/pbuffers2/glwidget.cpp b/examples/opengl/legacy/pbuffers2/glwidget.cpp index c99f9e40fa..447461dbb3 100644 --- a/examples/opengl/legacy/pbuffers2/glwidget.cpp +++ b/examples/opengl/legacy/pbuffers2/glwidget.cpp @@ -49,10 +49,9 @@ ****************************************************************************/ #include <QtGui/QImage> +#include <qmath.h> #include "glwidget.h" -#include <math.h> - #ifndef GL_MULTISAMPLE #define GL_MULTISAMPLE 0x809D #endif @@ -291,8 +290,6 @@ void GLWidget::restoreGLState() glPopAttrib(); } -#define PI 3.14159 - void GLWidget::timerEvent(QTimerEvent *) { if (QApplication::mouseButtons() != 0) @@ -310,7 +307,7 @@ void GLWidget::timerEvent(QTimerEvent *) rot_x += 0.1f; int dx, dy; // disturbance point - float s, v, W, t; + float s, v, W; int i, j; static float wt[128][128]; const int width = logo.width(); @@ -325,11 +322,11 @@ void GLWidget::timerEvent(QTimerEvent *) for ( j = 0; j < width; ++j) { s = sqrt((double) ((j - dx) * (j - dx) + (i - dy) * (i - dy))); wt[i][j] += 0.1f; - t = s / v; + const double angle = 2 * M_PI * W * (wt[i][j] + s / v); if (s != 0) - wave[i*width + j] = AMP * sin(2 * PI * W * (wt[i][j] + t)) / (0.2*(s + 2)); + wave[i * width + j] = AMP * sin(angle) / (0.2 * (s + 2)); else - wave[i*width + j] = AMP * sin(2 * PI * W * (wt[i][j] + t)); + wave[i * width + j] = AMP * sin(angle); } } } diff --git a/examples/opengl/legacy/samplebuffers/glwidget.cpp b/examples/opengl/legacy/samplebuffers/glwidget.cpp index 14c59c9143..da30de4d55 100644 --- a/examples/opengl/legacy/samplebuffers/glwidget.cpp +++ b/examples/opengl/legacy/samplebuffers/glwidget.cpp @@ -49,7 +49,7 @@ ****************************************************************************/ #include "glwidget.h" -#include <math.h> +#include <qmath.h> #ifndef GL_MULTISAMPLE #define GL_MULTISAMPLE 0x809D @@ -116,7 +116,6 @@ void GLWidget::timerEvent(QTimerEvent *) void GLWidget::makeObject() { QColor qtGreen(QColor::fromCmykF(0.40, 0.0, 1.0, 0.0)); - const double Pi = 3.14159265358979323846; const int NumSectors = 15; GLdouble x1 = +0.06; GLdouble y1 = -0.14; @@ -130,18 +129,19 @@ void GLWidget::makeObject() list = glGenLists(1); glNewList(list, GL_COMPILE); { + const double sectorAngle = 2 * M_PI / NumSectors; for (int i = 0; i < NumSectors; ++i) { - double angle1 = (i * 2 * Pi) / NumSectors; - GLdouble x5 = 0.30 * sin(angle1); - GLdouble y5 = 0.30 * cos(angle1); - GLdouble x6 = 0.20 * sin(angle1); - GLdouble y6 = 0.20 * cos(angle1); - - double angle2 = ((i + 1) * 2 * Pi) / NumSectors; - GLdouble x7 = 0.20 * sin(angle2); - GLdouble y7 = 0.20 * cos(angle2); - GLdouble x8 = 0.30 * sin(angle2); - GLdouble y8 = 0.30 * cos(angle2); + double angle = i * sectorAngle; + GLdouble x5 = 0.30 * sin(angle); + GLdouble y5 = 0.30 * cos(angle); + GLdouble x6 = 0.20 * sin(angle); + GLdouble y6 = 0.20 * cos(angle); + + angle += sectorAngle; + GLdouble x7 = 0.20 * sin(angle); + GLdouble y7 = 0.20 * cos(angle); + GLdouble x8 = 0.30 * sin(angle); + GLdouble y8 = 0.30 * cos(angle); qglColor(qtGreen); quad(GL_QUADS, x5, y5, x6, y6, x7, y7, x8, y8); diff --git a/examples/opengl/qopenglwidget/glwidget.cpp b/examples/opengl/qopenglwidget/glwidget.cpp index bb7c952a26..40a1258dd5 100644 --- a/examples/opengl/qopenglwidget/glwidget.cpp +++ b/examples/opengl/qopenglwidget/glwidget.cpp @@ -54,7 +54,7 @@ #include <QOpenGLShaderProgram> #include <QOpenGLTexture> #include <QCoreApplication> -#include <math.h> +#include <qmath.h> #include "mainwindow.h" #include "bubble.h" @@ -455,21 +455,21 @@ void GLWidget::createGeometry() extrude(x4, y4, y4, x4); extrude(y4, x4, y3, x3); - const qreal Pi = 3.14159f; const int NumSectors = 100; + const qreal sectorAngle = 2 * qreal(M_PI) / NumSectors; for (int i = 0; i < NumSectors; ++i) { - qreal angle1 = (i * 2 * Pi) / NumSectors; - qreal x5 = 0.30 * sin(angle1); - qreal y5 = 0.30 * cos(angle1); - qreal x6 = 0.20 * sin(angle1); - qreal y6 = 0.20 * cos(angle1); - - qreal angle2 = ((i + 1) * 2 * Pi) / NumSectors; - qreal x7 = 0.20 * sin(angle2); - qreal y7 = 0.20 * cos(angle2); - qreal x8 = 0.30 * sin(angle2); - qreal y8 = 0.30 * cos(angle2); + qreal angle = i * sectorAngle; + qreal x5 = 0.30 * sin(angle); + qreal y5 = 0.30 * cos(angle); + qreal x6 = 0.20 * sin(angle); + qreal y6 = 0.20 * cos(angle); + + angle += sectorAngle; + qreal x7 = 0.20 * sin(angle); + qreal y7 = 0.20 * cos(angle); + qreal x8 = 0.30 * sin(angle); + qreal y8 = 0.30 * cos(angle); quad(x5, y5, x6, y6, x7, y7, x8, y8); diff --git a/examples/opengl/qopenglwindow/background.frag b/examples/opengl/qopenglwindow/background.frag index eecb6d3120..4af85aae8e 100644 --- a/examples/opengl/qopenglwindow/background.frag +++ b/examples/opengl/qopenglwindow/background.frag @@ -1,4 +1,4 @@ -#define M_PI 3.1415926535897932384626433832795 +#define M_PI 3.14159265358979323846 #define SPEED 10000.0 uniform int currentTime; diff --git a/examples/opengl/threadedqopenglwidget/glwidget.cpp b/examples/opengl/threadedqopenglwidget/glwidget.cpp index f9738db2e5..cc528a734a 100644 --- a/examples/opengl/threadedqopenglwidget/glwidget.cpp +++ b/examples/opengl/threadedqopenglwidget/glwidget.cpp @@ -49,7 +49,7 @@ ****************************************************************************/ #include "glwidget.h" -#include <math.h> +#include <qmath.h> #include <QGuiApplication> GLWidget::GLWidget(QWidget *parent) @@ -282,21 +282,21 @@ void Renderer::createGeometry() extrude(x4, y4, y4, x4); extrude(y4, x4, y3, x3); - const qreal Pi = 3.14159f; const int NumSectors = 100; + const qreal sectorAngle = 2 * qreal(M_PI) / NumSectors; for (int i = 0; i < NumSectors; ++i) { - qreal angle1 = (i * 2 * Pi) / NumSectors; - qreal x5 = 0.30 * sin(angle1); - qreal y5 = 0.30 * cos(angle1); - qreal x6 = 0.20 * sin(angle1); - qreal y6 = 0.20 * cos(angle1); - - qreal angle2 = ((i + 1) * 2 * Pi) / NumSectors; - qreal x7 = 0.20 * sin(angle2); - qreal y7 = 0.20 * cos(angle2); - qreal x8 = 0.30 * sin(angle2); - qreal y8 = 0.30 * cos(angle2); + qreal angle = i * sectorAngle; + qreal x5 = 0.30 * sin(angle); + qreal y5 = 0.30 * cos(angle); + qreal x6 = 0.20 * sin(angle); + qreal y6 = 0.20 * cos(angle); + + angle += sectorAngle; + qreal x7 = 0.20 * sin(angle); + qreal y7 = 0.20 * cos(angle); + qreal x8 = 0.30 * sin(angle); + qreal y8 = 0.30 * cos(angle); quad(x5, y5, x6, y6, x7, y7, x8, y8); diff --git a/examples/touch/pinchzoom/mouse.cpp b/examples/touch/pinchzoom/mouse.cpp index 3b8e6b5690..7f8c238e6f 100644 --- a/examples/touch/pinchzoom/mouse.cpp +++ b/examples/touch/pinchzoom/mouse.cpp @@ -53,11 +53,10 @@ #include <QGraphicsScene> #include <QPainter> #include <QStyleOption> +#include <qmath.h> -#include <cmath> - -static const double Pi = 3.14159265358979323846264338327950288419717; -static double TwoPi = 2.0 * Pi; +const qreal Pi = M_PI; +const qreal TwoPi = 2 * M_PI; static qreal normalizeAngle(qreal angle) { diff --git a/examples/widgets/doc/src/painterpaths.qdoc b/examples/widgets/doc/src/painterpaths.qdoc index 2cc5ff410a..bd821ac1bf 100644 --- a/examples/widgets/doc/src/painterpaths.qdoc +++ b/examples/widgets/doc/src/painterpaths.qdoc @@ -98,14 +98,9 @@ \section1 Window Class Implementation - In the implementation of the \c Window class we first declare the - constant \c Pi with six significant figures: - - \snippet painting/painterpaths/window.cpp 0 - - In the constructor, we then define the various painter paths and - create corresponding \c RenderArea widgets which will render the - graphical shapes: + In the \c Window constructor, we define the various painter paths + and create corresponding \c RenderArea widgets which will render + the graphical shapes: \snippet painting/painterpaths/window.cpp 1 diff --git a/examples/widgets/effects/blurpicker/blurpicker.cpp b/examples/widgets/effects/blurpicker/blurpicker.cpp index 43823bed30..a00af2144a 100644 --- a/examples/widgets/effects/blurpicker/blurpicker.cpp +++ b/examples/widgets/effects/blurpicker/blurpicker.cpp @@ -52,13 +52,9 @@ #include <QtWidgets> #include <QtCore/qmath.h> - +#include <qmath.h> #include "blureffect.h" -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - BlurPicker::BlurPicker(QWidget *parent): QGraphicsView(parent), m_index(0.0), m_animation(this, "index") { setBackgroundBrush(QPixmap(":/images/background.jpg")); @@ -84,9 +80,10 @@ void BlurPicker::setIndex(qreal index) m_index = index; qreal baseline = 0; + const qreal iconAngle = 2 * M_PI / m_icons.count(); for (int i = 0; i < m_icons.count(); ++i) { QGraphicsItem *icon = m_icons[i]; - qreal a = ((i + m_index) * 2 * M_PI) / m_icons.count(); + qreal a = (i + m_index) * iconAngle; qreal xs = 170 * qSin(a); qreal ys = 100 * qCos(a); QPointF pos(xs, ys); diff --git a/examples/widgets/graphicsview/boxes/scene.cpp b/examples/widgets/graphicsview/boxes/scene.cpp index 9ac429c667..31b9553c75 100644 --- a/examples/widgets/graphicsview/boxes/scene.cpp +++ b/examples/widgets/graphicsview/boxes/scene.cpp @@ -52,7 +52,7 @@ #include "scene.h" #include <QtGui/qmatrix4x4.h> #include <QtGui/qvector3d.h> -#include <cmath> +#include <qmath.h> #include "3rdparty/fbm.h" @@ -868,11 +868,12 @@ void Scene::renderCubemaps() QVector3D center; + const float eachAngle = 2 * M_PI / m_cubemaps.size(); for (int i = m_frame % N; i < m_cubemaps.size(); i += N) { if (0 == m_cubemaps[i]) continue; - float angle = 2.0f * PI * i / m_cubemaps.size(); + float angle = i * eachAngle; center = m_trackBalls[1].rotation().rotatedVector(QVector3D(std::cos(angle), std::sin(angle), 0.0f)); diff --git a/examples/widgets/graphicsview/boxes/scene.h b/examples/widgets/graphicsview/boxes/scene.h index a2ba1d0b5a..ccb6f368cd 100644 --- a/examples/widgets/graphicsview/boxes/scene.h +++ b/examples/widgets/graphicsview/boxes/scene.h @@ -63,8 +63,6 @@ #include "glbuffers.h" #include "qtbox.h" -#define PI 3.14159265358979 - QT_BEGIN_NAMESPACE class QMatrix4x4; QT_END_NAMESPACE diff --git a/examples/widgets/graphicsview/collidingmice/mouse.cpp b/examples/widgets/graphicsview/collidingmice/mouse.cpp index cc1a15cd82..298e4aae64 100644 --- a/examples/widgets/graphicsview/collidingmice/mouse.cpp +++ b/examples/widgets/graphicsview/collidingmice/mouse.cpp @@ -53,11 +53,10 @@ #include <QGraphicsScene> #include <QPainter> #include <QStyleOption> +#include <qmath.h> -#include <cmath> - -static const double Pi = 3.14159265358979323846264338327950288419717; -static double TwoPi = 2.0 * Pi; +const qreal Pi = M_PI; +const qreal TwoPi = 2 * M_PI; static qreal normalizeAngle(qreal angle) { diff --git a/examples/widgets/graphicsview/diagramscene/arrow.cpp b/examples/widgets/graphicsview/diagramscene/arrow.cpp index ae7fa7af90..88160d9399 100644 --- a/examples/widgets/graphicsview/diagramscene/arrow.cpp +++ b/examples/widgets/graphicsview/diagramscene/arrow.cpp @@ -51,13 +51,10 @@ #include "arrow.h" -#include <cmath> - +#include <qmath.h> #include <QPen> #include <QPainter> -const qreal Pi = 3.14; - //! [0] Arrow::Arrow(DiagramItem *startItem, DiagramItem *endItem, QGraphicsItem *parent) : QGraphicsLineItem(parent) @@ -134,10 +131,10 @@ void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *, double angle = std::atan2(-line().dy(), line().dx()); - QPointF arrowP1 = line().p1() + QPointF(sin(angle + Pi / 3) * arrowSize, - cos(angle + Pi / 3) * arrowSize); - QPointF arrowP2 = line().p1() + QPointF(sin(angle + Pi - Pi / 3) * arrowSize, - cos(angle + Pi - Pi / 3) * arrowSize); + QPointF arrowP1 = line().p1() + QPointF(sin(angle + M_PI / 3) * arrowSize, + cos(angle + M_PI / 3) * arrowSize); + QPointF arrowP2 = line().p1() + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize, + cos(angle + M_PI - M_PI / 3) * arrowSize); arrowHead.clear(); arrowHead << line().p1() << arrowP1 << arrowP2; diff --git a/examples/widgets/graphicsview/elasticnodes/edge.cpp b/examples/widgets/graphicsview/elasticnodes/edge.cpp index d9e4c62e34..aec12b4225 100644 --- a/examples/widgets/graphicsview/elasticnodes/edge.cpp +++ b/examples/widgets/graphicsview/elasticnodes/edge.cpp @@ -51,12 +51,9 @@ #include "edge.h" #include "node.h" -#include <cmath> - +#include <qmath.h> #include <QPainter> -static const double Pi = 3.14159265358979323846264338327950288419717; - //! [0] Edge::Edge(Node *sourceNode, Node *destNode) : arrowSize(10) @@ -140,14 +137,14 @@ void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) // Draw the arrows double angle = std::atan2(-line.dy(), line.dx()); - QPointF sourceArrowP1 = sourcePoint + QPointF(sin(angle + Pi / 3) * arrowSize, - cos(angle + Pi / 3) * arrowSize); - QPointF sourceArrowP2 = sourcePoint + QPointF(sin(angle + Pi - Pi / 3) * arrowSize, - cos(angle + Pi - Pi / 3) * arrowSize); - QPointF destArrowP1 = destPoint + QPointF(sin(angle - Pi / 3) * arrowSize, - cos(angle - Pi / 3) * arrowSize); - QPointF destArrowP2 = destPoint + QPointF(sin(angle - Pi + Pi / 3) * arrowSize, - cos(angle - Pi + Pi / 3) * arrowSize); + QPointF sourceArrowP1 = sourcePoint + QPointF(sin(angle + M_PI / 3) * arrowSize, + cos(angle + M_PI / 3) * arrowSize); + QPointF sourceArrowP2 = sourcePoint + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize, + cos(angle + M_PI - M_PI / 3) * arrowSize); + QPointF destArrowP1 = destPoint + QPointF(sin(angle - M_PI / 3) * arrowSize, + cos(angle - M_PI / 3) * arrowSize); + QPointF destArrowP2 = destPoint + QPointF(sin(angle - M_PI + M_PI / 3) * arrowSize, + cos(angle - M_PI + M_PI / 3) * arrowSize); painter->setBrush(Qt::black); painter->drawPolygon(QPolygonF() << line.p1() << sourceArrowP1 << sourceArrowP2); diff --git a/examples/widgets/painting/painterpaths/window.cpp b/examples/widgets/painting/painterpaths/window.cpp index 7122411a6c..a987937b39 100644 --- a/examples/widgets/painting/painterpaths/window.cpp +++ b/examples/widgets/painting/painterpaths/window.cpp @@ -53,11 +53,7 @@ #include <QtWidgets> -#include <cmath> - -//! [0] -const float Pi = 3.14159f; -//! [0] +#include <qmath.h> //! [1] Window::Window() @@ -133,8 +129,8 @@ Window::Window() QPainterPath starPath; starPath.moveTo(90, 50); for (int i = 1; i < 5; ++i) { - starPath.lineTo(50 + 40 * std::cos(0.8 * i * Pi), - 50 + 40 * std::sin(0.8 * i * Pi)); + starPath.lineTo(50 + 40 * std::cos(0.8 * i * M_PI), + 50 + 40 * std::sin(0.8 * i * M_PI)); } starPath.closeSubpath(); //! [9] diff --git a/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp b/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp index c929ff6922..740d007d44 100644 --- a/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp +++ b/examples/widgets/tools/plugandpaint/plugins/basictools/basictoolsplugin.cpp @@ -50,13 +50,11 @@ #include <QtWidgets> -#include <cmath> +#include <qmath.h> #include <stdlib.h> #include "basictoolsplugin.h" -const float Pi = 3.14159f; - //! [0] QStringList BasicToolsPlugin::brushes() const { @@ -149,8 +147,8 @@ QPainterPath BasicToolsPlugin::generateShape(const QString &shape, } else if (shape == tr("Star")) { path.moveTo(90, 50); for (int i = 1; i < 5; ++i) { - path.lineTo(50 + 40 * std::cos(0.8 * i * Pi), - 50 + 40 * std::sin(0.8 * i * Pi)); + path.lineTo(50 + 40 * std::cos(0.8 * i * M_PI), + 50 + 40 * std::sin(0.8 * i * M_PI)); } path.closeSubpath(); } else if (shape == tr("Text...")) { diff --git a/src/corelib/doc/snippets/code/doc_src_qpair.cpp b/src/corelib/doc/snippets/code/doc_src_qpair.cpp index f94e3b0d37..e62f91830c 100644 --- a/src/corelib/doc/snippets/code/doc_src_qpair.cpp +++ b/src/corelib/doc/snippets/code/doc_src_qpair.cpp @@ -47,6 +47,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ +#include <qmath.h> //! [0] QPair<QString, double> pair; @@ -55,7 +56,7 @@ QPair<QString, double> pair; //! [1] pair.first = "pi"; -pair.second = 3.14159265358979323846; +pair.second = M_PI; //! [1] //! [struct] @@ -65,10 +66,10 @@ struct Variable { }; Variable v; v.name = "pi"; -v.value = 3.14159265358979323846; +v.value = M_PI; //! [struct] //! [2] QList<QPair<int, double> > list; -list.append(qMakePair(66, 3.14159)); +list.append(qMakePair(66, M_PI)); //! [2] diff --git a/tests/auto/corelib/kernel/qmath/tst_qmath.cpp b/tests/auto/corelib/kernel/qmath/tst_qmath.cpp index ad40b0140d..feb704e0aa 100644 --- a/tests/auto/corelib/kernel/qmath/tst_qmath.cpp +++ b/tests/auto/corelib/kernel/qmath/tst_qmath.cpp @@ -30,8 +30,6 @@ #include <QtTest/QtTest> #include <qmath.h> -static const double PI = 3.14159265358979323846264338327950288; - class tst_QMath : public QObject { Q_OBJECT @@ -55,8 +53,9 @@ void tst_QMath::fastSinCos() { // Test evenly spaced angles from 0 to 2pi radians. const int LOOP_COUNT = 100000; + const qreal loopAngle = 2 * M_PI / (LOOP_COUNT - 1); for (int i = 0; i < LOOP_COUNT; ++i) { - qreal angle = i * 2 * PI / (LOOP_COUNT - 1); + qreal angle = i * loopAngle; QVERIFY(qAbs(qSin(angle) - qFastSin(angle)) < 1e-5); QVERIFY(qAbs(qCos(angle) - qFastCos(angle)) < 1e-5); } @@ -69,18 +68,18 @@ void tst_QMath::degreesToRadians_data() QTest::addColumn<double>("degreesDouble"); QTest::addColumn<double>("radiansDouble"); - QTest::newRow( "pi" ) << 180.0f << float(M_PI) << 180.0 << PI; - QTest::newRow( "doublepi" ) << 360.0f << float(2*M_PI) << 360.0 << 2*PI; - QTest::newRow( "halfpi" ) << 90.0f << float(M_PI_2) << 90.0 << PI/2; + QTest::newRow( "pi" ) << 180.0f << float(M_PI) << 180.0 << M_PI; + QTest::newRow( "doublepi" ) << 360.0f << float(2 * M_PI) << 360.0 << 2 * M_PI; + QTest::newRow( "halfpi" ) << 90.0f << float(M_PI_2) << 90.0 << M_PI_2; QTest::newRow( "random" ) << 123.1234567f << 2.1489097058516724f << 123.123456789123456789 << 2.148909707407169856192285627; QTest::newRow( "bigrandom" ) << 987654321.9876543f << 17237819.79023679f << 987654321987654321.987654321987654321 << 17237819790236794.0; QTest::newRow( "zero" ) << 0.0f << 0.0f << 0.0 << 0.0; - QTest::newRow( "minuspi" ) << -180.0f << float(-M_PI) << 180.0 << PI; - QTest::newRow( "minusdoublepi" ) << -360.0f << float(-2*M_PI) << -360.0 << -2*PI; - QTest::newRow( "minushalfpi" ) << -90.0f << float(-M_PI_2) << -90.0 << -PI/2; + QTest::newRow( "minuspi" ) << -180.0f << float(-M_PI) << 180.0 << M_PI; + QTest::newRow( "minusdoublepi" ) << -360.0f << float(-2 * M_PI) << -360.0 << -2 * M_PI; + QTest::newRow( "minushalfpi" ) << -90.0f << float(-M_PI_2) << -90.0 << -M_PI_2; QTest::newRow( "minusrandom" ) << -123.1234567f << -2.1489097058516724f << -123.123456789123456789 << -2.148909707407169856192285627; QTest::newRow( "minusbigrandom" ) << -987654321.9876543f << -17237819.79023679f << -987654321987654321.987654321987654321 << -17237819790236794.0; @@ -104,18 +103,18 @@ void tst_QMath::radiansToDegrees_data() QTest::addColumn<double>("radiansDouble"); QTest::addColumn<double>("degreesDouble"); - QTest::newRow( "pi" ) << float(M_PI) << 180.0f << PI << 180.0; - QTest::newRow( "doublepi" ) << float(2*M_PI) << 360.0f << 2*PI << 360.0; - QTest::newRow( "halfpi" ) << float(M_PI_2) << 90.0f<< PI/2 << 90.0; + QTest::newRow( "pi" ) << float(M_PI) << 180.0f << M_PI << 180.0; + QTest::newRow( "doublepi" ) << float(2 * M_PI) << 360.0f << 2 * M_PI << 360.0; + QTest::newRow( "halfpi" ) << float(M_PI_2) << 90.0f << M_PI_2 << 90.0; QTest::newRow( "random" ) << 123.1234567f << 7054.454427971739f << 123.123456789123456789 << 7054.4544330781363896676339209079742431640625; QTest::newRow( "bigrandom" ) << 987654321.9876543f << 56588424267.74745f << 987654321987654321.987654321987654321 << 56588424267747450880.0; QTest::newRow( "zero" ) << 0.0f << 0.0f << 0.0 << 0.0; - QTest::newRow( "minuspi" ) << float(-M_PI) << -180.0f << -PI << -180.0; - QTest::newRow( "minusdoublepi" ) << float(-2*M_PI) << -360.0f << -2*PI << -360.0; - QTest::newRow( "minushalfpi" ) << float(-M_PI_2) << -90.0f << -PI/2 << -90.0; + QTest::newRow( "minuspi" ) << float(-M_PI) << -180.0f << -M_PI << -180.0; + QTest::newRow( "minusdoublepi" ) << float(-2 * M_PI) << -360.0f << -2 * M_PI << -360.0; + QTest::newRow( "minushalfpi" ) << float(-M_PI_2) << -90.0f << -M_PI_2 << -90.0; QTest::newRow( "minusrandom" ) << -123.1234567f << -7054.454427971739f << -123.123456789123456789 << -7054.4544330781363896676339209079742431640625; QTest::newRow( "minusbigrandom" ) << -987654321.9876543f << -56588424267.74745f << -987654321987654321.987654321987654321 << -56588424267747450880.0; diff --git a/tests/auto/gui/painting/qtransform/tst_qtransform.cpp b/tests/auto/gui/painting/qtransform/tst_qtransform.cpp index 0c089cdaa3..0a6a95daca 100644 --- a/tests/auto/gui/painting/qtransform/tst_qtransform.cpp +++ b/tests/auto/gui/painting/qtransform/tst_qtransform.cpp @@ -29,7 +29,6 @@ #include <QtTest/QtTest> #include "qtransform.h" -#include <math.h> #include <qpolygon.h> #include <qdebug.h> @@ -67,10 +66,6 @@ private: Q_DECLARE_METATYPE(QTransform) -#if defined(Q_OS_WIN) && !defined(M_PI) -#define M_PI 3.14159265897932384626433832795f -#endif - void tst_QTransform::mapRect_data() { mapping_data(); |