diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-10-28 02:34:45 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-10-28 12:35:11 +0100 |
commit | 16bec12e3e75e95d251745f904ac4e15af9c9724 (patch) | |
tree | fb4c24204dd1ff71fc55fb0b8a1eb909a35046fb /test/test-terrain.cpp | |
parent | Move OpenMesh/GLM compatibility structs to common place (diff) | |
download | ilt-16bec12e3e75e95d251745f904ac4e15af9c9724.tar.bz2 ilt-16bec12e3e75e95d251745f904ac4e15af9c9724.tar.xz ilt-16bec12e3e75e95d251745f904ac4e15af9c9724.zip |
Initial OpenMesh based terrain data and tests
Diffstat (limited to 'test/test-terrain.cpp')
-rw-r--r-- | test/test-terrain.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/test/test-terrain.cpp b/test/test-terrain.cpp new file mode 100644 index 0000000..b2358d6 --- /dev/null +++ b/test/test-terrain.cpp @@ -0,0 +1,48 @@ +#define BOOST_TEST_MODULE terrain +#include <boost/test/unit_test.hpp> +#include <stream_support.h> + +#include <game/terrain2.h> + +class TestTerrainMesh : public TerrainMesh { +public: + TestTerrainMesh() : TerrainMesh {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()); +} + +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_SUITE_END(); |