PostGIS  2.5.0dev-r@@SVN_REVISION@@
static void do_median_test ( char *  input,
char *  expected,
int  fail_if_not_converged,
int  iter_count 
)
static

Definition at line 1118 of file cu_algorithm.c.

References cu_error_msg, cu_error_msg_reset(), FP_EQUALS, FP_TOLERANCE, LW_FALSE, LW_PARSER_CHECK_NONE, LW_TRUE, lwgeom_as_lwpoint(), lwgeom_free(), lwgeom_from_wkt(), lwgeom_has_m(), lwgeom_has_z(), lwgeom_is_empty(), lwgeom_median(), lwgeom_to_ewkt(), lwpoint_free(), lwpoint_getPoint4d_p(), POINT4D::m, POINT4D::x, POINT4D::y, and POINT4D::z.

Referenced by test_median_robustness().

1119 {
1122  LWPOINT* expected_result = NULL;
1123  POINT4D actual_pt;
1124  POINT4D expected_pt;
1125 
1126  LWPOINT* result = lwgeom_median(g, FP_TOLERANCE / 10.0, iter_count, fail_if_not_converged);
1127  int passed = LW_FALSE;
1128 
1129  if (expected != NULL)
1130  {
1131  expected_result = lwgeom_as_lwpoint(lwgeom_from_wkt(expected, LW_PARSER_CHECK_NONE));
1132  lwpoint_getPoint4d_p(expected_result, &expected_pt);
1133  }
1134  if (result != NULL)
1135  {
1136  lwpoint_getPoint4d_p(result, &actual_pt);
1137  }
1138 
1139  if (result != NULL && expected != NULL) /* got something, expecting something */
1140  {
1141  passed = LW_TRUE;
1142  passed = passed && lwgeom_is_empty((LWGEOM*) expected_result) == lwgeom_is_empty((LWGEOM*) result);
1143  passed = passed && (lwgeom_has_z((LWGEOM*) expected_result) == lwgeom_has_z((LWGEOM*) result));
1144  if (!lwgeom_is_empty((LWGEOM*) result))
1145  {
1146  passed = passed && FP_EQUALS(actual_pt.x, expected_pt.x);
1147  passed = passed && FP_EQUALS(actual_pt.y, expected_pt.y);
1148  passed = passed && (!lwgeom_has_z((LWGEOM*) expected_result) || FP_EQUALS(actual_pt.z, expected_pt.z));
1149  passed = passed && (!lwgeom_has_m((LWGEOM*) expected_result) || FP_EQUALS(actual_pt.m, expected_pt.m));
1150  }
1151  if (!passed)
1152  printf("median_test input %s (parsed %s) expected %s got %s\n", input, lwgeom_to_ewkt(g), lwgeom_to_ewkt((LWGEOM*) expected_result), lwgeom_to_ewkt((LWGEOM*) result));
1153  }
1154  else if (result == NULL && expected == NULL) /* got nothing, expecting nothing */
1155  {
1156  passed = LW_TRUE;
1157  }
1158  else if (result != NULL && expected == NULL) /* got something, expecting nothing */
1159  {
1160  passed = LW_FALSE;
1161  printf("median_test input %s (parsed %s) expected NULL got %s\n", input, lwgeom_to_ewkt(g), lwgeom_to_ewkt((LWGEOM*) result));
1162  }
1163  else if (result == NULL && expected != NULL) /* got nothing, expecting something */
1164  {
1165  passed = LW_FALSE;
1166  printf("%s", cu_error_msg);
1167  printf("median_test input %s (parsed %s) expected %s got NULL\n", input, lwgeom_to_ewkt(g), lwgeom_to_ewkt((LWGEOM*) expected_result));
1168  }
1169 
1170  CU_ASSERT_TRUE(passed);
1171 
1172  lwgeom_free(g);
1173  lwpoint_free(expected_result);
1174  lwpoint_free(result);
1175 }
double x
Definition: liblwgeom.h:351
double m
Definition: liblwgeom.h:351
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:549
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:213
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1137
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:160
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:923
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1998
#define LW_FALSE
Definition: liblwgeom.h:76
void cu_error_msg_reset()
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
int lwpoint_getPoint4d_p(const LWPOINT *point, POINT4D *out)
Definition: lwpoint.c:57
#define FP_TOLERANCE
Floating point comparators.
double z
Definition: liblwgeom.h:351
#define FP_EQUALS(A, B)
LWPOINT * lwgeom_median(const LWGEOM *g, double tol, uint32_t maxiter, char fail_if_not_converged)
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1386
double y
Definition: liblwgeom.h:351
char cu_error_msg[MAX_CUNIT_ERROR_LENGTH+1]
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:930

Here is the call graph for this function:

Here is the caller graph for this function: