PostGIS  3.4.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 1407 of file cu_algorithm.c.

1408 {
1411  LWPOINT* expected_result = NULL;
1412  POINT4D actual_pt;
1413  POINT4D expected_pt;
1414  const double tolerance = FP_TOLERANCE / 10.0;
1415 
1416  LWPOINT* result = lwgeom_median(g, tolerance, iter_count, fail_if_not_converged);
1417  int passed = LW_FALSE;
1418 
1419  if (expected != NULL)
1420  {
1421  expected_result = lwgeom_as_lwpoint(lwgeom_from_wkt(expected, LW_PARSER_CHECK_NONE));
1422  lwpoint_getPoint4d_p(expected_result, &expected_pt);
1423  }
1424  if (result != NULL)
1425  {
1426  lwpoint_getPoint4d_p(result, &actual_pt);
1427  }
1428 
1429  if (result != NULL && expected != NULL) /* got something, expecting something */
1430  {
1431  passed = LW_TRUE;
1432  passed = passed && lwgeom_is_empty((LWGEOM*) expected_result) == lwgeom_is_empty((LWGEOM*) result);
1433  passed = passed && (lwgeom_has_z((LWGEOM*) expected_result) == lwgeom_has_z((LWGEOM*) result));
1434 
1435  if (passed && !lwgeom_is_empty((LWGEOM*) result))
1436  {
1437  if (g->type == POINTTYPE)
1438  {
1439  passed &= fabs(actual_pt.x - expected_pt.x) < tolerance;
1440  passed &= fabs(actual_pt.y - expected_pt.y) < tolerance;
1441  passed &= (!lwgeom_has_z((LWGEOM*) expected_result) || fabs(actual_pt.z - expected_pt.z) < tolerance);
1442  passed &= (!lwgeom_has_m((LWGEOM*) expected_result) || fabs(actual_pt.m - expected_pt.m) < tolerance);
1443  }
1444  else
1445  {
1446  /* Check that the difference between the obtained geometric
1447  median and the expected point is within tolerance */
1448  uint32_t npoints = 1;
1449  int input_empty = LW_TRUE;
1450  POINT4D* points = lwmpoint_extract_points_4d(lwgeom_as_lwmpoint(g), &npoints, &input_empty);
1451  double distance_expected = test_weighted_distance(&expected_pt, points, npoints);
1452  double distance_result = test_weighted_distance(&actual_pt, points, npoints);
1453 
1454  passed = distance_result <= (1.0 + tolerance) * distance_expected;
1455  if (!passed)
1456  {
1457  printf("Diff: Got %.10f Expected %.10f\n", distance_result, distance_expected);
1458  }
1459  lwfree(points);
1460  }
1461  }
1462 
1463  if (!passed)
1464  {
1465  printf("median_test input %s (parsed %s) expected %s got %s\n",
1466  input, lwgeom_to_ewkt(g),
1467  lwgeom_to_ewkt((LWGEOM*) expected_result),
1469  }
1470 
1471  }
1472  else if (result == NULL && expected == NULL) /* got nothing, expecting nothing */
1473  {
1474  passed = LW_TRUE;
1475  }
1476  else if (result != NULL && expected == NULL) /* got something, expecting nothing */
1477  {
1478  passed = LW_FALSE;
1479  printf("median_test input %s (parsed %s) expected NULL got %s\n", input, lwgeom_to_ewkt(g), lwgeom_to_ewkt((LWGEOM*) result));
1480  }
1481  else if (result == NULL && expected != NULL) /* got nothing, expecting something */
1482  {
1483  passed = LW_FALSE;
1484  printf("%s", cu_error_msg);
1485  printf("median_test input %s (parsed %s) expected %s got NULL\n", input, lwgeom_to_ewkt(g), lwgeom_to_ewkt((LWGEOM*) expected_result));
1486  }
1487 
1488  CU_ASSERT_TRUE(passed);
1489 
1490  lwgeom_free(g);
1491  lwpoint_free(expected_result);
1493 }
static double test_weighted_distance(const POINT4D *curr, const POINT4D *points, uint32_t npoints)
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
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:1155
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2114
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 alloced string.
Definition: lwgeom.c:565
void lwfree(void *mem)
Definition: lwutil.c:242
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:905
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:203
static LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwinline.h:131
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: