]> granicus.if.org Git - postgis/commitdiff
Add a couple more GBOX functions to map to B2DF4 requirements
authorPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 15 Jun 2011 20:22:13 +0000 (20:22 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 15 Jun 2011 20:22:13 +0000 (20:22 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@7401 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/g_box.c
liblwgeom/liblwgeom.h
postgis/lwgeom_box2dfloat4.c
postgis/lwgeom_gist.c

index ebfe9eadc45d381afadbe2ad11809b8e3b853ef5..fe9440a43c493356bff239dbd2ba5f1da7644408 100644 (file)
@@ -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))
index f09b96f84905c66dfd1c28742e343bd2f0b20891..33c38fd21c28dd2d22b018a47f940daadc113d69 100644 (file)
@@ -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.
 */
index f9322dbf7c8c6128701e0255fce34df88151eaa1..fc05c69b40eaeb49821f8a98aaca2aa336c7ad81 100644 (file)
@@ -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);
 }
 
index fb282ee062da55bf4c9493512726d1016a18b4c9..5e37f75acf7c13ef78559dd613bfa31f2921fc58 100644 (file)
@@ -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);
 }