From: Paul Ramsey Date: Wed, 15 Jun 2011 20:22:13 +0000 (+0000) Subject: Add a couple more GBOX functions to map to B2DF4 requirements X-Git-Tag: 2.0.0alpha1~1422 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f9cd6b90b5df7aa87f93c6f05ea6ae6a6ecb7bc;p=postgis Add a couple more GBOX functions to map to B2DF4 requirements git-svn-id: http://svn.osgeo.org/postgis/trunk@7401 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/g_box.c b/liblwgeom/g_box.c index ebfe9eadc..fe9440a43 100644 --- a/liblwgeom/g_box.c +++ b/liblwgeom/g_box.c @@ -107,6 +107,37 @@ void gbox_expand(GBOX *g, double d) } } +int gbox_union(const GBOX *g1, const GBOX *g2, GBOX *gout) +{ + if ( (g1 == NULL) && (g2 == NULL) ) + return LW_FALSE; + + if (g1 == NULL) + { + memcpy(gout, g2, sizeof(GBOX)); + return LW_TRUE; + } + if (g2 == NULL) + { + memcpy(gout, g1, sizeof(GBOX)); + return LW_TRUE; + } + + if (g1->xmin < g2->xmin) gout->xmin = g1->xmin; + else gout->xmin = g2->xmin; + + if (g1->ymin < g2->ymin) gout->ymin = g1->ymin; + else gout->ymin = g2->ymin; + + if (g1->xmax > g2->xmax) gout->xmax = g1->xmax; + else gout->xmax = g2->xmax; + + if (g1->ymax > g2->ymax) gout->ymax = g1->ymax; + else gout->ymax = g2->ymax; + + return LW_TRUE; +} + int gbox_same(const GBOX *g1, const GBOX *g2) { if (FLAGS_GET_ZM(g1->flags) != FLAGS_GET_ZM(g2->flags)) diff --git a/liblwgeom/liblwgeom.h b/liblwgeom/liblwgeom.h index f09b96f84..33c38fd21 100644 --- a/liblwgeom/liblwgeom.h +++ b/liblwgeom/liblwgeom.h @@ -1964,6 +1964,11 @@ extern void gbox_init(GBOX *gbox); */ extern int gbox_merge(const GBOX *new_box, GBOX *merged_box); +/** +* Update the output #GBOX to be large enough to include both inputs. +*/ +extern int gbox_union(const GBOX *g1, const GBOX *g2, GBOX *gout); + /** * Move the box minimums down and the maximums up by the distance provided. */ diff --git a/postgis/lwgeom_box2dfloat4.c b/postgis/lwgeom_box2dfloat4.c index f9322dbf7..fc05c69b4 100644 --- a/postgis/lwgeom_box2dfloat4.c +++ b/postgis/lwgeom_box2dfloat4.c @@ -371,7 +371,11 @@ Datum BOX2D_union(PG_FUNCTION_ARGS) BOX2DFLOAT4 *n; n = (BOX2DFLOAT4 *) lwalloc(sizeof(BOX2DFLOAT4)); +#ifdef GSERIALIZED_ON + if ( ! gbox_union(a,b,n) ) PG_RETURN_NULL(); +#else if ( ! box2d_union_p(a,b,n) ) PG_RETURN_NULL(); +#endif PG_RETURN_POINTER(n); } @@ -403,8 +407,12 @@ Datum BOX2DFLOAT4_expand(PG_FUNCTION_ARGS) BOX2DFLOAT4 *result = (BOX2DFLOAT4 *)palloc(sizeof(BOX2DFLOAT4)); memcpy(result, box, sizeof(BOX2DFLOAT4)); +#ifdef GSERIALIZED_ON + gbox_expand(result, d); +#else expand_box2d(result, d); - +#endif + PG_RETURN_POINTER(result); } diff --git a/postgis/lwgeom_gist.c b/postgis/lwgeom_gist.c index fb282ee06..5e37f75ac 100644 --- a/postgis/lwgeom_gist.c +++ b/postgis/lwgeom_gist.c @@ -819,7 +819,7 @@ Datum LWGEOM_gist_union(PG_FUNCTION_ARGS) *sizep = sizeof(BOX2DFLOAT4); - POSTGIS_DEBUGF(3, "GIST: gbox_union called with numranges=%i pageunion is: <%.16g %.16g,%.16g %.16g>", numranges,pageunion->xmin, pageunion->ymin, pageunion->xmax, pageunion->ymax); + POSTGIS_DEBUGF(3, "GIST: LWGEOM_gist_union called with numranges=%i pageunion is: <%.16g %.16g,%.16g %.16g>", numranges,pageunion->xmin, pageunion->ymin, pageunion->xmax, pageunion->ymax); PG_RETURN_POINTER(pageunion); }