summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2017-01-12 18:02:46 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2017-06-14 08:21:17 +0000
commit94f565a00cbc8d779251355cdb94704277711da7 (patch)
tree477bc020099d5dc60f1d0f7f5398afbda830e48e /tests
parent81d0c42c7e4b781365556e1e8d1c8de1e592ae47 (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: I80c81444c1867f8f0c07f192fa68de933f48bbc4 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/manual/chartwidgettest/mainwidget.cpp6
-rw-r--r--tests/manual/openglseriestest/datasource.cpp2
-rw-r--r--tests/manual/wavechart/wavechart.cpp9
3 files changed, 8 insertions, 9 deletions
diff --git a/tests/manual/chartwidgettest/mainwidget.cpp b/tests/manual/chartwidgettest/mainwidget.cpp
index 79530bb7..c471d0bc 100644
--- a/tests/manual/chartwidgettest/mainwidget.cpp
+++ b/tests/manual/chartwidgettest/mainwidget.cpp
@@ -48,7 +48,7 @@
#include <QtWidgets/QLabel>
#include <QtWidgets/QSpacerItem>
#include <QtWidgets/QMessageBox>
-#include <cmath>
+#include <qmath.h>
#include <QtCore/QDebug>
#include <QtGui/QStandardItemModel>
#include <QtCharts/QBarCategoryAxis>
@@ -216,9 +216,9 @@ QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QStr
QList <qreal> newColumn;
for (int i(0); i < rowCount; i++) {
if (dataCharacteristics == "Sin") {
- newColumn.append(std::abs(sin(3.14159265358979 / 50 * i) * 100));
+ newColumn.append(std::abs(sin(M_PI / 50 * i) * 100));
} else if (dataCharacteristics == "Sin + random") {
- newColumn.append(std::abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
+ newColumn.append(std::abs(sin(M_PI / 50 * i) * 100) + (rand() % 5));
} else if (dataCharacteristics == "Random") {
newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX);
} else if (dataCharacteristics == "Linear") {
diff --git a/tests/manual/openglseriestest/datasource.cpp b/tests/manual/openglseriestest/datasource.cpp
index 459b9f01..4017676b 100644
--- a/tests/manual/openglseriestest/datasource.cpp
+++ b/tests/manual/openglseriestest/datasource.cpp
@@ -117,7 +117,7 @@ void DataSource::generateData(int seriesIndex, int rowCount, int colCount)
qreal x(0);
qreal y(0);
// data with sin + random component
- y = height + (yMultiplier * qSin(3.14159265358979 / 50 * j)
+ y = height + (yMultiplier * qSin(M_PI / 50 * j)
+ (yMultiplier * (qreal) rand() / (qreal) RAND_MAX));
// 0.000001 added to make values logaxis compatible
x = 0.000001 + 20.0 * (qreal(j) / qreal(colCount)) + (xAdjustment * qreal(i));
diff --git a/tests/manual/wavechart/wavechart.cpp b/tests/manual/wavechart/wavechart.cpp
index d2995826..72e5e737 100644
--- a/tests/manual/wavechart/wavechart.cpp
+++ b/tests/manual/wavechart/wavechart.cpp
@@ -28,18 +28,17 @@
****************************************************************************/
#include "wavechart.h"
-#include <cmath>
+#include <qmath.h>
QT_CHARTS_USE_NAMESPACE
-#define PI 3.14159265358979
static const int numPoints =100;
WaveChart::WaveChart(QChart* chart, QWidget* parent) :
QChartView(chart, parent),
m_series(new QLineSeries()),
m_wave(0),
- m_step(2 * PI / numPoints)
+ m_step(2 * M_PI / numPoints)
{
QPen blue(Qt::blue);
blue.setWidth(3);
@@ -52,7 +51,7 @@ WaveChart::WaveChart(QChart* chart, QWidget* parent) :
int fluctuate = 100;
- for (qreal x = 0; x <= 2 * PI; x += m_step) {
+ for (qreal x = 0; x <= 2 * M_PI; x += m_step) {
m_series->append(x, fabs(sin(x) * fluctuate));
}
@@ -69,7 +68,7 @@ void WaveChart::update()
int fluctuate;
const QList<QPointF>& points = m_series->points();
- for (qreal i = 0, x = 0; x <= 2 * PI; x += m_step, i++) {
+ for (qreal i = 0, x = 0; x <= 2 * M_PI; x += m_step, i++) {
fluctuate = qrand() % 100;
m_series->replace(x,points[i].y(),x,fabs(sin(x) * fluctuate));