summaryrefslogtreecommitdiff
path: root/game/geoData.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-11-05 13:07:32 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-11-05 13:07:40 +0000
commit04078dbb3fe4acd09d150e016c2b2e0d5d036950 (patch)
treea612b49c5be8104dafe403674716f3b3403e65ae /game/geoData.cpp
parentRefactor to further simplify line/point operations (diff)
downloadilt-04078dbb3fe4acd09d150e016c2b2e0d5d036950.tar.bz2
ilt-04078dbb3fe4acd09d150e016c2b2e0d5d036950.tar.xz
ilt-04078dbb3fe4acd09d150e016c2b2e0d5d036950.zip
Add methods to walk the boundary of the terrain mesh
Diffstat (limited to 'game/geoData.cpp')
-rw-r--r--game/geoData.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/game/geoData.cpp b/game/geoData.cpp
index c58658a..f9c11bf 100644
--- a/game/geoData.cpp
+++ b/game/geoData.cpp
@@ -218,6 +218,43 @@ GeoData::walkUntil(const PointFace & from, const glm::vec2 to, const std::functi
}
}
+void
+GeoData::boundaryWalk(const std::function<void(HalfedgeHandle)> & op) const
+{
+ boundaryWalk(op, findBoundaryStart());
+}
+
+void
+GeoData::boundaryWalk(const std::function<void(HalfedgeHandle)> & op, HalfedgeHandle start) const
+{
+ assert(is_boundary(start));
+ boundaryWalkUntil(
+ [&op](auto heh) {
+ op(heh);
+ return false;
+ },
+ start);
+}
+
+void
+GeoData::boundaryWalkUntil(const std::function<bool(HalfedgeHandle)> & op) const
+{
+ boundaryWalkUntil(op, findBoundaryStart());
+}
+
+void
+GeoData::boundaryWalkUntil(const std::function<bool(HalfedgeHandle)> & op, HalfedgeHandle start) const
+{
+ assert(is_boundary(start));
+ if (!op(start)) {
+ for (auto heh = next_halfedge_handle(start); heh != start; heh = next_halfedge_handle(heh)) {
+ if (op(heh)) {
+ break;
+ }
+ }
+ }
+}
+
bool
GeoData::triangleContainsPoint(const glm::vec2 p, const Triangle<2> & t)
{
@@ -230,3 +267,11 @@ GeoData::triangleContainsPoint(const glm::vec2 p, FaceHandle face) const
{
return triangleContainsPoint(p, triangle<2>(face));
}
+
+GeoData::HalfedgeHandle
+GeoData::findBoundaryStart() const
+{
+ return *std::find_if(halfedges_begin(), halfedges_end(), [this](const auto heh) {
+ return is_boundary(heh);
+ });
+}