Skip to content

Commit

Permalink
CoordinateSequence: Add applyAt method
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston committed Nov 18, 2024
1 parent dc4e7b2 commit 32a3bf4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
10 changes: 10 additions & 0 deletions include/geos/geom/CoordinateSequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,16 @@ class GEOS_DLL CoordinateSequence {
}
}

template<typename F>
auto applyAt(size_t i, F&& fun) const {
switch(getCoordinateType()) {
case CoordinateType::XYZ: return fun(getAt<Coordinate>(i));
case CoordinateType::XYM: return fun(getAt<CoordinateXYM>(i));
case CoordinateType::XYZM: return fun(getAt<CoordinateXYZM>(i));
default: return fun(getAt<CoordinateXY>(i));
}
}

template<typename F>
void forEach(F&& fun) const {
switch(getCoordinateType()) {
Expand Down
11 changes: 2 additions & 9 deletions src/geom/SimpleCurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Point>
Expand Down

0 comments on commit 32a3bf4

Please sign in to comment.