PostGIS  3.2.2dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_pt_ptarrayarc()

static void test_lw_dist2d_pt_ptarrayarc ( void  )
static

Definition at line 1132 of file cu_measures.c.

1133 {
1134  /* lw_dist2d_pt_ptarrayarc(const POINT2D *p, const POINTARRAY *pa, DISTPTS *dl) */
1135  DISTPTS dl;
1136  int rv;
1137  LWLINE *lwline;
1138  POINT2D P;
1139 
1140  /* Unit semi-circle above X axis */
1141  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 0 1, 1 0)"));
1142 
1143  /* Point at origin */
1144  P.x = P.y = 0;
1146  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1147  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1148  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1149 
1150  /* Point above arc on Y axis */
1151  P.y = 2;
1153  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1154  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1155  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1156 
1157  /* Point 45 degrees off arc, 2 radii from center */
1158  P.y = P.x = 2 * cos(M_PI_4);
1160  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1161  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1162  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1163 
1164  /* Four unit semi-circles surrounding the 2x2 box around origin */
1165  lwline_free(lwline);
1166  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)"));
1167 
1168  /* Point at origin */
1169  P.x = P.y = 0;
1171  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1172  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1173  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0), 0.000001);
1174 
1175  /* Point on box edge */
1176  P.x = -1; P.y = 0;
1178  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1179  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1180  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1181 
1182  /* Point within a semicircle lobe */
1183  P.x = -1.5; P.y = 0;
1185  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1186  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1187  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1188 
1189  /* Point outside a semicircle lobe */
1190  P.x = -2.5; P.y = 0;
1192  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1193  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1194  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1195 
1196  /* Point outside a semicircle lobe */
1197  P.y = -2.5; P.x = 0;
1199  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1200  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1201  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1202 
1203  /* Point outside a semicircle lobe */
1204  P.y = 2; P.x = 1;
1206  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1207  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1208  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1.0, 0.000001);
1209 
1210  /* Clean up */
1211  lwline_free(lwline);
1212 }
static LWGEOM * lwgeom_from_text(const char *str)
Definition: cu_measures.c:25
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:162
#define LW_SUCCESS
Definition: liblwgeom.h:111
void lwline_free(LWLINE *line)
Definition: lwline.c:67
void lw_dist2d_distpts_init(DISTPTS *dl, int mode)
Definition: measures.c:64
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:1137
#define DIST_MIN
Definition: measures.h:44
double distance
Definition: measures.h:51
Structure used in distance-calculations.
Definition: measures.h:50
POINTARRAY * points
Definition: liblwgeom.h:497
double y
Definition: liblwgeom.h:404
double x
Definition: liblwgeom.h:404

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

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