PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_pt_ptarrayarc()

static void test_lw_dist2d_pt_ptarrayarc ( void  )
static

Definition at line 1125 of file cu_measures.c.

1126 {
1127  /* lw_dist2d_pt_ptarrayarc(const POINT2D *p, const POINTARRAY *pa, DISTPTS *dl) */
1128  DISTPTS dl;
1129  int rv;
1130  LWLINE *lwline;
1131  POINT2D P;
1132 
1133  /* Unit semi-circle above X axis */
1134  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 0 1, 1 0)"));
1135 
1136  /* Point at origin */
1137  P.x = P.y = 0;
1139  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1140  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1141  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1142 
1143  /* Point above arc on Y axis */
1144  P.y = 2;
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 45 degrees off arc, 2 radii from center */
1151  P.y = P.x = 2 * cos(M_PI_4);
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  /* Four unit semi-circles surrounding the 2x2 box around origin */
1158  lwline_free(lwline);
1159  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)"));
1160 
1161  /* Point at origin */
1162  P.x = P.y = 0;
1164  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1165  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1166  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0), 0.000001);
1167 
1168  /* Point on box edge */
1169  P.x = -1; 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, 1, 0.000001);
1174 
1175  /* Point within a semicircle lobe */
1176  P.x = -1.5; 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, 0.5, 0.000001);
1181 
1182  /* Point outside a semicircle lobe */
1183  P.x = -2.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.y = -2.5; P.x = 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; P.x = 1;
1199  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1200  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1201  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1.0, 0.000001);
1202 
1203  /* Clean up */
1204  lwline_free(lwline);
1205 }
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: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:1160
#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: