33 for (i = 0; i <
V; i++) {
37 for (i =
V; i <
V + extra; i++)
48 return (a.
y - b.
y) * (c.
x - b.
x) - (c.
y - b.
y) * (a.
x - b.
x);
59 w = (a.
y - b.
y) * (c.
x - b.
x) - (c.
y - b.
y) * (a.
x - b.
x);
61 return w > .0001 ? 1 : (w < -.0001 ? -1 : 0);
70 return (a.
x < c.
x && c.
x < b.
x) || (b.
x < c.
x && c.
x < a.
x);
72 return (a.
y < c.
y && c.
y < b.
y) || (b.
y < c.
y && c.
y < a.
y);
87 a_abc =
wind(a, b, c);
91 a_abd =
wind(a, b, d);
95 a_cda =
wind(c, d, a);
96 a_cdb =
wind(c, d, b);
101 return a_abc * a_abd < 0 && a_cda * a_cdb < 0;
110 int m =
wind(b, a0, a1);
111 int p =
wind(b, a1, a2);
113 if (
wind(a0, a1, a2) > 0)
114 return m >= 0 && p >= 0;
116 return m >= 0 || p >= 0;
127 return delx * delx + dely * dely;
135 return sqrt(
dist2(a, b));
140 return in_cone(pts[prevPt[i]], pts[i], pts[nextPt[i]], pts[j]);
153 for (k = 0; k < start; k++) {
154 if (
intersect(pti, ptj, pts[k], pts[nextPt[k]]))
157 for (k = end; k <
V; k++) {
158 if (
intersect(pti, ptj, pts[k], pts[nextPt[k]]))
174 int *nextPt = conf->
next;
175 int *prevPt = conf->
prev;
180 for (i = 0; i <
V; i++) {
186 d =
dist(pts[i], pts[previ]);
195 for (; j >= 0; j--) {
196 if (
inCone(i, j, pts, nextPt, prevPt) &&
197 inCone(j, i, pts, nextPt, prevPt) &&
198 clear(pts[i], pts[j],
V,
V,
V, pts, nextPt)) {
200 d =
dist(pts[i], pts[j]);
229 for (i = 0; i < conf->
Npoly; i++) {
249 const int V = conf->
N;
251 int *nextPt = conf->
next;
252 int *prevPt = conf->
prev;
263 start = conf->
start[pp];
264 end = conf->
start[pp + 1];
270 for (k = 0; k < start; k++) {
272 if (
in_cone(pts[prevPt[k]], pk, pts[nextPt[k]], p) &&
273 clear(p, pk, start, end,
V, pts, nextPt)) {
281 for (k = start; k < end; k++)
284 for (k = end; k <
V; k++) {
286 if (
in_cone(pts[prevPt[k]], pk, pts[nextPt[k]], p) &&
287 clear(p, pk, start, end,
V, pts, nextPt)) {
310 int *nextPt = conf->
next;
322 s2 = conf->
start[qp];
323 e2 = conf->
start[qp + 1];
328 s2 = conf->
start[pp];
329 e2 = conf->
start[pp + 1];
330 }
else if (pp <= qp) {
332 e1 = conf->
start[pp + 1];
333 s2 = conf->
start[qp];
334 e2 = conf->
start[qp + 1];
337 e1 = conf->
start[qp + 1];
338 s2 = conf->
start[pp];
339 e2 = conf->
start[pp + 1];
342 for (k = 0; k <
s1; k++) {
343 if (
intersect(p, q, pts[k], pts[nextPt[k]]))
346 for (k = e1; k < s2; k++) {
347 if (
intersect(p, q, pts[k], pts[nextPt[k]]))
350 for (k = e2; k <
V; k++) {
351 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)