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/Jamfile.jam | 5 +- test/perf-geoData.cpp | 18 ++++ test/perf-terrain.cpp | 18 ---- test/test-geo.cpp | 225 -------------------------------------------------- test/test-geoData.cpp | 175 +++++++++++++++++++++++++++++++++++++++ test/test-render.cpp | 3 +- test/test-terrain.cpp | 175 --------------------------------------- 7 files changed, 196 insertions(+), 423 deletions(-) create mode 100644 test/perf-geoData.cpp delete mode 100644 test/perf-terrain.cpp delete mode 100644 test/test-geo.cpp create mode 100644 test/test-geoData.cpp delete mode 100644 test/test-terrain.cpp (limited to 'test') diff --git a/test/Jamfile.jam b/test/Jamfile.jam index d88a238..6f62056 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -46,7 +46,7 @@ lib test : [ glob *.cpp : test-*.cpp perf-*.cpp ] ; run test-collection.cpp ; run test-maths.cpp ; run test-lib.cpp ; -run test-geo.cpp ; +run test-geoData.cpp : -- : fixtures/height/SD19.asc : test ; run test-network.cpp : : : test ; run test-persistence.cpp : -- : [ sequence.insertion-sort [ glob-tree fixtures : *.json ] ] : test ; run test-text.cpp : : : test ; @@ -55,13 +55,12 @@ run test-render.cpp : -- : test-assetFactory : test ; run test-glContextBhvr.cpp ; run test-assetFactory.cpp : -- : [ sequence.insertion-sort [ glob-tree $(res) : *.* ] fixtures/rgb.txt test-instancing ] : test ; run perf-assetFactory.cpp : -- : test-assetFactory : benchmark test ; +run perf-geoData.cpp : : : test benchmark ; run perf-persistence.cpp : -- : test-persistence : benchmark test ; run test-worker.cpp ; run test-instancing.cpp : : : test ; run test-glContainer.cpp : : : test ; run test-pack.cpp : : : test ; -run test-terrain.cpp : -- : fixtures/height/SD19.asc : test ..//OpenMeshCore ; -run perf-terrain.cpp : : : test ..//OpenMeshCore benchmark ; compile test-static-enumDetails.cpp ; compile test-static-stream_support.cpp ; explicit perf-assetFactory ; diff --git a/test/perf-geoData.cpp b/test/perf-geoData.cpp new file mode 100644 index 0000000..e1546c1 --- /dev/null +++ b/test/perf-geoData.cpp @@ -0,0 +1,18 @@ +#include +#include + +namespace { + const GeoData tm {GeoData::loadFromAsciiGrid(FIXTURESDIR "height/SD19.asc")}; + + void + terrain_findPoint(benchmark::State & state) + { + for (auto _ : state) { + benchmark::DoNotOptimize(tm.findPoint({315555, 495556})); + } + } +} + +BENCHMARK(terrain_findPoint); + +BENCHMARK_MAIN(); diff --git a/test/perf-terrain.cpp b/test/perf-terrain.cpp deleted file mode 100644 index e998f60..0000000 --- a/test/perf-terrain.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include - -namespace { - const TerrainMesh tm {FIXTURESDIR "height/SD19.asc"}; - - void - terrain_findPoint(benchmark::State & state) - { - for (auto _ : state) { - benchmark::DoNotOptimize(tm.findPoint({315555, 495556})); - } - } -} - -BENCHMARK(terrain_findPoint); - -BENCHMARK_MAIN(); diff --git a/test/test-geo.cpp b/test/test-geo.cpp deleted file mode 100644 index 9874fb7..0000000 --- a/test/test-geo.cpp +++ /dev/null @@ -1,225 +0,0 @@ -#define BOOST_TEST_MODULE test_geo - -#include "testHelpers.h" -#include -#include -#include - -#include -#include - -struct TestGeoData : public GeoData { - TestGeoData() : GeoData {{{-10, -5}, {30, 40}}, 5.F} { } -}; - -namespace std { - std::ostream & - operator<<(std::ostream & s, const Ray & r) - { - return (s << r.start << "->" << r.direction); - } -} - -BOOST_FIXTURE_TEST_SUITE(tgd, TestGeoData) - -BOOST_AUTO_TEST_CASE(initialize) -{ - BOOST_CHECK_EQUAL(limit.first, glm::ivec2(-10, -5)); - BOOST_CHECK_EQUAL(limit.second, glm::ivec2(30, 40)); - BOOST_CHECK_EQUAL(scale, 5.F); - BOOST_CHECK_EQUAL(size, glm::uvec2(41, 46)); - BOOST_CHECK_EQUAL(nodes.size(), 1886); - BOOST_CHECK(std::all_of(nodes.begin(), nodes.end(), [](const auto & n) { - return n.height == -1.5F; - })); -} - -BOOST_AUTO_TEST_CASE(coords) -{ - BOOST_CHECK_EQUAL(at(-10, -5), 0); - BOOST_CHECK_EQUAL(at(-9, -5), 1); - BOOST_CHECK_EQUAL(at(0, -5), 10); - BOOST_CHECK_EQUAL(at(30, -5), 40); - BOOST_CHECK_EQUAL(at(30, 40), 1885); -} - -BOOST_AUTO_TEST_CASE(coords_bad) -{ - BOOST_CHECK_THROW(std::ignore = at(-11, -5), std::range_error); - BOOST_CHECK_THROW(std::ignore = at(-10, -6), std::range_error); - BOOST_CHECK_THROW(std::ignore = at(-11, -6), std::range_error); - BOOST_CHECK_THROW(std::ignore = at(31, 40), std::range_error); - BOOST_CHECK_THROW(std::ignore = at(30, 41), std::range_error); - BOOST_CHECK_THROW(std::ignore = at(31, 41), std::range_error); -} - -BOOST_AUTO_TEST_CASE(gen_random) -{ - // Can only really its sanity - generateRandom(); - // Some terrain above sea level - BOOST_CHECK(std::any_of(nodes.begin(), nodes.end(), [](const auto & n) { - return n.height > 0; - })); - // Still an island - for (int x = limit.first.x; x <= limit.second.x; x += 1) { - BOOST_CHECK_EQUAL(nodes[at(x, limit.first.y)].height, -1.5F); - BOOST_CHECK_EQUAL(nodes[at(x, limit.second.y)].height, -1.5F); - } - for (int y = limit.first.y; y <= limit.second.y; y += 1) { - BOOST_CHECK_EQUAL(nodes[at(limit.first.x, y)].height, -1.5F); - BOOST_CHECK_EQUAL(nodes[at(limit.second.x, y)].height, -1.5F); - } -} - -BOOST_AUTO_TEST_CASE(load_uk_heightmap) -{ - loadFromImages(FIXTURESDIR "/height/V0txo.jpg", 100.F); - // Some terrain above sea level - BOOST_CHECK(std::any_of(nodes.begin(), nodes.end(), [](const auto & n) { - return n.height > 0; - })); -} - -BOOST_AUTO_TEST_CASE(get_height_at) -{ - // at(x,y) is index based - nodes[at(0, 0)].height = 1; - nodes[at(1, 0)].height = 2; - nodes[at(0, 1)].height = 3; - nodes[at(1, 1)].height = 4; - - // positionAt(x,y) is world based - // Corners - BOOST_CHECK_EQUAL(positionAt({0, 0}), glm::vec3(0, 0, 1)); - BOOST_CHECK_EQUAL(positionAt({5, 0}), glm::vec3(5, 0, 2)); - BOOST_CHECK_EQUAL(positionAt({0, 5}), glm::vec3(0, 5, 3)); - BOOST_CHECK_EQUAL(positionAt({5, 5}), glm::vec3(5, 5, 4)); - - // Edge midpoints - BOOST_CHECK_EQUAL(positionAt({0, 2.5F}), glm::vec3(0, 2.5F, 2)); - BOOST_CHECK_EQUAL(positionAt({5, 2.5F}), glm::vec3(5, 2.5F, 3)); - BOOST_CHECK_EQUAL(positionAt({2.5F, 0}), glm::vec3(2.5F, 0, 1.5F)); - BOOST_CHECK_EQUAL(positionAt({2.5F, 5}), glm::vec3(2.5F, 5, 3.5F)); - - // Centre - BOOST_CHECK_EQUAL(positionAt({2.5F, 2.5F}), glm::vec3(2.5F, 2.5F, 2.5F)); -} - -using TestRayTracerData = std::tuple>; -BOOST_TEST_DECORATOR(*boost::unit_test::timeout(1)) - -BOOST_DATA_TEST_CASE(raytracer, - boost::unit_test::data::make({ - {{1, 2}, {4, 5}, 4, - { - {0, 0}, - {0, 4}, - {4, 4}, - {4, 8}, - {8, 8}, - {8, 12}, - {12, 12}, - {12, 16}, - {12, 20}, - {16, 20}, - }}, - {{-1, -1}, {-4, -5}, 5, - { - {-5, -5}, - {-5, -10}, - {-10, -10}, - {-10, -15}, - {-15, -15}, - {-15, -20}, - {-20, -20}, - {-20, -25}, - }}, - }), - start, dir, scale, points) -{ - GeoData::RayTracer rt {start / scale, glm::normalize(dir)}; - for (const auto & point : points) { - BOOST_CHECK_CLOSE_VEC(point, rt.next() * scale); - } -} - -using TestRayData = std::tuple; -BOOST_TEST_DECORATOR(*boost::unit_test::timeout(1)) - -BOOST_DATA_TEST_CASE(intersect_ray, - boost::unit_test::data::make({ - {{-1, -1, 1.0}, {1, 1, 0}, {0, 0, 1}}, - {{-1, -1, 2.5}, {1, 1, 0}, {2.5F, 2.5F, 2.5F}}, - {{-20, -20, 2.5}, {1, 1, 0}, {2.5F, 2.5F, 2.5F}}, - // outside the map looking in - {{-205, -205, 4}, {1, 1, 0}, {5, 5, 4}}, - {{-205, 5, 4}, {1, 0, 0}, {5, 5, 4}}, - {{-205, 215, 4}, {1, -1, 0}, {5, 5, 4}}, - {{215, -205, 4}, {-1, 1, 0}, {5, 5, 4}}, - {{215, 5, 4}, {-1, 0, 0}, {5, 5, 4}}, - {{215, 215, 4}, {-1, -1, 0}, {5, 5, 4}}, - {{5, 215, 4}, {0, -1, 0}, {5, 5, 4}}, - {{5, -205, 4}, {0, 1, 0}, {5, 5, 4}}, - }), - start, dir, pos) -{ - // at(x,y) is index based - nodes[at(0, 0)].height = 1; - nodes[at(1, 0)].height = 2; - nodes[at(0, 1)].height = 3; - nodes[at(1, 1)].height = 4; - - const auto intersect = intersectRay({start, glm::normalize(dir)}); - - BOOST_CHECK_IF(has_intersect, intersect) { - BOOST_CHECK_CLOSE_VEC(*intersect, pos); - } -} - -auto xs = boost::unit_test::data::xrange(-20.F, 0.F, 0.6F), ys = boost::unit_test::data::xrange(-20.F, 0.F, 0.7F); -auto targetsx = boost::unit_test::data::xrange(0.2F, 4.9F, 1.3F), - targetsy = boost::unit_test::data::xrange(0.3F, 4.9F, 1.3F); -BOOST_TEST_DECORATOR(*boost::unit_test::timeout(1)) - -BOOST_DATA_TEST_CASE(intersect_ray_many, xs * ys * targetsx * targetsy, x, y, targetx, targety) -{ - // at(x,y) is index based - nodes[at(0, 0)].height = 1; - nodes[at(1, 0)].height = 2; - nodes[at(0, 1)].height = 3; - nodes[at(1, 1)].height = 4; - - const glm::vec3 start {x, y, 10}; - const auto target {this->positionAt({targetx, targety})}; - const Ray ray {start, glm::normalize(target - start)}; - - BOOST_TEST_CONTEXT(ray) { - const auto intersect = intersectRay(ray); - - BOOST_CHECK_IF(has_intersect, intersect) { - BOOST_CHECK_CLOSE_VEC(*intersect, target); - } - } -} - -BOOST_TEST_DECORATOR(*boost::unit_test::timeout(1)) - -BOOST_DATA_TEST_CASE(intersect_ray_miss, - boost::unit_test::data::make({ - {{3, 3, 5}, {-1, -1, 0}}, - {{0, 0, 5}, {0, 0, 1}}, - {{0, 0, 5}, {0, 0, -1}}, - }), - ray) -{ - // at(x,y) is index based - nodes[at(0, 0)].height = 1; - nodes[at(1, 0)].height = 2; - nodes[at(0, 1)].height = 3; - nodes[at(1, 1)].height = 4; - - BOOST_REQUIRE(!intersectRay(ray)); -} - -BOOST_AUTO_TEST_SUITE_END() 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()); +} diff --git a/test/test-render.cpp b/test/test-render.cpp index b16f241..fb2a71b 100644 --- a/test/test-render.cpp +++ b/test/test-render.cpp @@ -26,8 +26,7 @@ class TestScene : public SceneProvider { std::shared_ptr train1, train2; Terrain terrain {[]() { - auto gd = std::make_shared(GeoData::Limits {{0, 0}, {100, 100}}); - gd->generateRandom(); + auto gd = std::make_shared(GeoData::createFlat({0, 0}, {1000, 1000}, 1)); return gd; }()}; diff --git a/test/test-terrain.cpp b/test/test-terrain.cpp deleted file mode 100644 index 71fc1ec..0000000 --- a/test/test-terrain.cpp +++ /dev/null @@ -1,175 +0,0 @@ -#define BOOST_TEST_MODULE terrain -#include "testHelpers.h" -#include -#include -#include - -#include - -class TestTerrainMesh : public TerrainMesh { -public: - TestTerrainMesh() : TerrainMesh {TerrainMesh::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, TerrainMesh::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) -{ - TerrainMesh::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