PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwcompound_contains_point()

int lwcompound_contains_point ( const LWCOMPOUND comp,
const POINT2D pt 
)

Definition at line 145 of file lwcompound.c.

References LWCOMPOUND::geoms, LINETYPE, LW_BOUNDARY, LW_FALSE, LW_INSIDE, LW_OUTSIDE, lwerror(), lwgeom_as_lwcircstring(), lwgeom_as_lwline(), lwtype_name(), LWCOMPOUND::ngeoms, LWLINE::points, LWCIRCSTRING::points, ptarray_contains_point(), ptarray_contains_point_partial(), ptarrayarc_contains_point(), ptarrayarc_contains_point_partial(), and LWGEOM::type.

Referenced by lwgeom_contains_point().

146 {
147  int i;
148  LWLINE *lwline;
149  LWCIRCSTRING *lwcirc;
150  int wn = 0;
151  int winding_number = 0;
152  int result;
153 
154  for ( i = 0; i < comp->ngeoms; i++ )
155  {
156  LWGEOM *lwgeom = comp->geoms[i];
157  if ( lwgeom->type == LINETYPE )
158  {
159  lwline = lwgeom_as_lwline(lwgeom);
160  if ( comp->ngeoms == 1 )
161  {
162  return ptarray_contains_point(lwline->points, pt);
163  }
164  else
165  {
166  /* Don't check closure while doing p-i-p test */
167  result = ptarray_contains_point_partial(lwline->points, pt, LW_FALSE, &winding_number);
168  }
169  }
170  else
171  {
172  lwcirc = lwgeom_as_lwcircstring(lwgeom);
173  if ( ! lwcirc ) {
174  lwerror("Unexpected component of type %s in compound curve", lwtype_name(lwgeom->type));
175  return 0;
176  }
177  if ( comp->ngeoms == 1 )
178  {
179  return ptarrayarc_contains_point(lwcirc->points, pt);
180  }
181  else
182  {
183  /* Don't check closure while doing p-i-p test */
184  result = ptarrayarc_contains_point_partial(lwcirc->points, pt, LW_FALSE, &winding_number);
185  }
186  }
187 
188  /* Propogate boundary condition */
189  if ( result == LW_BOUNDARY )
190  return LW_BOUNDARY;
191 
192  wn += winding_number;
193  }
194 
195  /* Outside */
196  if (wn == 0)
197  return LW_OUTSIDE;
198 
199  /* Inside */
200  return LW_INSIDE;
201 }
#define LINETYPE
Definition: liblwgeom.h:86
int ptarrayarc_contains_point(const POINTARRAY *pa, const POINT2D *pt)
For POINTARRAYs representing CIRCULARSTRINGS.
Definition: ptarray.c:835
LWGEOM ** geoms
Definition: liblwgeom.h:522
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
#define LW_FALSE
Definition: liblwgeom.h:77
int ptarray_contains_point_partial(const POINTARRAY *pa, const POINT2D *pt, int check_closed, int *winding_number)
Definition: ptarray.c:742
#define LW_INSIDE
Constants for point-in-polygon return values.
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:138
LWCIRCSTRING * lwgeom_as_lwcircstring(const LWGEOM *lwgeom)
Definition: lwgeom.c:147
#define LW_BOUNDARY
int ngeoms
Definition: liblwgeom.h:520
uint8_t type
Definition: liblwgeom.h:396
int ptarray_contains_point(const POINTARRAY *pa, const POINT2D *pt)
Return 1 if the point is inside the POINTARRAY, -1 if it is outside, and 0 if it is on the boundary...
Definition: ptarray.c:736
POINTARRAY * points
Definition: liblwgeom.h:444
#define LW_OUTSIDE
int ptarrayarc_contains_point_partial(const POINTARRAY *pa, const POINT2D *pt, int check_closed, int *winding_number)
Definition: ptarray.c:841
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
POINTARRAY * points
Definition: liblwgeom.h:422
Here is the call graph for this function:
Here is the caller graph for this function: