PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_pt_ptarrayarc()

static void test_lw_dist2d_pt_ptarrayarc ( void  )
static

Definition at line 1117 of file cu_measures.c.

1118 {
1119  /* lw_dist2d_pt_ptarrayarc(const POINT2D *p, const POINTARRAY *pa, DISTPTS *dl) */
1120  DISTPTS dl;
1121  int rv;
1122  LWLINE *lwline;
1123  POINT2D P;
1124 
1125  /* Unit semi-circle above X axis */
1126  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 0 1, 1 0)"));
1127 
1128  /* Point at origin */
1129  P.x = P.y = 0;
1131  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1132  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1133  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1134 
1135  /* Point above arc on Y axis */
1136  P.y = 2;
1138  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1139  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1140  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1141 
1142  /* Point 45 degrees off arc, 2 radii from center */
1143  P.y = P.x = 2 * cos(M_PI_4);
1145  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1146  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1147  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1148 
1149  /* Four unit semi-circles surrounding the 2x2 box around origin */
1150  lwline_free(lwline);
1151  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)"));
1152 
1153  /* Point at origin */
1154  P.x = P.y = 0;
1156  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1157  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1158  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0), 0.000001);
1159 
1160  /* Point on box edge */
1161  P.x = -1; P.y = 0;
1163  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1164  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1165  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
1166 
1167  /* Point within a semicircle lobe */
1168  P.x = -1.5; P.y = 0;
1170  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1171  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1172  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1173 
1174  /* Point outside a semicircle lobe */
1175  P.x = -2.5; P.y = 0;
1177  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1178  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1179  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1180 
1181  /* Point outside a semicircle lobe */
1182  P.y = -2.5; P.x = 0;
1184  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1185  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1186  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
1187 
1188  /* Point outside a semicircle lobe */
1189  P.y = 2; P.x = 1;
1191  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
1192  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
1193  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1.0, 0.000001);
1194 
1195  /* Clean up */
1196  lwline_free(lwline);
1197 }
static LWGEOM * lwgeom_from_text(const char *str)
Definition: cu_measures.c:25
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:161
#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:1159
#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:469
double y
Definition: liblwgeom.h:376
double x
Definition: liblwgeom.h:376

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: