PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_ptarray_contains_point()

static void test_ptarray_contains_point ( )
static

Definition at line 343 of file cu_ptarray.c.

344 {
345 /* int ptarray_contains_point(const POINTARRAY *pa, const POINT2D *pt, int *winding_number) */
346 
347  LWLINE *lwline;
348  POINTARRAY *pa;
349  POINT2D pt;
350  int rv;
351 
352  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 0, 0 1, 1 1, 1 0, 0 0)"));
353  pa = lwline->points;
354 
355  /* Point in middle of square */
356  pt.x = 0.5;
357  pt.y = 0.5;
358  rv = ptarray_contains_point(pa, &pt);
359  CU_ASSERT_EQUAL(rv, LW_INSIDE);
360 
361  /* Point on left edge of square */
362  pt.x = 0;
363  pt.y = 0.5;
364  rv = ptarray_contains_point(pa, &pt);
365  CU_ASSERT_EQUAL(rv, LW_BOUNDARY);
366 
367  /* Point on top edge of square */
368  pt.x = 0.5;
369  pt.y = 1;
370  rv = ptarray_contains_point(pa, &pt);
371  CU_ASSERT_EQUAL(rv, LW_BOUNDARY);
372 
373  /* Point on bottom left corner of square */
374  pt.x = 0;
375  pt.y = 0;
376  rv = ptarray_contains_point(pa, &pt);
377  CU_ASSERT_EQUAL(rv, LW_BOUNDARY);
378 
379  /* Point on top left corner of square */
380  pt.x = 0;
381  pt.y = 1;
382  rv = ptarray_contains_point(pa, &pt);
383  CU_ASSERT_EQUAL(rv, LW_BOUNDARY);
384 
385  /* Point outside top left corner of square */
386  pt.x = -0.1;
387  pt.y = 1;
388  rv = ptarray_contains_point(pa, &pt);
389  CU_ASSERT_EQUAL(rv, LW_OUTSIDE);
390 
391  /* Point outside top left corner of square */
392  pt.x = 0;
393  pt.y = 1.1;
394  rv = ptarray_contains_point(pa, &pt);
395  CU_ASSERT_EQUAL(rv, LW_OUTSIDE);
396 
397  /* Point outside left side of square */
398  pt.x = -0.2;
399  pt.y = 0.5;
400  rv = ptarray_contains_point(pa, &pt);
401  CU_ASSERT_EQUAL(rv, LW_OUTSIDE);
402 
403  lwline_free(lwline);
404  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 0, 1 1, 2 0, 0 0)"));
405  pa = lwline->points;
406 
407  /* Point outside grazing top of triangle */
408  pt.x = 0;
409  pt.y = 1;
410  rv = ptarray_contains_point(pa, &pt);
411  CU_ASSERT_EQUAL(rv, LW_OUTSIDE);
412 
413  lwline_free(lwline);
414  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 0, 0 4, 1 4, 2 2, 3 4, 4 4, 4 0, 0 0)"));
415  pa = lwline->points;
416 
417  /* Point outside grazing top of triangle */
418  pt.x = 1;
419  pt.y = 2;
420  rv = ptarray_contains_point(pa, &pt);
421  CU_ASSERT_EQUAL(rv, LW_INSIDE);
422 
423  /* Point outside grazing top of triangle */
424  pt.x = 3;
425  pt.y = 2;
426  rv = ptarray_contains_point(pa, &pt);
427  CU_ASSERT_EQUAL(rv, LW_INSIDE);
428 
429  lwline_free(lwline);
430 }
static LWGEOM * lwgeom_from_text(const char *str)
Definition: cu_ptarray.c:24
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:170
void lwline_free(LWLINE *line)
Definition: lwline.c:76
#define LW_INSIDE
Constants for point-in-polygon return values.
#define LW_BOUNDARY
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:734
#define LW_OUTSIDE
POINTARRAY * points
Definition: liblwgeom.h:425
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331

References LW_BOUNDARY, LW_INSIDE, LW_OUTSIDE, lwgeom_as_lwline(), lwgeom_from_text(), lwline_free(), LWLINE::points, ptarray_contains_point(), POINT2D::x, and POINT2D::y.

Referenced by ptarray_suite_setup().

Here is the call graph for this function:
Here is the caller graph for this function: