PostGIS  2.5.0dev-r@@SVN_REVISION@@
static int point_in_ring ( POINTARRAY pts,
const POINT2D point 
)
static

Definition at line 733 of file lwgeom_functions_analytic.c.

References determineSide(), FP_CONTAINS_BOTTOM, getPoint2d_cp(), isOnSegment(), POINTARRAY::npoints, POINT2D::x, and POINT2D::y.

Referenced by point_in_multipolygon(), and point_in_polygon().

734 {
735  int wn = 0;
736  uint32_t i;
737  double side;
738  const POINT2D* seg1;
739  const POINT2D* seg2;
740 
741  POSTGIS_DEBUG(2, "point_in_ring called.");
742 
743  seg2 = getPoint2d_cp(pts, 0);
744  for (i=0; i<pts->npoints-1; i++)
745  {
746  seg1 = seg2;
747  seg2 = getPoint2d_cp(pts, i+1);
748 
749  side = determineSide(seg1, seg2, point);
750 
751  POSTGIS_DEBUGF(3, "segment: (%.8f, %.8f),(%.8f, %.8f)", seg1->x, seg1->y, seg2->x, seg2->y);
752  POSTGIS_DEBUGF(3, "side result: %.8f", side);
753  POSTGIS_DEBUGF(3, "counterclockwise wrap %d, clockwise wrap %d", FP_CONTAINS_BOTTOM(seg1->y, point->y, seg2->y), FP_CONTAINS_BOTTOM(seg2->y, point->y, seg1->y));
754 
755  /* zero length segments are ignored. */
756  if (((seg2->x - seg1->x)*(seg2->x - seg1->x) + (seg2->y - seg1->y)*(seg2->y - seg1->y)) < 1e-12*1e-12)
757  {
758  POSTGIS_DEBUG(3, "segment is zero length... ignoring.");
759 
760  continue;
761  }
762 
763  /* a point on the boundary of a ring is not contained. */
764  /* WAS: if (fabs(side) < 1e-12), see #852 */
765  if (side == 0.0)
766  {
767  if (isOnSegment(seg1, seg2, point) == 1)
768  {
769  POSTGIS_DEBUGF(3, "point on ring boundary between points %d, %d", i, i+1);
770 
771  return 0;
772  }
773  }
774 
775  /*
776  * If the point is to the left of the line, and it's rising,
777  * then the line is to the right of the point and
778  * circling counter-clockwise, so incremement.
779  */
780  if (FP_CONTAINS_BOTTOM(seg1->y, point->y, seg2->y) && side>0)
781  {
782  POSTGIS_DEBUG(3, "incrementing winding number.");
783 
784  ++wn;
785  }
786  /*
787  * If the point is to the right of the line, and it's falling,
788  * then the line is to the right of the point and circling
789  * clockwise, so decrement.
790  */
791  else if (FP_CONTAINS_BOTTOM(seg2->y, point->y, seg1->y) && side<0)
792  {
793  POSTGIS_DEBUG(3, "decrementing winding number.");
794 
795  --wn;
796  }
797  }
798 
799  POSTGIS_DEBUGF(3, "winding number %d", wn);
800 
801  if (wn == 0)
802  return -1;
803  return 1;
804 }
unsigned int uint32_t
Definition: uthash.h:78
double x
Definition: liblwgeom.h:327
double y
Definition: liblwgeom.h:327
static int isOnSegment(const POINT2D *seg1, const POINT2D *seg2, const POINT2D *point)
static double determineSide(const POINT2D *seg1, const POINT2D *seg2, const POINT2D *point)
#define FP_CONTAINS_BOTTOM(A, X, B)
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:364
uint32_t npoints
Definition: liblwgeom.h:370

Here is the call graph for this function:

Here is the caller graph for this function: