[postgis-commits] svn - r3805 - trunk/postgis
postgis-commits at postgis.refractions.net
postgis-commits at postgis.refractions.net
Sun Mar 8 09:36:20 PDT 2009
Author: mcayland
Date: 2009-03-08 09:36:20 -0700 (Sun, 08 Mar 2009)
New Revision: 3805
Modified:
trunk/postgis/lwgeom_box.c
trunk/postgis/lwgeom_box3d.c
trunk/postgis/lwgeom_functions_basic.c
trunk/postgis/lwgeom_pg.h
Log:
Alter the in-built casts between the internal PostgreSQL BOX type and the PostGIS geometry/BOX3D types so that they do not go through an intermediate BOX2DFLOAT4 first. This prevents the float4 rounding errors appearing in the numbers when invoking the casts.
Modified: trunk/postgis/lwgeom_box.c
===================================================================
--- trunk/postgis/lwgeom_box.c 2009-03-08 15:43:07 UTC (rev 3804)
+++ trunk/postgis/lwgeom_box.c 2009-03-08 16:36:20 UTC (rev 3805)
@@ -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 <mark.cave-ayland at siriusit.co.uk>
+ *
+ * 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;
}
Modified: trunk/postgis/lwgeom_box3d.c
===================================================================
--- trunk/postgis/lwgeom_box3d.c 2009-03-08 15:43:07 UTC (rev 3804)
+++ trunk/postgis/lwgeom_box3d.c 2009-03-08 16:36:20 UTC (rev 3805)
@@ -150,10 +150,9 @@
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);
}
Modified: trunk/postgis/lwgeom_functions_basic.c
===================================================================
--- trunk/postgis/lwgeom_functions_basic.c 2009-03-08 15:43:07 UTC (rev 3804)
+++ trunk/postgis/lwgeom_functions_basic.c 2009-03-08 16:36:20 UTC (rev 3805)
@@ -2400,17 +2400,18 @@
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);
}
Modified: trunk/postgis/lwgeom_pg.h
===================================================================
--- trunk/postgis/lwgeom_pg.h 2009-03-08 15:43:07 UTC (rev 3804)
+++ trunk/postgis/lwgeom_pg.h 2009-03-08 16:36:20 UTC (rev 3805)
@@ -82,8 +82,8 @@
/* 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);
More information about the postgis-commits
mailing list