[dia] uml: fix autogap for package shapes



commit 6fa3cd16dfa977c8411ace002b793ac8c33c56e3
Author: Hans Breuer <hans breuer org>
Date:   Wed Oct 5 21:54:52 2011 +0200

    uml: fix autogap for package shapes
    
    The autogap calculation depends on the distance_from() method
    to find the edge of the shape. To be more closely use two
    rectangles distance rather than just the bounding box.

 objects/UML/large_package.c |   15 +++++++++++++--
 objects/UML/small_package.c |   15 +++++++++++++--
 2 files changed, 26 insertions(+), 4 deletions(-)
---
diff --git a/objects/UML/large_package.c b/objects/UML/large_package.c
index 918314a..7284639 100644
--- a/objects/UML/large_package.c
+++ b/objects/UML/large_package.c
@@ -186,8 +186,19 @@ largepackage_set_props(LargePackage *largepackage, GPtrArray *props)
 static real
 largepackage_distance_from(LargePackage *pkg, Point *point)
 {
-  DiaObject *obj = &pkg->element.object;
-  return distance_rectangle_point(&obj->bounding_box, point);
+  /* need to calculate the distance from both rects to make the autogap
+   * use the right boundaries
+   */
+  Element *elem = &pkg->element;
+  real x = elem->corner.x;
+  real y = elem->corner.y;
+  Rectangle r1 = { x, y, x + elem->width, y + elem->height };
+  Rectangle r2 = { x, y - pkg->topheight, x + pkg->topwidth, y };
+  real d1 = distance_rectangle_point(&r1, point);
+  real d2 = distance_rectangle_point(&r2, point);
+
+  /* always return  the value closest to zero or below */
+  return MIN(d1, d2);
 }
 
 static void
diff --git a/objects/UML/small_package.c b/objects/UML/small_package.c
index 119e06e..1a7193d 100644
--- a/objects/UML/small_package.c
+++ b/objects/UML/small_package.c
@@ -183,8 +183,19 @@ smallpackage_set_props(SmallPackage *smallpackage,
 static real
 smallpackage_distance_from(SmallPackage *pkg, Point *point)
 {
-  DiaObject *obj = &pkg->element.object;
-  return distance_rectangle_point(&obj->bounding_box, point);
+  /* need to calculate the distance from both rects to make the autogap
+   * use the right boundaries
+   */
+  Element *elem = &pkg->element;
+  real x = elem->corner.x;
+  real y = elem->corner.y;
+  Rectangle r1 = { x, y, x + elem->width, y + elem->height };
+  Rectangle r2 = { x, y - SMALLPACKAGE_TOPHEIGHT, x + SMALLPACKAGE_TOPWIDTH, y };
+  real d1 = distance_rectangle_point(&r1, point);
+  real d2 = distance_rectangle_point(&r2, point);
+
+  /* always return  the value closest to zero or below */
+  return MIN(d1, d2);
 }
 
 static void



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