23 #define INTERSECT(a,b,c,d,e) intersect1((a),(b),(c),(d),(e))
25 #define INTERSECT(a,b,c,d,e) intersect((a),(b),(c),(d))
35 static array2 allocArray(
int V,
int extra)
41 arr = (
COORD **) malloc((V + extra) *
sizeof(
COORD *));
43 for (i = 0; i < V; i++) {
47 for (i = V; i < V + extra; i++)
58 return ((a.
y - b.
y) * (c.
x - b.
x) - (c.
y - b.
y) * (a.
x - b.
x));
69 w = ((a.
y - b.
y) * (c.
x - b.
x) - (c.
y - b.
y) * (a.
x - b.
x));
71 return (w > .0001) ? 1 : ((w < -.0001) ? -1 : 0);
81 return (((
area2(a, b, c) > 0 &&
area2(a, b, d) < 0) ||
95 return (((a.
x < c.
x) && (c.
x < b.
x))
96 || ((b.
x < c.
x) && (c.
x < a.
x)));
98 return (((a.
y < c.
y) && (c.
y < b.
y))
99 || ((b.
y < c.
y) && (c.
y < a.
y)));
131 w_abq =
wind(a, b, q);
132 w_abn =
wind(a, b, n);
135 if ((w_abq == 0) &&
inBetween(a, b, q)) {
136 return ((w_abn *
wind(a, b, p) < 0) || (
wind(p, q, n) > 0));
138 w_qna =
wind(q, n, a);
139 w_qnb =
wind(q, n, b);
143 return (((w_abq * w_abn) < 0) && ((w_qna * w_qnb) < 0));
160 a_abc =
wind(a, b, c);
161 if ((a_abc == 0) &&
inBetween(a, b, c)) {
164 a_abd =
wind(a, b, d);
165 if ((a_abd == 0) &&
inBetween(a, b, d)) {
168 a_cda =
wind(c, d, a);
169 a_cdb =
wind(c, d, b);
174 return (((a_abc * a_abd) < 0) && ((a_cda * a_cdb) < 0));
184 int m =
wind(b, a0, a1);
185 int p =
wind(b, a1, a2);
187 if (
wind(a0, a1, a2) > 0)
188 return (m >= 0 && p >= 0);
190 return (m >= 0 || p >= 0);
200 int m =
wind(b, a0, a1);
201 int p =
wind(b, a1, a2);
203 if (
wind(a0, a1, a2) >= 0)
204 return (m > 0 && p > 0);
206 return (m > 0 || p > 0);
218 return (delx * delx + dely * dely);
226 return sqrt(
dist2(a, b));
229 static int inCone(
int i,
int j,
Ppoint_t pts[],
int nextPt[],
int prevPt[])
231 return in_cone(pts[prevPt[i]], pts[i], pts[nextPt[i]], pts[j]);
240 int V,
Ppoint_t pts[],
int nextPt[],
int prevPt[])
244 for (k = 0; k < start; k++) {
245 if (
INTERSECT(pti, ptj, pts[k], pts[nextPt[k]], pts[prevPt[k]]))
248 for (k = end; k < V; k++) {
249 if (
INTERSECT(pti, ptj, pts[k], pts[nextPt[k]], pts[prevPt[k]]))
262 static void compVis(
vconfig_t * conf,
int start)
266 int *nextPt = conf->
next;
267 int *prevPt = conf->
prev;
272 for (i = start; i < V; i++) {
278 d =
dist(pts[i], pts[previ]);
287 for (; j >= 0; j--) {
288 if (inCone(i, j, pts, nextPt, prevPt) &&
289 inCone(j, i, pts, nextPt, prevPt) &&
290 clear(pts[i], pts[j], V, V, V, pts, nextPt, prevPt)) {
292 d =
dist(pts[i], pts[j]);
307 conf->
vis = allocArray(conf->
N, 2);
321 for (i = 0; i < conf->
Npoly; i++) {
322 poly.
ps = &(conf->
P[conf->
start[i]]);
343 int *nextPt = conf->
next;
344 int *prevPt = conf->
prev;
351 vadj = (
COORD *) malloc((V + 2) *
sizeof(
COORD));
355 pp = polyhit(conf, p);
357 start = conf->
start[pp];
358 end = conf->
start[pp + 1];
364 for (k = 0; k < start; k++) {
366 if (in_cone(pts[prevPt[k]], pk, pts[nextPt[k]], p) &&
367 clear(p, pk, start, end, V, pts, nextPt, prevPt)) {
375 for (k = start; k < end; k++)
378 for (k = end; k < V; k++) {
380 if (in_cone(pts[prevPt[k]], pk, pts[nextPt[k]], p) &&
381 clear(p, pk, start, end, V, pts, nextPt, prevPt)) {
404 int *nextPt = conf->
next;
417 s2 = conf->
start[qp];
418 e2 = conf->
start[qp + 1];
423 s2 = conf->
start[pp];
424 e2 = conf->
start[pp + 1];
425 }
else if (pp <= qp) {
426 s1 = conf->
start[pp];
427 e1 = conf->
start[pp + 1];
428 s2 = conf->
start[qp];
429 e2 = conf->
start[qp + 1];
431 s1 = conf->
start[qp];
432 e1 = conf->
start[qp + 1];
433 s2 = conf->
start[pp];
434 e2 = conf->
start[pp + 1];
437 for (k = 0; k <
s1; k++) {
438 if (
INTERSECT(p, q, pts[k], pts[nextPt[k]], pts[prevPt[k]]))
441 for (k = e1; k < s2; k++) {
442 if (
INTERSECT(p, q, pts[k], pts[nextPt[k]], pts[prevPt[k]]))
445 for (k = e2; k < V; k++) {
446 if (
INTERSECT(p, q, pts[k], pts[nextPt[k]], pts[prevPt[k]]))
void s1(graph_t *, node_t *)
COORD * ptVis(vconfig_t *, int, Ppoint_t)
COORD area2(Ppoint_t, Ppoint_t, Ppoint_t)
void visibility(vconfig_t *)
int intersect(Ppoint_t a, Ppoint_t b, Ppoint_t c, Ppoint_t d)
#define INTERSECT(a, b, c, d, e)
int directVis(Ppoint_t, int, Ppoint_t, int, vconfig_t *)
int in_poly(Ppoly_t argpoly, Ppoint_t q)
COORD dist2(Ppoint_t, Ppoint_t)
int wind(Ppoint_t a, Ppoint_t b, Ppoint_t c)
double dist(Site *s, Site *t)
int inBetween(Ppoint_t a, Ppoint_t b, Ppoint_t c)