File: scale

package info (click to toggle)
graphviz 14.1.2-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 139,476 kB
  • sloc: ansic: 142,288; cpp: 11,975; python: 7,883; makefile: 4,044; yacc: 3,030; xml: 2,972; tcl: 2,495; sh: 1,391; objc: 1,159; java: 560; lex: 423; perl: 243; awk: 156; pascal: 139; php: 58; ruby: 49; cs: 31; sed: 1
file content (46 lines) | stat: -rw-r--r-- 1,147 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* finds node n with root attribute 
 * finds distance minr of closest node
 * the layout is then scaled out from n so that 
 * a node is put on the smallest circle of radius x*minr
 * containing n
 */
BEG_G {
  node_t ctr;
  int cx, cy;
  int x, y;
  double delx, dely;
  int newx, newy;
  node_t n;
  edge_t e;
  int i, sc, d, mind = -1;
  double fact, newr, ang, minr;
  
  ctr = node($,aget($,"root"));
  sscanf (ctr.pos, "%d,%d", &cx, &cy);
  for (e = fstedge(ctr); e; e = nxtedge(e, ctr)) {
    if (e.head == ctr) n = e.tail;
    else n = e.head;
    sscanf (n.pos, "%d,%d", &x, &y);
    d = (x-cx)*(x-cx) + (y-cy)*(y-cy);
    if ((mind == -1) || (d < mind)) mind = d;
  } 
  minr = (int)sqrt((double)mind);
}

N [$ != ctr] {
  
    sscanf ($.pos, "%d,%d", &x, &y);
    dely = y - cy;
    delx = x - cx;
    d = delx*delx + dely*dely;
    sc = (int)sqrt((double)(d/mind));
    if (sc > 1) {
      fact = 2.0;
      for (i=1; i<sc-1;i++) fact *= 2.0;
      newr = minr*(2.0 - (1.0/fact));
      ang = atan2 (dely, delx);
      newx = newr*cos(ang) + cx; 
      newy = newr*sin(ang) + cy; 
      $.pos = sprintf ("%d,%d", newx, newy);
    }
}