]> granicus.if.org Git - graphviz/commitdiff
Add -Ecurved=true to neatosplines.c
authorStephen North <north@research.att.com>
Tue, 18 Sep 2012 21:01:52 +0000 (17:01 -0400)
committerStephen North <north@research.att.com>
Tue, 18 Sep 2012 21:01:52 +0000 (17:01 -0400)
lib/neatogen/neatosplines.c

index 0b5b37d8a19d88c0a54fdb9d2a4d3060b3439c00..281ba04e41bf212aa8af979f1adddb6cb67374a3 100644 (file)
@@ -31,6 +31,9 @@ extern double drand48(void);
 
 extern void printvis(vconfig_t * cp);
 extern int in_poly(Ppoly_t argpoly, Ppoint_t q);
+static pointf get_centroid(Agraph_t *g);
+static void bend(pointf[],pointf);
+
 
 static boolean spline_merge(node_t * n)
 {
@@ -264,6 +267,7 @@ makeStraightEdge(graph_t * g, edge_t * e, int doPolyline)
     node_t *n = agtail(e);
     node_t *head = aghead(e);
     int e_cnt = ED_count(e);
+       int curved = mapbool(agget(e,"curved"));
     pointf perp;
     pointf del;
     edge_t *e0;
@@ -275,9 +279,10 @@ makeStraightEdge(graph_t * g, edge_t * e, int doPolyline)
     p = dumb[1] = dumb[0] = add_pointf(ND_coord(n), ED_tail_port(e).p);
     q = dumb[2] = dumb[3] = add_pointf(ND_coord(head), ED_head_port(e).p);
     if ((e_cnt == 1) || Concentrate) {
-       clip_and_install(e, aghead(e), dumb, 4, &sinfo);
-       addEdgeLabels(g, e, p, q);
-       return;
+                       if (curved) bend(dumb,get_centroid(g));
+                       clip_and_install(e, aghead(e), dumb, 4, &sinfo);
+                       addEdgeLabels(g, e, p, q);
+                       return;
     }
 
     e0 = e;
@@ -1032,3 +1037,49 @@ void neato_set_aspect(graph_t * g)
     }
 }
 
+static pointf get_centroid(Agraph_t *g)
+{
+    int     cnt = 0;
+    static pointf   sum = {0.0, 0.0};
+    static Agraph_t *save;
+    Agnode_t *n;
+
+sum.x = (GD_bb(g).LL.x + GD_bb(g).UR.x) / 2.0;
+sum.y = (GD_bb(g).LL.y + GD_bb(g).UR.y) / 2.0;
+return sum;
+
+    if (save == g) return sum;
+    save = g;
+    for (n = agfstnode(g); n; n = agnxtnode(g,n)) {
+        sum.x += ND_pos(n)[0];
+        sum.y += ND_pos(n)[1];
+        cnt++;
+    }
+    sum.x = sum.x / cnt;
+    sum.y = sum.y / cnt;
+    return sum;
+}
+
+static void bend(pointf spl[4], pointf centroid)
+{
+    pointf  midpt,a;
+    double  r;
+    double  dist,dx,dy;
+
+    midpt.x = (spl[0].x + spl[3].x)/2.0;
+    midpt.y = (spl[0].y + spl[3].y)/2.0;
+    dx = (spl[3].x - spl[0].x);
+    dy = (spl[3].y - spl[0].y);
+    dist = sqrt(dx*dx + dy*dy);
+    r = dist/5.0;
+    {
+        double vX = centroid.x - midpt.x;
+        double vY = centroid.y - midpt.y;
+        double magV = sqrt(vX*vX + vY*vY);
+        a.x = midpt.x - vX / magV * r;      /* + would be closest point */
+        a.y = midpt.y - vY / magV * r;
+    }
+    /* this can be improved */
+    spl[1].x = spl[2].x = a.x;
+    spl[1].y = spl[2].y = a.y;
+}