PostGIS  2.5.0beta1dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_pt_ptarrayarc()

static void test_lw_dist2d_pt_ptarrayarc ( void  )
static

Definition at line 962 of file cu_measures.c.

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

Referenced by measures_suite_setup().

963 {
964  /* lw_dist2d_pt_ptarrayarc(const POINT2D *p, const POINTARRAY *pa, DISTPTS *dl) */
965  DISTPTS dl;
966  int rv;
967  LWLINE *lwline;
968  POINT2D P;
969 
970  /* Unit semi-circle above X axis */
971  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 0 1, 1 0)"));
972 
973  /* Point at origin */
974  P.x = P.y = 0;
976  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
977  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
978  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
979 
980  /* Point above arc on Y axis */
981  P.y = 2;
983  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
984  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
985  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
986 
987  /* Point 45 degrees off arc, 2 radii from center */
988  P.y = P.x = 2 * cos(M_PI_4);
990  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
991  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
992  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
993 
994  /* Four unit semi-circles surrounding the 2x2 box around origin */
995  lwline_free(lwline);
996  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)"));
997 
998  /* Point at origin */
999  P.x = P.y = 0;
1001  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1002  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1003  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0), 0.000001);
1004 
1005  /* Point on box edge */
1006  P.x = -1; P.y = 0;
1008  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1009  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1010  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1011 
1012  /* Point within a semicircle lobe */
1013  P.x = -1.5; P.y = 0;
1015  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1016  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1017  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1018 
1019  /* Point outside a semicircle lobe */
1020  P.x = -2.5; P.y = 0;
1022  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1023  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1024  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1025 
1026  /* Point outside a semicircle lobe */
1027  P.y = -2.5; P.x = 0;
1029  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1030  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1031  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1032 
1033  /* Point outside a semicircle lobe */
1034  P.y = 2; P.x = 1;
1036  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1037  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1038  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1.0, 0.000001);
1039 
1040  /* Clean up */
1041  lwline_free(lwline);
1042 }
#define LW_SUCCESS
Definition: liblwgeom.h:79
void lwline_free(LWLINE *line)
Definition: lwline.c:76
static LWGEOM * lwgeom_from_text(const char *str)
Definition: cu_measures.c:24
double x
Definition: liblwgeom.h:330
#define DIST_MIN
Definition: measures.h:41
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:1083
double y
Definition: liblwgeom.h:330
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:170
double distance
Definition: measures.h:48
Structure used in distance-calculations.
Definition: measures.h:46
void lw_dist2d_distpts_init(DISTPTS *dl, int mode)
Definition: measures.c:67
POINTARRAY * points
Definition: liblwgeom.h:424
Here is the call graph for this function:
Here is the caller graph for this function: