PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ gbox_get_sortable_hash()

uint64_t gbox_get_sortable_hash ( const GBOX g)

Return a sortable key based on the center point of the GBOX.

Definition at line 258 of file g_serialized.c.

References cart2geog(), floatuint::f, GBOX::flags, FLAGS_GET_GEODETIC, GEOGRAPHIC_POINT::lat, GEOGRAPHIC_POINT::lon, normalize(), floatuint::u, uint32_interleave_2(), POINT3D::x, GBOX::xmax, GBOX::xmin, POINT3D::y, GBOX::ymax, GBOX::ymin, POINT3D::z, GBOX::zmax, and GBOX::zmin.

Referenced by gserialized_cmp(), and rect_node_cmp().

259 {
260  union floatuint x, y;
261 
262  /*
263  * Since in theory the bitwise representation of an IEEE
264  * float is sortable (exponents come before mantissa, etc)
265  * we just copy the bits directly into an int and then
266  * interleave those ints.
267  */
268  if ( FLAGS_GET_GEODETIC(g->flags) )
269  {
270  GEOGRAPHIC_POINT gpt;
271  POINT3D p;
272  p.x = (g->xmax + g->xmin) / 2.0;
273  p.y = (g->ymax + g->ymin) / 2.0;
274  p.z = (g->zmax + g->zmin) / 2.0;
275  normalize(&p);
276  cart2geog(&p, &gpt);
277  x.f = gpt.lon;
278  y.f = gpt.lat;
279  }
280  else
281  {
282  /*
283  * Here we'd like to get two ordinates from 4 in the box.
284  * Since it's just a sortable bit representation we can omit division from (A+B)/2.
285  * All it should do is subtract 1 from exponent anyways.
286  */
287  x.f = g->xmax + g->xmin;
288  y.f = g->ymax + g->ymin;
289  }
290  return uint32_interleave_2(x.u, y.u);
291 }
void normalize(POINT3D *p)
Normalize to a unit vector.
Definition: lwgeodetic.c:584
double y
Definition: liblwgeom.h:342
#define FLAGS_GET_GEODETIC(flags)
Definition: liblwgeom.h:142
double xmax
Definition: liblwgeom.h:295
void cart2geog(const POINT3D *p, GEOGRAPHIC_POINT *g)
Convert cartesian coordinates on unit sphere to spherical coordinates.
Definition: lwgeodetic.c:383
double x
Definition: liblwgeom.h:342
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:47
double z
Definition: liblwgeom.h:342
double zmax
Definition: liblwgeom.h:299
double ymin
Definition: liblwgeom.h:296
static uint64_t uint32_interleave_2(uint32_t u1, uint32_t u2)
Definition: g_serialized.c:227
double xmin
Definition: liblwgeom.h:294
double ymax
Definition: liblwgeom.h:297
uint8_t flags
Definition: liblwgeom.h:293
double zmin
Definition: liblwgeom.h:298
Here is the call graph for this function:
Here is the caller graph for this function: