summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game/geoData.cpp4
-rw-r--r--lib/collections.h10
-rw-r--r--lib/util.h8
-rw-r--r--test/test-lib.cpp15
4 files changed, 25 insertions, 12 deletions
diff --git a/game/geoData.cpp b/game/geoData.cpp
index cfaf44b..fa96a33 100644
--- a/game/geoData.cpp
+++ b/game/geoData.cpp
@@ -345,8 +345,8 @@ GeoData::setHeights(const std::span<const GlobalPosition3D> triangleStrip, const
// Create temporary triangles from triangleStrip
const auto strip
- = materializeRange(triangleStrip | TriangleTriples | std::views::transform([](const auto & newVert) {
- return std::make_from_tuple<Triangle<3>>(*newVert);
+ = materializeRange(triangleStrip | triangleTriples | std::views::transform([](const auto & newVert) {
+ return std::make_from_tuple<Triangle<3>>(newVert);
}));
auto getTriangle = [&strip](const auto point) -> const Triangle<3> * {
if (const auto t = std::ranges::find_if(strip,
diff --git a/lib/collections.h b/lib/collections.h
index c81bede..27eff0a 100644
--- a/lib/collections.h
+++ b/lib/collections.h
@@ -251,15 +251,19 @@ strip_end(IterableCollection auto & cont)
return stripiter {cont.end()};
}
-struct TriangleTriplesImpl : public std::ranges::range_adaptor_closure<TriangleTriplesImpl> {
+inline constexpr auto dereference = std::views::transform([](const auto & iter) -> decltype(auto) {
+ return *iter;
+});
+
+struct TriangleTriples : public std::ranges::range_adaptor_closure<TriangleTriples> {
decltype(auto)
operator()(const auto & triangleStrip) const
{
- return std::views::iota(strip_begin(triangleStrip), strip_end(triangleStrip));
+ return std::views::iota(strip_begin(triangleStrip), strip_end(triangleStrip)) | dereference;
}
};
-constexpr TriangleTriplesImpl TriangleTriples;
+inline constexpr TriangleTriples triangleTriples;
template<typename T, typename Dist, typename Merger>
void
diff --git a/lib/util.h b/lib/util.h
index 2674eaf..cd7971b 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -29,7 +29,7 @@ namespace {
};
}
-template<size_t... N> constexpr auto Nth = GetNth<N...> {};
-constexpr auto GetFirst = Nth<0>;
-constexpr auto GetSecond = Nth<1>;
-constexpr auto GetSwapped = Nth<0, 1>;
+template<size_t... N> inline constexpr auto Nth = GetNth<N...> {};
+inline constexpr auto GetFirst = Nth<0>;
+inline constexpr auto GetSecond = Nth<1>;
+inline constexpr auto GetSwapped = Nth<0, 1>;
diff --git a/test/test-lib.cpp b/test/test-lib.cpp
index 7672acc..17c0f63 100644
--- a/test/test-lib.cpp
+++ b/test/test-lib.cpp
@@ -1,5 +1,6 @@
#define BOOST_TEST_MODULE test_lib
+#include "testHelpers.h"
#include <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>
#include <stream_support.h>
@@ -66,8 +67,16 @@ BOOST_AUTO_TEST_CASE(triangle_strip_iter)
out.push_back(c);
});
BOOST_REQUIRE_EQUAL(out.size(), (TRIANGLE_STRIP_IN.size() - 2) * 3);
- BOOST_CHECK_EQUAL_COLLECTIONS(
- out.begin(), out.end(), TRIANGLE_STRIP_EXPECTED.begin(), TRIANGLE_STRIP_EXPECTED.end());
+ BOOST_CHECK_EQUAL_COLCOL(out, TRIANGLE_STRIP_EXPECTED);
+}
+
+BOOST_AUTO_TEST_CASE(triangle_strip_range_adapter)
+{
+ using TriTuple = std::tuple<int, int, int>;
+ std::vector<TriTuple> outRange;
+ std::ranges::copy(TRIANGLE_STRIP_IN | triangleTriples, std::back_inserter(outRange));
+ constexpr std::array<TriTuple, 4> TRIANGLE_STRIP_EXPECTED_TUPLES {{{0, 1, 2}, {2, 1, 3}, {2, 3, 4}, {4, 3, 5}}};
+ BOOST_CHECK_EQUAL_COLCOL(outRange, TRIANGLE_STRIP_EXPECTED_TUPLES);
}
using MergeCloseData = std::tuple<std::vector<int>, int, std::vector<int>>;
@@ -99,5 +108,5 @@ BOOST_DATA_TEST_CASE(mergeCloseInts,
return (left + right) / 2;
},
tolerance)));
- BOOST_CHECK_EQUAL_COLLECTIONS(mutableCollection.begin(), mutableCollection.end(), expected.begin(), expected.end());
+ BOOST_CHECK_EQUAL_COLCOL(mutableCollection, expected);
}