PostGIS  2.3.7dev-r@@SVN_REVISION@@
int ptarray_contains_point_partial ( const POINTARRAY pa,
const POINT2D pt,
int  check_closed,
int *  winding_number 
)

Definition at line 739 of file ptarray.c.

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 lwcompound_contains_point(), and ptarray_contains_point().

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

Here is the call graph for this function:

Here is the caller graph for this function: