PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_ptarrayarc_contains_point()

static void test_ptarrayarc_contains_point ( )
static

Definition at line 432 of file cu_ptarray.c.

433 {
434  /* int ptarrayarc_contains_point(const POINTARRAY *pa, const POINT2D *pt) */
435 
436  LWLINE *lwline;
437  POINTARRAY *pa;
438  POINT2D pt;
439  int rv;
440 
441  /*** Collection of semi-circles surrounding unit square ***/
442  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)"));
443  pa = lwline->points;
444 
445  /* Point in middle of square */
446  pt.x = 0;
447  pt.y = 0;
448  rv = ptarrayarc_contains_point(pa, &pt);
449  CU_ASSERT_EQUAL(rv, LW_INSIDE);
450 
451  /* Point in left lobe */
452  pt.x = -1.1;
453  pt.y = 0.1;
454  rv = ptarrayarc_contains_point(pa, &pt);
455  CU_ASSERT_EQUAL(rv, LW_INSIDE);
456 
457  /* Point on boundary of left lobe */
458  pt.x = -1;
459  pt.y = 0;
460  rv = ptarrayarc_contains_point(pa, &pt);
461  CU_ASSERT_EQUAL(rv, LW_INSIDE);
462 
463  /* Point on boundary vertex */
464  pt.x = -1;
465  pt.y = 1;
466  rv = ptarrayarc_contains_point(pa, &pt);
467  CU_ASSERT_EQUAL(rv, LW_BOUNDARY);
468 
469  /* Point outside */
470  pt.x = -1.5;
471  pt.y = 1.5;
472  rv = ptarrayarc_contains_point(pa, &pt);
473  CU_ASSERT_EQUAL(rv, LW_OUTSIDE);
474 
475  /*** Two-edge ring made up of semi-circles (really, a circle) ***/
476  lwline_free(lwline);
477  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 0 1, 1 0, 0 -1, -1 0)"));
478  pa = lwline->points;
479 
480  /* Point outside */
481  pt.x = -1.5;
482  pt.y = 1.5;
483  rv = ptarrayarc_contains_point(pa, &pt);
484  CU_ASSERT_EQUAL(rv, LW_OUTSIDE);
485 
486  /* Point more outside */
487  pt.x = 2.5;
488  pt.y = 1.5;
489  rv = ptarrayarc_contains_point(pa, &pt);
490  CU_ASSERT_EQUAL(rv, LW_OUTSIDE);
491 
492  /* Point more outside */
493  pt.x = 2.5;
494  pt.y = 2.5;
495  rv = ptarrayarc_contains_point(pa, &pt);
496  CU_ASSERT_EQUAL(rv, LW_OUTSIDE);
497 
498  /* Point inside at middle */
499  pt.x = 0;
500  pt.y = 0;
501  rv = ptarrayarc_contains_point(pa, &pt);
502  CU_ASSERT_EQUAL(rv, LW_INSIDE);
503 
504  /* Point inside offset from middle */
505  pt.x = 0.01;
506  pt.y = 0.01;
507  rv = ptarrayarc_contains_point(pa, &pt);
508  CU_ASSERT_EQUAL(rv, LW_INSIDE);
509 
510  /* Point on edge vertex */
511  pt.x = 0;
512  pt.y = 1;
513  rv = ptarrayarc_contains_point(pa, &pt);
514  CU_ASSERT_EQUAL(rv, LW_BOUNDARY);
515 
516  /*** Two-edge ring, closed ***/
517  lwline_free(lwline);
518  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(1 6, 6 1, 9 7, 6 10, 1 6)"));
519  pa = lwline->points;
520 
521  /* Point to left of ring */
522  pt.x = 20;
523  pt.y = 4;
524  rv = ptarrayarc_contains_point(pa, &pt);
525  CU_ASSERT_EQUAL(rv, LW_OUTSIDE);
526 
527  /*** One-edge ring, closed circle ***/
528  lwline_free(lwline);
529  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 1 0, -1 0)"));
530  pa = lwline->points;
531 
532  /* Point inside */
533  pt.x = 0;
534  pt.y = 0;
535  rv = ptarrayarc_contains_point(pa, &pt);
536  CU_ASSERT_EQUAL(rv, LW_INSIDE);
537 
538  /* Point outside */
539  pt.x = 0;
540  pt.y = 2;
541  rv = ptarrayarc_contains_point(pa, &pt);
542  CU_ASSERT_EQUAL(rv, LW_OUTSIDE);
543 
544  /* Point on boundary */
545  pt.x = 0;
546  pt.y = 1;
547  rv = ptarrayarc_contains_point(pa, &pt);
548  CU_ASSERT_EQUAL(rv, LW_BOUNDARY);
549 
550  /*** Overshort ring ***/
551  lwline_free(lwline);
552  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 1 0)"));
553  pa = lwline->points;
555  rv = ptarrayarc_contains_point(pa, &pt);
556  //printf("%s\n", cu_error_msg);
557  ASSERT_STRING_EQUAL("ptarrayarc_contains_point called with even number of points", cu_error_msg);
558 
559  /*** Unclosed ring ***/
560  lwline_free(lwline);
561  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 1 0, 2 0)"));
562  pa = lwline->points;
564  rv = ptarrayarc_contains_point(pa, &pt);
565  ASSERT_STRING_EQUAL("ptarrayarc_contains_point called on unclosed ring", cu_error_msg);
566 
567  lwline_free(lwline);
568 }
static LWGEOM * lwgeom_from_text(const char *str)
Definition: cu_ptarray.c:24
void cu_error_msg_reset()
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]
#define ASSERT_STRING_EQUAL(o, e)
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 ptarrayarc_contains_point(const POINTARRAY *pa, const POINT2D *pt)
For POINTARRAYs representing CIRCULARSTRINGS.
Definition: ptarray.c:833
#define LW_OUTSIDE
POINTARRAY * points
Definition: liblwgeom.h:425
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331

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

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