summaryrefslogtreecommitdiff
path: root/lib/sorting.hpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-12-18 12:42:23 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2022-12-18 12:42:23 +0000
commit9300a4b0ba649af225f6c005dbfe70aa9c9e8c0e (patch)
tree43220a6814f569194b2123ab65a46f4fb1a034d3 /lib/sorting.hpp
parentHelper operator+ to join arrays (diff)
downloadilt-9300a4b0ba649af225f6c005dbfe70aa9c9e8c0e.tar.bz2
ilt-9300a4b0ba649af225f6c005dbfe70aa9c9e8c0e.tar.xz
ilt-9300a4b0ba649af225f6c005dbfe70aa9c9e8c0e.zip
Helper to sort glm::vecs by a specific axis
Diffstat (limited to 'lib/sorting.hpp')
-rw-r--r--lib/sorting.hpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/sorting.hpp b/lib/sorting.hpp
index 0604aaf..777de00 100644
--- a/lib/sorting.hpp
+++ b/lib/sorting.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <glm/fwd.hpp>
#include <type_traits>
template<typename T> struct PtrSorter {
@@ -28,3 +29,21 @@ template<typename T, auto M> struct PtrMemberSorter : public PtrSorter<T> {
return (*a).*M < b;
}
};
+
+struct CompareBy {
+ glm::length_t index;
+
+ template<typename T>
+ auto
+ operator()(const T & a, const T & b) const
+ {
+ return get(a) < get(b);
+ }
+
+ template<typename T>
+ auto
+ get(const T & a) const
+ {
+ return a[index];
+ }
+};