PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ _lwt_EdgeRingCrossingCount()

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

Definition at line 6555 of file lwgeom_topo.c.

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

Referenced by _lwt_EdgeRingContainsPoint().

6556 {
6557  int cn = 0; /* the crossing number counter */
6558  POINT2D v1, v2;
6559 #ifndef RELAX
6560  POINT2D v0;
6561 #endif
6562 
6563  if ( ! _lwt_EdgeRingIterator_next(it, &v1) ) return cn;
6564  v0 = v1;
6565  while ( _lwt_EdgeRingIterator_next(it, &v2) )
6566  {
6567  double vt;
6568 
6569  /* edge from vertex i to vertex i+1 */
6570  if
6571  (
6572  /* an upward crossing */
6573  ((v1.y <= p->y) && (v2.y > p->y))
6574  /* a downward crossing */
6575  || ((v1.y > p->y) && (v2.y <= p->y))
6576  )
6577  {
6578 
6579  vt = (double)(p->y - v1.y) / (v2.y - v1.y);
6580 
6581  /* P->x <intersect */
6582  if (p->x < v1.x + vt * (v2.x - v1.x))
6583  {
6584  /* a valid crossing of y=p->y right of p->x */
6585  ++cn;
6586  }
6587  }
6588  v1 = v2;
6589  }
6590 
6591  LWDEBUGF(3, "_lwt_EdgeRingCrossingCount returning %d", cn);
6592 
6593 #ifndef RELAX
6594  if ( memcmp(&v1, &v0, sizeof(POINT2D)) )
6595  {
6596  lwerror("_lwt_EdgeRingCrossingCount: V[n] != V[0] (%g %g != %g %g)",
6597  v1.x, v1.y, v0.x, v0.y);
6598  return -1;
6599  }
6600 #endif
6601 
6602  return cn;
6603 }
double x
Definition: liblwgeom.h:330
static int _lwt_EdgeRingIterator_next(LWT_EDGERING_POINT_ITERATOR *it, POINT2D *pt)
Definition: lwgeom_topo.c:6276
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: