diff options
-rw-r--r-- | game/terrain2.cpp | 11 | ||||
-rw-r--r-- | game/terrain2.h | 4 | ||||
-rw-r--r-- | test/test-terrain.cpp | 14 |
3 files changed, 22 insertions, 7 deletions
diff --git a/game/terrain2.cpp b/game/terrain2.cpp index e98cebb..5d1c595 100644 --- a/game/terrain2.cpp +++ b/game/terrain2.cpp @@ -115,7 +115,7 @@ TerrainMesh::findPoint(glm::vec2 p, OpenMesh::FaceHandle f) const } void -TerrainMesh::walk(const glm::vec2 from, const glm::vec2 to, const std::function<void(FaceHandle)> & op) const +TerrainMesh::walk(const PointFace & from, const glm::vec2 to, const std::function<void(FaceHandle)> & op) const { walkUntil(from, to, [&op](const auto & fh) { op(fh); @@ -124,10 +124,11 @@ TerrainMesh::walk(const glm::vec2 from, const glm::vec2 to, const std::function< } void -TerrainMesh::walkUntil(const glm::vec2 from, const glm::vec2 to, const std::function<bool(FaceHandle)> & op) const +TerrainMesh::walkUntil(const PointFace & from, const glm::vec2 to, const std::function<bool(FaceHandle)> & op) const { - auto f = findPoint(from); - assert(f.is_valid()); // TODO replace with a boundary search + locate(from); + assert(from.face.is_valid()); // TODO replace with a boundary search + auto f = from.face; FaceHandle previousFace; while (f.is_valid() && !op(f)) { for (auto next = cfh_iter(f); next.is_valid(); ++next) { @@ -135,7 +136,7 @@ TerrainMesh::walkUntil(const glm::vec2 from, const glm::vec2 to, const std::func if (f.is_valid() && f != previousFace) { const auto e1 = point(to_vertex_handle(*next)); const auto e2 = point(to_vertex_handle(opposite_halfedge_handle(*next))); - if (linesCross(from, to, e1, e2)) { + if (linesCross(from.point, to, e1, e2)) { previousFace = f; break; } diff --git a/game/terrain2.h b/game/terrain2.h index e516719..1a4e263 100644 --- a/game/terrain2.h +++ b/game/terrain2.h @@ -28,8 +28,8 @@ public: [[nodiscard]] FaceHandle findPoint(glm::vec2) const; [[nodiscard]] FaceHandle findPoint(glm::vec2, FaceHandle start) const; - void walk(const glm::vec2 from, const glm::vec2 to, const std::function<void(FaceHandle)> & op) const; - void walkUntil(const glm::vec2 from, const glm::vec2 to, const std::function<bool(FaceHandle)> & op) const; + void walk(const PointFace & from, const glm::vec2 to, const std::function<void(FaceHandle)> & op) const; + void walkUntil(const PointFace & from, const glm::vec2 to, const std::function<bool(FaceHandle)> & op) const; protected: [[nodiscard]] static bool triangleContainsPoint(const glm::vec2, const glm::vec2, const glm::vec2, const glm::vec2); diff --git a/test/test-terrain.cpp b/test/test-terrain.cpp index f737f4f..bf30179 100644 --- a/test/test-terrain.cpp +++ b/test/test-terrain.cpp @@ -96,6 +96,20 @@ BOOST_DATA_TEST_CASE(walkTerrain, BOOST_CHECK_EQUAL_COLLECTIONS(visited.begin(), visited.end(), visits.begin(), visits.end()); } +BOOST_DATA_TEST_CASE(walkTerrainSetsFromFace, + boost::unit_test::data::make<WalkTerrainData>({ + {{310002, 490003}, {310002, 490003}, {0}}, + {{310003, 490002}, {310003, 490002}, {1}}, + {{310002, 490003}, {310003, 490002}, {0, 1}}, + {{310003, 490002}, {310002, 490003}, {1, 0}}, + }), + from, to, visits) +{ + TerrainMesh::PointFace pf {from}; + BOOST_CHECK_NO_THROW(fixedTerrtain.walk(pf, to, [](auto) {})); + BOOST_CHECK_EQUAL(pf.face.idx(), visits.front()); +} + BOOST_DATA_TEST_CASE(walkTerrainUntil, boost::unit_test::data::make<WalkTerrainData>({ {{310002, 490003}, {310002, 490003}, {0}}, |