PostGIS  2.1.10dev-r@@SVN_REVISION@@
int PIP ( Point  P,
Point V,
int  n 
)

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 426 of file shp2pgsql-core.c.

References struct_point::x, struct_point::y, and pixval::y.

Referenced by FindPolygons().

427 {
428  int cn = 0; /* the crossing number counter */
429  int i;
430 
431  /* loop through all edges of the polygon */
432  for (i = 0; i < n-1; i++) /* edge from V[i] to V[i+1] */
433  {
434  if (((V[i].y <= P.y) && (V[i + 1].y > P.y)) /* an upward crossing */
435  || ((V[i].y > P.y) && (V[i + 1].y <= P.y))) /* a downward crossing */
436  {
437  double vt = (float)(P.y - V[i].y) / (V[i + 1].y - V[i].y);
438  if (P.x < V[i].x + vt * (V[i + 1].x - V[i].x)) /* P.x < intersect */
439  ++cn; /* a valid crossing of y=P.y right of P.x */
440  }
441  }
442 
443  return (cn&1); /* 0 if even (out), and 1 if odd (in) */
444 }
tuple y
Definition: pixval.py:54

Here is the caller graph for this function: