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

Definition at line 557 of file cu_ptarray.c.

References ASSERT_STRING_EQUAL, cu_error_msg, cu_error_msg_reset(), LW_BOUNDARY, LW_INSIDE, LW_OUTSIDE, lwgeom_as_lwline(), lwgeom_from_text(), lwline_free(), LWLINE::points, ptarrayarc_contains_point(), POINT2D::x, and POINT2D::y.

Referenced by ptarray_suite_setup().

558 {
559  /* int ptarrayarc_contains_point(const POINTARRAY *pa, const POINT2D *pt) */
560 
561  LWLINE *lwline;
562  POINTARRAY *pa;
563  POINT2D pt;
564  int rv;
565 
566  /*** Collection of semi-circles surrounding unit square ***/
567  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 -1, -2 0, -1 1, 0 2, 1 1, 2 0, 1 -1, 0 -2, -1 -1)"));
568  pa = lwline->points;
569 
570  /* Point in middle of square */
571  pt.x = 0;
572  pt.y = 0;
573  rv = ptarrayarc_contains_point(pa, &pt);
574  CU_ASSERT_EQUAL(rv, LW_INSIDE);
575 
576  /* Point in left lobe */
577  pt.x = -1.1;
578  pt.y = 0.1;
579  rv = ptarrayarc_contains_point(pa, &pt);
580  CU_ASSERT_EQUAL(rv, LW_INSIDE);
581 
582  /* Point on boundary of left lobe */
583  pt.x = -1;
584  pt.y = 0;
585  rv = ptarrayarc_contains_point(pa, &pt);
586  CU_ASSERT_EQUAL(rv, LW_INSIDE);
587 
588  /* Point on boundary vertex */
589  pt.x = -1;
590  pt.y = 1;
591  rv = ptarrayarc_contains_point(pa, &pt);
592  CU_ASSERT_EQUAL(rv, LW_BOUNDARY);
593 
594  /* Point outside */
595  pt.x = -1.5;
596  pt.y = 1.5;
597  rv = ptarrayarc_contains_point(pa, &pt);
598  CU_ASSERT_EQUAL(rv, LW_OUTSIDE);
599 
600  /*** Two-edge ring made up of semi-circles (really, a circle) ***/
601  lwline_free(lwline);
602  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 0 1, 1 0, 0 -1, -1 0)"));
603  pa = lwline->points;
604 
605  /* Point outside */
606  pt.x = -1.5;
607  pt.y = 1.5;
608  rv = ptarrayarc_contains_point(pa, &pt);
609  CU_ASSERT_EQUAL(rv, LW_OUTSIDE);
610 
611  /* Point more outside */
612  pt.x = 2.5;
613  pt.y = 1.5;
614  rv = ptarrayarc_contains_point(pa, &pt);
615  CU_ASSERT_EQUAL(rv, LW_OUTSIDE);
616 
617  /* Point more outside */
618  pt.x = 2.5;
619  pt.y = 2.5;
620  rv = ptarrayarc_contains_point(pa, &pt);
621  CU_ASSERT_EQUAL(rv, LW_OUTSIDE);
622 
623  /* Point inside at middle */
624  pt.x = 0;
625  pt.y = 0;
626  rv = ptarrayarc_contains_point(pa, &pt);
627  CU_ASSERT_EQUAL(rv, LW_INSIDE);
628 
629  /* Point inside offset from middle */
630  pt.x = 0.01;
631  pt.y = 0.01;
632  rv = ptarrayarc_contains_point(pa, &pt);
633  CU_ASSERT_EQUAL(rv, LW_INSIDE);
634 
635  /* Point on edge vertex */
636  pt.x = 0;
637  pt.y = 1;
638  rv = ptarrayarc_contains_point(pa, &pt);
639  CU_ASSERT_EQUAL(rv, LW_BOUNDARY);
640 
641  /*** Two-edge ring, closed ***/
642  lwline_free(lwline);
643  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(1 6, 6 1, 9 7, 6 10, 1 6)"));
644  pa = lwline->points;
645 
646  /* Point to left of ring */
647  pt.x = 20;
648  pt.y = 4;
649  rv = ptarrayarc_contains_point(pa, &pt);
650  CU_ASSERT_EQUAL(rv, LW_OUTSIDE);
651 
652  /*** One-edge ring, closed circle ***/
653  lwline_free(lwline);
654  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 1 0, -1 0)"));
655  pa = lwline->points;
656 
657  /* Point inside */
658  pt.x = 0;
659  pt.y = 0;
660  rv = ptarrayarc_contains_point(pa, &pt);
661  CU_ASSERT_EQUAL(rv, LW_INSIDE);
662 
663  /* Point outside */
664  pt.x = 0;
665  pt.y = 2;
666  rv = ptarrayarc_contains_point(pa, &pt);
667  CU_ASSERT_EQUAL(rv, LW_OUTSIDE);
668 
669  /* Point on boundary */
670  pt.x = 0;
671  pt.y = 1;
672  rv = ptarrayarc_contains_point(pa, &pt);
673  CU_ASSERT_EQUAL(rv, LW_BOUNDARY);
674 
675  /*** Overshort ring ***/
676  lwline_free(lwline);
677  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 1 0)"));
678  pa = lwline->points;
680  rv = ptarrayarc_contains_point(pa, &pt);
681  //printf("%s\n", cu_error_msg);
682  ASSERT_STRING_EQUAL("ptarrayarc_contains_point called with even number of points", cu_error_msg);
683 
684  /*** Unclosed ring ***/
685  lwline_free(lwline);
686  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 1 0, 2 0)"));
687  pa = lwline->points;
689  rv = ptarrayarc_contains_point(pa, &pt);
690  ASSERT_STRING_EQUAL("ptarrayarc_contains_point called on unclosed ring", cu_error_msg);
691 
692  lwline_free(lwline);
693 }
#define ASSERT_STRING_EQUAL(o, e)
int ptarrayarc_contains_point(const POINTARRAY *pa, const POINT2D *pt)
For POINTARRAYs representing CIRCULARSTRINGS.
Definition: ptarray.c:826
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
void cu_error_msg_reset()
#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
#define LW_OUTSIDE
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]
POINTARRAY * points
Definition: liblwgeom.h:421

Here is the call graph for this function:

Here is the caller graph for this function: