From 224ab310a2866b8aed1fca8882a25f7a86314f0c Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 29 Oct 2016 15:46:20 +0200 Subject: spline-widget: revert last commit In the last line of the blocks we're reducing the precision to reduce rounding errors. It's actually proper to use round rather than truncate here. --- spline-widget/spline-widget.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/spline-widget/spline-widget.cpp b/spline-widget/spline-widget.cpp index 762c63d7..47ae6fdd 100644 --- a/spline-widget/spline-widget.cpp +++ b/spline-widget/spline-widget.cpp @@ -543,17 +543,18 @@ QPointF spline_widget::pixel_coord_to_point(const QPoint& point) if (snap_x > 0) { - x += snap_x / 2.; + x += snap_x * .5; x -= std::fmod(x, snap_x); - const volatile int x_ = int(x * c); - x = x_ / double(c); + // truncate after few decimal places to reduce rounding errors. + // round upward to nearest. + x = int(x * c + .5/c) / double(c); } if (snap_y > 0) { - y += snap_y / 2.; + y += snap_y * .5; y -= std::fmod(y, snap_y); - const volatile int y_ = int(y * c); - y = y_ / double(c); + // idem + y = int(y * c + .5/c) / double(c); } if (x < 0) -- cgit v1.2.3