eps[0].y = tp.y;
eps[1].x = hp.x;
eps[1].y = hp.y;
- if (Pshortestpath(&poly, eps, &pl) == -1)
+ if (Pshortestpath(&poly, eps, &pl) < 0)
return NULL;
if (polyline)
} else
#endif
evs[1].x = evs[1].y = 0;
- if (Proutespline(edges, poly.pn, pl, evs, &spl) == -1)
+ if (Proutespline(edges, poly.pn, pl, evs, &spl) < 0)
return NULL;
}
poly.ps = polypoints, poly.pn = pi;
eps[0].x = pp->start.p.x, eps[0].y = pp->start.p.y;
eps[1].x = pp->end.p.x, eps[1].y = pp->end.p.y;
- if (Pshortestpath(&poly, eps, &pl) == -1) {
+ if (Pshortestpath(&poly, eps, &pl) < 0) {
agerr(AGERR, "in routesplines, Pshortestpath failed\n");
longjmp (jbuf, 1);
}
} else
evs[1].x = evs[1].y = 0;
- if (Proutespline(edges, poly.pn, pl, evs, &spl) == -1) {
+ if (Proutespline(edges, poly.pn, pl, evs, &spl) < 0) {
agerr(AGERR, "in routesplines, Proutespline failed\n");
longjmp (jbuf, 1);
}
makeSelfArcs(P, e, GD_nodesep(g));
} else if (ED_count(e)) {
objl = objectList(e, pm);
- if (Plegal_arrangement(objl->obs, objl->cnt))
+ if (Plegal_arrangement(objl->obs, objl->cnt)) {
vconfig = Pobsopen(objl->obs, objl->cnt);
+ if (!vconfig) {
+ agerr(AGWARN, "compoundEdges: could not construct obstacles - falling back to straight line edges\n");
+ rv = 1;
+ continue;
+ }
+ }
else {
if (Verbose)
fprintf(stderr,
{
pointf eps[2];
Pvector_t evs[2];
- pointf **cpts; /* lists of control points */
+ pointf **cpts = NULL; /* lists of control points */
Ppoly_t poly;
Ppolyline_t pl, spl;
int i, j;
int pn;
int mult = ED_count(e);
node_t* head = aghead(e);
+ int rv = 0;
+ poly.ps = NULL;
+ pl.pn = 0;
eps[0].x = trip->poly.ps[s].x, eps[0].y = trip->poly.ps[s].y;
eps[1].x = trip->poly.ps[t].x, eps[1].y = trip->poly.ps[t].y;
- Pshortestpath(&(trip->poly), eps, &pl);
+ if (Pshortestpath(&(trip->poly), eps, &pl) < 0) {
+ agerr(AGWARN, "Could not create control points for multiple spline for edge (%s,%s)\n", agnameof(agtail(e)), agnameof(aghead(e)));
+ rv = 1;
+ goto finish;
+ }
if (pl.pn == 2) {
makeStraightEdge(agraphof(head), e, doPolyline);
- return 0;
+ goto finish;
}
evs[0].x = evs[0].y = 0;
medges[j].b = poly.ps[(j + 1) % poly.pn];
}
tweakPath (poly, s, t, pl);
- Proutespline(medges, poly.pn, pl, evs, &spl);
+ if (Proutespline(medges, poly.pn, pl, evs, &spl) < 0) {
+ agerr(AGWARN, "Could not create control points for multiple spline for edge (%s,%s)\n", agnameof(agtail(e)), agnameof(aghead(e)));
+ rv = 1;
+ goto finish;
+ }
finishEdge (g, e, spl, aghead(e) != head, eps[0], eps[1]);
free(medges);
mkCtrlPts(t, mult+1, pl.ps[i], pl.ps[i + 1], pl.ps[i + 2], trip);
if (!cpts[i]) {
agerr(AGWARN, "Could not create control points for multiple spline for edge (%s,%s)\n", agnameof(agtail(e)), agnameof(aghead(e)));
- return 1;
+ rv = 1;
+ goto finish;
}
}
for (j = 1; j < pl.pn - 1; j++) {
poly.ps[pn - j] = cpts[j - 1][i + 1];
}
- Pshortestpath(&poly, eps, &mmpl);
+ if (Pshortestpath(&poly, eps, &mmpl) < 0) {
+ agerr(AGWARN, "Could not create control points for multiple spline for edge (%s,%s)\n", agnameof(agtail(e)), agnameof(aghead(e)));
+ rv = 1;
+ goto finish;
+ }
if (doPolyline) {
make_polyline (mmpl, &spl);
medges[j].b = poly.ps[(j + 1) % poly.pn];
}
tweakPath (poly, 0, pl.pn-1, mmpl);
- Proutespline(medges, poly.pn, mmpl, evs, &spl);
+ if (Proutespline(medges, poly.pn, mmpl, evs, &spl) < 0) {
+ agerr(AGWARN, "Could not create control points for multiple spline for edge (%s,%s)\n",
+ agnameof(agtail(e)), agnameof(aghead(e)));
+ rv = 1;
+ goto finish;
+ }
}
finishEdge (g, e, spl, aghead(e) != head, eps[0], eps[1]);
e = ED_to_virt(e);
}
- for (i = 0; i < pl.pn - 2; i++)
- free(cpts[i]);
- free(cpts);
+finish :
+ if (cpts) {
+ for (i = 0; i < pl.pn - 2; i++)
+ free(cpts[i]);
+ free(cpts);
+ }
free(medges);
free(poly.ps);
- return 0;
+ return rv;
}
#define NSMALL -0.0000000001
make_barriers(obs, npoly, pp, qp, &barriers, &n_barriers);
slopes[0].x = slopes[0].y = 0.0;
slopes[1].x = slopes[1].y = 0.0;
- Proutespline(barriers, n_barriers, line, slopes, &spline);
+ if (Proutespline(barriers, n_barriers, line, slopes, &spline) < 0) {
+ agerr (AGERR, "makeSpline: failed to make spline edge (%s,%s)\n", agnameof(agtail(e)), agnameof(aghead(e)));
+ return;
+ }
/* north why did you ever use int coords */
if (Verbose > 1)
#include <stdlib.h>
#include <stdio.h>
+#include <setjmp.h>
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
struct elist_t *next, *prev;
} elist_t;
+static jmp_buf jbuf;
+
#if 0
static p2e_t *p2es;
static int p2en;
static void listinsert(Pedge_t *, Ppoint_t);
#endif
+/* Proutespline:
+ * Given a set of edgen line segments edges as obstacles, a template
+ * path input, and endpoint vectors evs, construct a spline fitting the
+ * input and endpoing vectors, and return in output.
+ * Return 0 on success and -1 on failure, including no memory.
+ */
int Proutespline(Pedge_t * edges, int edgen, Ppolyline_t input,
Ppoint_t * evs, Ppolyline_t * output)
{
#if 0
if (!(p2es = (p2e_t *) malloc(sizeof(p2e_t) * (p2en = edgen * 2)))) {
prerror("cannot malloc p2es");
- abort();
+ return -1;
}
for (ei = 0, p2ei = 0; ei < edgen; ei++) {
if (edges[ei].a.x == edges[ei].b.x
}
}
#endif
+ if (setjmp(jbuf))
+ return -1;
+
/* generate the splines */
evs[0] = normv(evs[0]);
evs[1] = normv(evs[1]);
if (!ops) {
if (!(ops = (Ppoint_t *) malloc(POINTSIZE * newopn))) {
prerror("cannot malloc ops");
- abort();
+ longjmp(jbuf,1);
}
} else {
if (!(ops = (Ppoint_t *) realloc((void *) ops,
POINTSIZE * newopn))) {
prerror("cannot realloc ops");
- abort();
+ longjmp(jbuf,1);
}
}
opn = newopn;
#include <stdlib.h>
#include <stdio.h>
+#include <setjmp.h>
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
int pnlpn, fpnlpi, lpnlpi, apex;
} deque_t;
+static jmp_buf jbuf;
static pointnlink_t *pnls, **pnlps;
static int pnln, pnll;
static void growdq(int);
static void growops(int);
+/* Pshortestpath:
+ * Find a shortest path contained in the polygon polyp going between the
+ * points supplied in eps. The resulting polyline is stored in output.
+ * Return 0 on success, -1 on bad input, -2 on memory allocation problem.
+ */
int Pshortestpath(Ppoly_t * polyp, Ppoint_t * eps, Ppolyline_t * output)
{
int pi, minpi;
int pnli;
#endif
+ if (setjmp(jbuf))
+ return -2;
/* make space */
growpnls(polyp->pn);
pnll = 0;
if (!pnls) {
if (!(pnls = (pointnlink_t *) malloc(POINTNLINKSIZE * newpnln))) {
prerror("cannot malloc pnls");
- abort();
+ longjmp(jbuf,1);
}
if (!(pnlps = (pointnlink_t **) malloc(POINTNLINKPSIZE * newpnln))) {
prerror("cannot malloc pnlps");
- abort();
+ longjmp(jbuf,1);
}
} else {
if (!(pnls = (pointnlink_t *) realloc((void *) pnls,
POINTNLINKSIZE * newpnln))) {
prerror("cannot realloc pnls");
- abort();
+ longjmp(jbuf,1);
}
if (!(pnlps = (pointnlink_t **) realloc((void *) pnlps,
POINTNLINKPSIZE *
newpnln))) {
prerror("cannot realloc pnlps");
- abort();
+ longjmp(jbuf,1);
}
}
pnln = newpnln;
if (!tris) {
if (!(tris = (triangle_t *) malloc(TRIANGLESIZE * newtrin))) {
prerror("cannot malloc tris");
- abort();
+ longjmp(jbuf,1);
}
} else {
if (!(tris = (triangle_t *) realloc((void *) tris,
TRIANGLESIZE * newtrin))) {
prerror("cannot realloc tris");
- abort();
+ longjmp(jbuf,1);
}
}
trin = newtrin;
(dq.pnlps =
(pointnlink_t **) malloc(POINTNLINKPSIZE * newdqn))) {
prerror("cannot malloc dq.pnls");
- abort();
+ longjmp(jbuf,1);
}
} else {
if (!(dq.pnlps = (pointnlink_t **) realloc((void *) dq.pnlps,
POINTNLINKPSIZE *
newdqn))) {
prerror("cannot realloc dq.pnls");
- abort();
+ longjmp(jbuf,1);
}
}
dq.pnlpn = newdqn;
if (!ops) {
if (!(ops = (Ppoint_t *) malloc(POINTSIZE * newopn))) {
prerror("cannot malloc ops");
- abort();
+ longjmp(jbuf,1);
}
} else {
if (!(ops = (Ppoint_t *) realloc((void *) ops,
POINTSIZE * newopn))) {
prerror("cannot realloc ops");
- abort();
+ longjmp(jbuf,1);
}
}
opn = newopn;