PostGIS  2.5.2dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_pt_ptarrayarc()

static void test_lw_dist2d_pt_ptarrayarc ( void  )
static

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

1008 {
1009  /* lw_dist2d_pt_ptarrayarc(const POINT2D *p, const POINTARRAY *pa, DISTPTS *dl) */
1010  DISTPTS dl;
1011  int rv;
1012  LWLINE *lwline;
1013  POINT2D P;
1014 
1015  /* Unit semi-circle above X axis */
1016  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 0 1, 1 0)"));
1017 
1018  /* Point at origin */
1019  P.x = P.y = 0;
1021  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1022  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1023  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1024 
1025  /* Point above arc on Y axis */
1026  P.y = 2;
1028  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1029  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1030  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1031 
1032  /* Point 45 degrees off arc, 2 radii from center */
1033  P.y = P.x = 2 * cos(M_PI_4);
1035  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1036  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1037  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1038 
1039  /* Four unit semi-circles surrounding the 2x2 box around origin */
1040  lwline_free(lwline);
1041  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)"));
1042 
1043  /* Point at origin */
1044  P.x = P.y = 0;
1046  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1047  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1048  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0), 0.000001);
1049 
1050  /* Point on box edge */
1051  P.x = -1; P.y = 0;
1053  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1054  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1055  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1056 
1057  /* Point within a semicircle lobe */
1058  P.x = -1.5; P.y = 0;
1060  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1061  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1062  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1063 
1064  /* Point outside a semicircle lobe */
1065  P.x = -2.5; P.y = 0;
1067  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1068  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1069  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1070 
1071  /* Point outside a semicircle lobe */
1072  P.y = -2.5; P.x = 0;
1074  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1075  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1076  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1077 
1078  /* Point outside a semicircle lobe */
1079  P.y = 2; P.x = 1;
1081  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1082  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1083  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1.0, 0.000001);
1084 
1085  /* Clean up */
1086  lwline_free(lwline);
1087 }
#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:25
double x
Definition: liblwgeom.h:330
#define DIST_MIN
Definition: measures.h:44
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:51
Structure used in distance-calculations.
Definition: measures.h:49
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: