[gimp] app: fix drawing artifacts in GimpCanvasRectangle



commit b75b7de0647d1ab63e4b1465dcdcbfb2cea86b0a
Author: Michael Natterer <mitch gimp org>
Date:   Sun Apr 10 03:46:02 2011 +0200

    app: fix drawing artifacts in GimpCanvasRectangle
    
    The width/height returned by gimp_canvas_rectangle_transform() were
    off-by-one if the rectangle's width/height were exactly 0.0 and its
    x/y exact integers, causing too much drawing and/or too little
    invalidation.

 app/display/gimpcanvasrectangle.c |   31 +++++++++++++++++++------------
 1 files changed, 19 insertions(+), 12 deletions(-)
---
diff --git a/app/display/gimpcanvasrectangle.c b/app/display/gimpcanvasrectangle.c
index 114eb63..6381101 100644
--- a/app/display/gimpcanvasrectangle.c
+++ b/app/display/gimpcanvasrectangle.c
@@ -206,36 +206,43 @@ gimp_canvas_rectangle_transform (GimpCanvasItem   *item,
                                  gdouble          *h)
 {
   GimpCanvasRectanglePrivate *private = GET_PRIVATE (item);
+  gdouble                     x1, y1;
+  gdouble                     x2, y2;
 
   gimp_display_shell_transform_xy_f (shell,
                                      MIN (private->x,
                                           private->x + private->width),
                                      MIN (private->y,
                                           private->y + private->height),
-                                     x, y);
+                                     &x1, &y1);
   gimp_display_shell_transform_xy_f (shell,
                                      MAX (private->x,
                                           private->x + private->width),
                                      MAX (private->y,
                                           private->y + private->height),
-                                     w, h);
+                                     &x2, &y2);
 
-  *w -= *x;
-  *h -= *y;
+  x1 = floor (x1);
+  y1 = floor (y1);
+  x2 = ceil (x2);
+  y2 = ceil (y2);
 
   if (private->filled)
     {
-      *x = floor (*x);
-      *y = floor (*y);
-      *w = ceil (*w);
-      *h = ceil (*h);
+      *x = x1;
+      *y = y1;
+      *w = x2 - x1;
+      *h = y2 - y1;
     }
   else
     {
-      *x = floor (*x) + 0.5;
-      *y = floor (*y) + 0.5;
-      *w = ceil (*w) - 1.0;
-      *h = ceil (*h) - 1.0;
+      *x = x1 + 0.5;
+      *y = y1 + 0.5;
+      *w = x2 - 0.5 - *x;
+      *h = y2 - 0.5 - *y;
+
+      *w = MAX (0.0, *w);
+      *h = MAX (0.0, *h);
     }
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]