PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ point_in_ring()

static int point_in_ring ( POINTARRAY pts,
const POINT2D point 
)
static

Definition at line 796 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().

797 {
798  int wn = 0;
799  int i;
800  double side;
801  const POINT2D* seg1;
802  const POINT2D* seg2;
803 
804  POSTGIS_DEBUG(2, "point_in_ring called.");
805 
806  seg2 = getPoint2d_cp(pts, 0);
807  for (i=0; i<pts->npoints-1; i++)
808  {
809  seg1 = seg2;
810  seg2 = getPoint2d_cp(pts, i+1);
811 
812  side = determineSide(seg1, seg2, point);
813 
814  POSTGIS_DEBUGF(3, "segment: (%.8f, %.8f),(%.8f, %.8f)", seg1->x, seg1->y, seg2->x, seg2->y);
815  POSTGIS_DEBUGF(3, "side result: %.8f", side);
816  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));
817 
818  /* zero length segments are ignored. */
819  if (((seg2->x - seg1->x)*(seg2->x - seg1->x) + (seg2->y - seg1->y)*(seg2->y - seg1->y)) < 1e-12*1e-12)
820  {
821  POSTGIS_DEBUG(3, "segment is zero length... ignoring.");
822 
823  continue;
824  }
825 
826  /* a point on the boundary of a ring is not contained. */
827  /* WAS: if (fabs(side) < 1e-12), see #852 */
828  if (side == 0.0)
829  {
830  if (isOnSegment(seg1, seg2, point) == 1)
831  {
832  POSTGIS_DEBUGF(3, "point on ring boundary between points %d, %d", i, i+1);
833 
834  return 0;
835  }
836  }
837 
838  /*
839  * If the point is to the left of the line, and it's rising,
840  * then the line is to the right of the point and
841  * circling counter-clockwise, so incremement.
842  */
843  if (FP_CONTAINS_BOTTOM(seg1->y, point->y, seg2->y) && side>0)
844  {
845  POSTGIS_DEBUG(3, "incrementing winding number.");
846 
847  ++wn;
848  }
849  /*
850  * If the point is to the right of the line, and it's falling,
851  * then the line is to the right of the point and circling
852  * clockwise, so decrement.
853  */
854  else if (FP_CONTAINS_BOTTOM(seg2->y, point->y, seg1->y) && side<0)
855  {
856  POSTGIS_DEBUG(3, "decrementing winding number.");
857 
858  --wn;
859  }
860  }
861 
862  POSTGIS_DEBUGF(3, "winding number %d", wn);
863 
864  if (wn == 0)
865  return -1;
866  return 1;
867 }
int npoints
Definition: liblwgeom.h:370
double x
Definition: liblwgeom.h:327
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, int n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:485
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)
Here is the call graph for this function:
Here is the caller graph for this function: