static int routeinit;
/* static data used across multiple edges */
-static pointf *ps; /* final spline points */
-static int maxpn; /* size of ps[] */
static Ppoint_t *polypoints; /* vertices of polygon defined by boxes */
static int polypointn; /* size of polypoints[] */
static Pedge_t *edges; /* polygon edges passed to Proutespline */
static int edgen; /* size of edges[] */
static int checkpath(int, boxf*, path*);
-static int mkspacep(int size);
static void printpath(path * pp);
#ifdef DEBUG
static void printboxes(int boxn, boxf* boxes)
return NULL;
}
- if (mkspacep(spl.pn))
+ pointf *ps = calloc(spl.pn, sizeof(ps[0]));
+ if (ps == NULL) {
+ agerr(AGERR, "cannot allocate ps\n");
return NULL;
+ }
for (i = 0; i < spl.pn; i++) {
ps[i] = spl.ps[i];
}
routesplinesinit()
{
if (++routeinit > 1) return 0;
- if (!(ps = calloc(PINC, sizeof(pointf)))) {
- agerr(AGERR, "routesplinesinit: cannot allocate ps\n");
- return 1;
- }
- maxpn = PINC;
#ifdef DEBUG
if (Show_boxes) {
for (int i = 0; Show_boxes[i]; i++)
void routesplinesterm()
{
if (--routeinit > 0) return;
- free(ps);
if (Verbose)
fprintf(stderr,
"routesplines: %d edges, %d boxes %.2f sec\n",
}
#endif
}
- if (mkspacep(spl.pn))
+ pointf *ps = calloc(spl.pn, sizeof(ps[0]));
+ if (ps == NULL) {
+ agerr(AGERR, "cannot allocate ps\n");
return NULL; /* Bailout if no memory left */
+ }
for (bi = 0; bi < boxn; bi++) {
boxes[bi].LL.x = INT_MAX;
return 0;
}
-static int mkspacep(int size)
-{
- if (size > maxpn) {
- int newmax = maxpn + (size / PINC + 1) * PINC;
- ps = realloc(ps, newmax * sizeof(pointf));
- if (!ps) {
- agerr(AGERR, "cannot re-allocate ps\n");
- return 1;
- }
- maxpn = newmax;
- }
- return 0;
-}
-
static void printpath(path * pp)
{
int bi;
static void
makeSimpleFlatLabels (node_t* tn, node_t* hn, edge_t** edges, int ind, int cnt, int et, int n_lbls)
{
- pointf *ps;
Ppoly_t poly;
int pn;
edge_t* e = edges[ind];
}
poly.pn = 8;
poly.ps = (Ppoint_t*)points;
- ps = simpleSplineRoute (tp, hp, poly, &pn, et == EDGETYPE_PLINE);
- if (pn == 0) return;
+ pointf *ps = simpleSplineRoute(tp, hp, poly, &pn, et == EDGETYPE_PLINE);
+ if (pn == 0) {
+ free(ps);
+ return;
+ }
ED_label(e)->pos.x = ctrx;
ED_label(e)->pos.y = ctry;
ED_label(e)->set = TRUE;
clip_and_install(e, aghead(e), ps, pn, &sinfo);
+ free(ps);
}
/* edges with no labels */
}
poly.pn = 8;
poly.ps = (Ppoint_t*)points;
- ps = simpleSplineRoute (tp, hp, poly, &pn, et == EDGETYPE_PLINE);
- if (pn == 0) return;
+ pointf *ps = simpleSplineRoute(tp, hp, poly, &pn, et == EDGETYPE_PLINE);
+ if (pn == 0) {
+ free(ps);
+ return;
+ }
clip_and_install(e, aghead(e), ps, pn, &sinfo);
+ free(ps);
}
free (earray);
{
node_t *tn, *hn, *ln;
pointf *ps;
+ bool ps_needs_free = false;
pathend_t tend, hend;
boxf lb;
int i, pn, ydelta;
for (size_t j = 0; j < boxn; j++) add_box(P, boxes[j]);
for (i = hend.boxn - 1; i >= 0; i--) add_box(P, hend.boxes[i]);
+ ps_needs_free = true;
if (et == EDGETYPE_SPLINE) ps = routesplines(P, &pn);
else ps = routepolylines(P, &pn);
- if (pn == 0) return;
+ if (pn == 0) {
+ free(ps);
+ return;
+ }
}
clip_and_install(e, aghead(e), ps, pn, &sinfo);
+ if (ps_needs_free)
+ free(ps);
}
/* make_flat_bottom_edges:
int j, i, r;
double stepx, stepy, vspace;
rank_t* nextr;
- int pn;
- pointf *ps;
pathend_t tend, hend;
tn = agtail(e);
for (size_t k = 0; k < boxn; k++) add_box(P, boxes[k]);
for (j = hend.boxn - 1; j >= 0; j--) add_box(P, hend.boxes[j]);
+ pointf *ps = NULL;
+ int pn = 0;
if (splines) ps = routesplines(P, &pn);
else ps = routepolylines(P, &pn);
- if (pn == 0)
+ if (pn == 0) {
+ free(ps);
return;
+ }
clip_and_install(e, aghead(e), ps, pn, &sinfo);
+ free(ps);
P->nbox = 0;
}
}
edge_t *e;
int j, i, r, isAdjacent;
double stepx, stepy, vspace;
- int tside, hside, pn;
- pointf *ps;
+ int tside, hside;
pathend_t tend, hend;
fwdedge.out.base.data = (Agrec_t*)&fwdedgei;
for (size_t k = 0; k < boxn; k++) add_box(P, boxes[k]);
for (j = hend.boxn - 1; j >= 0; j--) add_box(P, hend.boxes[j]);
+ pointf *ps = NULL;
+ int pn = 0;
if (et == EDGETYPE_SPLINE) ps = routesplines(P, &pn);
else ps = routepolylines(P, &pn);
- if (pn == 0)
+ if (pn == 0) {
+ free(ps);
return;
+ }
clip_and_install(e, aghead(e), ps, pn, &sinfo);
+ free(ps);
P->nbox = 0;
}
}
Agedgeinfo_t fwdedgeai, fwdedgebi, fwdedgei;
Agedgepair_t fwdedgea, fwdedgeb, fwdedge;
edge_t *e, *fe, *le, *segfirst;
- pointf *ps;
pathend_t tend, hend;
boxf b;
- int sl, si, smode, i, j, dx, pn, hackflag, longedge;
+ int sl, si, smode, i, j, dx, hackflag, longedge;
static pointf* pointfs;
static pointf* pointfs2;
static int numpts;
assert(boxes.size <= (size_t)INT_MAX && "integer overflow");
completeregularpath(P, segfirst, e, &tend, &hend, boxes.data,
(int)boxes.size, 1);
+ pointf *ps = NULL;
+ int pn = 0;
if (is_spline) ps = routesplines(P, &pn);
else {
ps = routepolylines (P, &pn);
}
}
if (pn == 0) {
+ free(ps);
boxes_free(&boxes);
return;
}
for (i = 0; i < pn; i++) {
pointfs[pointn++] = ps[i];
}
+ free(ps);
e = straight_path(ND_out(hn).list[0], sl, pointfs, &pointn);
recover_slack(segfirst, P);
segfirst = e;
completeregularpath(P, segfirst, e, &tend, &hend, boxes.data, (int)boxes.size,
longedge);
boxes_free(&boxes);
+ pointf *ps = NULL;
+ int pn = 0;
if (is_spline) ps = routesplines(P, &pn);
else ps = routepolylines (P, &pn);
if (et == EDGETYPE_LINE && pn > 4) {
ps[3] = ps[2] = ps[pn-1];
pn = 4;
}
- if (pn == 0)
+ if (pn == 0) {
+ free(ps);
return;
+ }
if (pointn + pn > numpts) {
numpts = 2*(pointn+pn);
pointfs = RALLOC(numpts, pointfs, pointf);
for (i = 0; i < pn; i++) {
pointfs[pointn++] = ps[i];
}
+ free(ps);
recover_slack(segfirst, P);
hn = hackflag ? aghead(&fwdedgeb.out) : aghead(e);
}