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)
{
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;
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;
}
}
+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;
+}