PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ _lwt_EdgeRingCrossingCount()

static int _lwt_EdgeRingCrossingCount ( const POINT2D p,
LWT_EDGERING_POINT_ITERATOR it 
)
static

Definition at line 6325 of file lwgeom_topo.c.

References _lwt_EdgeRingIterator_next(), LWDEBUGF, lwerror(), POINT2D::x, and POINT2D::y.

Referenced by _lwt_EdgeRingContainsPoint().

6326 {
6327  int cn = 0; /* the crossing number counter */
6328  POINT2D v1, v2;
6329 #ifndef RELAX
6330  POINT2D v0;
6331 #endif
6332 
6333  if ( ! _lwt_EdgeRingIterator_next(it, &v1) ) return cn;
6334  v0 = v1;
6335  while ( _lwt_EdgeRingIterator_next(it, &v2) )
6336  {
6337  double vt;
6338 
6339  /* edge from vertex i to vertex i+1 */
6340  if
6341  (
6342  /* an upward crossing */
6343  ((v1.y <= p->y) && (v2.y > p->y))
6344  /* a downward crossing */
6345  || ((v1.y > p->y) && (v2.y <= p->y))
6346  )
6347  {
6348 
6349  vt = (double)(p->y - v1.y) / (v2.y - v1.y);
6350 
6351  /* P->x <intersect */
6352  if (p->x < v1.x + vt * (v2.x - v1.x))
6353  {
6354  /* a valid crossing of y=p->y right of p->x */
6355  ++cn;
6356  }
6357  }
6358  v1 = v2;
6359  }
6360 
6361  LWDEBUGF(3, "_lwt_EdgeRingCrossingCount returning %d", cn);
6362 
6363 #ifndef RELAX
6364  if ( memcmp(&v1, &v0, sizeof(POINT2D)) )
6365  {
6366  lwerror("_lwt_EdgeRingCrossingCount: V[n] != V[0] (%g %g != %g %g)",
6367  v1.x, v1.y, v0.x, v0.y);
6368  return -1;
6369  }
6370 #endif
6371 
6372  return cn;
6373 }
double x
Definition: liblwgeom.h:330
static int _lwt_EdgeRingIterator_next(LWT_EDGERING_POINT_ITERATOR *it, POINT2D *pt)
Definition: lwgeom_topo.c:6046
double y
Definition: liblwgeom.h:330
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
Here is the call graph for this function:
Here is the caller graph for this function: