diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-11-26 13:51:33 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-11-26 14:14:13 +0000 |
commit | 7fba471728f2216d7e3b7900297fc3b3531e286c (patch) | |
tree | 5caef3b2efc23aefccb215ec9005cd8e7d2e91b8 /test/test-geoData.cpp | |
parent | Fix todo for handling a terrain walk from outside the mesh (diff) | |
parent | Model positions as integers (diff) | |
download | ilt-7fba471728f2216d7e3b7900297fc3b3531e286c.tar.bz2 ilt-7fba471728f2216d7e3b7900297fc3b3531e286c.tar.xz ilt-7fba471728f2216d7e3b7900297fc3b3531e286c.zip |
Merge branch 'ints' into terrain
Conflicts fix, compiles, some test failures remain.
Trees not added, possibility of OM invalid handle assertion failures,
normals broken due to integer overflow in Newell's method.
Diffstat (limited to 'test/test-geoData.cpp')
-rw-r--r-- | test/test-geoData.cpp | 122 |
1 files changed, 63 insertions, 59 deletions
diff --git a/test/test-geoData.cpp b/test/test-geoData.cpp index 447ab37..4e85f73 100644 --- a/test/test-geoData.cpp +++ b/test/test-geoData.cpp @@ -11,7 +11,7 @@ public: TestTerrainMesh() : GeoData {GeoData::loadFromAsciiGrid(FIXTURESDIR "height/SD19.asc")} { } }; -constexpr size_t ncols = 200, nrows = 200, xllcorner = 310000, yllcorner = 490000, cellsize = 50; +constexpr size_t ncols = 200, nrows = 200, xllcorner = 310000000, yllcorner = 490000000, cellsize = 50000; BOOST_FIXTURE_TEST_SUITE(ttm, TestTerrainMesh); @@ -20,18 +20,22 @@ 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(319950, 499950, 571.6)); + BOOST_CHECK_EQUAL(lower, GlobalPosition3D(310000000, 490000000, -2600)); + BOOST_CHECK_EQUAL(upper, GlobalPosition3D(319950000, 499950000, 571600)); } 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_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; + }), + n_vertices()); } BOOST_AUTO_TEST_CASE(trianglesContainsPoints) @@ -39,13 +43,13 @@ BOOST_AUTO_TEST_CASE(trianglesContainsPoints) const auto face = face_handle(0); 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)); - 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_CHECK(triangleContainsPoint(GlobalPosition2D {xllcorner, yllcorner}, face)); + BOOST_CHECK(triangleContainsPoint(GlobalPosition2D {xllcorner + cellsize, yllcorner + cellsize}, face)); + BOOST_CHECK(triangleContainsPoint(GlobalPosition2D {xllcorner, yllcorner + cellsize}, face)); + BOOST_CHECK(triangleContainsPoint(GlobalPosition2D {xllcorner + 1, yllcorner + 1}, face)); + BOOST_CHECK(triangleContainsPoint(GlobalPosition2D {xllcorner + 1, yllcorner + 2}, face)); + BOOST_CHECK(!triangleContainsPoint(GlobalPosition2D {xllcorner + 3, yllcorner + 2}, face)); + BOOST_CHECK(!triangleContainsPoint(GlobalPosition2D {xllcorner + cellsize, yllcorner}, face)); } } @@ -55,7 +59,7 @@ static const TestTerrainMesh fixedTerrtain; BOOST_AUTO_TEST_CASE(locatePointFace) { - const GeoData::PointFace pf {{310002, 490003}}; + const GeoData::PointFace pf {{310002000, 490003000}}; BOOST_CHECK(!pf.isLocated()); BOOST_CHECK(pf.face(&fixedTerrtain).is_valid()); BOOST_CHECK_EQUAL(pf.face(&fixedTerrtain).idx(), 0); @@ -63,19 +67,19 @@ BOOST_AUTO_TEST_CASE(locatePointFace) BOOST_AUTO_TEST_CASE(preLocatePointFace) { - const GeoData::PointFace pf {{310002, 490003}, &fixedTerrtain}; + const GeoData::PointFace pf {{310002000, 490003000}, &fixedTerrtain}; BOOST_CHECK(pf.isLocated()); BOOST_CHECK_EQUAL(pf.face(&fixedTerrtain).idx(), 0); } -using FindPointData = std::tuple<glm::vec2, int>; +using FindPointData = std::tuple<GlobalPosition2D, int>; // No boundary cases as these can produce different valid results depending on starting point BOOST_DATA_TEST_CASE(findPointOnTerrain, boost::unit_test::data::make<FindPointData>({ {{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 + {{315555000, 495556000}, 44400}, // perf test target }) * boost::unit_test::data::make<int>( {0, 1, 2, 3, 4, 5, 6, 10, 100, 150, 200, 1000, 1234, 17439, 79201, 79200, 79199}), @@ -84,38 +88,38 @@ BOOST_DATA_TEST_CASE(findPointOnTerrain, BOOST_CHECK_EQUAL(fh, fixedTerrtain.findPoint(p, GeoData::FaceHandle(start)).idx()); } -using FindPositionData = std::tuple<glm::vec2, float>; +using FindPositionData = std::tuple<GlobalPosition2D, GlobalDistance>; BOOST_DATA_TEST_CASE(findPositionAt, boost::unit_test::data::make<FindPositionData>({ // corners - {{310000, 490000}, 32.8F}, - {{310050, 490050}, 33.0F}, - {{310000, 490050}, 32.7F}, - {{310050, 490000}, 33.2F}, - {{310750, 490150}, 58.4F}, + {{310000000, 490000000}, 32800}, + {{310050000, 490050000}, 33000}, + {{310000000, 490050000}, 32700}, + {{310050000, 490000000}, 33200}, + {{310750000, 490150000}, 58399}, // midpoints - {{310025, 490025}, 32.9F}, - {{310025, 490050}, 32.85F}, - {{310000, 490025}, 32.75F}, + {{310025000, 490025000}, 32900}, + {{310025000, 490050000}, 32850}, + {{310000000, 490025000}, 32750}, // other - {{310751, 490152}, 58.326F}, + {{310751000, 490152000}, 58326}, }), p, h) { - BOOST_CHECK_CLOSE_VEC(fixedTerrtain.positionAt(p), p ^ h); + BOOST_CHECK_EQUAL(fixedTerrtain.positionAt(p), GlobalPosition3D(p, h)); } -using FindRayIntersectData = std::tuple<glm::vec3, glm::vec3, glm::vec3>; +using FindRayIntersectData = std::tuple<GlobalPosition3D, Direction3D, GlobalPosition3D>; BOOST_DATA_TEST_CASE(findRayIntersect, boost::unit_test::data::make<FindRayIntersectData>({ - {{310000, 490000, 50}, {1, 1, -2}, {310008.59, 490008.59, 32.834301}}, - {{310000, 490000, 50}, {1, 1, -1}, {310017.12, 490017.12, 32.868526}}, + {{310000000, 490000000, 50000}, {1, 1, -2}, {310008585, 490008585, 32834}}, + {{310000000, 490000000, 50000}, {1, 1, -1}, {310017136, 490017136, 32868}}, }), p, d, i) { - BOOST_CHECK_CLOSE_VEC(fixedTerrtain.intersectRay({p, d}).value(), i); + BOOST_CHECK_EQUAL(fixedTerrtain.intersectRay({p, d}).value(), i); } BOOST_AUTO_TEST_CASE(boundaryWalk) @@ -128,22 +132,22 @@ BOOST_AUTO_TEST_CASE(boundaryWalk) BOOST_CHECK_EQUAL(count, 2 * (ncols + nrows - 2)); } -using WalkTerrainData = std::tuple<glm::vec2, glm::vec2, std::vector<int>>; +using WalkTerrainData = std::tuple<GlobalPosition2D, GlobalPosition2D, std::vector<int>>; BOOST_DATA_TEST_CASE(walkTerrain, 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}}, - {{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}}, + {{310002000, 490003000}, {310002000, 490003000}, {0}}, + {{310003000, 490002000}, {310003000, 490002000}, {1}}, + {{310002000, 490003000}, {310003000, 490002000}, {0, 1}}, + {{310003000, 490002000}, {310002000, 490003000}, {1, 0}}, + {{310002000, 490003000}, {310202000, 490003000}, {0, 1, 2, 3, 4, 5, 6, 7, 8}}, + {{310202000, 490003000}, {310002000, 490003000}, {8, 7, 6, 5, 4, 3, 2, 1, 0}}, + {{310002000, 490003000}, {310002000, 490203000}, {0, 399, 398, 797, 796, 1195, 1194, 1593, 1592}}, + {{310002000, 490003000}, {309999000, 489999000}, {0}}, + {{309999000, 489999000}, {310002000, 490003000}, {0}}, + {{320002000, 500003000}, {319949000, 499948000}, {79201}}, + {{309999000, 490003000}, {310004000, 489997000}, {0, 1}}, + {{310004000, 489997000}, {309999000, 490003000}, {1, 0}}, }), from, to, visits) { @@ -156,10 +160,10 @@ BOOST_DATA_TEST_CASE(walkTerrain, 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}}, + {{310002000, 490003000}, {310002000, 490003000}, {0}}, + {{310003000, 490002000}, {310003000, 490002000}, {1}}, + {{310002000, 490003000}, {310003000, 490002000}, {0, 1}}, + {{310003000, 490002000}, {310002000, 490003000}, {1, 0}}, }), from, to, visits) { @@ -170,13 +174,13 @@ BOOST_DATA_TEST_CASE(walkTerrainSetsFromFace, BOOST_DATA_TEST_CASE(walkTerrainUntil, 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}}, - {{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}}, + {{310002000, 490003000}, {310002000, 490003000}, {0}}, + {{310003000, 490002000}, {310003000, 490002000}, {1}}, + {{310002000, 490003000}, {310003000, 490002000}, {0, 1}}, + {{310003000, 490002000}, {310002000, 490003000}, {1, 0}}, + {{310002000, 490003000}, {310202000, 490003000}, {0, 1, 2, 3, 4}}, + {{310202000, 490003000}, {310002000, 490003000}, {8, 7, 6, 5, 4}}, + {{310002000, 490003000}, {310002000, 490203000}, {0, 399, 398, 797, 796}}, }), from, to, visits) { |