From 582ac127f763f512c45f35e17b768487e3b51796 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 4 Nov 2023 17:07:58 +0000 Subject: Rename TerrainMesh to GeoData to drop inplace --- test/test-geoData.cpp | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 test/test-geoData.cpp (limited to 'test/test-geoData.cpp') diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp new file mode 100644 index 0000000..d79f5b8 --- /dev/null +++ b/test/test-geoData.cpp @@ -0,0 +1,175 @@ +#define BOOST_TEST_MODULE terrain +#include "testHelpers.h" +#include +#include +#include + +#include + +class TestTerrainMesh : public GeoData { +public: + TestTerrainMesh() : GeoData {GeoData::loadFromAsciiGrid(FIXTURESDIR "height/SD19.asc")} { } +}; + +constexpr size_t ncols = 200, nrows = 200, xllcorner = 310000, yllcorner = 490000, cellsize = 50; + +BOOST_FIXTURE_TEST_SUITE(ttm, TestTerrainMesh); + +BOOST_AUTO_TEST_CASE(loadSuccess) +{ + BOOST_CHECK_EQUAL(ncols * nrows, n_vertices()); + BOOST_CHECK_EQUAL(2 * (ncols - 1) * (nrows - 1), n_faces()); + const auto [lower, upper] = getExtents(); + BOOST_CHECK_EQUAL(lower, glm::vec3(310000, 490000, -2.6)); + BOOST_CHECK_EQUAL(upper, glm::vec3(320000, 500000, 571.6)); +} + +BOOST_AUTO_TEST_CASE(normalsAllPointUp) +{ + BOOST_CHECK(std::all_of(faces_begin(), faces_end(), [this](auto && vh) { + return normal(vh).z > 0; + })); + BOOST_CHECK(std::all_of(vertices_begin(), vertices_end(), [this](auto && vh) { + return normal(vh).z > 0; + })); +} + +BOOST_AUTO_TEST_CASE(trianglesContainsPoints) +{ + const auto face = face_handle(0); + auto vertices = cfv_iter(face); + + BOOST_TEST_CONTEXT(point(*vertices++) << point(*vertices++) << point(*vertices++)) { + BOOST_CHECK(triangleContainsPoint(glm::vec2 {xllcorner, yllcorner}, face)); + BOOST_CHECK(triangleContainsPoint(glm::vec2 {xllcorner + cellsize, yllcorner + cellsize}, face)); + BOOST_CHECK(triangleContainsPoint(glm::vec2 {xllcorner, yllcorner + cellsize}, face)); + BOOST_CHECK(triangleContainsPoint(glm::vec2 {xllcorner + 1, yllcorner + 1}, face)); + BOOST_CHECK(triangleContainsPoint(glm::vec2 {xllcorner + 1, yllcorner + 2}, face)); + BOOST_CHECK(!triangleContainsPoint(glm::vec2 {xllcorner + 3, yllcorner + 2}, face)); + BOOST_CHECK(!triangleContainsPoint(glm::vec2 {xllcorner + cellsize, yllcorner}, face)); + } +} + +BOOST_AUTO_TEST_CASE(locatePointFace) +{ + const PointFace pf {{310002, 490003}}; + BOOST_CHECK(!pf.isLocated()); + BOOST_CHECK(pf.face(this).is_valid()); + BOOST_CHECK_EQUAL(pf.face(this).idx(), 0); +} + +BOOST_AUTO_TEST_CASE(preLocatePointFace) +{ + const PointFace pf {{310002, 490003}, this}; + BOOST_CHECK(pf.isLocated()); + BOOST_CHECK_EQUAL(pf.face(this).idx(), 0); +} + +BOOST_AUTO_TEST_SUITE_END(); + +using FindPointData = std::tuple; + +static const TestTerrainMesh fixedTerrtain; + +// No boundary cases as these can produce different valid results depending on starting point +BOOST_DATA_TEST_CASE(findPointOnTerrain, + boost::unit_test::data::make({ + {{0, 0}, -1}, {{xllcorner, 0}, -1}, {{0, yllcorner}, -1}, {{xllcorner + 1, yllcorner + 2}, 0}, + {{xllcorner + (cellsize * (nrows - 1)) - 2, yllcorner + (cellsize * (ncols - 1)) - 1}, 79200}, + {{315555, 495556}, 44400}, // perf test target + }) + * boost::unit_test::data::make( + {0, 1, 2, 3, 4, 5, 6, 10, 100, 150, 200, 1000, 1234, 17439, 79201, 79200, 79199}), + p, fh, start) +{ + BOOST_CHECK_EQUAL(fh, fixedTerrtain.findPoint(p, GeoData::FaceHandle(start)).idx()); +} + +using FindPositionData = std::tuple; + +BOOST_DATA_TEST_CASE(findPositionAt, + boost::unit_test::data::make({ + // corners + {{310000, 490000}, 32.8F}, + {{310050, 490050}, 33.0F}, + {{310000, 490050}, 32.7F}, + {{310050, 490000}, 33.2F}, + {{310750, 490150}, 58.4F}, + // midpoints + {{310025, 490025}, 32.9F}, + {{310025, 490050}, 32.85F}, + {{310000, 490025}, 32.75F}, + // other + {{310751, 490152}, 58.326F}, + }), + p, h) +{ + BOOST_CHECK_CLOSE_VEC(fixedTerrtain.positionAt(p), p ^ h); +} + +using FindRayIntersectData = std::tuple; + +BOOST_DATA_TEST_CASE(findRayIntersect, + boost::unit_test::data::make({ + {{310000, 490000, 50}, {1, 1, -2}, {310008.59, 490008.59, 32.834301}}, + {{310000, 490000, 50}, {1, 1, -1}, {310017.12, 490017.12, 32.868526}}, + }), + p, d, i) +{ + BOOST_CHECK_CLOSE_VEC(fixedTerrtain.intersectRay({p, d}).value(), i); +} + +using WalkTerrainData = std::tuple>; + +BOOST_DATA_TEST_CASE(walkTerrain, + boost::unit_test::data::make({ + {{310002, 490003}, {310002, 490003}, {0}}, + {{310003, 490002}, {310003, 490002}, {1}}, + {{310002, 490003}, {310003, 490002}, {0, 1}}, + {{310003, 490002}, {310002, 490003}, {1, 0}}, + {{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}}, + }), + from, to, visits) +{ + std::vector visited; + BOOST_CHECK_NO_THROW(fixedTerrtain.walk(from, to, [&visited](auto fh) { + visited.emplace_back(fh.idx()); + })); + BOOST_CHECK_EQUAL_COLLECTIONS(visited.begin(), visited.end(), visits.begin(), visits.end()); +} + +BOOST_DATA_TEST_CASE(walkTerrainSetsFromFace, + boost::unit_test::data::make({ + {{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) +{ + GeoData::PointFace pf {from}; + BOOST_CHECK_NO_THROW(fixedTerrtain.walk(pf, to, [](auto) {})); + BOOST_CHECK_EQUAL(pf.face(&fixedTerrtain).idx(), visits.front()); +} + +BOOST_DATA_TEST_CASE(walkTerrainUntil, + boost::unit_test::data::make({ + {{310002, 490003}, {310002, 490003}, {0}}, + {{310003, 490002}, {310003, 490002}, {1}}, + {{310002, 490003}, {310003, 490002}, {0, 1}}, + {{310003, 490002}, {310002, 490003}, {1, 0}}, + {{310002, 490003}, {310202, 490003}, {0, 1, 2, 3, 4}}, + {{310202, 490003}, {310002, 490003}, {8, 7, 6, 5, 4}}, + {{310002, 490003}, {310002, 490203}, {0, 399, 398, 797, 796}}, + }), + from, to, visits) +{ + std::vector visited; + BOOST_CHECK_NO_THROW(fixedTerrtain.walkUntil(from, to, [&visited](auto fh) { + visited.emplace_back(fh.idx()); + return visited.size() >= 5; + })); + BOOST_CHECK_EQUAL_COLLECTIONS(visited.begin(), visited.end(), visits.begin(), visits.end()); +} -- cgit v1.2.3 From 5ed36466b48aa347277c70422eb00bee264a5c8b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 4 Nov 2023 17:07:58 +0000 Subject: Simplify some logic with the triangle construct --- test/test-geoData.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/test-geoData.cpp') diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp index d79f5b8..b33c61e 100644 --- a/test/test-geoData.cpp +++ b/test/test-geoData.cpp @@ -37,9 +37,8 @@ BOOST_AUTO_TEST_CASE(normalsAllPointUp) BOOST_AUTO_TEST_CASE(trianglesContainsPoints) { const auto face = face_handle(0); - auto vertices = cfv_iter(face); - BOOST_TEST_CONTEXT(point(*vertices++) << point(*vertices++) << point(*vertices++)) { + BOOST_TEST_CONTEXT(GeoData::Triangle<2>(this, fv_range(face))) { BOOST_CHECK(triangleContainsPoint(glm::vec2 {xllcorner, yllcorner}, face)); BOOST_CHECK(triangleContainsPoint(glm::vec2 {xllcorner + cellsize, yllcorner + cellsize}, face)); BOOST_CHECK(triangleContainsPoint(glm::vec2 {xllcorner, yllcorner + cellsize}, face)); -- cgit v1.2.3 From 9ab1214aca7d77e1083476b05c6ddc2bb351bbac Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 4 Nov 2023 19:09:58 +0000 Subject: More tests can just use the global fixed data --- test/test-geoData.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'test/test-geoData.cpp') diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp index b33c61e..258bd9c 100644 --- a/test/test-geoData.cpp +++ b/test/test-geoData.cpp @@ -49,27 +49,27 @@ BOOST_AUTO_TEST_CASE(trianglesContainsPoints) } } +BOOST_AUTO_TEST_SUITE_END(); + +static const TestTerrainMesh fixedTerrtain; + BOOST_AUTO_TEST_CASE(locatePointFace) { - const PointFace pf {{310002, 490003}}; + const GeoData::PointFace pf {{310002, 490003}}; BOOST_CHECK(!pf.isLocated()); - BOOST_CHECK(pf.face(this).is_valid()); - BOOST_CHECK_EQUAL(pf.face(this).idx(), 0); + BOOST_CHECK(pf.face(&fixedTerrtain).is_valid()); + BOOST_CHECK_EQUAL(pf.face(&fixedTerrtain).idx(), 0); } BOOST_AUTO_TEST_CASE(preLocatePointFace) { - const PointFace pf {{310002, 490003}, this}; + const GeoData::PointFace pf {{310002, 490003}, &fixedTerrtain}; BOOST_CHECK(pf.isLocated()); - BOOST_CHECK_EQUAL(pf.face(this).idx(), 0); + BOOST_CHECK_EQUAL(pf.face(&fixedTerrtain).idx(), 0); } -BOOST_AUTO_TEST_SUITE_END(); - using FindPointData = std::tuple; -static const TestTerrainMesh fixedTerrtain; - // No boundary cases as these can produce different valid results depending on starting point BOOST_DATA_TEST_CASE(findPointOnTerrain, boost::unit_test::data::make({ -- cgit v1.2.3 From 04078dbb3fe4acd09d150e016c2b2e0d5d036950 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 5 Nov 2023 13:07:32 +0000 Subject: Add methods to walk the boundary of the terrain mesh --- test/test-geoData.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/test-geoData.cpp') diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp index 258bd9c..34c9cb6 100644 --- a/test/test-geoData.cpp +++ b/test/test-geoData.cpp @@ -118,6 +118,16 @@ BOOST_DATA_TEST_CASE(findRayIntersect, BOOST_CHECK_CLOSE_VEC(fixedTerrtain.intersectRay({p, d}).value(), i); } +BOOST_AUTO_TEST_CASE(boundaryWalk) +{ + size_t count {}; + fixedTerrtain.boundaryWalk([&count](auto heh) { + BOOST_CHECK(fixedTerrtain.is_boundary(heh)); + count++; + }); + BOOST_CHECK_EQUAL(count, 2 * (ncols + nrows - 2)); +} + using WalkTerrainData = std::tuple>; BOOST_DATA_TEST_CASE(walkTerrain, -- cgit v1.2.3 From acca54f3a12225454633dca2d56506c0dcebb653 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 5 Nov 2023 15:37:13 +0000 Subject: Fix calculating extents --- test/test-geoData.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/test-geoData.cpp') diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp index 34c9cb6..2ea9b26 100644 --- a/test/test-geoData.cpp +++ b/test/test-geoData.cpp @@ -21,7 +21,7 @@ BOOST_AUTO_TEST_CASE(loadSuccess) BOOST_CHECK_EQUAL(2 * (ncols - 1) * (nrows - 1), n_faces()); const auto [lower, upper] = getExtents(); BOOST_CHECK_EQUAL(lower, glm::vec3(310000, 490000, -2.6)); - BOOST_CHECK_EQUAL(upper, glm::vec3(320000, 500000, 571.6)); + BOOST_CHECK_EQUAL(upper, glm::vec3(319950, 499950, 571.6)); } BOOST_AUTO_TEST_CASE(normalsAllPointUp) -- cgit v1.2.3 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 --- test/test-geoData.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/test-geoData.cpp') 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) { -- cgit v1.2.3 From 3abe940a22d99939b666bd806214c8b986cb3ed9 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 26 Nov 2023 14:20:28 +0000 Subject: Calculate vertex normals only Doesn't require half edge normals or face normals, which uses Newell's method, which results in integer overflow... Not to mention we don't need all the other normals. --- test/test-geoData.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'test/test-geoData.cpp') diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp index 4e85f73..cb0466e 100644 --- a/test/test-geoData.cpp +++ b/test/test-geoData.cpp @@ -26,11 +26,6 @@ BOOST_AUTO_TEST_CASE(loadSuccess) BOOST_AUTO_TEST_CASE(normalsAllPointUp) { - BOOST_CHECK_EQUAL(std::count_if(faces_begin(), faces_end(), - [this](auto && vh) { - return normal(vh).z > 0; - }), - n_faces()); BOOST_CHECK_EQUAL(std::count_if(vertices_begin(), vertices_end(), [this](auto && vh) { return normal(vh).z > 0; -- cgit v1.2.3 From 0f56b13766fc6d8b45dabc4febf378756620ab32 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 2 Dec 2023 12:26:36 +0000 Subject: Replace positionAt with pure integer version --- test/test-geoData.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/test-geoData.cpp') diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp index cb0466e..164a6a5 100644 --- a/test/test-geoData.cpp +++ b/test/test-geoData.cpp @@ -92,7 +92,7 @@ BOOST_DATA_TEST_CASE(findPositionAt, {{310050000, 490050000}, 33000}, {{310000000, 490050000}, 32700}, {{310050000, 490000000}, 33200}, - {{310750000, 490150000}, 58399}, + {{310750000, 490150000}, 58400}, // midpoints {{310025000, 490025000}, 32900}, {{310025000, 490050000}, 32850}, -- cgit v1.2.3 From 9ae29335b72b6db037a78428ff8493d1fb587103 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 2 Dec 2023 16:38:12 +0000 Subject: Test case for finding ray entry points --- test/test-geoData.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/test-geoData.cpp') diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp index 164a6a5..d1c6b8b 100644 --- a/test/test-geoData.cpp +++ b/test/test-geoData.cpp @@ -186,3 +186,16 @@ BOOST_DATA_TEST_CASE(walkTerrainUntil, })); BOOST_CHECK_EQUAL_COLLECTIONS(visited.begin(), visited.end(), visits.begin(), visits.end()); } + +using FindEntiesData = std::tuple; + +BOOST_DATA_TEST_CASE(findEntries, + boost::unit_test::data::make({ + {{307739360, 494851616}, {314056992, 500079744}, 160667}, + {{308597952, 498417056}, {315154144, 504671456}, 233623}, + {{302690592, 502270912}, {311585184, 497868064}, 207311}, + }), + from, to, heh) +{ + BOOST_CHECK_EQUAL(fixedTerrtain.findEntry(from, to).idx(), heh); +} -- cgit v1.2.3