PostGIS
3.0.6dev-r@@SVN_REVISION@@
◆
pt_in_ring_2d()
int pt_in_ring_2d
(
const
POINT2D
*
p
,
const
POINTARRAY
*
ring
)
Definition at line
282
of file
lwalgorithm.c
.
283
{
284
int
cn = 0;
/* the crossing number counter */
285
uint32_t i;
286
const
POINT2D
*v1, *v2;
287
const
POINT2D
*first, *last;
288
289
first =
getPoint2d_cp
(ring, 0);
290
last =
getPoint2d_cp
(ring, ring->
npoints
-1);
291
if
( memcmp(first, last,
sizeof
(
POINT2D
)) )
292
{
293
lwerror
(
"pt_in_ring_2d: V[n] != V[0] (%g %g != %g %g)"
,
294
first->
x
, first->
y
, last->
x
, last->
y
);
295
return
LW_FALSE
;
296
297
}
298
299
LWDEBUGF
(2,
"pt_in_ring_2d called with point: %g %g"
, p->
x
, p->
y
);
300
/* printPA(ring); */
301
302
/* loop through all edges of the polygon */
303
v1 =
getPoint2d_cp
(ring, 0);
304
for
(i=0; i<ring->
npoints
-1; i++)
305
{
306
double
vt;
307
v2 =
getPoint2d_cp
(ring, i+1);
308
309
/* edge from vertex i to vertex i+1 */
310
if
311
(
312
/* an upward crossing */
313
((v1->
y
<= p->
y
) && (v2->
y
> p->
y
))
314
/* a downward crossing */
315
|| ((v1->
y
> p->
y
) && (v2->
y
<= p->
y
))
316
)
317
{
318
319
vt = (double)(p->
y
- v1->
y
) / (v2->
y
- v1->
y
);
320
321
/* P->x <intersect */
322
if
(p->
x
< v1->
x
+ vt * (v2->
x
- v1->
x
))
323
{
324
/* a valid crossing of y=p->y right of p->x */
325
++cn;
326
}
327
}
328
v1 = v2;
329
}
330
331
LWDEBUGF
(3,
"pt_in_ring_2d returning %d"
, cn&1);
332
333
return
(cn&1);
/* 0 if even (out), and 1 if odd (in) */
334
}
LW_FALSE
#define LW_FALSE
Definition:
liblwgeom.h:108
LWDEBUGF
#define LWDEBUGF(level, msg,...)
Definition:
lwgeom_log.h:88
lwerror
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition:
lwutil.c:190
getPoint2d_cp
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
POINT2D::y
double y
Definition:
liblwgeom.h:376
POINT2D::x
double x
Definition:
liblwgeom.h:376
POINT2D
Definition:
liblwgeom.h:375
POINTARRAY::npoints
uint32_t npoints
Definition:
liblwgeom.h:413
liblwgeom
liblwgeom_internal.h
Generated by
1.9.1