PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ point_in_ring_rtree()

static int point_in_ring_rtree ( RTREE_NODE root,
const POINT2D point 
)
static

Definition at line 695 of file lwgeom_functions_analytic.c.

696 {
697  int wn = 0;
698  uint32_t i;
699  double side;
700  const POINT2D *seg1;
701  const POINT2D *seg2;
702  LWMLINE *lines;
703 
704  POSTGIS_DEBUG(2, "point_in_ring called.");
705 
706  lines = RTreeFindLineSegments(root, point->y);
707  if (!lines)
708  return -1;
709 
710  for (i=0; i<lines->ngeoms; i++)
711  {
712  seg1 = getPoint2d_cp(lines->geoms[i]->points, 0);
713  seg2 = getPoint2d_cp(lines->geoms[i]->points, 1);
714 
715  side = determineSide(seg1, seg2, point);
716 
717  POSTGIS_DEBUGF(3, "segment: (%.8f, %.8f),(%.8f, %.8f)", seg1->x, seg1->y, seg2->x, seg2->y);
718  POSTGIS_DEBUGF(3, "side result: %.8f", side);
719  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));
720 
721  /* zero length segments are ignored. */
722  if (((seg2->x - seg1->x)*(seg2->x - seg1->x) + (seg2->y - seg1->y)*(seg2->y - seg1->y)) < 1e-12*1e-12)
723  {
724  POSTGIS_DEBUG(3, "segment is zero length... ignoring.");
725 
726  continue;
727  }
728 
729  /* a point on the boundary of a ring is not contained. */
730  /* WAS: if (fabs(side) < 1e-12), see #852 */
731  if (side == 0.0)
732  {
733  if (isOnSegment(seg1, seg2, point) == 1)
734  {
735  POSTGIS_DEBUGF(3, "point on ring boundary between points %d, %d", i, i+1);
736 
737  return 0;
738  }
739  }
740 
741  /*
742  * If the point is to the left of the line, and it's rising,
743  * then the line is to the right of the point and
744  * circling counter-clockwise, so increment.
745  */
746  if ((seg1->y <= point->y) && (point->y < seg2->y) && (side > 0))
747  {
748  POSTGIS_DEBUG(3, "incrementing winding number.");
749 
750  ++wn;
751  }
752  /*
753  * If the point is to the right of the line, and it's falling,
754  * then the line is to the right of the point and circling
755  * clockwise, so decrement.
756  */
757  else if ((seg2->y <= point->y) && (point->y < seg1->y) && (side < 0))
758  {
759  POSTGIS_DEBUG(3, "decrementing winding number.");
760 
761  --wn;
762  }
763  }
764 
765  POSTGIS_DEBUGF(3, "winding number %d", wn);
766 
767  if (wn == 0)
768  return -1;
769  return 1;
770 }
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)
LWMLINE * RTreeFindLineSegments(RTREE_NODE *root, double value)
Retrieves a collection of line segments given the root and crossing value.
Definition: lwgeom_rtree.c:450
POINTARRAY * points
Definition: liblwgeom.h:425
LWLINE ** geoms
Definition: liblwgeom.h:486
uint32_t ngeoms
Definition: liblwgeom.h:484
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331
unsigned int uint32_t
Definition: uthash.h:78

References determineSide(), FP_CONTAINS_BOTTOM, LWMLINE::geoms, getPoint2d_cp(), isOnSegment(), LWMLINE::ngeoms, LWLINE::points, RTreeFindLineSegments(), POINT2D::x, and POINT2D::y.

Referenced by point_in_multipolygon_rtree(), and point_in_polygon_rtree().

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