PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_ptarray_contains_point()

static void test_ptarray_contains_point ( )
static

Definition at line 463 of file cu_ptarray.c.

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().

464 {
465 /* int ptarray_contains_point(const POINTARRAY *pa, const POINT2D *pt, int *winding_number) */
466 
467  LWLINE *lwline;
468  POINTARRAY *pa;
469  POINT2D pt;
470  int rv;
471 
472  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 0, 0 1, 1 1, 1 0, 0 0)"));
473  pa = lwline->points;
474 
475  /* Point in middle of square */
476  pt.x = 0.5;
477  pt.y = 0.5;
478  rv = ptarray_contains_point(pa, &pt);
479  CU_ASSERT_EQUAL(rv, LW_INSIDE);
480 
481  /* Point on left edge of square */
482  pt.x = 0;
483  pt.y = 0.5;
484  rv = ptarray_contains_point(pa, &pt);
485  CU_ASSERT_EQUAL(rv, LW_BOUNDARY);
486 
487  /* Point on top edge of square */
488  pt.x = 0.5;
489  pt.y = 1;
490  rv = ptarray_contains_point(pa, &pt);
491  CU_ASSERT_EQUAL(rv, LW_BOUNDARY);
492 
493  /* Point on bottom left corner of square */
494  pt.x = 0;
495  pt.y = 0;
496  rv = ptarray_contains_point(pa, &pt);
497  CU_ASSERT_EQUAL(rv, LW_BOUNDARY);
498 
499  /* Point on top left corner of square */
500  pt.x = 0;
501  pt.y = 1;
502  rv = ptarray_contains_point(pa, &pt);
503  CU_ASSERT_EQUAL(rv, LW_BOUNDARY);
504 
505  /* Point outside top left corner of square */
506  pt.x = -0.1;
507  pt.y = 1;
508  rv = ptarray_contains_point(pa, &pt);
509  CU_ASSERT_EQUAL(rv, LW_OUTSIDE);
510 
511  /* Point outside top left corner of square */
512  pt.x = 0;
513  pt.y = 1.1;
514  rv = ptarray_contains_point(pa, &pt);
515  CU_ASSERT_EQUAL(rv, LW_OUTSIDE);
516 
517  /* Point outside left side of square */
518  pt.x = -0.2;
519  pt.y = 0.5;
520  rv = ptarray_contains_point(pa, &pt);
521  CU_ASSERT_EQUAL(rv, LW_OUTSIDE);
522 
523  lwline_free(lwline);
524  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 0, 1 1, 2 0, 0 0)"));
525  pa = lwline->points;
526 
527  /* Point outside grazing top of triangle */
528  pt.x = 0;
529  pt.y = 1;
530  rv = ptarray_contains_point(pa, &pt);
531  CU_ASSERT_EQUAL(rv, LW_OUTSIDE);
532 
533  lwline_free(lwline);
534  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 0, 0 4, 1 4, 2 2, 3 4, 4 4, 4 0, 0 0)"));
535  pa = lwline->points;
536 
537  /* Point outside grazing top of triangle */
538  pt.x = 1;
539  pt.y = 2;
540  rv = ptarray_contains_point(pa, &pt);
541  CU_ASSERT_EQUAL(rv, LW_INSIDE);
542 
543  /* Point outside grazing top of triangle */
544  pt.x = 3;
545  pt.y = 2;
546  rv = ptarray_contains_point(pa, &pt);
547  CU_ASSERT_EQUAL(rv, LW_INSIDE);
548 
549  lwline_free(lwline);
550 }
void lwline_free(LWLINE *line)
Definition: lwline.c:76
double x
Definition: liblwgeom.h:328
static LWGEOM * lwgeom_from_text(const char *str)
Definition: cu_ptarray.c:24
#define LW_INSIDE
Constants for point-in-polygon return values.
double y
Definition: liblwgeom.h:328
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:138
#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:736
#define LW_OUTSIDE
POINTARRAY * points
Definition: liblwgeom.h:422
Here is the call graph for this function:
Here is the caller graph for this function: