]> granicus.if.org Git - postgis/commitdiff
Clarify retry logic in lwgeom_offsetcurve
authorDaniel Baston <dbaston@gmail.com>
Wed, 25 Jul 2018 20:15:43 +0000 (20:15 +0000)
committerDaniel Baston <dbaston@gmail.com>
Wed, 25 Jul 2018 20:15:43 +0000 (20:15 +0000)
Closes https://github.com/postgis/postgis/pull/273

git-svn-id: http://svn.osgeo.org/postgis/trunk@16670 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/lwgeom_geos.c

index 6e0c8ce28cbeba203cf3ee2a87e069648f5ad416..756deb3ced351264ec43694aa11d5d66645c6bbf 100644 (file)
@@ -1456,7 +1456,6 @@ lwgeom_offsetcurve(const LWGEOM* geom, double size, int quadsegs, int joinStyle,
 {
        int32_t srid = RESULT_SRID(geom);
        LWGEOM *result = NULL;
-       LWGEOM *noded = NULL;
        if (srid == SRID_INVALID) return NULL;
 
        if (lwgeom_dimension(geom) != 1)
@@ -1465,41 +1464,40 @@ lwgeom_offsetcurve(const LWGEOM* geom, double size, int quadsegs, int joinStyle,
                return NULL;
        }
 
-       while (!result)
+       switch (geom->type)
        {
-               switch (geom->type)
-               {
-               case LINETYPE:
-                       result = lwline_offsetcurve(lwgeom_as_lwline(geom), size, quadsegs, joinStyle, mitreLimit);
-                       break;
-               case COLLECTIONTYPE:
-               case MULTILINETYPE:
-                       result = lwcollection_offsetcurve(lwgeom_as_lwcollection(geom), size, quadsegs, joinStyle, mitreLimit);
-                       break;
-               default:
-                       lwerror("%s: unsupported geometry type: %s", __func__, lwtype_name(geom->type));
-                       return NULL;
-               }
+       case LINETYPE:
+               result = lwline_offsetcurve(lwgeom_as_lwline(geom), size, quadsegs, joinStyle, mitreLimit);
+               break;
+       case COLLECTIONTYPE:
+       case MULTILINETYPE:
+               result = lwcollection_offsetcurve(lwgeom_as_lwcollection(geom), size, quadsegs, joinStyle, mitreLimit);
+               break;
+       default:
+               lwerror("%s: unsupported geometry type: %s", __func__, lwtype_name(geom->type));
+               return NULL;
+       }
 
-               if (result)
-                       return result;
-               else if (!noded)
-               {
-                       noded = lwgeom_node(geom);
-                       if (!noded)
-                       {
-                               lwfree(noded);
-                               lwerror("lwgeom_offsetcurve: cannot node input");
-                               return NULL;
-                       }
-                       geom = noded;
-               }
-               else
+       if (!result)
+       {
+               /* Node the input geometry and try again */
+               LWGEOM* noded = lwgeom_node(geom);
+               if (!noded)
                {
-                       lwerror("lwgeom_offsetcurve: noded geometry cannot be offset");
+                       lwerror("%s: cannot node input", __func__);
                        return NULL;
                }
+
+               result = lwgeom_offsetcurve(noded, size, quadsegs, joinStyle, mitreLimit);
+               lwfree(noded);
+       }
+
+       if (!result)
+       {
+               lwerror("%s: noded geometry cannot be offset", __func__);
+               return NULL;
        }
+
        return result;
 }