26 static void printVis(
char *
lbl,
COORD * vis,
int n);
27 static void printDad(
int *vis,
int n);
31 static void gasp_print_obstacles(
vconfig_t * conf);
32 static void gasp_print_point(
Ppoint_t p);
33 static void gasp_print_polyline(
Ppolyline_t * route);
38 static void *myrealloc(
void *p,
size_t newsize)
45 rv = realloc(p, newsize);
50 static void *mymalloc(
size_t newsize)
65 int poly_i, pt_i, i, n;
75 for (poly_i = 0; poly_i < n_obs; poly_i++)
76 n = n + obs[poly_i]->pn;
78 rv->
start = mymalloc((n_obs + 1) *
sizeof(
int));
79 rv->
next = mymalloc(n *
sizeof(
int));
80 rv->
prev = mymalloc(n *
sizeof(
int));
86 for (poly_i = 0; poly_i < n_obs; poly_i++) {
88 rv->
start[poly_i] = start;
89 end = start + obs[poly_i]->
pn - 1;
90 for (pt_i = 0; pt_i < obs[poly_i]->
pn; pt_i++) {
91 rv->
P[i] = obs[poly_i]->
ps[pt_i];
96 rv->
next[end] = start;
97 rv->
prev[start] = end;
99 rv->
start[poly_i] = i;
111 free(config->
vis[0]);
123 COORD *ptvis0, *ptvis1;
126 gasp_print_obstacles(config);
128 ptvis0 =
ptVis(config, poly0, p0);
129 ptvis1 =
ptVis(config, poly1, p1);
132 gasp_print_point(p0);
133 gasp_print_point(p1);
135 dad =
makePath(p0, poly0, ptvis0, p1, poly1, ptvis1, config);
138 for (i = dad[config->
N]; i != config->
N + 1; i = dad[i])
141 ops = malloc(opn *
sizeof(
Ppoint_t));
145 for (i = dad[config->
N]; i != config->
N + 1; i = dad[i])
146 ops[j--] = config->
P[i];
151 printVconfig(config);
152 printVis(
"p", ptvis0, config->
N + 1);
153 printVis(
"q", ptvis1, config->
N + 1);
154 printDad(dad, config->
N + 1);
162 output_route->
pn = opn;
163 output_route->
ps = ops;
165 gasp_print_polyline(output_route);
175 *barriers = malloc(config->
N *
sizeof(
Pedge_t));
176 *n_barriers = config->
N;
178 for (i = 0; i < config->
N; i++) {
179 barriers[i]->
a.
x = config->
P[i].
x;
180 barriers[i]->
a.
y = config->
P[i].
y;
182 barriers[i]->
b.
x = config->
P[j].
x;
183 barriers[i]->
b.
y = config->
P[j].
y;
201 printf(
"this next prev point\n");
202 for (i = 0; i < cp->
N; i++)
203 printf(
"%3d %3d %3d (%3g,%3g)\n", i, next[i], prev[i],
208 for (i = 0; i < cp->
N; i++) {
209 for (j = 0; j < cp->
N; j++)
210 printf(
"%4.1f ", arr[i][j]);
215 static void printVis(
char *
lbl,
COORD * vis,
int n)
220 for (i = 0; i < n; i++)
221 printf(
"%4.1f ", vis[i]);
225 static void printDad(
int *vis,
int n)
230 for (i = 0; i < n; i++) {
235 for (i = 0; i < n; i++) {
236 printf(
"%3d ", vis[i]);
250 (Bezpt[Bezctr - 1].x != p.
x) || (Bezpt[Bezctr - 1].
y != p.
y))
262 for (j = 0; j <= degree; j++) {
267 for (i = 1; i <= degree; i++) {
268 for (j = 0; j <= degree - i; j++) {
270 (1.0 - t) * Vtemp[i - 1][j].x + t * Vtemp[i - 1][j + 1].x;
272 (1.0 - t) * Vtemp[i - 1][j].y + t * Vtemp[i - 1][j + 1].y;
277 for (j = 0; j <= degree; j++)
278 Left[j] = Vtemp[j][0];
280 for (j = 0; j <= degree; j++)
281 Right[j] = Vtemp[degree - j][j];
282 return (Vtemp[degree][0]);
290 a = fabs(
area2(bezier[0], bezier[1], bezier[2]))
291 + fabs(
area2(bezier[2], bezier[3], bezier[0]));
296 (void)
Bezier(bezier, 3, .5, left, right);
298 append_bezier(right);
302 FILE *GASPout = stderr;
304 static void gasp_print_point(
Ppoint_t p)
306 fprintf(GASPout,
"%3g %3g\n", p.
x, p.
y);
309 void gasp_print_obstacles(
vconfig_t * conf)
314 fprintf(GASPout,
"%d\n", conf->
Npoly);
315 for (i = 0; i < conf->
Npoly; i++) {
316 poly.
ps = &(conf->
P[conf->
start[i]]);
318 fprintf(GASPout,
"%d\n", poly.
pn);
319 for (j = 0; j < poly.
pn; j++)
320 gasp_print_point(poly.
ps[j]);
329 for (i = 0; i + 3 < route->
pn; i += 3)
330 append_bezier(route->
ps + i);
331 fprintf(GASPout,
"%d\n", Bezctr);
332 for (i = 0; i < Bezctr; i++)
333 gasp_print_point(Bezpt[i]);
341 fprintf(GASPout,
"%d\n", route->
pn);
342 for (i = 0; i < route->
pn; i++)
343 gasp_print_point(route->
ps[i]);
COORD * ptVis(vconfig_t *, int, Ppoint_t)
COORD area2(Ppoint_t, Ppoint_t, Ppoint_t)
void visibility(vconfig_t *)
int Pobsbarriers(vconfig_t *config, Pedge_t **barriers, int *n_barriers)
vconfig_t * Pobsopen(Ppoly_t **obs, int n_obs)
void Pobsclose(vconfig_t *config)
pointf Bezier(pointf *V, int degree, double t, pointf *Left, pointf *Right)
void addpt(Point *c, Point a, Point b)
int * makePath(Ppoint_t p, int pp, COORD *pvis, Ppoint_t q, int qp, COORD *qvis, vconfig_t *conf)
int Pobspath(vconfig_t *config, Ppoint_t p0, int poly0, Ppoint_t p1, int poly1, Ppolyline_t *output_route)