PostGIS  2.5.0dev-r@@SVN_REVISION@@
static void test_ptarray_contains_point ( )
static

Definition at line 468 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().

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

Here is the call graph for this function:

Here is the caller graph for this function: