From 272ee133ed74b20d54431b0cfd41e0600b02478b Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Sun, 18 May 2003 21:41:53 +0000 Subject: [PATCH] snap correctly to the bottom and right sides of the rectangle. Also snap 2003-05-18 Michael Natterer * app/core/gimpimage-guides.c (gimp_image_snap_rectangle): snap correctly to the bottom and right sides of the rectangle. Also snap to the closer guide if we snap twice on one axis. Fixes bug #113233. All snapping functions: use ROUND() instead of truncating the double coords. --- ChangeLog | 10 ++++++++ app/core/gimpimage-guides.c | 49 +++++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index df09918ee4..225a23c806 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2003-05-18 Michael Natterer + + * app/core/gimpimage-guides.c (gimp_image_snap_rectangle): snap + correctly to the bottom and right sides of the rectangle. Also + snap to the closer guide if we snap twice on one axis. + Fixes bug #113233. + + All snapping functions: use ROUND() instead of truncating the + double coords. + 2003-05-18 Michael Natterer * app/display/gimpdisplayshell-callbacks.c diff --git a/app/core/gimpimage-guides.c b/app/core/gimpimage-guides.c index a25eb67667..66037ff00c 100644 --- a/app/core/gimpimage-guides.c +++ b/app/core/gimpimage-guides.c @@ -231,7 +231,7 @@ gimp_image_snap_x (GimpImage *gimage, g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE); g_return_val_if_fail (tx != NULL, FALSE); - *tx = x; + *tx = ROUND (x); if (x < 0 || x >= gimage->width) return FALSE; @@ -273,7 +273,7 @@ gimp_image_snap_y (GimpImage *gimage, g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE); g_return_val_if_fail (ty != NULL, FALSE); - *ty = y; + *ty = ROUND (y); if (y < 0 || y >= gimage->height) return FALSE; @@ -318,8 +318,8 @@ gimp_image_snap_point (GimpImage *gimage, g_return_val_if_fail (tx != NULL, FALSE); g_return_val_if_fail (ty != NULL, FALSE); - *tx = x; - *ty = y; + *tx = ROUND (x); + *ty = ROUND (y); if (x < 0 || x >= gimage->width || y < 0 || y >= gimage->height) @@ -386,28 +386,39 @@ gimp_image_snap_rectangle (GimpImage *gimage, g_return_val_if_fail (tx1 != NULL, FALSE); g_return_val_if_fail (ty1 != NULL, FALSE); - *tx1 = x1; - *ty1 = y1; + *tx1 = ROUND (x1); + *ty1 = ROUND (y1); snap1 = gimp_image_snap_x (gimage, x1, &nx1); snap2 = gimp_image_snap_x (gimage, x2, &nx2); snap3 = gimp_image_snap_y (gimage, y1, &ny1); snap4 = gimp_image_snap_y (gimage, y2, &ny2); - if (snap1 || snap2 || snap3 || snap4) + if (snap1 && snap2) { - if (x1 != nx1) - *tx1 = nx1; - else if (x2 != nx2) - *tx1 = x1 + (nx2 - x2); - - if (y1 != ny1) - *ty1 = ny1; - else if (y2 != ny2) - *ty1 = y1 + (ny2 - y2); - - return TRUE; + if (ABS (x1 - nx1) > ABS (x2 - nx2)) + snap1 = FALSE; + else + snap2 = FALSE; } - return FALSE; + if (snap1) + *tx1 = nx1; + else if (snap2) + *tx1 = ROUND (x1 + (nx2 - x2)); + + if (snap3 && snap4) + { + if (ABS (y1 - ny1) > ABS (y2 - ny2)) + snap3 = FALSE; + else + snap4 = FALSE; + } + + if (snap3) + *ty1 = ny1; + else if (snap4) + *ty1 = ROUND (y1 + (ny2 - y2)); + + return (snap1 || snap2 || snap3 || snap4); }