]> granicus.if.org Git - postgis/commitdiff
Add lwgeom_refresh_bbox to replace drop/add twostep
authorPaul Ramsey <pramsey@cleverelephant.ca>
Mon, 11 Dec 2017 15:04:01 +0000 (15:04 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Mon, 11 Dec 2017 15:04:01 +0000 (15:04 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@16143 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/liblwgeom.h.in
liblwgeom/lwgeom.c
liblwgeom/lwline.c
liblwgeom/lwlinearreferencing.c
postgis/geography_inout.c
postgis/lwgeom_functions_basic.c
postgis/lwgeom_transform.c

index 873496730c3d719abc58a44d91a103b62b79d0dc..ea8c9e5de48ddd1f56babdff3ca8b103fe1f5b01 100644 (file)
@@ -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);
index 9d52572a0a70d40973ad4dda4e03b6250eb19ca2..d5940524a04f024e29727a6ad34e94981b7403b7 100644 (file)
@@ -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);
        }
 }
 
index 73f06e62f1f73c3a8c0ab3fe049b5872d65181d2..617597c2a311bc6255b18e1677c773924f4a17a5 100644 (file)
@@ -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);
        }
 }
 
index 5cb81bb21dfc5dbae1c5b99f4aa8a23e2b5fc1bb..e83fbf642dd23a3c898f85d7306258a36dba8733 100644 (file)
@@ -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;
index 16dad0034a91b1d820c8b6838eab397d79bad6e7..2b43d577e2dce103b2de146291c7941387aa5c4d 100644 (file)
@@ -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. */
index 72a084d3261a9d3ab1ef9b6c8612ea0566d766dd..6606033ad79dd795c6fd0de391745f178720a19e 100644 (file)
@@ -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);
 
index d6a5c1055bc6016625502292da8cb0c34e5212ed..c0ab2ce32c942ce1ed5eeb433686e3a56631f47e 100644 (file)
@@ -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);