From 47c9a5f164a32b9f1859e06d2de55d5c4362a023 Mon Sep 17 00:00:00 2001 From: Jonathan Wilkes <jon.w.wilkes@gmail.com> Date: Fri, 30 Oct 2020 15:38:48 -0400 Subject: [PATCH] Simplify snapping algorithms: removing redundant floor call and unneeded parens --- pd/src/g_editor.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pd/src/g_editor.c b/pd/src/g_editor.c index 8692c76d3..21cd923bb 100644 --- a/pd/src/g_editor.c +++ b/pd/src/g_editor.c @@ -5818,19 +5818,18 @@ static void canvas_snap_to_grid(t_canvas *x, int xwas, int ywas, int xnew, /* First, get the distance the selection should be displaced in order to align the anchor object with a grid line. */ - snap_dx = floor((obx + (gsize / 2)) / gsize) * gsize - obx; - - snap_dy = floor((oby + (gsize / 2)) / gsize) * gsize - oby; - obx = floor(obx / gsize) * gsize; - oby = floor(oby / gsize) * gsize; + snap_dx = ((obx + gsize / 2) / gsize) * gsize - obx; + snap_dy = ((oby + gsize / 2) / gsize) * gsize - oby; + obx = obx / gsize * gsize; + oby = oby / gsize * gsize; anchor_xoff = xnew - obx; anchor_yoff = ynew - oby; snap_got_anchor = 1; } - *dx = floor((xnew - anchor_xoff + gsize / 2) / gsize) * gsize - - floor((xwas - anchor_xoff + gsize / 2) / gsize) * gsize + snap_dx; - *dy = floor((ynew - anchor_yoff + gsize / 2) / gsize) * gsize - - floor((ywas - anchor_yoff + gsize / 2) / gsize) * gsize + snap_dy; + *dx = ((xnew - anchor_xoff + gsize / 2) / gsize) * gsize - + ((xwas - anchor_xoff + gsize / 2) / gsize) * gsize + snap_dx; + *dy = ((ynew - anchor_yoff + gsize / 2) / gsize) * gsize - + ((ywas - anchor_yoff + gsize / 2) / gsize) * gsize + snap_dy; } static void delay_move(t_canvas *x) -- GitLab