From ba792163ba0ea5a013f7c6d7fe8530661e22721e 2013-03-21 08:05:30 From: Miikka Heikkinen Date: 2013-03-21 08:05:30 Subject: [PATCH] Fix int-qreal rounding errors in axislayout calculations Task-number: QTRD-1930 Reviewed-by: Mika Salmela --- diff --git a/src/axis/barcategoryaxis/chartbarcategoryaxisx.cpp b/src/axis/barcategoryaxis/chartbarcategoryaxisx.cpp index b4b296e..8d86b12 100644 --- a/src/axis/barcategoryaxis/chartbarcategoryaxisx.cpp +++ b/src/axis/barcategoryaxis/chartbarcategoryaxisx.cpp @@ -60,7 +60,7 @@ QVector ChartBarCategoryAxisX::calculateLayout() const points.resize(count + 2); for (int i = 0; i < count + 2; ++i) - points[i] = offset + (i * delta) + gridRect.left(); + points[i] = offset + (qreal(i) * delta) + gridRect.left(); return points; } diff --git a/src/axis/barcategoryaxis/chartbarcategoryaxisy.cpp b/src/axis/barcategoryaxis/chartbarcategoryaxisy.cpp index e35aea6..0ca8116 100644 --- a/src/axis/barcategoryaxis/chartbarcategoryaxisy.cpp +++ b/src/axis/barcategoryaxis/chartbarcategoryaxisy.cpp @@ -60,7 +60,7 @@ QVector ChartBarCategoryAxisY::calculateLayout() const points.resize(count + 2); for (int i = 0; i < count + 2; ++i) - points[i] = gridRect.bottom() - (i * delta) - offset; + points[i] = gridRect.bottom() - (qreal(i) * delta) - offset; return points; } diff --git a/src/axis/datetimeaxis/chartdatetimeaxisx.cpp b/src/axis/datetimeaxis/chartdatetimeaxisx.cpp index 591daf9..39fc3ba 100644 --- a/src/axis/datetimeaxis/chartdatetimeaxisx.cpp +++ b/src/axis/datetimeaxis/chartdatetimeaxisx.cpp @@ -50,11 +50,9 @@ QVector ChartDateTimeAxisX::calculateLayout() const QVector points; points.resize(tickCount); const QRectF &gridRect = gridGeometry(); - const qreal deltaX = gridRect.width() / (tickCount - 1); - for (int i = 0; i < tickCount; ++i) { - int x = i * deltaX + gridRect.left(); - points[i] = x; - } + const qreal deltaX = gridRect.width() / (qreal(tickCount) - 1.0); + for (int i = 0; i < tickCount; ++i) + points[i] = qreal(i) * deltaX + gridRect.left(); return points; } diff --git a/src/axis/datetimeaxis/chartdatetimeaxisy.cpp b/src/axis/datetimeaxis/chartdatetimeaxisy.cpp index 8b27d1c..a534617 100644 --- a/src/axis/datetimeaxis/chartdatetimeaxisy.cpp +++ b/src/axis/datetimeaxis/chartdatetimeaxisy.cpp @@ -50,11 +50,9 @@ QVector ChartDateTimeAxisY::calculateLayout() const QVector points; points.resize(tickCount); const QRectF &gridRect = gridGeometry(); - const qreal deltaY = gridRect.height() / (tickCount - 1); - for (int i = 0; i < tickCount; ++i) { - int y = i * -deltaY + gridRect.bottom(); - points[i] = y; - } + const qreal deltaY = gridRect.height() / (qreal(tickCount) - 1.0); + for (int i = 0; i < tickCount; ++i) + points[i] = qreal(i) * -deltaY + gridRect.bottom(); return points; } diff --git a/src/axis/valueaxis/chartvalueaxisx.cpp b/src/axis/valueaxis/chartvalueaxisx.cpp index ccf4925..a084ac3 100644 --- a/src/axis/valueaxis/chartvalueaxisx.cpp +++ b/src/axis/valueaxis/chartvalueaxisx.cpp @@ -53,10 +53,9 @@ QVector ChartValueAxisX::calculateLayout() const points.resize(tickCount); const QRectF &gridRect = gridGeometry(); - const qreal deltaX = gridRect.width() / (tickCount - 1); - for (int i = 0; i < tickCount; ++i) { - points[i] = i * deltaX + gridRect.left(); - } + const qreal deltaX = gridRect.width() / (qreal(tickCount) - 1.0); + for (int i = 0; i < tickCount; ++i) + points[i] = qreal(i) * deltaX + gridRect.left(); return points; } diff --git a/src/axis/valueaxis/chartvalueaxisy.cpp b/src/axis/valueaxis/chartvalueaxisy.cpp index 848d4ae..14b2d20 100644 --- a/src/axis/valueaxis/chartvalueaxisy.cpp +++ b/src/axis/valueaxis/chartvalueaxisy.cpp @@ -53,10 +53,9 @@ QVector ChartValueAxisY::calculateLayout() const const QRectF &gridRect = gridGeometry(); - const qreal deltaY = gridRect.height() / (tickCount - 1); - for (int i = 0; i < tickCount; ++i) { - points[i] = i * -deltaY + gridRect.bottom(); - } + const qreal deltaY = gridRect.height() / (qreal(tickCount) - 1.0); + for (int i = 0; i < tickCount; ++i) + points[i] = qreal(i) * -deltaY + gridRect.bottom(); return points; }