17static void squarify(
size_t n,
double *area,
rectangle *recs,
size_t nadded,
double maxarea,
double minarea,
double totalarea,
28 double w = fmin(fillrec.
size[0], fillrec.
size[1]);
33 fprintf(stderr,
"trying to add to rect {%f +/- %f, %f +/- %f}\n",fillrec.
x[0], fillrec.
size[0], fillrec.
x[1], fillrec.
size[1]);
34 fprintf(stderr,
"total added so far = %" PRISIZE_T "\n", nadded);
39 maxarea = minarea = area[0];
40 asp = fmax(area[0] / (w * w), w * w / area[0]);
42 squarify(n, area, recs, nadded, maxarea, minarea, totalarea, asp, fillrec);
44 double newmaxarea, newminarea,
s, h, maxw, minw, newasp, hh, ww, xx, yy;
46 newmaxarea = fmax(maxarea, area[nadded]);
47 newminarea = fmin(minarea, area[nadded]);
48 s = totalarea + area[nadded];
52 newasp = fmax(h / minw, maxw / h);
54 if (nadded < n && newasp <= asp){
55 squarify(n, area, recs, ++nadded, newmaxarea, newminarea,
s, newasp, fillrec);
59 " items, total area = %f, w = %f, area/w=%f\n",
60 nadded, totalarea, w, totalarea/w);
61 if (fillrec.
size[0] <= fillrec.
size[1]) {
64 xx = fillrec.
x[0] - fillrec.
size[0]/2;
65 for (
size_t i = 0; i < nadded; i++){
69 recs[i].
x[1] = fillrec.
x[1] + 0.5*(fillrec.
size[1]) - hh/2;
70 recs[i].
x[0] = xx + ww/2;
74 fillrec.
size[1] -= hh;
77 yy = fillrec.
x[1] + fillrec.
size[1]/2;
78 for (
size_t i = 0; i < nadded; i++){
82 recs[i].
x[0] = fillrec.
x[0] - 0.5*(fillrec.
size[0]) + ww/2;
83 recs[i].
x[1] = yy - hh/2;
87 fillrec.
size[0] -= ww;
89 squarify(n - nadded, area + nadded, recs + nadded, 0, 0., 0., 0., 1., fillrec);
104 double total = 0, minarea = 1., maxarea = 0., asp = 1, totalarea = 0;
106 for (
size_t i = 0; i < n; i++) total += area[i];
108 if (total > fillrec.
size[0] * fillrec.
size[1] + 0.001)
112 squarify(n, area, recs, 0, maxarea, minarea, totalarea, asp, fillrec);
static void squarify(size_t n, double *area, rectangle *recs, size_t nadded, double maxarea, double minarea, double totalarea, double asp, rectangle fillrec)