PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ test_gbox_from_spherical_coordinates()

static void test_gbox_from_spherical_coordinates ( void  )
static

Definition at line 224 of file cu_geodetic.c.

References LWGEOM::flags, FLAGS_SET_GEODETIC, gbox_geocentric_slow, gbox_to_string(), LW_FALSE, LW_TRUE, lwgeom_calculate_gbox_geodetic(), lwgeom_free(), lwline_as_lwgeom(), lwline_construct(), ptarray_construct_reference_data(), RANDOM_TEST, SRID_UNKNOWN, GBOX::xmax, GBOX::xmin, GBOX::ymax, GBOX::ymin, GBOX::zmax, and GBOX::zmin.

Referenced by geodetic_suite_setup().

225 {
226 #if RANDOM_TEST
227  const double gtolerance = 0.000001;
228  const int loops = RANDOM_TEST;
229  int i;
230  double ll[64];
231  GBOX gbox;
232  GBOX gbox_slow;
233  int rndlat;
234  int rndlon;
235 
236  POINTARRAY *pa;
237  LWGEOM *lwline;
238 
239  ll[0] = -3.083333333333333333333333333333333;
240  ll[1] = 9.83333333333333333333333333333333;
241  ll[2] = 15.5;
242  ll[3] = -5.25;
243 
244  pa = ptarray_construct_reference_data(0, 0, 2, (uint8_t*)ll);
245 
247  FLAGS_SET_GEODETIC(lwline->flags, 1);
248 
249  srandomdev();
250 
251  for ( i = 0; i < loops; i++ )
252  {
253  rndlat = (int)(90.0 - 180.0 * (double)random() / pow(2.0, 31.0));
254  rndlon = (int)(180.0 - 360.0 * (double)random() / pow(2.0, 31.0));
255  ll[0] = (double)rndlon;
256  ll[1] = (double)rndlat;
257 
258  rndlat = (int)(90.0 - 180.0 * (double)random() / pow(2.0, 31.0));
259  rndlon = (int)(180.0 - 360.0 * (double)random() / pow(2.0, 31.0));
260  ll[2] = (double)rndlon;
261  ll[3] = (double)rndlat;
262 
264  lwgeom_calculate_gbox_geodetic(lwline, &gbox);
266  lwgeom_calculate_gbox_geodetic(lwline, &gbox_slow);
268 
269  if (
270  ( fabs( gbox.xmin - gbox_slow.xmin ) > gtolerance ) ||
271  ( fabs( gbox.xmax - gbox_slow.xmax ) > gtolerance ) ||
272  ( fabs( gbox.ymin - gbox_slow.ymin ) > gtolerance ) ||
273  ( fabs( gbox.ymax - gbox_slow.ymax ) > gtolerance ) ||
274  ( fabs( gbox.zmin - gbox_slow.zmin ) > gtolerance ) ||
275  ( fabs( gbox.zmax - gbox_slow.zmax ) > gtolerance ) )
276  {
277  printf("\n-------\n");
278  printf("If you are seeing this, cut and paste it, it is a randomly generated test case!\n");
279  printf("LOOP: %d\n", i);
280  printf("SEGMENT (Lon Lat): (%.9g %.9g) (%.9g %.9g)\n", ll[0], ll[1], ll[2], ll[3]);
281  printf("CALC: %s\n", gbox_to_string(&gbox));
282  printf("SLOW: %s\n", gbox_to_string(&gbox_slow));
283  printf("-------\n\n");
284  CU_FAIL_FATAL(Slow (GOOD) and fast (CALC) box calculations returned different values!!);
285  }
286 
287  }
288 
289  lwgeom_free(lwline);
290 #endif /* RANDOM_TEST */
291 }
int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox)
Calculate the geodetic bounding box for an LWGEOM.
Definition: lwgeodetic.c:2940
char * gbox_to_string(const GBOX *gbox)
Allocate a string representation of the GBOX, based on dimensionality of flags.
Definition: g_box.c:399
uint8_t flags
Definition: liblwgeom.h:399
double xmax
Definition: liblwgeom.h:295
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
#define FLAGS_SET_GEODETIC(flags, value)
Definition: liblwgeom.h:148
double zmax
Definition: liblwgeom.h:299
double ymin
Definition: liblwgeom.h:296
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:330
double xmin
Definition: liblwgeom.h:294
#define LW_FALSE
Definition: liblwgeom.h:76
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:187
POINTARRAY * ptarray_construct_reference_data(char hasz, char hasm, uint32_t npoints, uint8_t *ptlist)
Construct a new POINTARRAY, referencing to the data from ptlist.
Definition: ptarray.c:293
#define RANDOM_TEST
Definition: cu_geodetic.c:27
double ymax
Definition: liblwgeom.h:297
int gbox_geocentric_slow
For testing geodetic bounding box, we have a magic global variable.
Definition: lwgeodetic.c:36
double zmin
Definition: liblwgeom.h:298
unsigned char uint8_t
Definition: uthash.h:79
Here is the call graph for this function:
Here is the caller graph for this function: