From: Daniel Baston Date: Wed, 25 Jul 2018 20:15:43 +0000 (+0000) Subject: Clarify retry logic in lwgeom_offsetcurve X-Git-Tag: 2.5.0beta2~20 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e6e96d1d05c5e32d49055a791fe6d341996a6ce8;p=postgis Clarify retry logic in lwgeom_offsetcurve Closes https://github.com/postgis/postgis/pull/273 git-svn-id: http://svn.osgeo.org/postgis/trunk@16670 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/lwgeom_geos.c b/liblwgeom/lwgeom_geos.c index 6e0c8ce28..756deb3ce 100644 --- a/liblwgeom/lwgeom_geos.c +++ b/liblwgeom/lwgeom_geos.c @@ -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; }