PostGIS  3.6.1dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_pt_ptarrayarc()

static void test_lw_dist2d_pt_ptarrayarc ( void  )
static

Definition at line 1166 of file cu_measures.c.

1167 {
1168  /* lw_dist2d_pt_ptarrayarc(const POINT2D *p, const POINTARRAY *pa, DISTPTS *dl) */
1169  DISTPTS dl;
1170  int rv;
1171  LWLINE *lwline;
1172  POINT2D P;
1173 
1174  /* Unit semi-circle above X axis */
1175  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 0 1, 1 0)"));
1176 
1177  /* Point at origin */
1178  P.x = P.y = 0;
1180  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1181  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1182  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1183 
1184  /* Point above arc on Y axis */
1185  P.y = 2;
1187  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1188  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1189  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1190 
1191  /* Point 45 degrees off arc, 2 radii from center */
1192  P.y = P.x = 2 * cos(M_PI_4);
1194  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1195  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1196  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1197 
1198  /* Four unit semi-circles surrounding the 2x2 box around origin */
1199  lwline_free(lwline);
1200  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)"));
1201 
1202  /* Point at origin */
1203  P.x = P.y = 0;
1205  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1206  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1207  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0), 0.000001);
1208 
1209  /* Point on box edge */
1210  P.x = -1; P.y = 0;
1212  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1213  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1214  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1215 
1216  /* Point within a semicircle lobe */
1217  P.x = -1.5; P.y = 0;
1219  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1220  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1221  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1222 
1223  /* Point outside a semicircle lobe */
1224  P.x = -2.5; P.y = 0;
1226  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1227  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1228  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1229 
1230  /* Point outside a semicircle lobe */
1231  P.y = -2.5; P.x = 0;
1233  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1234  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1235  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1236 
1237  /* Point outside a semicircle lobe */
1238  P.y = 2; P.x = 1;
1240  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1241  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1242  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1.0, 0.000001);
1243 
1244  /* Clean up */
1245  lwline_free(lwline);
1246 }
static LWGEOM * lwgeom_from_text(const char *str)
Definition: cu_measures.c:25
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:179
#define LW_SUCCESS
Definition: liblwgeom.h:97
void lwline_free(LWLINE *line)
Definition: lwline.c:67
void lw_dist2d_distpts_init(DISTPTS *dl, int mode)
Definition: measures.c:67
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:1148
#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:483
double y
Definition: liblwgeom.h:390
double x
Definition: liblwgeom.h:390

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: