PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ point_in_ring_rtree()

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

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

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