PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ point_in_ring_rtree()

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

Definition at line 713 of file lwgeom_functions_analytic.c.

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().

714 {
715  int wn = 0;
716  int i;
717  double side;
718  const POINT2D *seg1;
719  const POINT2D *seg2;
720  LWMLINE *lines;
721 
722  POSTGIS_DEBUG(2, "point_in_ring called.");
723 
724  lines = RTreeFindLineSegments(root, point->y);
725  if (!lines)
726  return -1;
727 
728  for (i=0; i<lines->ngeoms; i++)
729  {
730  seg1 = getPoint2d_cp(lines->geoms[i]->points, 0);
731  seg2 = getPoint2d_cp(lines->geoms[i]->points, 1);
732 
733  side = determineSide(seg1, seg2, point);
734 
735  POSTGIS_DEBUGF(3, "segment: (%.8f, %.8f),(%.8f, %.8f)", seg1->x, seg1->y, seg2->x, seg2->y);
736  POSTGIS_DEBUGF(3, "side result: %.8f", side);
737  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));
738 
739  /* zero length segments are ignored. */
740  if (((seg2->x - seg1->x)*(seg2->x - seg1->x) + (seg2->y - seg1->y)*(seg2->y - seg1->y)) < 1e-12*1e-12)
741  {
742  POSTGIS_DEBUG(3, "segment is zero length... ignoring.");
743 
744  continue;
745  }
746 
747  /* a point on the boundary of a ring is not contained. */
748  /* WAS: if (fabs(side) < 1e-12), see #852 */
749  if (side == 0.0)
750  {
751  if (isOnSegment(seg1, seg2, point) == 1)
752  {
753  POSTGIS_DEBUGF(3, "point on ring boundary between points %d, %d", i, i+1);
754 
755  return 0;
756  }
757  }
758 
759  /*
760  * If the point is to the left of the line, and it's rising,
761  * then the line is to the right of the point and
762  * circling counter-clockwise, so incremement.
763  */
764  if (FP_CONTAINS_BOTTOM(seg1->y, point->y, seg2->y) && side>0)
765  {
766  POSTGIS_DEBUG(3, "incrementing winding number.");
767 
768  ++wn;
769  }
770  /*
771  * If the point is to the right of the line, and it's falling,
772  * then the line is to the right of the point and circling
773  * clockwise, so decrement.
774  */
775  else if (FP_CONTAINS_BOTTOM(seg2->y, point->y, seg1->y) && side<0)
776  {
777  POSTGIS_DEBUG(3, "decrementing winding number.");
778 
779  --wn;
780  }
781  }
782 
783  POSTGIS_DEBUGF(3, "winding number %d", wn);
784 
785  if (wn == 0)
786  return -1;
787  return 1;
788 }
LWMLINE * RTreeFindLineSegments(RTREE_NODE *root, double value)
Retrieves a collection of line segments given the root and crossing value.
Definition: lwgeom_rtree.c:450
int ngeoms
Definition: liblwgeom.h:480
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
LWLINE ** geoms
Definition: liblwgeom.h:482
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)
POINTARRAY * points
Definition: liblwgeom.h:421
Here is the call graph for this function:
Here is the caller graph for this function: