diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2013-11-25 12:19:18 +0200 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2013-11-25 14:22:32 +0200 |
commit | e029d0ea1d486dd3dbbfa4519a2125da202f22e4 (patch) | |
tree | fc9f87f637a9adcca5a555355d96717d43eddc77 /tests/surfacetest/graphmodifier.cpp | |
parent | e7e01ec065d3874d28e9e28d213783c4275d8813 (diff) |
Change qreals to floats
+ Fix default axes to sensible
+ Fix some rounding errors in surface creation
Task-number: QTRD-2622
Change-Id: I44450efc1e77ac8d8dbefc75814345949b8fb1f1
Reviewed-by: Mika Salmela <mika.salmela@digia.com>
Diffstat (limited to 'tests/surfacetest/graphmodifier.cpp')
-rw-r--r-- | tests/surfacetest/graphmodifier.cpp | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/tests/surfacetest/graphmodifier.cpp b/tests/surfacetest/graphmodifier.cpp index 568d57c9..5a367c7a 100644 --- a/tests/surfacetest/graphmodifier.cpp +++ b/tests/surfacetest/graphmodifier.cpp @@ -30,7 +30,7 @@ QT_DATAVISUALIZATION_USE_NAMESPACE //#define JITTER_PLANE -#define WONKY_PLANE +//#define WONKY_PLANE GraphModifier::GraphModifier(Q3DSurface *graph) : m_graph(graph), @@ -91,10 +91,10 @@ void GraphModifier::toggleSqrtSin(bool enable) if (enable) { qDebug() << "Create Sqrt&Sin surface, (" << m_xCount << ", " << m_zCount << ")"; - float minX = -10.0; - float maxX = 10.0; - float minZ = -10.0; - float maxZ = 10.0; + float minX = -10.0f; + float maxX = 10.0f; + float minZ = -10.0f; + float maxZ = 10.0f; float stepX = (maxX - minX) / float(m_xCount - 1); float stepZ = (maxZ - minZ) / float(m_zCount - 1); @@ -102,9 +102,11 @@ void GraphModifier::toggleSqrtSin(bool enable) dataArray->reserve(m_zCount); for (float i = 0; i < m_zCount; i++) { QSurfaceDataRow *newRow = new QSurfaceDataRow(m_xCount); + // Keep values within range bounds, since just adding step can cause minor drift due + // to the rounding errors. + float z = qMin(maxZ, (i * stepZ + minZ)); for (float j = 0; j < m_xCount; j++) { - float x = j * stepX + minX; - float z = i * stepZ + minZ; + float x = qMin(maxX, (j * stepX + minX)); float R = qSqrt(x * x + z * z) + 0.01f; float y = (qSin(R) / R + 0.24f) * 1.61f + 1.0f; (*newRow)[j].setPosition(QVector3D(x, y, z)); @@ -139,10 +141,10 @@ void GraphModifier::togglePlane(bool enable) m_graph->axisZ()->setLabelFormat("%.2f"); m_planeArray->reserve(m_zCount); - float minX = -10.0; - float maxX = 20.0; - float minZ = -10.0; - float maxZ = 10.0; + float minX = -10.0f; + float maxX = 20.0f; + float minZ = -10.0f; + float maxZ = 10.0f; float stepX = (maxX - minX) / float(m_xCount - 1); float stepZ = (maxZ - minZ) / float(m_zCount - 1); #ifdef WONKY_PLANE @@ -172,8 +174,18 @@ void GraphModifier::togglePlane(bool enable) #else for (float i = 0; i < m_zCount; i++) { QSurfaceDataRow *newRow = new QSurfaceDataRow(m_xCount); - for (float j = 0; j < m_xCount; j++) - (*newRow)[j].setPosition(QVector3D(j * stepX + minX, -0.04f, i * stepZ + minZ)); + // Keep values within range bounds, since just adding step can cause minor drift due + // to the rounding errors. + float zVal; + if (i == (m_zCount - 1)) + zVal = maxZ; + else + zVal = i * stepZ + minZ; + + float j = 0; + for (; j < m_xCount - 1; j++) + (*newRow)[j].setPosition(QVector3D(j * stepX + minX, -0.04f, zVal)); + (*newRow)[j].setPosition(QVector3D(maxX, -0.04f, zVal)); *m_planeArray << newRow; } @@ -365,7 +377,7 @@ void GraphModifier::timeout() m_theSeries->dataProxy()->resetArray(m_planeArray); } -void GraphModifier::resetArrayAndSliders(QSurfaceDataArray *array, qreal minZ, qreal maxZ, qreal minX, qreal maxX) +void GraphModifier::resetArrayAndSliders(QSurfaceDataArray *array, float minZ, float maxZ, float minX, float maxX) { m_axisMinSliderX->setValue(minX); m_axisMinSliderZ->setValue(minZ); |