PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_median_robustness()

static void test_median_robustness ( void  )
static

Definition at line 1236 of file cu_algorithm.c.

1237 {
1238  /* A simple implementation of Weiszfeld's algorithm will fail if the median is equal
1239  * to any one of the inputs, during any iteration of the algorithm.
1240  *
1241  * Because the algorithm uses the centroid as a starting point, this situation will
1242  * occur in the test case below.
1243  */
1244  do_median_test("MULTIPOINT ((0 -1), (0 0), (0 1))", "POINT (0 0)", LW_TRUE, 1000);
1245 
1246  /* Same as above but 3D, and shifter */
1247  do_median_test("MULTIPOINT ((1 -1 3), (1 0 2), (2 1 1))", "POINT (1 0 2)", LW_TRUE, 1000);
1248 
1249  /* Starting point is duplicated */
1250  do_median_test("MULTIPOINT ((0 -1), (0 0), (0 0), (0 1))", "POINT (0 0)", LW_TRUE, 1000);
1251 
1252  /* Cube */
1253  do_median_test("MULTIPOINT ((10 10 10), (10 20 10), (20 10 10), (20 20 10), (10 10 20), (10 20 20), (20 10 20), (20 20 20))",
1254  "POINT (15 15 15)", LW_TRUE, 1000);
1255 
1256  /* Some edge cases */
1257  do_median_test("POINT (7 6)", "POINT (7 6)", LW_TRUE, 1000);
1258  do_median_test("POINT (7 6 2)", "POINT (7 6 2)", LW_TRUE, 1000);
1259  do_median_test("MULTIPOINT ((7 6 2), EMPTY)", "POINT (7 6 2)", LW_TRUE, 1000);
1260 
1261  /* Empty input */
1262  do_median_test("MULTIPOINT EMPTY", "POINT EMPTY", LW_FALSE, 1000);
1263  do_median_test("MULTIPOINT (EMPTY)", "POINT EMPTY", LW_FALSE, 1000);
1264  do_median_test("MULTIPOINT EMPTY", "POINT EMPTY", LW_TRUE, 1000);
1265  do_median_test("MULTIPOINT (EMPTY)", "POINT EMPTY", LW_TRUE, 1000);
1266  do_median_test("MULTIPOINT ZM (1 -1 3 1, 1 0 2 7, 2 1 1 1, EMPTY)", "POINT (1 0 2)", LW_TRUE, 1000);
1267 
1268  /* Weighted input */
1269  do_median_test("MULTIPOINT ZM (1 -1 3 1, 1 0 2 7, 2 1 1 1)", "POINT (1 0 2)", LW_TRUE, 1000);
1270  do_median_test("MULTIPOINT ZM (-1 1 -3 1, -1 0 -2 7, -2 -1 -1 1)", "POINT (-1 0 -2)", LW_TRUE, 1000);
1271  do_median_test("MULTIPOINT ZM (-1 1 -3 1, -1 0 -2 7, -2 -1 -1 0.5, -2 -1 -1 0.5)", "POINT (-1 0 -2)", LW_TRUE, 1000);
1272 
1273  /* Point that is replaced by two half-weighted */
1274  do_median_test("MULTIPOINT ZM ((0 -1 0 1), (0 0 0 1), (0 1 0 0.5), (0 1 0 0.5))", "POINT (0 0 0)", LW_TRUE, 1000);
1275  /* Point is doubled and then erased by negative weight */
1276  do_median_test("MULTIPOINT ZM ((1 -1 3 1), (1 0 2 7), (2 1 1 2), (2 1 1 -1))", NULL, LW_TRUE, 1000);
1277  do_median_test("MULTIPOINT ZM ((1 -1 3 1), (1 0 2 7), (2 1 1 2), (2 1 1 -1))", NULL, LW_FALSE, 1000);
1278  /* Weightless input won't converge */
1279  do_median_test("MULTIPOINT ZM ((0 -1 0 0), (0 0 0 0), (0 0 0 0), (0 1 0 0))", NULL, LW_FALSE, 1000);
1280  do_median_test("MULTIPOINT ZM ((0 -1 0 0), (0 0 0 0), (0 0 0 0), (0 1 0 0))", NULL, LW_TRUE, 1000);
1281  /* Negative weight won't converge */
1282  do_median_test("MULTIPOINT ZM ((0 -1 0 -1), (0 0 0 -1), (0 1 0 -1))", NULL, LW_FALSE, 1000);
1283  do_median_test("MULTIPOINT ZM ((0 -1 0 -1), (0 0 0 -1), (0 1 0 -1))", NULL, LW_TRUE, 1000);
1284 
1285  /* Bind convergence too tightly */
1286  do_median_test("MULTIPOINT ((0 0), (1 1), (0 1), (2 2))", "POINT(0.75 1.0)", LW_FALSE, 0);
1287  do_median_test("MULTIPOINT ((0 0), (1 1), (0 1), (2 2))", NULL, LW_TRUE, 1);
1288  /* Unsupported geometry type */
1289  do_median_test("POLYGON((1 0,0 1,1 2,2 1,1 0))", NULL, LW_TRUE, 1000);
1290  do_median_test("POLYGON((1 0,0 1,1 2,2 1,1 0))", NULL, LW_FALSE, 1000);
1291 
1292  /* Median point is included */
1293  do_median_test("MULTIPOINT ZM ("
1294  "(1480 0 200 100),"
1295  "(620 0 200 100),"
1296  "(1000 0 -200 100),"
1297  "(1000 0 -590 100),"
1298  "(1025 0 65 100),"
1299  "(1025 0 -65 100)"
1300  ")",
1301  "POINT (1025 0 -65)", LW_TRUE, 10000);
1302 
1303 #if 0
1304  /* Leads to invalid result (0 0 0) with 80bit (fmulp + faddp) precision. ok with 64 bit float ops */
1305  do_median_test("MULTIPOINT ZM ("
1306  "(0 0 20000 0.5),"
1307  "(0 0 59000 0.5),"
1308  "(0 -3000 -3472.22222222222262644208967685699462890625 1),"
1309  "(0 3000 3472.22222222222262644208967685699462890625 1),"
1310  "(0 0 -1644.736842105263121993630193173885345458984375 1),"
1311  "(0 0 1644.736842105263121993630193173885345458984375 1),"
1312  "(0 48000 -20000 1.3),"
1313  "(0 -48000 -20000 1.3)"
1314  ")",
1315  "POINT (0 0 0)", LW_TRUE, 10000);
1316 #endif
1317 
1318 #if 0
1319  /* Leads to invalid result (0 0 0) with 64bit (vfmadd231sd) precision. Ok with 80 bit float ops */
1320  do_median_test("MULTIPOINT ZM ("
1321  "(0 0 20000 0.5),"
1322  "(0 0 59000 0.5),"
1323  "(0 -3000 -3472.22222222222262644208967685699462890625 1),"
1324  "(0 3000 3472.22222222222262644208967685699462890625 1),"
1325  "(0 -0.00000000000028047739569477638384522295466033823196 -1644.736842105263121993630193173885345458984375 1),"
1326  "(0 0.00000000000028047739569477638384522295466033823196 1644.736842105263121993630193173885345458984375 1),"
1327  "(0 48000 -20000 1.3),"
1328  "(0 -48000 -20000 1.3)"
1329  ")",
1330  "POINT (0 0 0)", LW_TRUE, 10000);
1331 #endif
1332 }
static void do_median_test(char *input, char *expected, int fail_if_not_converged, int iter_count)
#define LW_FALSE
Definition: liblwgeom.h:77
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76

References do_median_test(), LW_FALSE, and LW_TRUE.

Referenced by algorithms_suite_setup().

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