diff --git a/include/geos/geom/CoordinateSequence.h b/include/geos/geom/CoordinateSequence.h index b49b8693f..c135ce18d 100644 --- a/include/geos/geom/CoordinateSequence.h +++ b/include/geos/geom/CoordinateSequence.h @@ -679,6 +679,16 @@ class GEOS_DLL CoordinateSequence { } } + template + auto applyAt(size_t i, F&& fun) const { + switch(getCoordinateType()) { + case CoordinateType::XYZ: return fun(getAt(i)); + case CoordinateType::XYM: return fun(getAt(i)); + case CoordinateType::XYZM: return fun(getAt(i)); + default: return fun(getAt(i)); + } + } + template void forEach(F&& fun) const { switch(getCoordinateType()) { diff --git a/src/geom/SimpleCurve.cpp b/src/geom/SimpleCurve.cpp index 882fb9402..952d207d0 100644 --- a/src/geom/SimpleCurve.cpp +++ b/src/geom/SimpleCurve.cpp @@ -252,16 +252,9 @@ SimpleCurve::getPointN(std::size_t n) const assert(getFactory()); assert(points.get()); - if (hasM() || hasZ()) { - CoordinateXYZM c; - points->getAt(n, c); + return points->applyAt(n, [this](const auto& c) { return getFactory()->createPoint(c); - } - else { - CoordinateXY c; - points->getAt(n, c); - return getFactory()->createPoint(c); - } + }); } std::unique_ptr