Debian Codegraph @

cmd/gvpr/lib/scale

raw
1 /* finds node n with root attribute
2 * finds distance minr of closest node
3 * the layout is then scaled out from n so that
4 * a node is put on the smallest circle of radius x*minr
5 * containing n
6 */
7 BEG_G {
8 node_t ctr;
9 int cx, cy;
10 int x, y;
11 double delx, dely;
12 int newx, newy;
13 node_t n;
14 edge_t e;
15 int i, sc, d, mind = -1;
16 double fact, newr, ang, minr;
17
18 ctr = node($,aget($,"root"));
19 sscanf (ctr.pos, "%d,%d", &cx, &cy);
20 for (e = fstedge(ctr); e; e = nxtedge(e, ctr)) {
21 if (e.head == ctr) n = e.tail;
22 else n = e.head;
23 sscanf (n.pos, "%d,%d", &x, &y);
24 d = (x-cx)*(x-cx) + (y-cy)*(y-cy);
25 if ((mind == -1) || (d < mind)) mind = d;
26 }
27 minr = (int)sqrt((double)mind);
28 }
29
30 N [$ != ctr] {
31
32 sscanf ($.pos, "%d,%d", &x, &y);
33 dely = y - cy;
34 delx = x - cx;
35 d = delx*delx + dely*dely;
36 sc = (int)sqrt((double)(d/mind));
37 if (sc > 1) {
38 fact = 2.0;
39 for (i=1; i<sc-1;i++) fact *= 2.0;
40 newr = minr*(2.0 - (1.0/fact));
41 ang = atan2 (dely, delx);
42 newx = newr*cos(ang) + cx;
43 newy = newr*sin(ang) + cy;
44 $.pos = sprintf ("%d,%d", newx, newy);
45 }
46 }