[dia] Bug 733344 - Zigzagline has wrong arrow head if placed without the "zag" part



commit fb12c9f22a4cc265fe8a77e1c11cc34c7a3014d1
Author: Hans Breuer <hans breuer org>
Date:   Sun Aug 3 14:50:57 2014 +0200

    Bug 733344 - Zigzagline has wrong arrow head if placed without the "zag" part
    
    arrows.c: don't move arrow if it would change direction
    autoroute.c: distribute points even for straight lines to have room for
    arrow movement (non zero line length)

 lib/arrows.c    |   44 ++++++++++++++++++++++++++++++--------------
 lib/autoroute.c |    5 ++++-
 2 files changed, 34 insertions(+), 15 deletions(-)
---
diff --git a/lib/arrows.c b/lib/arrows.c
index 8b345da..8df1580 100644
--- a/lib/arrows.c
+++ b/lib/arrows.c
@@ -81,6 +81,7 @@ calculate_arrow_point(const Arrow *arrow, const Point *to, const Point *from,
   real add_len;
   real angle;
   Point tmp;
+  real dist;
   ArrowType arrow_type = arrow->type;
   /* Otherwise line is drawn through arrow
    * head for some hollow arrow heads
@@ -88,6 +89,7 @@ calculate_arrow_point(const Arrow *arrow, const Point *to, const Point *from,
   if (linewidth == 0.0)
     linewidth = 0.0001;
 
+  dist = distance_point_point (from, to);
   /** Since some of the calculations are sensitive to small values,
    * ignore small arrowheads.  They won't be visible anyway.
    */
@@ -96,6 +98,9 @@ calculate_arrow_point(const Arrow *arrow, const Point *to, const Point *from,
     arrow_type = ARROW_NONE;
   }
 
+  /* default to non-moving arrow */
+  move_arrow->x = 0.0;
+  move_arrow->y = 0.0;
   /* First, we move the arrow head backwards.
    * This in most cases just accounts for the linewidth of the arrow.
    * In pointy arrows, this means we must look at the angle of the
@@ -108,18 +113,23 @@ calculate_arrow_point(const Arrow *arrow, const Point *to, const Point *from,
   case ARROW_FILLED_CONCAVE:
   case ARROW_BLANKED_CONCAVE:
   case ARROW_DOUBLE_HOLLOW_TRIANGLE:
-    if (arrow->width < 0.0000001) return;
-    angle = atan(arrow->length/(arrow->width/2));
+    if (arrow->width < 0.0000001)
+      angle = 75*2*G_PI/360.0; /* -> add_len=0 */
+    else
+      angle = atan(arrow->length/(arrow->width/2));
     if (angle < 75*2*G_PI/360.0) {
       add_len = .5*linewidth/cos(angle);
     } else {
       add_len = 0;
     }
 
-    *move_arrow = *to;
-    point_sub(move_arrow, from);
-    point_normalize(move_arrow);    
-    point_scale(move_arrow, add_len);
+    /* don't move arrow if it would change direction */
+    if (fabs(add_len) < dist) {
+      *move_arrow = *to;
+      point_sub(move_arrow, from);
+      point_normalize(move_arrow);    
+      point_scale(move_arrow, add_len);
+    }
     break;
   case ARROW_HALF_HEAD:
     if (arrow->width < 0.0000001) return;
@@ -130,10 +140,13 @@ calculate_arrow_point(const Arrow *arrow, const Point *to, const Point *from,
       add_len = 0;
     }
 
-    *move_arrow = *to;
-    point_sub(move_arrow, from);
-    point_normalize(move_arrow);    
-    point_scale(move_arrow, add_len);
+    /* don't move arrow if it would change direction */
+    if (fabs(add_len) < dist) {
+      *move_arrow = *to;
+      point_sub(move_arrow, from);
+      point_normalize(move_arrow);    
+      point_scale(move_arrow, add_len);
+    }
     break;
   case ARROW_FILLED_TRIANGLE:
   case ARROW_HOLLOW_ELLIPSE:
@@ -143,10 +156,13 @@ calculate_arrow_point(const Arrow *arrow, const Point *to, const Point *from,
   case ARROW_BLANKED_BOX:
     add_len = .5*linewidth;
 
-    *move_arrow = *to;
-    point_sub(move_arrow, from);
-    point_normalize(move_arrow);
-    point_scale(move_arrow, add_len);
+    /* don't move arrow if it would change direction */
+    if (fabs(add_len) < dist) {
+      *move_arrow = *to;
+      point_sub(move_arrow, from);
+      point_normalize(move_arrow);
+      point_scale(move_arrow, add_len);
+    }
     break;
   case ARROW_ONE_EXACTLY:
   case ARROW_ONE_OR_NONE:
diff --git a/lib/autoroute.c b/lib/autoroute.c
index 0dbc6ae..d64834d 100644
--- a/lib/autoroute.c
+++ b/lib/autoroute.c
@@ -351,8 +351,9 @@ autoroute_layout_parallel(Point *to, guint *num_points, Point **points)
     *num_points = 4;
     ps = g_new0(Point, *num_points);
     /* points[0] is 0,0 */
+    ps[1].x = to->x/2;
     ps[1].y = top;
-    ps[2].x = to->x;
+    ps[2].x = to->x/2;
     ps[2].y = top;
     ps[3] = *to;
   } else if (to->y > 0) { /* Close together, end below */
@@ -496,6 +497,8 @@ autoroute_layout_opposite(Point *to, guint *num_points, Point **points)
     ps = g_new0(Point, *num_points);
     if (fabs(to->x) < 0.00000001) {
       ps[2] = ps[3] = *to;
+      /* distribute y */
+      ps[1].y = ps[2].y = to->y / 2;
       *points = ps;
       return length_badness(fabs(to->y))+2*EXTRA_SEGMENT_BADNESS;
     } else {


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