PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ do_median_test()

static void do_median_test ( char *  input,
char *  expected,
int  fail_if_not_converged,
int  iter_count 
)
static

Definition at line 1406 of file cu_algorithm.c.

1407 {
1410  LWPOINT* expected_result = NULL;
1411  POINT4D actual_pt;
1412  POINT4D expected_pt;
1413  const double tolerance = FP_TOLERANCE / 10.0;
1414 
1415  LWPOINT* result = lwgeom_median(g, tolerance, iter_count, fail_if_not_converged);
1416  int passed = LW_FALSE;
1417 
1418  if (expected != NULL)
1419  {
1420  expected_result = lwgeom_as_lwpoint(lwgeom_from_wkt(expected, LW_PARSER_CHECK_NONE));
1421  lwpoint_getPoint4d_p(expected_result, &expected_pt);
1422  }
1423  if (result != NULL)
1424  {
1425  lwpoint_getPoint4d_p(result, &actual_pt);
1426  }
1427 
1428  if (result != NULL && expected != NULL) /* got something, expecting something */
1429  {
1430  passed = LW_TRUE;
1431  passed = passed && lwgeom_is_empty((LWGEOM*) expected_result) == lwgeom_is_empty((LWGEOM*) result);
1432  passed = passed && (lwgeom_has_z((LWGEOM*) expected_result) == lwgeom_has_z((LWGEOM*) result));
1433 
1434  if (passed && !lwgeom_is_empty((LWGEOM*) result))
1435  {
1436  if (g->type == POINTTYPE)
1437  {
1438  passed &= fabs(actual_pt.x - expected_pt.x) < tolerance;
1439  passed &= fabs(actual_pt.y - expected_pt.y) < tolerance;
1440  passed &= (!lwgeom_has_z((LWGEOM*) expected_result) || fabs(actual_pt.z - expected_pt.z) < tolerance);
1441  passed &= (!lwgeom_has_m((LWGEOM*) expected_result) || fabs(actual_pt.m - expected_pt.m) < tolerance);
1442  }
1443  else
1444  {
1445  /* Check that the difference between the obtained geometric
1446  median and the expected point is within tolerance */
1447  uint32_t npoints = 1;
1448  int input_empty = LW_TRUE;
1449  POINT4D* points = lwmpoint_extract_points_4d(lwgeom_as_lwmpoint(g), &npoints, &input_empty);
1450  double distance_expected = test_weighted_distance(&expected_pt, points, npoints);
1451  double distance_result = test_weighted_distance(&actual_pt, points, npoints);
1452 
1453  passed = distance_result <= (1.0 + tolerance) * distance_expected;
1454  if (!passed)
1455  {
1456  printf("Diff: Got %.10f Expected %.10f\n", distance_result, distance_expected);
1457  }
1458  lwfree(points);
1459  }
1460  }
1461 
1462  if (!passed)
1463  {
1464  printf("median_test input %s (parsed %s) expected %s got %s\n",
1465  input, lwgeom_to_ewkt(g),
1466  lwgeom_to_ewkt((LWGEOM*) expected_result),
1468  }
1469 
1470  }
1471  else if (result == NULL && expected == NULL) /* got nothing, expecting nothing */
1472  {
1473  passed = LW_TRUE;
1474  }
1475  else if (result != NULL && expected == NULL) /* got something, expecting nothing */
1476  {
1477  passed = LW_FALSE;
1478  printf("median_test input %s (parsed %s) expected NULL got %s\n", input, lwgeom_to_ewkt(g), lwgeom_to_ewkt((LWGEOM*) result));
1479  }
1480  else if (result == NULL && expected != NULL) /* got nothing, expecting something */
1481  {
1482  passed = LW_FALSE;
1483  printf("%s", cu_error_msg);
1484  printf("median_test input %s (parsed %s) expected %s got NULL\n", input, lwgeom_to_ewkt(g), lwgeom_to_ewkt((LWGEOM*) expected_result));
1485  }
1486 
1487  CU_ASSERT_TRUE(passed);
1488 
1489  lwgeom_free(g);
1490  lwpoint_free(expected_result);
1492 }
static double test_weighted_distance(const POINT4D *curr, const POINT4D *points, uint32_t npoints)
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
void cu_error_msg_reset()
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition: lwpoint.c:57
#define LW_FALSE
Definition: liblwgeom.h:94
LWMPOINT * lwgeom_as_lwmpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:242
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:213
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1218
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2146
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:934
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:102
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an allocated string.
Definition: lwgeom.c:565
void lwfree(void *mem)
Definition: lwutil.c:248
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:940
LWPOINT * lwgeom_median(const LWGEOM *g, double tol, uint32_t maxiter, char fail_if_not_converged)
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:93
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:941
POINT4D * lwmpoint_extract_points_4d(const LWMPOINT *g, uint32_t *npoints, int *input_empty)
#define FP_TOLERANCE
Floating point comparators.
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwinline.h:199
static LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwinline.h:127
uint8_t type
Definition: liblwgeom.h:462
double m
Definition: liblwgeom.h:414
double x
Definition: liblwgeom.h:414
double z
Definition: liblwgeom.h:414
double y
Definition: liblwgeom.h:414

References cu_error_msg, cu_error_msg_reset(), FP_TOLERANCE, LW_FALSE, LW_PARSER_CHECK_NONE, LW_TRUE, lwfree(), lwgeom_as_lwmpoint(), lwgeom_as_lwpoint(), lwgeom_free(), lwgeom_from_wkt(), lwgeom_has_m(), lwgeom_has_z(), lwgeom_is_empty(), lwgeom_median(), lwgeom_to_ewkt(), lwmpoint_extract_points_4d(), lwpoint_free(), lwpoint_getPoint4d_p(), POINT4D::m, POINTTYPE, result, test_weighted_distance(), LWGEOM::type, POINT4D::x, POINT4D::y, and POINT4D::z.

Referenced by test_median_robustness().

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