#include <stdlib.h>
#include <stdio.h>
-#include <setjmp.h>
#include <stdlib.h>
#include <math.h>
#include <pathplan/pathutil.h>
Ppoint_t a[2];
} tna_t;
-#define prerror(msg) \
- fprintf (stderr, "libpath/%s:%d: %s\n", __FILE__, __LINE__, (msg))
-
#define DISTSQ(a, b) ( \
(((a).x - (b).x) * ((a).x - (b).x)) + (((a).y - (b).y) * ((a).y - (b).y)) \
)
#define POINTSIZE sizeof (Ppoint_t)
-static jmp_buf jbuf;
-
static Ppoint_t *ops;
static int opn, opl;
static Pvector_t normv(Pvector_t);
-static void growops(int);
+static int growops(int);
static Ppoint_t add(Ppoint_t, Ppoint_t);
static Ppoint_t sub(Ppoint_t, Ppoint_t);
inps = input.ps;
inpn = input.pn;
- if (setjmp(jbuf))
- return -1;
-
/* generate the splines */
evs[0] = normv(evs[0]);
evs[1] = normv(evs[1]);
opl = 0;
- growops(4);
+ if (growops(4) < 0) {
+ return -1;
+ }
ops[opl++] = inps[0];
if (reallyroutespline(edges, edgen, inps, inpn, evs[0], evs[1]) == -1)
return -1;
}
if (mkspline(inps, inpn, tnas, ev0, ev1, &p1, &v1, &p2, &v2) == -1)
return -1;
- if (splinefits(edges, edgen, p1, v1, p2, v2, inps, inpn))
+ int fit = splinefits(edges, edgen, p1, v1, p2, v2, inps, inpn);
+ if (fit > 0) {
return 0;
+ }
+ if (fit < 0) {
+ return -1;
+ }
cp1 = add(p1, scale(v1, 1 / 3.0));
cp2 = sub(p2, scale(v2, 1 / 3.0));
for (maxd = -1, maxi = -1, i = 1; i < inpn - 1; i++) {
first = 0;
if (splineisinside(edges, edgen, &sps[0])) {
- growops(opl + 4);
+ if (growops(opl + 4) < 0) {
+ return -1;
+ }
for (pi = 1; pi < 4; pi++)
ops[opl].x = sps[pi].x, ops[opl++].y = sps[pi].y;
#if defined(DEBUG) && DEBUG >= 1
}
if (a == 0 && b == 0) {
if (forceflag) {
- growops(opl + 4);
+ if (growops(opl + 4) < 0) {
+ return -1;
+ }
for (pi = 1; pi < 4; pi++)
ops[opl].x = sps[pi].x, ops[opl++].y = sps[pi].y;
#if defined(DEBUG) && DEBUG >= 1
return v;
}
-static void growops(int newopn)
+static int growops(int newopn)
{
if (newopn <= opn)
- return;
+ return 0;
if (!(ops = realloc(ops, POINTSIZE * newopn))) {
- prerror("cannot realloc ops");
- longjmp(jbuf,1);
+ return -1;
}
opn = newopn;
+ return 0;
}
static Ppoint_t add(Ppoint_t p1, Ppoint_t p2)