summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/maths.h24
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/maths.h b/lib/maths.h
index 2999d01..86f2e05 100644
--- a/lib/maths.h
+++ b/lib/maths.h
@@ -77,11 +77,23 @@ constexpr auto degreesToRads = pi / 180.F;
constexpr auto earthMeanRadius = 6371.01F; // In km
constexpr auto astronomicalUnit = 149597890.F; // In km
-template<glm::length_t D>
+// 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, std::floating_point T, glm::qualifier Q>
constexpr GlobalPosition<D>
-operator+(const GlobalPosition<D> & global, const RelativePosition<D> & relative)
+operator+(const GlobalPosition<D> & global, const glm::vec<D, T, Q> & relative)
{
- return global + GlobalPosition<D>(glm::round(relative));
+ return global + GlobalPosition<D> {lround(relative)};
}
template<glm::length_t D>
@@ -91,11 +103,11 @@ operator+(const GlobalPosition<D> & global, const CalcPosition<D> & relative)
return global + GlobalPosition<D>(relative);
}
-template<glm::length_t D>
+template<glm::length_t D, std::floating_point T, glm::qualifier Q>
constexpr GlobalPosition<D>
-operator-(const GlobalPosition<D> & global, const RelativePosition<D> & relative)
+operator-(const GlobalPosition<D> & global, const glm::vec<D, T, Q> & relative)
{
- return global - GlobalPosition<D>(glm::round(relative));
+ return global - GlobalPosition<D> {lround(relative)};
}
template<glm::length_t D>