31 for (i = 0; i <
V; i++) {
35 for (i =
V; i <
V + extra; i++)
46 return (a.
y - b.
y) * (c.
x - b.
x) - (c.
y - b.
y) * (a.
x - b.
x);
57 w = (a.
y - b.
y) * (c.
x - b.
x) - (c.
y - b.
y) * (a.
x - b.
x);
59 return w > .0001 ? 1 : (w < -.0001 ? -1 : 0);
68 return (a.
x < c.
x && c.
x < b.
x) || (b.
x < c.
x && c.
x < a.
x);
70 return (a.
y < c.
y && c.
y < b.
y) || (b.
y < c.
y && c.
y < a.
y);
85 a_abc =
wind(a, b, c);
89 a_abd =
wind(a, b, d);
93 a_cda =
wind(c, d, a);
94 a_cdb =
wind(c, d, b);
99 return a_abc * a_abd < 0 && a_cda * a_cdb < 0;
108 int m =
wind(b, a0, a1);
109 int p =
wind(b, a1, a2);
111 if (
wind(a0, a1, a2) > 0)
112 return m >= 0 && p >= 0;
114 return m >= 0 || p >= 0;
125 return delx * delx + dely * dely;
133 return sqrt(
dist2(a, b));
138 return in_cone(pts[prevPt[i]], pts[i], pts[nextPt[i]], pts[j]);
151 for (k = 0; k < start; k++) {
152 if (
intersect(pti, ptj, pts[k], pts[nextPt[k]]))
155 for (k = end; k <
V; k++) {
156 if (
intersect(pti, ptj, pts[k], pts[nextPt[k]]))
172 int *nextPt = conf->
next;
173 int *prevPt = conf->
prev;
178 for (i = 0; i <
V; i++) {
184 d =
dist(pts[i], pts[previ]);
193 for (; j >= 0; j--) {
194 if (
inCone(i, j, pts, nextPt, prevPt) &&
195 inCone(j, i, pts, nextPt, prevPt) &&
196 clear(pts[i], pts[j],
V,
V,
V, pts, nextPt)) {
198 d =
dist(pts[i], pts[j]);
227 for (i = 0; i < conf->
Npoly; i++) {
247 const int V = conf->
N;
249 int *nextPt = conf->
next;
250 int *prevPt = conf->
prev;
261 start = conf->
start[pp];
262 end = conf->
start[pp + 1];
268 for (k = 0; k < start; k++) {
270 if (
in_cone(pts[prevPt[k]], pk, pts[nextPt[k]], p) &&
271 clear(p, pk, start, end,
V, pts, nextPt)) {
279 for (k = start; k < end; k++)
282 for (k = end; k <
V; k++) {
284 if (
in_cone(pts[prevPt[k]], pk, pts[nextPt[k]], p) &&
285 clear(p, pk, start, end,
V, pts, nextPt)) {
308 int *nextPt = conf->
next;
320 s2 = conf->
start[qp];
321 e2 = conf->
start[qp + 1];
326 s2 = conf->
start[pp];
327 e2 = conf->
start[pp + 1];
328 }
else if (pp <= qp) {
330 e1 = conf->
start[pp + 1];
331 s2 = conf->
start[qp];
332 e2 = conf->
start[qp + 1];
335 e1 = conf->
start[qp + 1];
336 s2 = conf->
start[pp];
337 e2 = conf->
start[pp + 1];
340 for (k = 0; k <
s1; k++) {
341 if (
intersect(p, q, pts[k], pts[nextPt[k]]))
344 for (k = e1; k < s2; k++) {
345 if (
intersect(p, q, pts[k], pts[nextPt[k]]))
348 for (k = e2; k <
V; k++) {
349 if (
intersect(p, q, pts[k], pts[nextPt[k]]))
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
bool in_poly(const Ppoly_t poly, Ppoint_t q)
NEATOPROCS_API void s1(graph_t *, node_t *)
static bool inCone(int i, int j, Ppoint_t pts[], int nextPt[], int prevPt[])
COORD * ptVis(vconfig_t *conf, int pp, Ppoint_t p)
static COORD dist(Ppoint_t a, Ppoint_t b)
static bool inBetween(Ppoint_t a, Ppoint_t b, Ppoint_t c)
int wind(Ppoint_t a, Ppoint_t b, Ppoint_t c)
static bool clear(Ppoint_t pti, Ppoint_t ptj, int start, int end, int V, Ppoint_t pts[], int nextPt[])
static bool intersect(Ppoint_t a, Ppoint_t b, Ppoint_t c, Ppoint_t d)
void visibility(vconfig_t *conf)
static array2 allocArray(int V, int extra)
COORD area2(Ppoint_t a, Ppoint_t b, Ppoint_t c)
static bool in_cone(Ppoint_t a0, Ppoint_t a1, Ppoint_t a2, Ppoint_t b)
bool directVis(Ppoint_t p, int pp, Ppoint_t q, int qp, vconfig_t *conf)
COORD dist2(Ppoint_t a, Ppoint_t b)
static void compVis(vconfig_t *conf)
static int polyhit(vconfig_t *conf, Ppoint_t p)