PostGIS  2.5.7dev-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 740 of file ptarray.c.

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

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: