PostGIS  2.1.10dev-r@@SVN_REVISION@@
static void test_lw_dist2d_pt_ptarrayarc ( void  )
static

Definition at line 681 of file cu_measures.c.

References DIST_MIN, DISTPTS::distance, lw_dist2d_distpts_init(), lw_dist2d_pt_ptarrayarc(), lwgeom_as_lwline(), lwgeom_from_text(), lwline_free(), LWLINE::points, POINT2D::x, and POINT2D::y.

Referenced by measures_suite_setup().

682 {
683  /* lw_dist2d_pt_ptarrayarc(const POINT2D *p, const POINTARRAY *pa, DISTPTS *dl) */
684  DISTPTS dl;
685  int rv;
686  LWLINE *lwline;
687  POINT2D P;
688 
689  /* Unit semi-circle above X axis */
690  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 0 1, 1 0)"));
691 
692  /* Point at origin */
693  P.x = P.y = 0;
695  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
696  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
697 
698  /* Point above arc on Y axis */
699  P.y = 2;
701  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
702  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
703 
704  /* Point 45 degrees off arc, 2 radii from center */
705  P.y = P.x = 2 * cos(M_PI/4);
707  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
708  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
709 
710  /* Four unit semi-circles surrounding the 2x2 box around origin */
711  lwline_free(lwline);
712  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)"));
713 
714  /* Point at origin */
715  P.x = P.y = 0;
717  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
718  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0), 0.000001);
719 
720  /* Point on box edge */
721  P.x = -1; P.y = 0;
723  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
724  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
725 
726  /* Point within a semicircle lobe */
727  P.x = -1.5; P.y = 0;
729  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
730  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
731 
732  /* Point outside a semicircle lobe */
733  P.x = -2.5; P.y = 0;
735  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
736  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
737 
738  /* Point outside a semicircle lobe */
739  P.y = -2.5; P.x = 0;
741  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
742  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
743 
744  /* Point outside a semicircle lobe */
745  P.y = 2; P.x = 1;
747  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
748  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1.0, 0.000001);
749 
750  /* Clean up */
751  lwline_free(lwline);
752 }
#define DIST_MIN
void lwline_free(LWLINE *line)
Definition: lwline.c:63
static LWGEOM * lwgeom_from_text(const char *str)
Definition: cu_measures.c:23
double x
Definition: liblwgeom.h:284
int lw_dist2d_pt_ptarrayarc(const POINT2D *p, const POINTARRAY *pa, DISTPTS *dl)
Search all the arcs of pointarray to see which one is closest to p1 Returns minimum distance between ...
Definition: measures.c:1039
double y
Definition: liblwgeom.h:284
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:89
double distance
Definition: measures.h:23
Structure used in distance-calculations.
Definition: measures.h:21
void lw_dist2d_distpts_init(DISTPTS *dl, int mode)
Definition: measures.c:27
POINTARRAY * points
Definition: liblwgeom.h:378

Here is the call graph for this function:

Here is the caller graph for this function: