PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ test_ptarrayarc_contains_point()

static void test_ptarrayarc_contains_point ( )
static

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

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