diff options
Diffstat (limited to 'lib/maths.h')
-rw-r--r-- | lib/maths.h | 51 |
1 files changed, 24 insertions, 27 deletions
diff --git a/lib/maths.h b/lib/maths.h index 5886326..63b752a 100644 --- a/lib/maths.h +++ b/lib/maths.h @@ -8,17 +8,28 @@ #include <stdexcept> #include <utility> -struct Arc : public std::pair<float, float> { - using std::pair<float, float>::pair; +struct Arc : public std::pair<Angle, Angle> { + template<glm::length_t Lc, glm::length_t Le, typename T, glm::qualifier Q> + 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()}} + { + } - template<typename T, glm::qualifier Q> - Arc(const glm::vec<3, T, Q> & centre3, const glm::vec<3, T, Q> & e0p, const glm::vec<3, T, Q> & e1p); + Arc(const RelativePosition2D & dir0, const RelativePosition2D & dir1); + Arc(const Angle angb, const Angle anga); auto operator[](bool i) const { return i ? second : first; } + + [[nodiscard]] constexpr inline float + length() const + { + return second - first; + } }; constexpr const RelativePosition3D up {0, 0, 1}; @@ -84,9 +95,16 @@ glm::mat4 rotate_pitch(float); glm::mat4 rotate_yp(Rotation2D); glm::mat4 rotate_ypr(Rotation3D); -float vector_yaw(const Direction3D & diff); +float vector_yaw(const Direction2D & diff); float vector_pitch(const Direction3D & diff); +template<typename T, glm::qualifier Q> +glm::vec<2, T, Q> +vector_normal(const glm::vec<2, T, Q> & v) +{ + return {-v.y, v.x}; +}; + float round_frac(const float & v, const float & frac); template<typename T> @@ -111,7 +129,7 @@ template<std::integral T, glm::qualifier Q> inline constexpr glm::vec<3, T, Q> crossProduct(const glm::vec<3, T, Q> a, const glm::vec<3, T, Q> b) { - return crossProduct<int64_t, Q>(a, b); + return crossProduct<Q>(a, b); } template<std::floating_point T, glm::qualifier Q> @@ -171,12 +189,6 @@ operator%=(glm::vec<L, T, Q> & p, const glm::mat<L + 1, L + 1, T, Q> & mutation) return p = p % mutation; } -constexpr inline float -arc_length(const Arc & arc) -{ - return arc.second - arc.first; -} - float normalize(float ang); template<typename T, glm::qualifier Q> @@ -244,21 +256,6 @@ midpoint(const std::pair<T, T> & v) return std::midpoint(v.first, v.second); } -template<typename T, glm::qualifier Q> -Arc::Arc(const glm::vec<3, T, Q> & centre3, const glm::vec<3, T, Q> & e0p, const glm::vec<3, T, Q> & e1p) : - Arc([&]() -> Arc { - const auto diffa = e0p - centre3; - const auto diffb = e1p - centre3; - const auto anga = vector_yaw(diffa); - const auto angb = [&diffb, &anga]() { - const auto angb = vector_yaw(diffb); - return (angb < anga) ? angb + two_pi : angb; - }(); - return {anga, angb}; - }()) -{ -} - // Conversions template<typename T> inline constexpr auto |