Return -1 if g1 is "less than" g2, 1 if g1 is "greater than" g2 and 0 if g1 and g2 are the "same".
Equality is evaluated with a memcmp and size check. So it is possible that two identical objects where one lacks a bounding box could be evaluated as non-equal initially. Greater and less than are evaluated by calculating a sortable key from the center point of the object bounds.
Definition at line 294 of file g_serialized.c.
References GSERIALIZED::data, floatuint::f, GSERIALIZED::flags, FLAGS_GET_BBOX, FLAGS_GET_GEODETIC, gbox_get_sortable_hash(), gserialized_cmp_srid(), gserialized_get_gbox_p(), gserialized_get_type(), gserialized_header_size(), LW_FAILURE, POINTTYPE, GSERIALIZED::size, SIZE_GET, floatuint::u, uint32_interleave_2(), GBOX::xmax, GBOX::xmin, GBOX::ymax, and GBOX::ymin.
Referenced by geography_cmp(), geography_eq(), geography_ge(), geography_gt(), geography_le(), geography_lt(), lwgeom_cmp(), lwgeom_eq(), lwgeom_ge(), lwgeom_gt(), lwgeom_le(), and lwgeom_lt().
296 int g1_is_empty, g2_is_empty, cmp;
298 uint64_t hash1, hash2;
317 double *dptr = (
double*)(g1->
data);
322 dptr = (
double*)(g2->
data);
340 size_t bsz1 = sz1 - hsz1;
341 size_t bsz2 = sz2 - hsz2;
342 size_t bsz = bsz1 < bsz2 ? bsz1 : bsz2;
350 if (g1_is_empty && g2_is_empty)
356 return t1 == t2 ? 0 : (t1 < t2 ? -1 : 1);
368 cmp = memcmp(b1, b2, bsz);
369 if ( bsz1 == bsz2 && cmp_srid == 0 && cmp == 0 )
380 else if ( hash1 < hash2 )
409 else if (hsz1 > hsz2)
413 return cmp == 0 ? 0 : (cmp > 0 ? 1 : -1);
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *box)
Read the bounding box off a serialization and calculate one if it is not already there.
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area...
static int gserialized_cmp_srid(const GSERIALIZED *s1, const GSERIALIZED *s2)
#define FLAGS_GET_GEODETIC(flags)
uint64_t gbox_get_sortable_hash(const GBOX *g)
Return a sortable key based on the center point of the GBOX.
static uint64_t uint32_interleave_2(uint32_t u1, uint32_t u2)
#define FLAGS_GET_BBOX(flags)
#define SIZE_GET(varsize)
Macro for reading the size from the GSERIALIZED size attribute.
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
uint32_t gserialized_header_size(const GSERIALIZED *gser)
Returns the size in bytes of the header, from the start of the object up to the type number...