summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2026-01-15 00:52:57 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2026-01-15 00:52:57 +0000
commitf3536344c274073fcdbeb5501261e122830a869c (patch)
treece8da8f2cab4d7c0b40aa3a3708d8487da613e7f /lib
parentBump glad to v2.0.8 (diff)
downloadilt-f3536344c274073fcdbeb5501261e122830a869c.tar.bz2
ilt-f3536344c274073fcdbeb5501261e122830a869c.tar.xz
ilt-f3536344c274073fcdbeb5501261e122830a869c.zip
Add constexpr lround for glm::vec
Diffstat (limited to 'lib')
-rw-r--r--lib/maths.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/maths.h b/lib/maths.h
index 43d6dcd..4a835d3 100644
--- a/lib/maths.h
+++ b/lib/maths.h
@@ -76,6 +76,18 @@ constexpr auto degreesToRads = pi / 180.F;
constexpr auto earthMeanRadius = 6371.01F; // In km
constexpr auto astronomicalUnit = 149597890.F; // In km
+// GLM round is not constexpr :( And we can use lround to convert at the same time
+template<glm::length_t D, std::floating_point T, glm::qualifier Q>
+[[nodiscard]] constexpr glm::vec<D, long, Q>
+lround(const glm::vec<D, T, Q> & value)
+{
+ glm::vec<D, long, Q> out {};
+ for (glm::length_t axis = 0; axis < D; ++axis) {
+ out[axis] = std::lround(value[axis]);
+ }
+ return out;
+}
+
template<glm::length_t D>
constexpr GlobalPosition<D>
operator+(const GlobalPosition<D> & global, const RelativePosition<D> & relative)