From 8f10ddbfffd0f7f60b6b9488a0d3b0c60d8d5131 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 6 Jan 2025 20:28:16 +0000 Subject: Add default Q = glm::defaultp to maths functions Makes getting a pointer to the function more trivial --- lib/maths.h | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/lib/maths.h b/lib/maths.h index 671313d..17ca795 100644 --- a/lib/maths.h +++ b/lib/maths.h @@ -15,7 +15,7 @@ template concept Arithmetic = std::is_arithmetic_v; struct Arc : public std::pair { - template + template requires(Lc >= 2, Le >= 2) Arc(const glm::vec & centre, const glm::vec & e0p, const glm::vec & e1p) : Arc {RelativePosition2D {e0p.xy() - centre.xy()}, RelativePosition2D {e1p.xy() - centre.xy()}} @@ -101,10 +101,10 @@ operator-(const GlobalPosition & global, const CalcPosition & relative) return global - GlobalPosition(relative); } -template +template using DifferenceVector = glm::vec, T, float>, Q>; -template +template constexpr DifferenceVector difference(const glm::vec & globalA, const glm::vec & globalB) { @@ -147,7 +147,8 @@ namespace { } // Helper to lookup into a matrix given an xy vector coordinate - template + template constexpr auto & operator^(glm::mat & matrix, const glm::vec<2, I> rowCol) { @@ -155,7 +156,7 @@ namespace { } // Create a matrix for the angle, given the targets into the matrix - template + template constexpr auto rotation(const T angle, const glm::vec<2, I> cos1, const glm::vec<2, I> sin1, const glm::vec<2, I> cos2, const glm::vec<2, I> negSin1) @@ -245,7 +246,7 @@ vector_pitch(const glm::vec & diff) return std::atan(diff.z); } -template +template constexpr glm::vec<2, T, Q> vector_normal(const glm::vec<2, T, Q> & vector) { @@ -267,7 +268,7 @@ sq(T value) return value * value; } -template +template constexpr glm::vec<3, int64_t, Q> crossProduct(const glm::vec<3, int64_t, Q> & valueA, const glm::vec<3, int64_t, Q> & valueB) { @@ -278,14 +279,14 @@ crossProduct(const glm::vec<3, int64_t, Q> & valueA, const glm::vec<3, int64_t, }; } -template +template constexpr glm::vec<3, T, Q> crossProduct(const glm::vec<3, T, Q> & valueA, const glm::vec<3, T, Q> & valueB) { return crossProduct(valueA, valueB); } -template +template constexpr glm::vec<3, T, Q> crossProduct(const glm::vec<3, T, Q> & valueA, const glm::vec<3, T, Q> & valueB) { @@ -300,35 +301,35 @@ ratio(const Ta valueA, const Tb valueB) return static_cast((static_cast(valueA) / static_cast(valueB))); } -template +template constexpr auto ratio(const glm::vec<2, T, Q> & value) { return ratio(value.x, value.y); } -template +template constexpr auto perspective_divide(const glm::vec<4, T, Q> & value) { return value / value.w; } -template +template constexpr glm::vec operator||(const glm::vec valueA, const glm::vec valueB) { return {valueA, valueB}; } -template +template constexpr glm::vec operator||(const glm::vec valueA, const T valueB) { return {valueA, valueB}; } -template +template constexpr glm::vec perspectiveMultiply(const glm::vec & base, const glm::mat & mutation) { @@ -336,7 +337,7 @@ perspectiveMultiply(const glm::vec & base, const glm::mat +template constexpr glm::vec perspectiveApply(glm::vec & base, const glm::mat & mutation) { @@ -384,7 +385,7 @@ linesIntersectAt(const glm::vec<2, T, Q> Aabs, const glm::vec<2, T, Q> Babs, con return Aabs + CVec {(b1 * c2) / -determinant, (a1 * c2) / determinant}; } -template +template std::pair, bool> find_arc_centre(glm::vec<2, T, Q> start, Rotation2D startDir, glm::vec<2, T, Q> end, Rotation2D endDir) { @@ -397,7 +398,7 @@ find_arc_centre(glm::vec<2, T, Q> start, Rotation2D startDir, glm::vec<2, T, Q> throw std::runtime_error("no intersection"); } -template +template std::pair, bool> find_arc_centre(glm::vec<2, T, Q> start, Angle entrys, glm::vec<2, T, Q> end, Angle entrye) { @@ -407,7 +408,7 @@ find_arc_centre(glm::vec<2, T, Q> start, Angle entrys, glm::vec<2, T, Q> end, An return find_arc_centre(start, sincos(entrys + half_pi), end, sincos(entrye - half_pi)); } -template +template Angle find_arcs_radius(glm::vec<2, T, Q> start, Rotation2D ad, glm::vec<2, T, Q> end, Rotation2D bd) { @@ -432,7 +433,7 @@ find_arcs_radius(glm::vec<2, T, Q> start, Rotation2D ad, glm::vec<2, T, Q> end, / (2 * (sq(X) - 2 * X * Z + sq(Z) + sq(Y) - 2 * Y * W + sq(W) - 4)); } -template +template std::pair find_arcs_radius(glm::vec<2, T, Q> start, Angle entrys, glm::vec<2, T, Q> end, Angle entrye) { @@ -449,7 +450,7 @@ midpoint(const std::pair & v) return std::midpoint(v.first, v.second); } -template +template auto midpoint(const glm::vec & valueA, const glm::vec & valueB) { -- cgit v1.2.3