From: Paul Ramsey Date: Mon, 11 Dec 2017 15:04:01 +0000 (+0000) Subject: Add lwgeom_refresh_bbox to replace drop/add twostep X-Git-Tag: 2.5.0alpha~292 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9715e11745bb54a981c7402d46b4191e9d680a81;p=postgis Add lwgeom_refresh_bbox to replace drop/add twostep git-svn-id: http://svn.osgeo.org/postgis/trunk@16143 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in index 873496730..ea8c9e5de 100644 --- a/liblwgeom/liblwgeom.h.in +++ b/liblwgeom/liblwgeom.h.in @@ -735,6 +735,10 @@ extern void lwgeom_drop_srid(LWGEOM *lwgeom); */ extern void lwgeom_add_bbox(LWGEOM *lwgeom); /** +* Drop current bbox and calculate a fresh one. +*/ +extern void lwgeom_refresh_bbox(LWGEOM *lwgeom); +/** * Compute a box for geom and all sub-geometries, if not already computed */ extern void lwgeom_add_bbox_deep(LWGEOM *lwgeom, GBOX *gbox); diff --git a/liblwgeom/lwgeom.c b/liblwgeom/lwgeom.c index 9d52572a0..d5940524a 100644 --- a/liblwgeom/lwgeom.c +++ b/liblwgeom/lwgeom.c @@ -687,6 +687,13 @@ lwgeom_add_bbox(LWGEOM *lwgeom) lwgeom_calculate_gbox(lwgeom, lwgeom->bbox); } +void +lwgeom_refresh_bbox(LWGEOM *lwgeom) +{ + lwgeom_drop_bbox(lwgeom); + lwgeom_add_bbox(lwgeom); +} + void lwgeom_add_bbox_deep(LWGEOM *lwgeom, GBOX *gbox) { @@ -1556,8 +1563,7 @@ void lwgeom_swap_ordinates(LWGEOM *in, LWORD o1, LWORD o2) /* only refresh bbox if X or Y changed */ if ( in->bbox && (o1 < 2 || o2 < 2) ) { - lwgeom_drop_bbox(in); - lwgeom_add_bbox(in); + lwgeom_refresh_bbox(in); } } diff --git a/liblwgeom/lwline.c b/liblwgeom/lwline.c index 73f06e62f..617597c2a 100644 --- a/liblwgeom/lwline.c +++ b/liblwgeom/lwline.c @@ -344,8 +344,7 @@ lwline_add_lwpoint(LWLINE *line, LWPOINT *point, int where) /* Update the bounding box */ if ( line->bbox ) { - lwgeom_drop_bbox(lwline_as_lwgeom(line)); - lwgeom_add_bbox(lwline_as_lwgeom(line)); + lwgeom_refresh_bbox((LWGEOM*)line); } return LW_SUCCESS; @@ -377,8 +376,7 @@ lwline_setPoint4d(LWLINE *line, uint32_t index, POINT4D *newpoint) /* Update the box, if there is one to update */ if ( line->bbox ) { - lwgeom_drop_bbox((LWGEOM*)line); - lwgeom_add_bbox((LWGEOM*)line); + lwgeom_refresh_bbox((LWGEOM*)line); } } diff --git a/liblwgeom/lwlinearreferencing.c b/liblwgeom/lwlinearreferencing.c index 5cb81bb21..e83fbf642 100644 --- a/liblwgeom/lwlinearreferencing.c +++ b/liblwgeom/lwlinearreferencing.c @@ -400,8 +400,7 @@ lwpoint_clip_to_ordinate_range(const LWPOINT *point, char ordinate, double from, /* Set the bbox, if necessary */ if ( lwgeom_out->bbox ) { - lwgeom_drop_bbox((LWGEOM*)lwgeom_out); - lwgeom_add_bbox((LWGEOM*)lwgeom_out); + lwgeom_refresh_bbox((LWGEOM*)lwgeom_out); } return lwgeom_out; @@ -457,8 +456,7 @@ lwmpoint_clip_to_ordinate_range(const LWMPOINT *mpoint, char ordinate, double fr /* Set the bbox, if necessary */ if ( lwgeom_out->bbox ) { - lwgeom_drop_bbox((LWGEOM*)lwgeom_out); - lwgeom_add_bbox((LWGEOM*)lwgeom_out); + lwgeom_refresh_bbox((LWGEOM*)lwgeom_out); } return lwgeom_out; @@ -528,8 +526,7 @@ lwmline_clip_to_ordinate_range(const LWMLINE *mline, char ordinate, double from, } if ( lwgeom_out->bbox ) { - lwgeom_drop_bbox((LWGEOM*)lwgeom_out); - lwgeom_add_bbox((LWGEOM*)lwgeom_out); + lwgeom_refresh_bbox((LWGEOM*)lwgeom_out); } if ( ! homogeneous ) @@ -762,8 +759,7 @@ lwline_clip_to_ordinate_range(const LWLINE *line, char ordinate, double from, do if ( lwgeom_out->bbox && lwgeom_out->ngeoms > 0 ) { - lwgeom_drop_bbox((LWGEOM*)lwgeom_out); - lwgeom_add_bbox((LWGEOM*)lwgeom_out); + lwgeom_refresh_bbox((LWGEOM*)lwgeom_out); } return lwgeom_out; diff --git a/postgis/geography_inout.c b/postgis/geography_inout.c index 16dad0034..2b43d577e 100644 --- a/postgis/geography_inout.c +++ b/postgis/geography_inout.c @@ -638,8 +638,7 @@ Datum geometry_from_geography(PG_FUNCTION_ARGS) /* Recalculate the boxes after re-setting the geodetic bit */ lwgeom_set_geodetic(lwgeom, false); - lwgeom_drop_bbox(lwgeom); - lwgeom_add_bbox(lwgeom); + lwgeom_refresh_bbox(lwgeom); /* We want "geometry" to think all our "geography" has an SRID, and the implied SRID is the default, so we fill that in if our SRID is actually unknown. */ diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c index 72a084d32..6606033ad 100644 --- a/postgis/lwgeom_functions_basic.c +++ b/postgis/lwgeom_functions_basic.c @@ -2632,8 +2632,7 @@ Datum LWGEOM_affine(PG_FUNCTION_ARGS) /* COMPUTE_BBOX TAINTING */ if ( lwgeom->bbox ) { - lwgeom_drop_bbox(lwgeom); - lwgeom_add_bbox(lwgeom); + lwgeom_refresh_bbox(lwgeom); } ret = geometry_serialize(lwgeom); diff --git a/postgis/lwgeom_transform.c b/postgis/lwgeom_transform.c index d6a5c1055..c0ab2ce32 100644 --- a/postgis/lwgeom_transform.c +++ b/postgis/lwgeom_transform.c @@ -55,30 +55,27 @@ Datum transform(PG_FUNCTION_ARGS) output_srid = PG_GETARG_INT32(1); if (output_srid == SRID_UNKNOWN) { - elog(ERROR,"%d is an invalid target SRID",SRID_UNKNOWN); + elog(ERROR, "%d is an invalid target SRID", SRID_UNKNOWN); PG_RETURN_NULL(); } + /* Input SRID and output SRID are equal, noop */ + if ( input_srid == output_srid ) + PG_RETURN_POINTER(PG_GETARG_DATUM(0)); + geom = PG_GETARG_GSERIALIZED_P_COPY(0); input_srid = gserialized_get_srid(geom); if ( input_srid == SRID_UNKNOWN ) { PG_FREE_IF_COPY(geom, 0); - elog(ERROR,"Input geometry has unknown (%d) SRID",SRID_UNKNOWN); + elog(ERROR, "Input geometry has unknown (%d) SRID", SRID_UNKNOWN); PG_RETURN_NULL(); } - /* - * If input SRID and output SRID are equal, return geometry - * without transform it - */ - if ( input_srid == output_srid ) - PG_RETURN_POINTER(PG_GETARG_DATUM(0)); - if ( GetProjectionsUsingFCInfo(fcinfo, input_srid, output_srid, &input_pj, &output_pj) == LW_FAILURE ) { PG_FREE_IF_COPY(geom, 0); - elog(ERROR,"Failure reading projections from spatial_ref_sys."); + elog(ERROR, "Failure reading projections from spatial_ref_sys."); PG_RETURN_NULL(); } @@ -90,8 +87,7 @@ Datum transform(PG_FUNCTION_ARGS) /* Re-compute bbox if input had one (COMPUTE_BBOX TAINTING) */ if ( lwgeom->bbox ) { - lwgeom_drop_bbox(lwgeom); - lwgeom_add_bbox(lwgeom); + lwgeom_refresh_bbox(lwgeom); } result = geometry_serialize(lwgeom); @@ -186,8 +182,7 @@ Datum transform_geom(PG_FUNCTION_ARGS) /* Re-compute bbox if input had one (COMPUTE_BBOX TAINTING) */ if ( lwgeom->bbox ) { - lwgeom_drop_bbox(lwgeom); - lwgeom_add_bbox(lwgeom); + lwgeom_refresh_bbox(lwgeom); } result = geometry_serialize(lwgeom);