PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ point_in_ring()

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

Definition at line 778 of file lwgeom_functions_analytic.c.

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

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

Referenced by point_in_multipolygon(), and point_in_polygon().

Here is the call graph for this function:
Here is the caller graph for this function: