PostGIS  3.7.0dev-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 763 of file ptarray.c.

764 {
765  int wn = 0;
766  uint32_t i;
767  double side;
768  const POINT2D *seg1;
769  const POINT2D *seg2;
770  double ymin, ymax;
771 
772  seg1 = getPoint2d_cp(pa, 0);
773  seg2 = getPoint2d_cp(pa, pa->npoints-1);
774  if ( check_closed && ! p2d_same(seg1, seg2) )
775  lwerror("ptarray_contains_point called on unclosed ring");
776 
777  for ( i=1; i < pa->npoints; i++ )
778  {
779  seg2 = getPoint2d_cp(pa, i);
780 
781  /* Zero length segments are ignored. */
782  if ( seg1->x == seg2->x && seg1->y == seg2->y )
783  {
784  seg1 = seg2;
785  continue;
786  }
787 
788  ymin = FP_MIN(seg1->y, seg2->y);
789  ymax = FP_MAX(seg1->y, seg2->y);
790 
791  /* Only test segments in our vertical range */
792  if ( pt->y > ymax || pt->y < ymin )
793  {
794  seg1 = seg2;
795  continue;
796  }
797 
798  side = lw_segment_side(seg1, seg2, pt);
799 
800  /*
801  * A point on the boundary of a ring is not contained.
802  * WAS: if (fabs(side) < 1e-12), see #852
803  */
804  if ( (side == 0) && lw_pt_in_seg(pt, seg1, seg2) )
805  {
806  return LW_BOUNDARY;
807  }
808 
809  /*
810  * If the point is to the left of the line, and it's rising,
811  * then the line is to the right of the point and
812  * circling counter-clockwise, so increment.
813  */
814  if ( (side < 0) && (seg1->y <= pt->y) && (pt->y < seg2->y) )
815  {
816  wn++;
817  }
818 
819  /*
820  * If the point is to the right of the line, and it's falling,
821  * then the line is to the right of the point and circling
822  * clockwise, so decrement.
823  */
824  else if ( (side > 0) && (seg2->y <= pt->y) && (pt->y < seg1->y) )
825  {
826  wn--;
827  }
828 
829  seg1 = seg2;
830  }
831 
832  /* Sent out the winding number for calls that are building on this as a primitive */
833  if ( winding_number )
834  *winding_number = wn;
835 
836  /* Outside */
837  if (wn == 0)
838  {
839  return LW_OUTSIDE;
840  }
841 
842  /* Inside */
843  return LW_INSIDE;
844 }
#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:101
#define LW_OUTSIDE
int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
lw_segment_side()
Definition: lwalgorithm.c:70
int p2d_same(const POINT2D *p1, const POINT2D *p2)
Definition: lwalgorithm.c:57
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
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:97
double y
Definition: liblwgeom.h:390
double x
Definition: liblwgeom.h:390
uint32_t npoints
Definition: liblwgeom.h:427

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_CheckEdgeCrossing(), _lwt_SplitAllEdgesToNewNode(), 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: