summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-11-05 15:52:02 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-11-05 15:52:02 +0000
commit58402765133fab24d08b64f3752553bd2b8393b9 (patch)
treea5719e50031d8433912e27184bd8b4b89820bac7
parentFix calculating extents (diff)
downloadilt-58402765133fab24d08b64f3752553bd2b8393b9.tar.bz2
ilt-58402765133fab24d08b64f3752553bd2b8393b9.tar.xz
ilt-58402765133fab24d08b64f3752553bd2b8393b9.zip
Fix todo for handling a terrain walk from outside the mesh
-rw-r--r--game/geoData.cpp22
-rw-r--r--game/geoData.h2
-rw-r--r--test/test-geoData.cpp5
3 files changed, 27 insertions, 2 deletions
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<vo
void
GeoData::walkUntil(const PointFace & from, const glm::vec2 to, const std::function<bool(FaceHandle)> & 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<void(HalfedgeHandle)> & 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<bool(HalfedgeHandle)> & 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)
{
diff --git a/game/geoData.h b/game/geoData.h
index 15d7e24..474731b 100644
--- a/game/geoData.h
+++ b/game/geoData.h
@@ -83,6 +83,8 @@ public:
void boundaryWalkUntil(const std::function<bool(HalfedgeHandle)> &) const;
void boundaryWalkUntil(const std::function<bool(HalfedgeHandle)> &, HalfedgeHandle start) const;
+ [[nodiscard]] HalfedgeHandle findEntry(const glm::vec2 from, const glm::vec2 to) const;
+
[[nodiscard]] auto
getExtents() const
{
diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp
index 2ea9b26..447ab37 100644
--- a/test/test-geoData.cpp
+++ b/test/test-geoData.cpp
@@ -139,6 +139,11 @@ BOOST_DATA_TEST_CASE(walkTerrain,
{{310002, 490003}, {310202, 490003}, {0, 1, 2, 3, 4, 5, 6, 7, 8}},
{{310202, 490003}, {310002, 490003}, {8, 7, 6, 5, 4, 3, 2, 1, 0}},
{{310002, 490003}, {310002, 490203}, {0, 399, 398, 797, 796, 1195, 1194, 1593, 1592}},
+ {{310002, 490003}, {309999, 489999}, {0}},
+ {{309999, 489999}, {310002, 490003}, {0}},
+ {{320002, 500003}, {319949, 499948}, {79201}},
+ {{309999, 490003}, {310004, 489997}, {0, 1}},
+ {{310004, 489997}, {309999, 490003}, {1, 0}},
}),
from, to, visits)
{