From c587590ddb8a4f76a134018155588e2470992600 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 5 Sep 2016 12:40:31 +0200 Subject: spline-widget: allow for non-integral snap values --- spline-widget/spline-widget.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'spline-widget/spline-widget.cpp') diff --git a/spline-widget/spline-widget.cpp b/spline-widget/spline-widget.cpp index 6e3a95b3..ff18a2f9 100644 --- a/spline-widget/spline-widget.cpp +++ b/spline-widget/spline-widget.cpp @@ -19,9 +19,9 @@ spline_widget::spline_widget(QWidget *parent) : QWidget(parent), _config(nullptr), - moving_control_point_idx(-1), snap_x(0), snap_y(0), + moving_control_point_idx(-1), _draw_function(true), _preview_only(false) { @@ -472,10 +472,12 @@ QPointF spline_widget::pixel_coord_to_point(const QPointF& point) qreal x = round((point.x() - pixel_bounds.x()) / c.x()); qreal y = round((pixel_bounds.height() - point.y() + pixel_bounds.y()) / c.y()); + const volatile int c = 8192; + if (snap_x > 0) - x -= int(x) % snap_x; + x = std::nearbyint(x * c - (int(x * c) % int(snap_x * c))) / double(c); if (snap_y > 0) - y -= int(y) % snap_y; + y = std::nearbyint(y * c - (int(y * c) % int(snap_y * c))) / double(c); if (x < 0) x = 0; -- cgit v1.2.3