PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ ptarray_contains_point_partial()

int ptarray_contains_point_partial ( const POINTARRAY pa,
const POINT2D pt,
int  check_closed,
int *  winding_number 
)

Definition at line 738 of file ptarray.c.

739 {
740  int wn = 0;
741  uint32_t i;
742  double side;
743  const POINT2D *seg1;
744  const POINT2D *seg2;
745  double ymin, ymax;
746 
747  seg1 = getPoint2d_cp(pa, 0);
748  seg2 = getPoint2d_cp(pa, pa->npoints-1);
749  if ( check_closed && ! p2d_same(seg1, seg2) )
750  lwerror("ptarray_contains_point called on unclosed ring");
751 
752  for ( i=1; i < pa->npoints; i++ )
753  {
754  seg2 = getPoint2d_cp(pa, i);
755 
756  /* Zero length segments are ignored. */
757  if ( seg1->x == seg2->x && seg1->y == seg2->y )
758  {
759  seg1 = seg2;
760  continue;
761  }
762 
763  ymin = FP_MIN(seg1->y, seg2->y);
764  ymax = FP_MAX(seg1->y, seg2->y);
765 
766  /* Only test segments in our vertical range */
767  if ( pt->y > ymax || pt->y < ymin )
768  {
769  seg1 = seg2;
770  continue;
771  }
772 
773  side = lw_segment_side(seg1, seg2, pt);
774 
775  /*
776  * A point on the boundary of a ring is not contained.
777  * WAS: if (fabs(side) < 1e-12), see #852
778  */
779  if ( (side == 0) && lw_pt_in_seg(pt, seg1, seg2) )
780  {
781  return LW_BOUNDARY;
782  }
783 
784  /*
785  * If the point is to the left of the line, and it's rising,
786  * then the line is to the right of the point and
787  * circling counter-clockwise, so increment.
788  */
789  if ( (side < 0) && (seg1->y <= pt->y) && (pt->y < seg2->y) )
790  {
791  wn++;
792  }
793 
794  /*
795  * If the point is to the right of the line, and it's falling,
796  * then the line is to the right of the point and circling
797  * clockwise, so decrement.
798  */
799  else if ( (side > 0) && (seg2->y <= pt->y) && (pt->y < seg1->y) )
800  {
801  wn--;
802  }
803 
804  seg1 = seg2;
805  }
806 
807  /* Sent out the winding number for calls that are building on this as a primitive */
808  if ( winding_number )
809  *winding_number = wn;
810 
811  /* Outside */
812  if (wn == 0)
813  {
814  return LW_OUTSIDE;
815  }
816 
817  /* Inside */
818  return LW_INSIDE;
819 }
#define LW_INSIDE
Constants for point-in-polygon return values.
#define LW_BOUNDARY
#define FP_MAX(A, B)
#define FP_MIN(A, B)
int lw_pt_in_seg(const POINT2D *P, const POINT2D *A1, const POINT2D *A2)
Returns true if P is between A1/A2.
Definition: lwalgorithm.c:96
#define LW_OUTSIDE
int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
lw_segment_side()
Definition: lwalgorithm.c:65
int p2d_same(const POINT2D *p1, const POINT2D *p2)
Definition: lwalgorithm.c:50
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition: lwinline.h:91
double y
Definition: liblwgeom.h:376
double x
Definition: liblwgeom.h:376
uint32_t npoints
Definition: liblwgeom.h:413

References FP_MAX, FP_MIN, getPoint2d_cp(), LW_BOUNDARY, LW_INSIDE, LW_OUTSIDE, lw_pt_in_seg(), lw_segment_side(), lwerror(), POINTARRAY::npoints, p2d_same(), POINT2D::x, and POINT2D::y.

Referenced by _lwt_AddPoint(), _lwt_CheckEdgeCrossing(), lwcompound_contains_point(), lwt_ChangeEdgeGeom(), and ptarray_contains_point().

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