PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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 LWCIRCSTRING *lwcirc;
437 POINTARRAY *pa;
438 POINT2D pt;
439 int rv;
440
441 /*** Collection of semi-circles surrounding unit square ***/
442 lwcirc = lwgeom_as_lwcircstring(lwgeom_from_text("CIRCULARSTRING(-1 -1, -2 0, -1 1, 0 2, 1 1, 2 0, 1 -1, 0 -2, -1 -1)"));
443 pa = lwcirc->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 lwcircstring_free(lwcirc);
477 lwcirc = lwgeom_as_lwcircstring(lwgeom_from_text("CIRCULARSTRING(-1 0, 0 1, 1 0, 0 -1, -1 0)"));
478 pa = lwcirc->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 lwcircstring_free(lwcirc);
518 lwcirc = lwgeom_as_lwcircstring(lwgeom_from_text("CIRCULARSTRING(1 6, 6 1, 9 7, 6 10, 1 6)"));
519 pa = lwcirc->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 lwcircstring_free(lwcirc);
529 lwcirc = lwgeom_as_lwcircstring(lwgeom_from_text("CIRCULARSTRING(-1 0, 1 0, -1 0)"));
530 pa = lwcirc->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 lwcircstring_free(lwcirc);
552 lwcirc = lwgeom_as_lwcircstring(lwgeom_from_text("CIRCULARSTRING(-1 0, 1 0)"));
553 pa = lwcirc->points;
555 rv = ptarrayarc_contains_point(pa, &pt);
556 //printf("%s\n", cu_error_msg);
557 ASSERT_STRING_EQUAL(cu_error_msg, "ptarrayarc_raycast_intersections called with even number of points");
558
559 /*** Unclosed ring ***/
560 lwcircstring_free(lwcirc);
561 lwcirc = lwgeom_as_lwcircstring(lwgeom_from_text("CIRCULARSTRING(-1 0, 1 0, 2 0)"));
562 pa = lwcirc->points;
564 rv = ptarrayarc_contains_point(pa, &pt);
565 ASSERT_STRING_EQUAL(cu_error_msg, "ptarrayarc_contains_point called on unclosed ring");
566
567 lwcircstring_free(lwcirc);
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)
void lwcircstring_free(LWCIRCSTRING *curve)
LWCIRCSTRING * lwgeom_as_lwcircstring(const LWGEOM *lwgeom)
Definition lwgeom.c:216
#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:1123
#define LW_OUTSIDE
POINTARRAY * points
Definition liblwgeom.h:507
double y
Definition liblwgeom.h:390
double x
Definition liblwgeom.h:390

References ASSERT_STRING_EQUAL, cu_error_msg, cu_error_msg_reset(), LW_BOUNDARY, LW_INSIDE, LW_OUTSIDE, lwcircstring_free(), lwgeom_as_lwcircstring(), lwgeom_from_text(), LWCIRCSTRING::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: