From: Mark Cave-Ayland Date: Wed, 30 Dec 2009 14:52:52 +0000 (+0000) Subject: Fix ST_Envelope() and ST_Expand() so that they use double precision arithmetic rather... X-Git-Tag: 1.5.0b1~27 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=901d61196cb5a4fdfb64b6972c981e49e7c6623c;p=postgis Fix ST_Envelope() and ST_Expand() so that they use double precision arithmetic rather than single precision arithmetic for their calculations. The internal BOX2DFLOAT4s should *never* be used for calculation purposes. git-svn-id: http://svn.osgeo.org/postgis/trunk@5080 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c index 29e7a3d31..6a75d6752 100644 --- a/postgis/lwgeom_functions_basic.c +++ b/postgis/lwgeom_functions_basic.c @@ -2536,7 +2536,7 @@ Datum LWGEOM_expand(PG_FUNCTION_ARGS) { PG_LWGEOM *geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); double d = PG_GETARG_FLOAT8(1); - BOX2DFLOAT4 box; + BOX3D box3d; POINT2D *pts = lwalloc(sizeof(POINT2D)*5); POINTARRAY *pa[1]; LWPOLY *poly; @@ -2546,7 +2546,7 @@ Datum LWGEOM_expand(PG_FUNCTION_ARGS) POSTGIS_DEBUG(2, "LWGEOM_expand called."); /* get geometry box */ - if ( ! getbox2d_p(SERIALIZED_FORM(geom), &box) ) + if ( ! compute_serialized_box3d_p(SERIALIZED_FORM(geom), &box3d) ) { /* must be an EMPTY geometry */ PG_RETURN_POINTER(geom); @@ -2556,19 +2556,19 @@ Datum LWGEOM_expand(PG_FUNCTION_ARGS) SRID = lwgeom_getsrid(SERIALIZED_FORM(geom)); /* expand it */ - expand_box2d(&box, d); + expand_box3d(&box3d, d); /* Assign coordinates to POINT2D array */ - pts[0].x = box.xmin; - pts[0].y = box.ymin; - pts[1].x = box.xmin; - pts[1].y = box.ymax; - pts[2].x = box.xmax; - pts[2].y = box.ymax; - pts[3].x = box.xmax; - pts[3].y = box.ymin; - pts[4].x = box.xmin; - pts[4].y = box.ymin; + pts[0].x = box3d.xmin; + pts[0].y = box3d.ymin; + pts[1].x = box3d.xmin; + pts[1].y = box3d.ymax; + pts[2].x = box3d.xmax; + pts[2].y = box3d.ymax; + pts[3].x = box3d.xmax; + pts[3].y = box3d.ymin; + pts[4].x = box3d.xmin; + pts[4].y = box3d.ymin; /* Construct point array */ pa[0] = lwalloc(sizeof(POINTARRAY)); @@ -2577,7 +2577,7 @@ Datum LWGEOM_expand(PG_FUNCTION_ARGS) pa[0]->npoints = 5; /* Construct polygon */ - poly = lwpoly_construct(SRID, box2d_clone(&box), 1, pa); + poly = lwpoly_construct(SRID, ptarray_compute_box2d(pa[0]), 1, pa); /* Construct PG_LWGEOM */ result = pglwgeom_serialize((LWGEOM *)poly); @@ -2676,26 +2676,24 @@ Datum LWGEOM_envelope(PG_FUNCTION_ARGS) { LWPOLY *poly; POINT2D *pts = lwalloc(sizeof(POINT2D)*5); - BOX2DFLOAT4 box2d; - getbox2d_p(SERIALIZED_FORM(geom), &box2d); /* Assign coordinates to POINT2D array */ - pts[0].x = box2d.xmin; - pts[0].y = box2d.ymin; - pts[1].x = box2d.xmin; - pts[1].y = box2d.ymax; - pts[2].x = box2d.xmax; - pts[2].y = box2d.ymax; - pts[3].x = box2d.xmax; - pts[3].y = box2d.ymin; - pts[4].x = box2d.xmin; - pts[4].y = box2d.ymin; + pts[0].x = box.xmin; + pts[0].y = box.ymin; + pts[1].x = box.xmin; + pts[1].y = box.ymax; + pts[2].x = box.xmax; + pts[2].y = box.ymax; + pts[3].x = box.xmax; + pts[3].y = box.ymin; + pts[4].x = box.xmin; + pts[4].y = box.ymin; /* Construct point array */ pa = pointArray_construct((uchar *)pts, 0, 0, 5); /* Construct polygon */ - poly = lwpoly_construct(SRID, box2d_clone(&box2d), 1, &pa); + poly = lwpoly_construct(SRID, ptarray_compute_box2d(pa), 1, &pa); /* Serialize polygon */ ser = lwpoly_serialize(poly); diff --git a/regress/sql-mm-circularstring_expected b/regress/sql-mm-circularstring_expected index 2ba6cca74..6c45ea683 100644 --- a/regress/sql-mm-circularstring_expected +++ b/regress/sql-mm-circularstring_expected @@ -94,13 +94,13 @@ ERROR: Exception in LWGEOM2GEOS: curved geometry not supported. ERROR: Exception in LWGEOM2GEOS: curved geometry not supported. ERROR: Exception in LWGEOM2GEOS: curved geometry not supported. ERROR: Exception in LWGEOM2GEOS: curved geometry not supported. -envelope01|POLYGON((0 0,0 1.41421366,0.58578646 1.41421366,0.58578646 0,0 0)) +envelope01|POLYGON((0 0,0 1.41421356,0.58578644 1.41421356,0.58578644 0,0 0)) envelope01|POLYGON((-5 0,-5 5,15 5,15 0,-5 0)) -envelope02|POLYGON((0 0,0 1.41421366,0.58578646 1.41421366,0.58578646 0,0 0)) +envelope02|POLYGON((0 0,0 1.41421356,0.58578644 1.41421356,0.58578644 0,0 0)) envelope02|POLYGON((-5 0,-5 5,15 5,15 0,-5 0)) -envelope03|POLYGON((0 0,0 1.41421366,0.58578646 1.41421366,0.58578646 0,0 0)) +envelope03|POLYGON((0 0,0 1.41421356,0.58578644 1.41421356,0.58578644 0,0 0)) envelope03|POLYGON((-5 0,-5 5,15 5,15 0,-5 0)) -envelope04|POLYGON((0 0,0 1.41421366,0.58578646 1.41421366,0.58578646 0,0 0)) +envelope04|POLYGON((0 0,0 1.41421356,0.58578644 1.41421356,0.58578644 0,0 0)) envelope04|POLYGON((-5 0,-5 5,15 5,15 0,-5 0)) astext01|CIRCULARSTRING(0 0,0.267949192431123 1,0.585786437626905 1.4142135623731) astext01|CIRCULARSTRING(-5 0,0 5,5 0,10 -5,15 0) @@ -142,13 +142,13 @@ ERROR: Exception in LWGEOM2GEOS: curved geometry not supported. ERROR: Exception in LWGEOM2GEOS: curved geometry not supported. ERROR: Exception in LWGEOM2GEOS: curved geometry not supported. ERROR: Exception in LWGEOM2GEOS: curved geometry not supported. -envelope01|POLYGON((0 0,0 1.41421366,0.58578646 1.41421366,0.58578646 0,0 0)) +envelope01|POLYGON((0 0,0 1.41421356,0.58578644 1.41421356,0.58578644 0,0 0)) envelope01|POLYGON((-5 0,-5 5,15 5,15 0,-5 0)) -envelope02|POLYGON((0 0,0 1.41421366,0.58578646 1.41421366,0.58578646 0,0 0)) +envelope02|POLYGON((0 0,0 1.41421356,0.58578644 1.41421356,0.58578644 0,0 0)) envelope02|POLYGON((-5 0,-5 5,15 5,15 0,-5 0)) -envelope03|POLYGON((0 0,0 1.41421366,0.58578646 1.41421366,0.58578646 0,0 0)) +envelope03|POLYGON((0 0,0 1.41421356,0.58578644 1.41421356,0.58578644 0,0 0)) envelope03|POLYGON((-5 0,-5 5,15 5,15 0,-5 0)) -envelope04|POLYGON((0 0,0 1.41421366,0.58578646 1.41421366,0.58578646 0,0 0)) +envelope04|POLYGON((0 0,0 1.41421356,0.58578644 1.41421356,0.58578644 0,0 0)) envelope04|POLYGON((-5 0,-5 5,15 5,15 0,-5 0)) public.circularstring.the_geom_4d effectively removed. public.circularstring.the_geom_3dz effectively removed. diff --git a/regress/sql-mm-compoundcurve_expected b/regress/sql-mm-compoundcurve_expected index da5b6b24d..e935b8f1f 100644 --- a/regress/sql-mm-compoundcurve_expected +++ b/regress/sql-mm-compoundcurve_expected @@ -54,10 +54,10 @@ ERROR: Exception in LWGEOM2GEOS: curved geometry not supported. ERROR: Exception in LWGEOM2GEOS: curved geometry not supported. ERROR: Exception in LWGEOM2GEOS: curved geometry not supported. ERROR: Exception in LWGEOM2GEOS: curved geometry not supported. -envelope01|POLYGON((0 0,0 1.41421366,2 1.41421366,2 0,0 0)) -envelope02|POLYGON((0 0,0 1.41421366,2 1.41421366,2 0,0 0)) -envelope03|POLYGON((0 0,0 1.41421366,2 1.41421366,2 0,0 0)) -envelope04|POLYGON((0 0,0 1.41421366,2 1.41421366,2 0,0 0)) +envelope01|POLYGON((0 0,0 1.41421356,2 1.41421356,2 0,0 0)) +envelope02|POLYGON((0 0,0 1.41421356,2 1.41421356,2 0,0 0)) +envelope03|POLYGON((0 0,0 1.41421356,2 1.41421356,2 0,0 0)) +envelope04|POLYGON((0 0,0 1.41421356,2 1.41421356,2 0,0 0)) astext01|COMPOUNDCURVE(CIRCULARSTRING(0 0,0.267949192431123 1,0.585786437626905 1.4142135623731),(0.585786437626905 1.4142135623731,2 0,0 0)) astext02|COMPOUNDCURVE(CIRCULARSTRING(0 0,0.267949192431123 1,0.585786437626905 1.4142135623731),(0.585786437626905 1.4142135623731,2 0,0 0)) astext03|COMPOUNDCURVE(CIRCULARSTRING(0 0,0.267949192431123 1,0.585786437626905 1.4142135623731),(0.585786437626905 1.4142135623731,2 0,0 0)) @@ -82,10 +82,10 @@ ERROR: Exception in LWGEOM2GEOS: curved geometry not supported. ERROR: Exception in LWGEOM2GEOS: curved geometry not supported. ERROR: Exception in LWGEOM2GEOS: curved geometry not supported. ERROR: Exception in LWGEOM2GEOS: curved geometry not supported. -envelope01|POLYGON((0 0,0 1.41421366,2 1.41421366,2 0,0 0)) -envelope02|POLYGON((0 0,0 1.41421366,2 1.41421366,2 0,0 0)) -envelope03|POLYGON((0 0,0 1.41421366,2 1.41421366,2 0,0 0)) -envelope04|POLYGON((0 0,0 1.41421366,2 1.41421366,2 0,0 0)) +envelope01|POLYGON((0 0,0 1.41421356,2 1.41421356,2 0,0 0)) +envelope02|POLYGON((0 0,0 1.41421356,2 1.41421356,2 0,0 0)) +envelope03|POLYGON((0 0,0 1.41421356,2 1.41421356,2 0,0 0)) +envelope04|POLYGON((0 0,0 1.41421356,2 1.41421356,2 0,0 0)) public.compoundcurve.the_geom_4d effectively removed. public.compoundcurve.the_geom_3dz effectively removed. public.compoundcurve.the_geom_3dm effectively removed. diff --git a/regress/tickets_expected b/regress/tickets_expected index 574d38553..69fceb566 100644 --- a/regress/tickets_expected +++ b/regress/tickets_expected @@ -4,7 +4,7 @@ t ERROR: AddGeometryColumns() - invalid SRID #44|t|t -#58|POLYGON((220187.375 150406.421875,220187.375 150506.71875,220288.828125 150506.71875,220288.828125 150406.421875,220187.375 150406.421875)) +#58|POLYGON((220187.382089758 150406.434743975,220187.382089758 150506.717070259,220288.81590723 150506.717070259,220288.81590723 150406.434743975,220187.382089758 150406.434743975)) ERROR: geometry_to_gml2: 'CurvePolygon' geometry type not supported #66|CIRCULARSTRING(0 0,1 1,2 2) #68a|MULTIPOINT(1 3,4 5)