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 313 of file gserialized.c.
316 uint64_t hash1, hash2;
321 uint8_t *b1 = (uint8_t*)g1 + hsz1;
322 uint8_t *b2 = (uint8_t*)g2 + hsz2;
323 size_t bsz1 = sz1 - hsz1;
324 size_t bsz2 = sz2 - hsz2;
325 size_t bsz_min = bsz1 < bsz2 ? bsz1 : bsz2;
330 int cmp = memcmp(b1, b2, bsz_min);
336 if (bsz1 == bsz2 && cmp_srid == 0 && cmp == 0 && g1hasz == g2hasz && g1hasm == g2hasm)
346 if (g1_is_empty && !g2_is_empty)
350 if (!g1_is_empty && g2_is_empty)
353 if (!g1_is_empty && !g2_is_empty)
366 if (bsz1 != bsz2 && cmp == 0)
370 else if (bsz1 > bsz2)
376 return (srid1 > srid2) ? 1 : -1;
379 if (g1hasz != g2hasz)
380 return (g1hasz > g2hasz) ? 1 : -1;
382 if (g1hasm != g2hasm)
383 return (g1hasm > g2hasm) ? 1 : -1;
386 return cmp > 0 ? 1 : -1;
uint64_t gbox_get_sortable_hash(const GBOX *g, const int32_t srid)
Return a sortable key based on the center point of the GBOX.
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
static size_t gserialized_header_size(const GSERIALIZED *g)
int gserialized_get_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Read the box from the GSERIALIZED or calculate it if necessary.
int gserialized_has_m(const GSERIALIZED *g)
Check if a GSERIALIZED has an M ordinate.
static int gserialized_cmp_srid(const GSERIALIZED *g1, const GSERIALIZED *g2)
int gserialized_has_z(const GSERIALIZED *g)
Check if a GSERIALIZED has a Z ordinate.
#define SIZE_GET(varsize)
Macro for reading the size from the GSERIALIZED size attribute.
References gbox_get_sortable_hash(), gserialized_cmp_srid(), gserialized_get_gbox_p(), gserialized_get_srid(), gserialized_has_m(), gserialized_has_z(), gserialized_header_size(), LW_FAILURE, GSERIALIZED::size, and SIZE_GET.
Referenced by geography_cmp(), geography_eq(), geography_ge(), geography_gt(), geography_le(), geography_lt(), lwgeom_cmp(), lwgeom_cmp_full(), lwgeom_eq(), lwgeom_ge(), lwgeom_gt(), lwgeom_le(), lwgeom_lt(), and LWGEOM_same().