* graph is constructed where it will be.
*/
static void
-placeFixed(ginfo * info, PointSet * ps, point * place, point center)
+placeFixed(ginfo * info, PointSet * ps, point * place)
{
point *cells = info->cells;
int n = info->nc;
int i;
- place->x = -center.x;
- place->y = -center.y;
+ /* place->x = -center.x; */
+ /* place->y = -center.y; */
+ place->x = 0;
+ place->y = 0;
for (i = 0; i < n; i++) {
insertPS(ps, *cells++);
* First graph (i == 0) is centered on the origin if possible.
*/
static void
-placeGraph(int i, ginfo * info, PointSet * ps, point * place, int step,
- int margin, boxf* bbs)
+placeGraph(int tryCenter, ginfo * info, PointSet * ps, point * place, int step,
+ int margin, boxf* bbs, int cx, int cy)
{
int x, y;
int W, H;
int bnd;
boxf bb = bbs[info->index];
- if (i == 0) {
+ if (tryCenter) {
W = GRID(bb.UR.x - bb.LL.x + 2 * margin, step);
H = GRID(bb.UR.y - bb.LL.y + 2 * margin, step);
if (fits(-W / 2, -H / 2, info, ps, place, step, bbs))
return;
}
- if (fits(0, 0, info, ps, place, step, bbs))
+ if (fits(cx, cy, info, ps, place, step, bbs))
return;
W = ceil(bb.UR.x - bb.LL.x);
H = ceil(bb.UR.y - bb.LL.y);
x = 0;
y = -bnd;
for (; x < bnd; x++)
- if (fits(x, y, info, ps, place, step, bbs))
+ if (fits(cx+x, cy+y, info, ps, place, step, bbs))
return;
for (; y < bnd; y++)
- if (fits(x, y, info, ps, place, step, bbs))
+ if (fits(cx+x, cy+y, info, ps, place, step, bbs))
return;
for (; x > -bnd; x--)
- if (fits(x, y, info, ps, place, step, bbs))
+ if (fits(cx+x, cy+y, info, ps, place, step, bbs))
return;
for (; y > -bnd; y--)
- if (fits(x, y, info, ps, place, step, bbs))
+ if (fits(cx+x, cy+y, info, ps, place, step, bbs))
return;
for (; x < 0; x++)
- if (fits(x, y, info, ps, place, step, bbs))
+ if (fits(cx+x, cy+y, info, ps, place, step, bbs))
return;
}
} else {
y = 0;
x = -bnd;
for (; y > -bnd; y--)
- if (fits(x, y, info, ps, place, step, bbs))
+ if (fits(cx+x, cy+y, info, ps, place, step, bbs))
return;
for (; x < bnd; x++)
- if (fits(x, y, info, ps, place, step, bbs))
+ if (fits(cx+x, cy+y, info, ps, place, step, bbs))
return;
for (; y < bnd; y++)
- if (fits(x, y, info, ps, place, step, bbs))
+ if (fits(cx+x, cy+y, info, ps, place, step, bbs))
return;
for (; x > -bnd; x--)
- if (fits(x, y, info, ps, place, step, bbs))
+ if (fits(cx+x, cy+y, info, ps, place, step, bbs))
return;
for (; y > 0; y--)
- if (fits(x, y, info, ps, place, step, bbs))
+ if (fits(cx+x, cy+y, info, ps, place, step, bbs))
return;
}
}
ps = newPS();
places = N_NEW(ng, point);
for (i = 0; i < ng; i++)
- placeGraph(i, sinfo[i], ps, places + (sinfo[i]->index),
- stepSize, pinfo->margin, gs);
+ placeGraph(i==0, sinfo[i], ps, places + (sinfo[i]->index),
+ stepSize, pinfo->margin, gs, 0, 0);
free(sinfo);
for (i = 0; i < ng; i++)
info = N_NEW(ng, ginfo);
for (i = 0; i < ng; i++) {
Agraph_t *g = gs[i];
+ point ctr;
info[i].index = i;
+
+ if (fixed && fixed[i]) {
+ ctr.x = ROUND(GD_bb(g).LL.x);
+ ctr.y = ROUND(GD_bb(g).LL.y);
+ }
+ else
+ ctr = center;
if (pinfo->mode == l_graph)
- genBox(GD_bb(g), info + i, stepSize, pinfo->margin, center, agnameof(g));
- else if (genPoly(root, gs[i], info + i, stepSize, pinfo, center)) {
+ genBox(GD_bb(g), info + i, stepSize, pinfo->margin, ctr, agnameof(g));
+ else if (genPoly(root, gs[i], info + i, stepSize, pinfo, ctr)) {
return 0;
}
}
ps = newPS();
places = N_NEW(ng, point);
if (fixed) {
+ CELL(center,stepSize);
for (i = 0; i < ng; i++) {
- if (fixed[i])
- placeFixed(sinfo[i], ps, places + (sinfo[i]->index),
- center);
+ if (fixed[sinfo[i]->index])
+ placeFixed(sinfo[i], ps, places + (sinfo[i]->index));
}
for (i = 0; i < ng; i++) {
- if (!fixed[i])
- placeGraph(i, sinfo[i], ps, places + (sinfo[i]->index),
- stepSize, pinfo->margin, bbs);
+ if (!fixed[sinfo[i]->index])
+ placeGraph(0, sinfo[i], ps, places + (sinfo[i]->index),
+ stepSize, pinfo->margin, bbs, center.x, center.y);
}
} else {
for (i = 0; i < ng; i++)
- placeGraph(i, sinfo[i], ps, places + (sinfo[i]->index),
- stepSize, pinfo->margin, bbs);
+ placeGraph(i==0, sinfo[i], ps, places + (sinfo[i]->index),
+ stepSize, pinfo->margin, bbs, 0, 0);
}
free(sinfo);