[gimp] app: fix bounding box calculation for lines that are not axis-aligned



commit 870faec2102e6c58fccf7d34dce3bdaceb1e7338
Author: Michael Natterer <mitch gimp org>
Date:   Fri Sep 24 11:21:44 2010 +0200

    app: fix bounding box calculation for lines that are not axis-aligned
    
    because the square caps make these line extend up to
    sqrt(1.5^2 + 1.5^2) beyond the end points.

 app/display/gimpcanvasline.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/app/display/gimpcanvasline.c b/app/display/gimpcanvasline.c
index e64fd46..00689e1 100644
--- a/app/display/gimpcanvasline.c
+++ b/app/display/gimpcanvasline.c
@@ -232,10 +232,20 @@ gimp_canvas_line_get_extents (GimpCanvasItem   *item,
 
   gimp_canvas_line_transform (item, shell, &x1, &y1, &x2, &y2);
 
-  rectangle.x      = MIN (x1, x2) - 1.5;
-  rectangle.y      = MIN (y1, y2) - 1.5;
-  rectangle.width  = ABS (x2 - x1) + 3.0;
-  rectangle.height = ABS (y2 - y1) + 3.0;
+  if (x1 == x2 || y1 == y2)
+    {
+      rectangle.x      = MIN (x1, x2) - 1.5;
+      rectangle.y      = MIN (y1, y2) - 1.5;
+      rectangle.width  = ABS (x2 - x1) + 3.0;
+      rectangle.height = ABS (y2 - y1) + 3.0;
+    }
+  else
+    {
+      rectangle.x      = floor (MIN (x1, x2) - 2.5);
+      rectangle.y      = floor (MIN (y1, y2) - 2.5);
+      rectangle.width  = ceil (ABS (x2 - x1) + 5.0);
+      rectangle.height = ceil (ABS (y2 - y1) + 5.0);
+    }
 
   return gdk_region_rectangle (&rectangle);
 }



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