From 25e693cc46324b4ec588530de542bba8af6f47c6 Mon Sep 17 00:00:00 2001 From: skal Date: Sat, 31 Jan 2026 21:11:11 +0100 Subject: style: add vertical compression rules to clang-format - Enabled AllowShortFunctionsOnASingleLine: All - Enabled AllowShortBlocksOnASingleLine: Always - Enabled AllowShortIfStatementsOnASingleLine: Always - Enabled AllowShortLoopsOnASingleLine: true - Set MaxEmptyLinesToKeep: 1 - Applied formatting to all source files. --- src/util/mini_math.h | 61 ++++++++++++++++------------------------------------ 1 file changed, 18 insertions(+), 43 deletions(-) (limited to 'src/util/mini_math.h') diff --git a/src/util/mini_math.h b/src/util/mini_math.h index 3024737..d3c9bc5 100644 --- a/src/util/mini_math.h +++ b/src/util/mini_math.h @@ -18,25 +18,18 @@ // T: Class Name (e.g., vec3) // N: Number of active components for math (e.g., 3) #define VEC_OPERATORS(T, N) \ - float &operator[](int i) { \ - return v[i]; \ - } \ - const float &operator[](int i) const { \ - return v[i]; \ - } \ + float &operator[](int i) { return v[i]; } \ + const float &operator[](int i) const { return v[i]; } \ T &operator+=(const T &r) { \ - for (int i = 0; i < N; ++i) \ - v[i] += r.v[i]; \ + for (int i = 0; i < N; ++i) v[i] += r.v[i]; \ return *this; \ } \ T &operator-=(const T &r) { \ - for (int i = 0; i < N; ++i) \ - v[i] -= r.v[i]; \ + for (int i = 0; i < N; ++i) v[i] -= r.v[i]; \ return *this; \ } \ T &operator*=(float s) { \ - for (int i = 0; i < N; ++i) \ - v[i] *= s; \ + for (int i = 0; i < N; ++i) v[i] *= s; \ return *this; \ } \ T operator+(const T &r) const { \ @@ -56,32 +49,22 @@ } \ T operator-() const { \ T res; \ - for (int i = 0; i < N; ++i) \ - res.v[i] = -v[i]; \ + for (int i = 0; i < N; ++i) res.v[i] = -v[i]; \ return res; \ } \ static float dot(const T &a, const T &b) { \ float s = 0; \ - for (int i = 0; i < N; ++i) \ - s += a.v[i] * b.v[i]; \ + for (int i = 0; i < N; ++i) s += a.v[i] * b.v[i]; \ return s; \ } \ - float dot(const T &a) const { \ - return dot(*this, a); \ - } \ - float norm() const { \ - return std::sqrt(dot(*this, *this)); \ - } \ - float len() const { \ - return norm(); \ - } \ + float dot(const T &a) const { return dot(*this, a); } \ + float norm() const { return std::sqrt(dot(*this, *this)); } \ + float len() const { return norm(); } \ float inv_norm() const { \ float l2 = dot(*this, *this); \ return l2 > 0 ? 1.0f / std::sqrt(l2) : 0; \ } \ - T normalize() const { \ - return (*this) * inv_norm(); \ - } + T normalize() const { return (*this) * inv_norm(); } #ifdef USE_VEC2 struct vec2 { @@ -91,8 +74,7 @@ struct vec2 { }; float v[2]; }; - vec2(float x = 0, float y = 0) : x(x), y(y) { - } + vec2(float x = 0, float y = 0) : x(x), y(y) {} VEC_OPERATORS(vec2, 2) }; #endif @@ -106,8 +88,7 @@ struct vec3 { }; // _ is padding for 16-byte alignment float v[4]; // Size 4 to match alignment }; - vec3(float x = 0, float y = 0, float z = 0) : x(x), y(y), z(z), _(0) { - } + vec3(float x = 0, float y = 0, float z = 0) : x(x), y(y), z(z), _(0) {} VEC_OPERATORS(vec3, 3) // Operators only touch x,y,z (indices 0,1,2) static vec3 cross(vec3 a, vec3 b) { @@ -126,8 +107,7 @@ struct vec4 { float v[4]; }; vec4(float x = 0, float y = 0, float z = 0, float w = 0) - : x(x), y(y), z(z), w(w) { - } + : x(x), y(y), z(z), w(w) {} VEC_OPERATORS(vec4, 4) }; #endif @@ -179,8 +159,7 @@ struct quat { float v[4]; }; quat(float x = 0, float y = 0, float z = 0, float w = 1) - : x(x), y(y), z(z), w(w) { - } + : x(x), y(y), z(z), w(w) {} VEC_OPERATORS(quat, 4) quat operator*(const quat &q) const { @@ -198,8 +177,7 @@ struct quat { static quat from_to(vec3 a, vec3 b) { float d = vec3::dot(a, b); vec3 axis = vec3::cross(a, b); - if (d < -0.9999f) - return {0, 1, 0, 0}; + if (d < -0.9999f) return {0, 1, 0, 0}; float s = std::sqrt((1.0f + d) * 2.0f), inv_s = 1.0f / s; return {axis.x * inv_s, axis.y * inv_s, axis.z * inv_s, s * 0.5f}; } @@ -259,8 +237,7 @@ inline quat slerp(quat a, quat b, float t) { } if (d > 0.9995f) { // Linear fall-back quat r; - for (int i = 0; i < 4; ++i) - r.v[i] = a.v[i] + (b.v[i] - a.v[i]) * t; + for (int i = 0; i < 4; ++i) r.v[i] = a.v[i] + (b.v[i] - a.v[i]) * t; return r; } float th0 = std::acos(d), th = th0 * t, s0 = std::sin(th0), @@ -275,9 +252,7 @@ template inline T lerp(const T &a, const T &b, float t) { #ifdef USE_EASING namespace ease { -inline float out_cubic(float t) { - return 1.0f - std::pow(1.0f - t, 3.0f); -} +inline float out_cubic(float t) { return 1.0f - std::pow(1.0f - t, 3.0f); } inline float in_out_quad(float t) { return t < 0.5f ? 2.0f * t * t : 1.0f - std::pow(-2.0f * t + 2.0f, 2.0f) / 2.0f; -- cgit v1.2.3