aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2017-01-12 18:02:45 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2017-06-14 08:19:47 +0000
commita021bd87755ccfbe49e132f942ded935c9719b00 (patch)
tree1fe242bfb77cd4723ed01d4fdd1815ab6338c706
parent784ea8c09d448a418b3128be8bee14d9535e36c9 (diff)
Be (somewhat more) consistent about the value of pi
Use M_PI in C++ and Math.PI in JavaScript (including QML). Use qmath.h's value for M_PI where we can't avoid an explicit value. Task-number: QTBUG-58083 Change-Id: Iabe938aff62ceac27b939ec33c6ee5e854aac15e Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r--examples/quick/scenegraph/graph/shaders/line.fsh2
-rw-r--r--examples/quick/scenegraph/graph/shaders/noisy.fsh2
-rw-r--r--examples/quick/scenegraph/shared/logorenderer.cpp4
-rw-r--r--examples/quick/scenegraph/textureinsgnode/main.qml2
-rw-r--r--examples/quick/scenegraph/textureinthread/main.qml2
-rw-r--r--examples/quick/scenegraph/twotextureproviders/main.qml2
-rw-r--r--src/quick/doc/snippets/qml/layerblending.qml2
-rw-r--r--src/quick/doc/snippets/qml/opacitymask.qml2
-rw-r--r--src/quick/util/qquicksvgparser.cpp8
-rw-r--r--tests/auto/qml/qqmlecmascript/data/dynamicString.qml2
-rw-r--r--tests/manual/v4/typedarrays.js4
11 files changed, 15 insertions, 17 deletions
diff --git a/examples/quick/scenegraph/graph/shaders/line.fsh b/examples/quick/scenegraph/graph/shaders/line.fsh
index 5d38c46d4d..41c0ee3c00 100644
--- a/examples/quick/scenegraph/graph/shaders/line.fsh
+++ b/examples/quick/scenegraph/graph/shaders/line.fsh
@@ -44,7 +44,7 @@ uniform lowp float spread;
varying lowp float vT;
-#define PI 3.14159265359
+#define PI 3.14159265358979323846
void main(void)
{
diff --git a/examples/quick/scenegraph/graph/shaders/noisy.fsh b/examples/quick/scenegraph/graph/shaders/noisy.fsh
index 30b0def932..c217e635ef 100644
--- a/examples/quick/scenegraph/graph/shaders/noisy.fsh
+++ b/examples/quick/scenegraph/graph/shaders/noisy.fsh
@@ -45,7 +45,7 @@ uniform lowp vec4 color;
varying highp vec2 vTexCoord;
varying lowp vec2 vShadeCoord;
-#define PI 3.14159265359
+#define PI 3.14159265358979323846
void main()
{
diff --git a/examples/quick/scenegraph/shared/logorenderer.cpp b/examples/quick/scenegraph/shared/logorenderer.cpp
index 8eb2d44c1e..5c3a770f54 100644
--- a/examples/quick/scenegraph/shared/logorenderer.cpp
+++ b/examples/quick/scenegraph/shared/logorenderer.cpp
@@ -41,7 +41,7 @@
#include "logorenderer.h"
#include <QPainter>
#include <QPaintEngine>
-#include <math.h>
+#include <qmath.h>
LogoRenderer::LogoRenderer()
{
@@ -166,7 +166,7 @@ void LogoRenderer::createGeometry()
extrude(x4, y4, y4, x4);
extrude(y4, x4, y3, x3);
- const qreal Pi = 3.14159f;
+ const qreal Pi = M_PI;
const int NumSectors = 100;
for (int i = 0; i < NumSectors; ++i) {
diff --git a/examples/quick/scenegraph/textureinsgnode/main.qml b/examples/quick/scenegraph/textureinsgnode/main.qml
index fe145b0f05..ba110a278d 100644
--- a/examples/quick/scenegraph/textureinsgnode/main.qml
+++ b/examples/quick/scenegraph/textureinsgnode/main.qml
@@ -64,7 +64,7 @@ Item {
uniform highp vec2 pixelSize;
varying highp vec2 qt_TexCoord0;
void main() {
- highp vec2 tc = sign(sin(3.14152 * qt_TexCoord0 * pixelSize));
+ highp vec2 tc = sign(sin(3.14159265358979323846 * qt_TexCoord0 * pixelSize));
if (tc.x != tc.y)
gl_FragColor = color1;
else
diff --git a/examples/quick/scenegraph/textureinthread/main.qml b/examples/quick/scenegraph/textureinthread/main.qml
index 9108f0281d..2d61488e85 100644
--- a/examples/quick/scenegraph/textureinthread/main.qml
+++ b/examples/quick/scenegraph/textureinthread/main.qml
@@ -64,7 +64,7 @@ Item {
uniform highp vec2 pixelSize;
varying highp vec2 qt_TexCoord0;
void main() {
- highp vec2 tc = sign(sin(3.14152 * qt_TexCoord0 * pixelSize));
+ highp vec2 tc = sign(sin(3.14159265358979323846 * qt_TexCoord0 * pixelSize));
if (tc.x != tc.y)
gl_FragColor = color1;
else
diff --git a/examples/quick/scenegraph/twotextureproviders/main.qml b/examples/quick/scenegraph/twotextureproviders/main.qml
index af07f9badd..a6202b5a09 100644
--- a/examples/quick/scenegraph/twotextureproviders/main.qml
+++ b/examples/quick/scenegraph/twotextureproviders/main.qml
@@ -61,7 +61,7 @@ Item {
uniform highp vec2 pixelSize;
varying highp vec2 qt_TexCoord0;
void main() {
- highp vec2 tc = sign(sin(3.14152 * qt_TexCoord0 * pixelSize));
+ highp vec2 tc = sign(sin(3.14159265358979323846 * qt_TexCoord0 * pixelSize));
if (tc.x != tc.y)
gl_FragColor = color1;
else
diff --git a/src/quick/doc/snippets/qml/layerblending.qml b/src/quick/doc/snippets/qml/layerblending.qml
index a922f7896c..3e75a607a6 100644
--- a/src/quick/doc/snippets/qml/layerblending.qml
+++ b/src/quick/doc/snippets/qml/layerblending.qml
@@ -62,7 +62,7 @@ Item {
uniform highp vec2 pixelSize;
varying highp vec2 qt_TexCoord0;
void main() {
- highp vec2 tc = sign(sin(3.14152 * qt_TexCoord0 * pixelSize));
+ highp vec2 tc = sign(sin(3.14159265358979323846 * qt_TexCoord0 * pixelSize));
if (tc.x != tc.y)
gl_FragColor = color1;
else
diff --git a/src/quick/doc/snippets/qml/opacitymask.qml b/src/quick/doc/snippets/qml/opacitymask.qml
index beffb633d6..beb5cc6f67 100644
--- a/src/quick/doc/snippets/qml/opacitymask.qml
+++ b/src/quick/doc/snippets/qml/opacitymask.qml
@@ -63,7 +63,7 @@ Item {
uniform highp vec2 pixelSize;
varying highp vec2 qt_TexCoord0;
void main() {
- highp vec2 tc = sign(sin(3.14152 * qt_TexCoord0 * pixelSize));
+ highp vec2 tc = sign(sin(3.14159265358979323846 * qt_TexCoord0 * pixelSize));
if (tc.x != tc.y)
gl_FragColor = color1;
else
diff --git a/src/quick/util/qquicksvgparser.cpp b/src/quick/util/qquicksvgparser.cpp
index 310b600965..086c6d0b28 100644
--- a/src/quick/util/qquicksvgparser.cpp
+++ b/src/quick/util/qquicksvgparser.cpp
@@ -45,8 +45,6 @@
QT_BEGIN_NAMESPACE
-static const double Q_PI = 3.14159265358979323846; // pi
-
//copied from Qt SVG (qsvghandler.cpp).
Q_CORE_EXPORT double qstrtod(const char *s00, char const **se, bool *ok);
// '0' is 0x30 and '9' is 0x39
@@ -253,11 +251,11 @@ void QQuickSvgParser::pathArc(QPainterPath &path,
th_arc = th1 - th0;
if (th_arc < 0 && sweep_flag)
- th_arc += 2 * Q_PI;
+ th_arc += 2 * M_PI;
else if (th_arc > 0 && !sweep_flag)
- th_arc -= 2 * Q_PI;
+ th_arc -= 2 * M_PI;
- n_segs = qCeil(qAbs(th_arc / (Q_PI * 0.5 + 0.001)));
+ n_segs = qCeil(qAbs(th_arc / (M_PI * 0.5 + 0.001)));
for (i = 0; i < n_segs; i++) {
pathArcSegment(path, xc, yc,
diff --git a/tests/auto/qml/qqmlecmascript/data/dynamicString.qml b/tests/auto/qml/qqmlecmascript/data/dynamicString.qml
index 5693794c71..c704161eb5 100644
--- a/tests/auto/qml/qqmlecmascript/data/dynamicString.qml
+++ b/tests/auto/qml/qqmlecmascript/data/dynamicString.qml
@@ -11,6 +11,6 @@ MyTypeObject {
date.setHours(5);
date.setMinutes(30);
date.setSeconds(50);
- stringProperty = stringProperty.arg("Hello World").arg(false).arg(true).arg(100).arg(-100).arg(3.1415926).arg(Qt.formatDateTime(date, "yyyy-MM-dd hh::mm:ss"));
+ stringProperty = stringProperty.arg("Hello World").arg(false).arg(true).arg(100).arg(-100).arg(Math.PI).arg(Qt.formatDateTime(date, "yyyy-MM-dd hh::mm:ss"));
}
}
diff --git a/tests/manual/v4/typedarrays.js b/tests/manual/v4/typedarrays.js
index 8cf2b8c75a..f727df7185 100644
--- a/tests/manual/v4/typedarrays.js
+++ b/tests/manual/v4/typedarrays.js
@@ -670,12 +670,12 @@ function TestDataViewConstructor() {
/* This is wrong according to ecma 6 and should throw:
- var d4 = new DataView(ab, 1, 3.1415926);
+ var d4 = new DataView(ab, 1, Math.PI);
assertSame(ab, d4.buffer);
assertSame(1, d4.byteOffset);
assertSame(3, d4.byteLength);
*/
- assertThrows(function() { new DataView(ab, 3.1415926); }, RangeError);
+ assertThrows(function() { new DataView(ab, Math.PI); }, RangeError);
// error cases
assertThrows(function() { new DataView(ab, -1); }, RangeError);