PostGIS  2.1.10dev-r@@SVN_REVISION@@
static void test_gbox_from_spherical_coordinates ( void  )
static

Definition at line 204 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().

205 {
206 #if RANDOM_TEST
207  const double gtolerance = 0.000001;
208  const int loops = RANDOM_TEST;
209  int i;
210  double ll[64];
211  GBOX gbox;
212  GBOX gbox_slow;
213  int rndlat;
214  int rndlon;
215 
216  POINTARRAY *pa;
217  LWGEOM *lwline;
218 
219  ll[0] = -3.083333333333333333333333333333333;
220  ll[1] = 9.83333333333333333333333333333333;
221  ll[2] = 15.5;
222  ll[3] = -5.25;
223 
224  pa = ptarray_construct_reference_data(0, 0, 2, (uint8_t*)ll);
225 
227  FLAGS_SET_GEODETIC(lwline->flags, 1);
228 
229  srandomdev();
230 
231  for ( i = 0; i < loops; i++ )
232  {
233  rndlat = (int)(90.0 - 180.0 * (double)random() / pow(2.0, 31.0));
234  rndlon = (int)(180.0 - 360.0 * (double)random() / pow(2.0, 31.0));
235  ll[0] = (double)rndlon;
236  ll[1] = (double)rndlat;
237 
238  rndlat = (int)(90.0 - 180.0 * (double)random() / pow(2.0, 31.0));
239  rndlon = (int)(180.0 - 360.0 * (double)random() / pow(2.0, 31.0));
240  ll[2] = (double)rndlon;
241  ll[3] = (double)rndlat;
242 
244  lwgeom_calculate_gbox_geodetic(lwline, &gbox);
246  lwgeom_calculate_gbox_geodetic(lwline, &gbox_slow);
248 
249  if (
250  ( fabs( gbox.xmin - gbox_slow.xmin ) > gtolerance ) ||
251  ( fabs( gbox.xmax - gbox_slow.xmax ) > gtolerance ) ||
252  ( fabs( gbox.ymin - gbox_slow.ymin ) > gtolerance ) ||
253  ( fabs( gbox.ymax - gbox_slow.ymax ) > gtolerance ) ||
254  ( fabs( gbox.zmin - gbox_slow.zmin ) > gtolerance ) ||
255  ( fabs( gbox.zmax - gbox_slow.zmax ) > gtolerance ) )
256  {
257  printf("\n-------\n");
258  printf("If you are seeing this, cut and paste it, it is a randomly generated test case!\n");
259  printf("LOOP: %d\n", i);
260  printf("SEGMENT (Lon Lat): (%.9g %.9g) (%.9g %.9g)\n", ll[0], ll[1], ll[2], ll[3]);
261  printf("CALC: %s\n", gbox_to_string(&gbox));
262  printf("SLOW: %s\n", gbox_to_string(&gbox_slow));
263  printf("-------\n\n");
264  CU_FAIL_FATAL(Slow (GOOD) and fast (CALC) box calculations returned different values!!);
265  }
266 
267  }
268 
269  lwgeom_free(lwline);
270 #endif /* RANDOM_TEST */
271 }
int lwgeom_calculate_gbox_geodetic(const LWGEOM *geom, GBOX *gbox)
Calculate the geodetic bounding box for an LWGEOM.
Definition: lwgeodetic.c:2612
char * gbox_to_string(const GBOX *gbox)
Allocate a string representation of the GBOX, based on dimensionality of flags.
Definition: g_box.c:328
uint8_t flags
Definition: liblwgeom.h:353
double xmax
Definition: liblwgeom.h:249
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
#define FLAGS_SET_GEODETIC(flags, value)
Definition: liblwgeom.h:115
double zmax
Definition: liblwgeom.h:253
double ymin
Definition: liblwgeom.h:250
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:249
double xmin
Definition: liblwgeom.h:248
#define LW_FALSE
Definition: liblwgeom.h:52
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:51
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:29
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:154
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:280
#define RANDOM_TEST
Definition: cu_geodetic.c:22
double ymax
Definition: liblwgeom.h:251
int gbox_geocentric_slow
For testing geodetic bounding box, we have a magic global variable.
Definition: lwgeodetic.c:22
double zmin
Definition: liblwgeom.h:252

Here is the call graph for this function:

Here is the caller graph for this function: