From 58402765133fab24d08b64f3752553bd2b8393b9 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 5 Nov 2023 15:52:02 +0000 Subject: Fix todo for handling a terrain walk from outside the mesh --- game/geoData.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'game/geoData.cpp') diff --git a/game/geoData.cpp b/game/geoData.cpp index 781b41e..61dedda 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -210,8 +210,10 @@ GeoData::walk(const PointFace & from, const glm::vec2 to, const std::function & op) const { - assert(from.face(this).is_valid()); // TODO replace with a boundary search auto f = from.face(this); + if (!f.is_valid()) { + f = opposite_face_handle(findEntry(from.point, to)); + } FaceHandle previousFace; while (f.is_valid() && !op(f)) { for (auto next = cfh_iter(f); next.is_valid(); ++next) { @@ -241,7 +243,7 @@ GeoData::boundaryWalk(const std::function & op, HalfedgeHa assert(is_boundary(start)); boundaryWalkUntil( [&op](auto heh) { - op(heh); + op(heh); return false; }, start); @@ -266,6 +268,22 @@ GeoData::boundaryWalkUntil(const std::function & op, Halfe } } +GeoData::HalfedgeHandle +GeoData::findEntry(const glm::vec2 from, const glm::vec2 to) const +{ + HalfedgeHandle entry; + boundaryWalkUntil([this, from, to, &entry](auto he) { + const auto e1 = point(to_vertex_handle(he)); + const auto e2 = point(to_vertex_handle(opposite_halfedge_handle(he))); + if (linesCrossLtR(from, to, e1, e2)) { + entry = he; + return true; + } + return false; + }); + return entry; +} + bool GeoData::triangleContainsPoint(const glm::vec2 p, const Triangle<2> & t) { -- cgit v1.2.3