diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-10-29 15:46:20 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-10-29 15:46:20 +0200 |
commit | 224ab310a2866b8aed1fca8882a25f7a86314f0c (patch) | |
tree | 7500acb88e327d5328e97c4bfd75268382cb06f6 | |
parent | bdffe51bade6b35e46bb5f78cb3be77c8310e4c7 (diff) |
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.
-rw-r--r-- | spline-widget/spline-widget.cpp | 13 |
1 files 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) |