PIP(): crossing number test for a point in a polygon input: P = a point, V[] = vertex points of a polygon V[n+1] with V[n]=V[0].
- Returns
- 0 = outside, 1 = inside
Definition at line 417 of file shp2pgsql-core.c.
418{
419 int cn = 0;
420 int i;
421
422
423 for (i = 0; i < n-1; i++)
424 {
425 if (((V[i].y <= P.
y) && (V[i + 1].y > P.
y))
426 || ((V[i].y > P.
y) && (V[i + 1].y <= P.
y)))
427 {
428 double vt = (float)(P.
y - V[i].y) / (V[i + 1].
y - V[i].
y);
429 if (P.
x < V[i].x + vt * (V[i + 1].x - V[i].x))
430 ++cn;
431 }
432 }
433
434 return (cn&1);
435}
References struct_ring::n, struct_point::x, and struct_point::y.
Referenced by FindPolygons().