diff --git a/postgis/lwgeom_box.c b/postgis/lwgeom_box.c index 2babe68be..4bb36a839 100644 --- a/postgis/lwgeom_box.c +++ b/postgis/lwgeom_box.c @@ -1,3 +1,16 @@ +/********************************************************************** + * $Id$ + * + * PostGIS - Spatial Types for PostgreSQL + * http://postgis.refractions.net + * Copyright 2001-2009 Refractions Research Inc. + * Copyright 2009 Mark Cave-Ayland + * + * This is free software; you can redistribute and/or modify it under + * the terms of the GNU General Public Licence. See the COPYING file. + * + **********************************************************************/ + #include "postgres.h" #include "utils/geo_decls.h" @@ -5,38 +18,38 @@ #include "liblwgeom.h" -void box_to_box2df(BOX *box, BOX2DFLOAT4 *out); +void box_to_box3d(BOX *box, BOX3D *out); +void box3d_to_box_p(BOX3D *box, BOX *out); - -/* convert postgresql BOX to BOX2D */ +/* convert postgresql BOX to BOX3D */ void -box_to_box2df(BOX *box, BOX2DFLOAT4 *out) +box_to_box3d(BOX *box, BOX3D *out) { #if PARANOIA_LEVEL > 0 if (box == NULL) return; #endif - out->xmin = nextDown_f(box->low.x); - out->ymin = nextDown_f(box->low.y); + out->xmin = box->low.x; + out->ymin = box->low.y; - out->xmax = nextUp_f(box->high.x); - out->ymax = nextUp_f(box->high.x); + out->xmax = box->high.x; + out->ymax = box->high.y; } -/* convert BOX2D to postgresql BOX */ +/* convert BOX3D to postgresql BOX */ void -box2df_to_box_p(BOX2DFLOAT4 *box, BOX *out) +box3d_to_box_p(BOX3D *box, BOX *out) { #if PARANOIA_LEVEL > 0 if (box == NULL) return; #endif - out->low.x = nextDown_d(box->xmin); - out->low.y = nextDown_d(box->ymin); + out->low.x = box->xmin; + out->low.y = box->ymin; - out->high.x = nextUp_d(box->xmax); - out->high.y = nextUp_d(box->ymax); + out->high.x = box->xmax; + out->high.y = box->ymax; } diff --git a/postgis/lwgeom_box3d.c b/postgis/lwgeom_box3d.c index 813fcd86f..4d1d1df79 100644 --- a/postgis/lwgeom_box3d.c +++ b/postgis/lwgeom_box3d.c @@ -150,10 +150,9 @@ PG_FUNCTION_INFO_V1(BOX3D_to_BOX); Datum BOX3D_to_BOX(PG_FUNCTION_ARGS) { BOX3D *in = (BOX3D *)PG_GETARG_POINTER(0); - BOX2DFLOAT4 *box2d = box3d_to_box2df(in); BOX *box = palloc(sizeof(BOX)); - box2df_to_box_p(box2d, box); + box3d_to_box_p(in, box); PG_RETURN_POINTER(box); } diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c index 98d31a00f..6892cb517 100644 --- a/postgis/lwgeom_functions_basic.c +++ b/postgis/lwgeom_functions_basic.c @@ -2400,17 +2400,18 @@ Datum LWGEOM_expand(PG_FUNCTION_ARGS) PG_FUNCTION_INFO_V1(LWGEOM_to_BOX); Datum LWGEOM_to_BOX(PG_FUNCTION_ARGS) { - PG_LWGEOM *lwgeom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); - BOX2DFLOAT4 box2d; + PG_LWGEOM *pg_lwgeom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + BOX3D *box3d; BOX *result = (BOX *)lwalloc(sizeof(BOX)); + LWGEOM *lwgeom = lwgeom_deserialize(SERIALIZED_FORM(pg_lwgeom)); - if ( ! getbox2d_p(SERIALIZED_FORM(lwgeom), &box2d) ) - { - PG_RETURN_NULL(); /* must be the empty geometry */ - } - box2df_to_box_p(&box2d, result); + /* Calculate the BOX3D of the geometry */ + box3d = lwgeom_compute_box3d(lwgeom); + box3d_to_box_p(box3d, result); + lwfree(box3d); + lwfree(lwgeom); - PG_FREE_IF_COPY(lwgeom, 0); + PG_FREE_IF_COPY(pg_lwgeom, 0); PG_RETURN_POINTER(result); } diff --git a/postgis/lwgeom_pg.h b/postgis/lwgeom_pg.h index d9be4e051..08a8c3145 100644 --- a/postgis/lwgeom_pg.h +++ b/postgis/lwgeom_pg.h @@ -82,8 +82,8 @@ extern Oid getGeometryOID(void); /* PG-dependant */ /* BOX is postgresql standard type */ -extern void box_to_box2df_p(BOX *box, BOX2DFLOAT4 *out); -extern void box2df_to_box_p(BOX2DFLOAT4 *box, BOX *out); +extern void box_to_box3d_p(BOX *box, BOX3D *out); +extern void box3d_to_box_p(BOX3D *box, BOX *out); /* PG-exposed */ Datum BOX2D_same(PG_FUNCTION_ARGS);