34 fprintf(stderr,
"trying to add to rect {%f +/- %f, %f +/- %f}\n",fillrec.
x[0], fillrec.
size[0], fillrec.
x[1], fillrec.
size[1]);
35 fprintf(stderr,
"total added so far = %d\n", nadded);
40 maxarea = minarea = area[0];
41 asp =
MAX(area[0]/(w*w), (w*w)/area[0]);
43 squarify(n, area, recs, nadded, maxarea, minarea, totalarea, asp, fillrec);
45 real newmaxarea, newminarea,
s, h, maxw, minw, newasp, hh, ww, xx, yy;
47 newmaxarea =
MAX(maxarea, area[nadded]);
48 newminarea =
MIN(minarea, area[nadded]);
49 s = totalarea + area[nadded];
53 newasp =
MAX(h/minw, maxw/h);
55 if (nadded < n && newasp <= asp){
56 squarify(n, area, recs, ++nadded, newmaxarea, newminarea, s, newasp, fillrec);
59 if (
Verbose) fprintf(stderr,
"adding %d items, total area = %f, w = %f, area/w=%f\n",nadded, totalarea, w, totalarea/w);
60 if (w == fillrec.
size[0]){
62 xx = fillrec.
x[0] - fillrec.
size[0]/2;
63 for (i = 0; i < nadded; i++){
67 recs[i].
x[1] = fillrec.
x[1] + 0.5*(fillrec.
size[1]) - hh/2;
68 recs[i].
x[0] = xx + ww/2;
72 fillrec.
size[1] -= hh;
75 yy = fillrec.
x[1] + fillrec.
size[1]/2;
76 for (i = 0; i < nadded; i++){
80 recs[i].
x[0] = fillrec.
x[0] - 0.5*(fillrec.
size[0]) + ww/2;
81 recs[i].
x[1] = yy - hh/2;
85 fillrec.
size[0] -= ww;
87 squarify(n - nadded, area + nadded, recs + nadded, 0, 0., 0., 0., 1., fillrec);
104 real total = 0, minarea = 1., maxarea = 0., asp = 1, totalarea = 0;
107 for (i = 0; i < n; i++) total += area[i];
109 if (total > fillrec.
size[0] * fillrec.
size[1] + 0.001)
113 squarify(n, area, recs, nadded, maxarea, minarea, totalarea, asp, fillrec);
rectangle * tree_map(int n, real *area, rectangle fillrec)
rectangle rectangle_new(real x, real y, real width, real height)
EXTERN unsigned char Verbose