diff options
-rw-r--r-- | lib/maths.h | 41 |
1 files 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<typename T> concept Arithmetic = std::is_arithmetic_v<T>; struct Arc : public std::pair<Angle, Angle> { - template<glm::length_t Lc, glm::length_t Le, Arithmetic T, glm::qualifier Q> + template<glm::length_t Lc, glm::length_t Le, Arithmetic T, glm::qualifier Q = glm::defaultp> requires(Lc >= 2, Le >= 2) Arc(const glm::vec<Lc, T, Q> & centre, const glm::vec<Le, T, Q> & e0p, const glm::vec<Le, T, Q> & e1p) : Arc {RelativePosition2D {e0p.xy() - centre.xy()}, RelativePosition2D {e1p.xy() - centre.xy()}} @@ -101,10 +101,10 @@ operator-(const GlobalPosition<D> & global, const CalcPosition<D> & relative) return global - GlobalPosition<D>(relative); } -template<glm::length_t D, Arithmetic T, glm::qualifier Q> +template<glm::length_t D, Arithmetic T, glm::qualifier Q = glm::defaultp> using DifferenceVector = glm::vec<D, std::conditional_t<std::is_floating_point_v<T>, T, float>, Q>; -template<glm::length_t D, Arithmetic T, glm::qualifier Q> +template<glm::length_t D, Arithmetic T, glm::qualifier Q = glm::defaultp> constexpr DifferenceVector<D, T, Q> difference(const glm::vec<D, T, Q> & globalA, const glm::vec<D, T, Q> & globalB) { @@ -147,7 +147,8 @@ namespace { } // Helper to lookup into a matrix given an xy vector coordinate - template<glm::length_t C, glm::length_t R, Arithmetic T, glm::qualifier Q, std::integral I = glm::length_t> + template<glm::length_t C, glm::length_t R, Arithmetic T, glm::qualifier Q = glm::defaultp, + std::integral I = glm::length_t> constexpr auto & operator^(glm::mat<C, R, T, Q> & 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<glm::length_t D, std::floating_point T, glm::qualifier Q, std::integral I = glm::length_t> + template<glm::length_t D, std::floating_point T, glm::qualifier Q = glm::defaultp, std::integral I = glm::length_t> 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<D, T, Q> & diff) return std::atan(diff.z); } -template<Arithmetic T, glm::qualifier Q> +template<Arithmetic T, glm::qualifier Q = glm::defaultp> 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<glm::qualifier Q> +template<glm::qualifier Q = glm::defaultp> 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<std::integral T, glm::qualifier Q> +template<std::integral T, glm::qualifier Q = glm::defaultp> constexpr glm::vec<3, T, Q> crossProduct(const glm::vec<3, T, Q> & valueA, const glm::vec<3, T, Q> & valueB) { return crossProduct<Q>(valueA, valueB); } -template<std::floating_point T, glm::qualifier Q> +template<std::floating_point T, glm::qualifier Q = glm::defaultp> 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<R>((static_cast<Common>(valueA) / static_cast<Common>(valueB))); } -template<Arithmetic R = float, Arithmetic T, glm::qualifier Q> +template<Arithmetic R = float, Arithmetic T, glm::qualifier Q = glm::defaultp> constexpr auto ratio(const glm::vec<2, T, Q> & value) { return ratio<R>(value.x, value.y); } -template<glm::length_t L = 3, std::floating_point T, glm::qualifier Q> +template<glm::length_t L = 3, std::floating_point T, glm::qualifier Q = glm::defaultp> constexpr auto perspective_divide(const glm::vec<4, T, Q> & value) { return value / value.w; } -template<glm::length_t L1, glm::length_t L2, Arithmetic T, glm::qualifier Q> +template<glm::length_t L1, glm::length_t L2, Arithmetic T, glm::qualifier Q = glm::defaultp> constexpr glm::vec<L1 + L2, T, Q> operator||(const glm::vec<L1, T, Q> valueA, const glm::vec<L2, T, Q> valueB) { return {valueA, valueB}; } -template<glm::length_t L, Arithmetic T, glm::qualifier Q> +template<glm::length_t L, Arithmetic T, glm::qualifier Q = glm::defaultp> constexpr glm::vec<L + 1, T, Q> operator||(const glm::vec<L, T, Q> valueA, const T valueB) { return {valueA, valueB}; } -template<glm::length_t L, std::floating_point T, glm::qualifier Q> +template<glm::length_t L, std::floating_point T, glm::qualifier Q = glm::defaultp> constexpr glm::vec<L, T, Q> perspectiveMultiply(const glm::vec<L, T, Q> & base, const glm::mat<L + 1, L + 1, T, Q> & mutation) { @@ -336,7 +337,7 @@ perspectiveMultiply(const glm::vec<L, T, Q> & base, const glm::mat<L + 1, L + 1, return mutated / mutated.w; } -template<glm::length_t L, std::floating_point T, glm::qualifier Q> +template<glm::length_t L, std::floating_point T, glm::qualifier Q = glm::defaultp> constexpr glm::vec<L, T, Q> perspectiveApply(glm::vec<L, T, Q> & base, const glm::mat<L + 1, L + 1, T, Q> & 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<Arithmetic T, glm::qualifier Q> +template<Arithmetic T, glm::qualifier Q = glm::defaultp> std::pair<glm::vec<2, T, Q>, 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<Arithmetic T, glm::qualifier Q> +template<Arithmetic T, glm::qualifier Q = glm::defaultp> std::pair<glm::vec<2, T, Q>, 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<Arithmetic T, glm::qualifier Q> +template<Arithmetic T, glm::qualifier Q = glm::defaultp> 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<Arithmetic T, glm::qualifier Q> +template<Arithmetic T, glm::qualifier Q = glm::defaultp> std::pair<Angle, Angle> 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<T, T> & v) return std::midpoint(v.first, v.second); } -template<glm::length_t D, std::integral T, glm::qualifier Q> +template<glm::length_t D, std::integral T, glm::qualifier Q = glm::defaultp> auto midpoint(const glm::vec<D, T, Q> & valueA, const glm::vec<D, T, Q> & valueB) { |