PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ point_in_ring_rtree()

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

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

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