From 271f04581cdf166659fe4d51372bd998dfd5b664 Mon Sep 17 00:00:00 2001 From: Slendi Date: Fri, 14 Nov 2025 16:29:56 +0200 Subject: [PATCH] Quick style fixes Signed-off-by: Slendi --- include/smath.hpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/include/smath.hpp b/include/smath.hpp index 551e065..6f3a282 100644 --- a/include/smath.hpp +++ b/include/smath.hpp @@ -225,14 +225,14 @@ public: VEC_OP_ASSIGN(/) #undef VEC_OP_ASSIGN - constexpr bool operator==(Vec const &v) const noexcept { + constexpr auto operator==(Vec const &v) const noexcept -> bool { for (std::size_t i = 0; i < N; ++i) if ((*this)[i] != v[i]) return false; return true; } - constexpr bool operator!=(Vec const &v) const noexcept { + constexpr auto operator!=(Vec const &v) const noexcept -> bool { return !(*this == v); } @@ -252,34 +252,33 @@ public: template requires std::is_floating_point_v - constexpr Vec normalized_safe(U eps = eps_default) const noexcept { + constexpr auto normalized_safe(U eps = EPS_DEFAULT) const noexcept -> Vec { auto m = magnitude(); return (m > eps) ? (*this) / m : Vec{}; } template requires std::is_floating_point_v - constexpr Vec normalize_safe(U eps = eps_default) const noexcept { + constexpr auto normalize_safe(U eps = EPS_DEFAULT) const noexcept -> Vec { return normalized_safe(eps); } - [[nodiscard]] constexpr auto normalized() noexcept -> Vec const + [[nodiscard]] constexpr auto normalized() noexcept -> Vec requires std::is_floating_point_v { return (*this) / this->magnitude(); } - [[nodiscard]] constexpr auto normalize() noexcept -> Vec const + [[nodiscard]] constexpr auto normalize() noexcept -> Vec requires std::is_floating_point_v { return this->normalized(); } - [[nodiscard]] constexpr auto unit() noexcept -> Vec const + [[nodiscard]] constexpr auto unit() noexcept -> Vec requires std::is_floating_point_v { return this->normalized(); } - [[nodiscard]] constexpr auto dot(Vec const &other) const noexcept - -> T const { + [[nodiscard]] constexpr auto dot(Vec const &other) const noexcept -> T { T res = 0; for (std::size_t i = 0; i < N; ++i) { res += (*this)[i] * other[i]; @@ -287,11 +286,11 @@ public: return res; } - static constexpr T eps_default = T(1e-6); + static constexpr T EPS_DEFAULT = T(1e-6); template requires std::is_floating_point_v [[nodiscard]] constexpr auto - approx_equal(Vec const &rhs, U eps = eps_default) const noexcept { + approx_equal(Vec const &rhs, U eps = EPS_DEFAULT) const noexcept { using F = std::conditional_t, U, double>; for (size_t i = 0; i < N; ++i) if (std::abs(F((*this)[i] - rhs[i])) > F(eps)) @@ -312,19 +311,19 @@ public: template requires(N == 3) - constexpr Vec cross(const Vec &r) const noexcept { + constexpr auto cross(const Vec &r) const noexcept -> Vec { return {(*this)[1] * r[2] - (*this)[2] * r[1], (*this)[2] * r[0] - (*this)[0] * r[2], (*this)[0] * r[1] - (*this)[1] * r[0]}; } - constexpr T distance(Vec const &r) const noexcept + constexpr auto distance(Vec const &r) const noexcept -> T requires std::is_floating_point_v { return (*this - r).magnitude(); } - constexpr Vec project_onto(Vec const &n) const noexcept + constexpr auto project_onto(Vec const &n) const noexcept -> Vec requires std::is_floating_point_v { auto d = this->dot(n); @@ -352,7 +351,7 @@ public: template requires(std::is_arithmetic_v && !std::is_same_v) - constexpr Vec &operator=(Vec const &rhs) noexcept { + constexpr auto operator=(Vec const &rhs) noexcept -> Vec & { for (std::size_t i = 0; i < N; ++i) (*this)[i] = static_cast(rhs[i]); return *this;