[postgis-tickets] r16670 - Clarify retry logic in lwgeom_offsetcurve

Daniel Baston dbaston at gmail.com
Wed Jul 25 01:15:44 PDT 2018


Author: dbaston
Date: 2018-07-25 13:15:43 -0700 (Wed, 25 Jul 2018)
New Revision: 16670

Modified:
   trunk/liblwgeom/lwgeom_geos.c
Log:
Clarify retry logic in lwgeom_offsetcurve

Closes https://github.com/postgis/postgis/pull/273



Modified: trunk/liblwgeom/lwgeom_geos.c
===================================================================
--- trunk/liblwgeom/lwgeom_geos.c	2018-07-24 20:55:20 UTC (rev 16669)
+++ trunk/liblwgeom/lwgeom_geos.c	2018-07-25 20:15:43 UTC (rev 16670)
@@ -1456,7 +1456,6 @@
 {
 	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 @@
 		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;
+	}
+
+	if (!result)
+	{
+		/* Node the input geometry and try again */
+		LWGEOM* noded = lwgeom_node(geom);
+		if (!noded)
 		{
-		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));
+			lwerror("%s: cannot node input", __func__);
 			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
-		{
-			lwerror("lwgeom_offsetcurve: noded geometry cannot be offset");
-			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;
 }
 



More information about the postgis-tickets mailing list