PostGIS  2.5.0beta1dev-r@@SVN_REVISION@@

◆ point_in_ring()

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

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

776 {
777  int wn = 0;
778  uint32_t i;
779  double side;
780  const POINT2D* seg1;
781  const POINT2D* seg2;
782 
783  POSTGIS_DEBUG(2, "point_in_ring called.");
784 
785  seg2 = getPoint2d_cp(pts, 0);
786  for (i=0; i<pts->npoints-1; i++)
787  {
788  seg1 = seg2;
789  seg2 = getPoint2d_cp(pts, i+1);
790 
791  side = determineSide(seg1, seg2, point);
792 
793  POSTGIS_DEBUGF(3, "segment: (%.8f, %.8f),(%.8f, %.8f)", seg1->x, seg1->y, seg2->x, seg2->y);
794  POSTGIS_DEBUGF(3, "side result: %.8f", side);
795  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));
796 
797  /* zero length segments are ignored. */
798  if (((seg2->x - seg1->x)*(seg2->x - seg1->x) + (seg2->y - seg1->y)*(seg2->y - seg1->y)) < 1e-12*1e-12)
799  {
800  POSTGIS_DEBUG(3, "segment is zero length... ignoring.");
801 
802  continue;
803  }
804 
805  /* a point on the boundary of a ring is not contained. */
806  /* WAS: if (fabs(side) < 1e-12), see #852 */
807  if (side == 0.0)
808  {
809  if (isOnSegment(seg1, seg2, point) == 1)
810  {
811  POSTGIS_DEBUGF(3, "point on ring boundary between points %d, %d", i, i+1);
812 
813  return 0;
814  }
815  }
816 
817  /*
818  * If the point is to the left of the line, and it's rising,
819  * then the line is to the right of the point and
820  * circling counter-clockwise, so increment.
821  */
822  if (FP_CONTAINS_BOTTOM(seg1->y, point->y, seg2->y) && side>0)
823  {
824  POSTGIS_DEBUG(3, "incrementing winding number.");
825 
826  ++wn;
827  }
828  /*
829  * If the point is to the right of the line, and it's falling,
830  * then the line is to the right of the point and circling
831  * clockwise, so decrement.
832  */
833  else if (FP_CONTAINS_BOTTOM(seg2->y, point->y, seg1->y) && side<0)
834  {
835  POSTGIS_DEBUG(3, "decrementing winding number.");
836 
837  --wn;
838  }
839  }
840 
841  POSTGIS_DEBUGF(3, "winding number %d", wn);
842 
843  if (wn == 0)
844  return -1;
845  return 1;
846 }
unsigned int uint32_t
Definition: uthash.h:78
double x
Definition: liblwgeom.h:330
double y
Definition: liblwgeom.h:330
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:373
Here is the call graph for this function:
Here is the caller graph for this function: