From: Sandro Santilli Date: Thu, 12 Jan 2012 08:51:53 +0000 (+0000) Subject: Expose gbox_float_round to liblwgeom API X-Git-Tag: 2.0.0alpha1~97 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a58b999828bc032ee40b0c3f98a0af0783c1191f;p=postgis Expose gbox_float_round to liblwgeom API git-svn-id: http://svn.osgeo.org/postgis/trunk@8783 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/g_box.c b/liblwgeom/g_box.c index fb6bcf521..61cb1d6db 100644 --- a/liblwgeom/g_box.c +++ b/liblwgeom/g_box.c @@ -568,3 +568,22 @@ int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox) lwerror("unsupported type (%d) - %s", lwgeom->type, lwtype_name(lwgeom->type)); return LW_FAILURE; } + +void gbox_float_round(GBOX *gbox) +{ + gbox->xmin = next_float_down(gbox->xmin); + gbox->xmax = next_float_up(gbox->xmax); + + gbox->ymin = next_float_down(gbox->ymin); + gbox->ymax = next_float_up(gbox->ymax); + + gbox->mmin = next_float_down(gbox->mmin); + gbox->mmax = next_float_up(gbox->mmax); + + if ( FLAGS_GET_Z(gbox->flags) ) + { + gbox->zmin = next_float_down(gbox->zmin); + gbox->zmax = next_float_up(gbox->zmax); + } +} + diff --git a/liblwgeom/g_serialized.c b/liblwgeom/g_serialized.c index e706c977f..9006cbf44 100644 --- a/liblwgeom/g_serialized.c +++ b/liblwgeom/g_serialized.c @@ -126,25 +126,6 @@ char* gserialized_to_string(const GSERIALIZED *g) return lwgeom_to_wkt(lwgeom_from_gserialized(g), WKT_ISO, 12, 0); } -/* TODO: expose to internal API ? */ -static void gbox_float_round(GBOX *gbox) -{ - gbox->xmin = next_float_down(gbox->xmin); - gbox->xmax = next_float_up(gbox->xmax); - - gbox->ymin = next_float_down(gbox->ymin); - gbox->ymax = next_float_up(gbox->ymax); - - gbox->mmin = next_float_down(gbox->mmin); - gbox->mmax = next_float_up(gbox->mmax); - - if ( FLAGS_GET_Z(gbox->flags) ) - { - gbox->zmin = next_float_down(gbox->zmin); - gbox->zmax = next_float_up(gbox->zmax); - } -} - int gserialized_read_gbox_p(const GSERIALIZED *g, GBOX *gbox) { diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in index 3c20e6872..b4f340d7b 100644 --- a/liblwgeom/liblwgeom.h.in +++ b/liblwgeom/liblwgeom.h.in @@ -1547,6 +1547,14 @@ extern size_t gbox_serialized_size(uint8_t flags); */ extern int gbox_same(const GBOX *g1, const GBOX *g2); +/** + * Round given GBOX to float boundaries + * + * This turns a GBOX into the version it would become + * after a serialize/deserialize round trip. + */ +extern void gbox_float_round(GBOX *gbox); + /** * Utility function to get type number from string. For example, a string 'POINTZ' * would return type of 1 and z of 1 and m of 0. Valid