From 32a3bf4923b6c1c8ce38f21260d6e1a02d0bbb2f Mon Sep 17 00:00:00 2001 From: Daniel Baston Date: Mon, 18 Nov 2024 08:39:42 -0500 Subject: [PATCH] CoordinateSequence: Add applyAt method --- include/geos/geom/CoordinateSequence.h | 10 ++++++++++ src/geom/SimpleCurve.cpp | 11 ++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/geos/geom/CoordinateSequence.h b/include/geos/geom/CoordinateSequence.h index b49b8693f9..c135ce18da 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 882fb94029..952d207d07 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