From ececc7991c1854121ee366d92a3cdddc77d4bab3 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 6 Apr 2024 13:05:32 +0200 Subject: [PATCH] Backported dome of the codestyle improvements to math types from https://github.com/godotengine/godot/commit/3fb36bf395f2cc03ca8bb060d0afdb412c0855b4 . --- core/math/basis.cpp | 2 +- core/math/basis.h | 6 +++--- core/math/color.cpp | 8 ++++---- core/math/color.h | 8 ++++---- core/math/quaternion.cpp | 10 +++++----- core/math/quaternion.h | 28 ++++++++++++++-------------- core/math/vector2i.cpp | 8 ++++---- core/math/vector2i.h | 8 ++++---- 8 files changed, 39 insertions(+), 39 deletions(-) diff --git a/core/math/basis.cpp b/core/math/basis.cpp index e78b71780..83c616e97 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -1062,7 +1062,7 @@ void Basis::set_diagonal(const Vector3 &p_diag) { rows[2][2] = p_diag.z; } -Basis Basis::slerp(const Basis &p_to, const real_t &p_weight) const { +Basis Basis::slerp(const Basis &p_to, const real_t p_weight) const { //consider scale Quaternion from(*this); Quaternion to(p_to); diff --git a/core/math/basis.h b/core/math/basis.h index 70a3f3bb7..17975d0ed 100644 --- a/core/math/basis.h +++ b/core/math/basis.h @@ -175,8 +175,8 @@ struct _NO_DISCARD_CLASS_ Basis { bool is_diagonal() const; bool is_rotation() const; - Basis slerp(const Basis &p_to, const real_t &p_weight) const; - _FORCE_INLINE_ Basis lerp(const Basis &p_to, const real_t &p_weight) const; + Basis slerp(const Basis &p_to, const real_t p_weight) const; + _FORCE_INLINE_ Basis lerp(const Basis &p_to, const real_t p_weight) const; void rotate_sh(real_t *p_values); operator String() const; @@ -393,7 +393,7 @@ real_t Basis::determinant() const { rows[2][0] * (rows[0][1] * rows[1][2] - rows[1][1] * rows[0][2]); } -Basis Basis::lerp(const Basis &p_to, const real_t &p_weight) const { +Basis Basis::lerp(const Basis &p_to, const real_t p_weight) const { Basis b; b.rows[0] = rows[0].linear_interpolate(p_to.rows[0], p_weight); b.rows[1] = rows[1].linear_interpolate(p_to.rows[1], p_weight); diff --git a/core/math/color.cpp b/core/math/color.cpp index ad88556d0..fb8a6a733 100644 --- a/core/math/color.cpp +++ b/core/math/color.cpp @@ -505,7 +505,7 @@ Color Color::operator*(const Color &p_color) const { a * p_color.a); } -Color Color::operator*(const real_t &rvalue) const { +Color Color::operator*(const real_t rvalue) const { return Color( r * rvalue, g * rvalue, @@ -520,7 +520,7 @@ void Color::operator*=(const Color &p_color) { a = a * p_color.a; } -void Color::operator*=(const real_t &rvalue) { +void Color::operator*=(const real_t rvalue) { r = r * rvalue; g = g * rvalue; b = b * rvalue; @@ -535,7 +535,7 @@ Color Color::operator/(const Color &p_color) const { a / p_color.a); } -Color Color::operator/(const real_t &rvalue) const { +Color Color::operator/(const real_t rvalue) const { return Color( r / rvalue, g / rvalue, @@ -550,7 +550,7 @@ void Color::operator/=(const Color &p_color) { a = a / p_color.a; } -void Color::operator/=(const real_t &rvalue) { +void Color::operator/=(const real_t rvalue) { if (rvalue == 0) { r = 1.0; g = 1.0; diff --git a/core/math/color.h b/core/math/color.h index 61f7aec77..520ee4c92 100644 --- a/core/math/color.h +++ b/core/math/color.h @@ -76,14 +76,14 @@ struct _NO_DISCARD_CLASS_ Color { void operator-=(const Color &p_color); Color operator*(const Color &p_color) const; - Color operator*(const real_t &rvalue) const; + Color operator*(const real_t rvalue) const; void operator*=(const Color &p_color); - void operator*=(const real_t &rvalue); + void operator*=(const real_t rvalue); Color operator/(const Color &p_color) const; - Color operator/(const real_t &rvalue) const; + Color operator/(const real_t rvalue) const; void operator/=(const Color &p_color); - void operator/=(const real_t &rvalue); + void operator/=(const real_t rvalue); bool is_equal_approx(const Color &p_color) const; diff --git a/core/math/quaternion.cpp b/core/math/quaternion.cpp index 904ecdf8b..2a26d21c5 100644 --- a/core/math/quaternion.cpp +++ b/core/math/quaternion.cpp @@ -170,7 +170,7 @@ Quaternion Quaternion::exp() const { return Quaternion(src_v.normalized(), theta); } -Quaternion Quaternion::slerp(const Quaternion &p_to, const real_t &p_weight) const { +Quaternion Quaternion::slerp(const Quaternion &p_to, const real_t p_weight) const { #ifdef MATH_CHECKS ERR_FAIL_COND_V_MSG(!is_normalized(), Quaternion(), "The start quaternion must be normalized."); ERR_FAIL_COND_V_MSG(!p_to.is_normalized(), Quaternion(), "The end quaternion must be normalized."); @@ -217,7 +217,7 @@ Quaternion Quaternion::slerp(const Quaternion &p_to, const real_t &p_weight) con scale0 * w + scale1 * to1.w); } -Quaternion Quaternion::slerpni(const Quaternion &p_to, const real_t &p_weight) const { +Quaternion Quaternion::slerpni(const Quaternion &p_to, const real_t p_weight) const { #ifdef MATH_CHECKS ERR_FAIL_COND_V_MSG(!is_normalized(), Quaternion(), "The start quaternion must be normalized."); ERR_FAIL_COND_V_MSG(!p_to.is_normalized(), Quaternion(), "The end quaternion must be normalized."); @@ -241,7 +241,7 @@ Quaternion Quaternion::slerpni(const Quaternion &p_to, const real_t &p_weight) c invFactor * from.w + newFactor * p_to.w); } -Quaternion Quaternion::cubic_slerp(const Quaternion &p_b, const Quaternion &p_pre_a, const Quaternion &p_post_b, const real_t &p_weight) const { +Quaternion Quaternion::cubic_slerp(const Quaternion &p_b, const Quaternion &p_pre_a, const Quaternion &p_post_b, const real_t p_weight) const { #ifdef MATH_CHECKS ERR_FAIL_COND_V_MSG(!is_normalized(), Quaternion(), "The start quaternion must be normalized."); ERR_FAIL_COND_V_MSG(!p_b.is_normalized(), Quaternion(), "The end quaternion must be normalized."); @@ -253,7 +253,7 @@ Quaternion Quaternion::cubic_slerp(const Quaternion &p_b, const Quaternion &p_pr return sp.slerpni(sq, t2); } -Quaternion Quaternion::spherical_cubic_interpolate(const Quaternion &p_b, const Quaternion &p_pre_a, const Quaternion &p_post_b, const real_t &p_weight) const { +Quaternion Quaternion::spherical_cubic_interpolate(const Quaternion &p_b, const Quaternion &p_pre_a, const Quaternion &p_post_b, const real_t p_weight) const { #ifdef MATH_CHECKS ERR_FAIL_COND_V_MSG(!is_normalized(), Quaternion(), "The start quaternion must be normalized."); ERR_FAIL_COND_V_MSG(!p_b.is_normalized(), Quaternion(), "The end quaternion must be normalized."); @@ -319,7 +319,7 @@ Quaternion::operator String() const { return "(" + String::num_real(x) + ", " + String::num_real(y) + ", " + String::num_real(z) + ", " + String::num_real(w) + ")"; } -void Quaternion::set_axis_angle(const Vector3 &axis, const real_t &angle) { +void Quaternion::set_axis_angle(const Vector3 &axis, const real_t angle) { #ifdef MATH_CHECKS ERR_FAIL_COND_MSG(!axis.is_normalized(), "The axis Vector3 must be normalized."); #endif diff --git a/core/math/quaternion.h b/core/math/quaternion.h index 3528ef522..74312462b 100644 --- a/core/math/quaternion.h +++ b/core/math/quaternion.h @@ -75,15 +75,15 @@ struct _NO_DISCARD_CLASS_ Quaternion { void set_euler(const Vector3 &p_euler) { set_euler_yxz(p_euler); }; Vector3 get_euler() const { return get_euler_yxz(); }; - Quaternion slerp(const Quaternion &p_to, const real_t &p_weight) const; - Quaternion slerpni(const Quaternion &p_to, const real_t &p_weight) const; - Quaternion cubic_slerp(const Quaternion &p_b, const Quaternion &p_pre_a, const Quaternion &p_post_b, const real_t &p_weight) const; - Quaternion spherical_cubic_interpolate(const Quaternion &p_b, const Quaternion &p_pre_a, const Quaternion &p_post_b, const real_t &p_weight) const; + Quaternion slerp(const Quaternion &p_to, const real_t p_weight) const; + Quaternion slerpni(const Quaternion &p_to, const real_t p_weight) const; + Quaternion cubic_slerp(const Quaternion &p_b, const Quaternion &p_pre_a, const Quaternion &p_post_b, const real_t p_weight) const; + Quaternion spherical_cubic_interpolate(const Quaternion &p_b, const Quaternion &p_pre_a, const Quaternion &p_post_b, const real_t p_weight) const; Vector3 get_axis() const; float get_angle() const; - void set_axis_angle(const Vector3 &axis, const real_t &angle); + void set_axis_angle(const Vector3 &axis, const real_t angle); _FORCE_INLINE_ void get_axis_angle(Vector3 &r_axis, real_t &r_angle) const { r_angle = 2 * Math::acos(w); real_t r = ((real_t)1) / Math::sqrt(1 - w * w); @@ -113,13 +113,13 @@ struct _NO_DISCARD_CLASS_ Quaternion { _FORCE_INLINE_ void operator+=(const Quaternion &p_q); _FORCE_INLINE_ void operator-=(const Quaternion &p_q); - _FORCE_INLINE_ void operator*=(const real_t &s); - _FORCE_INLINE_ void operator/=(const real_t &s); + _FORCE_INLINE_ void operator*=(const real_t s); + _FORCE_INLINE_ void operator/=(const real_t s); _FORCE_INLINE_ Quaternion operator+(const Quaternion &q2) const; _FORCE_INLINE_ Quaternion operator-(const Quaternion &q2) const; _FORCE_INLINE_ Quaternion operator-() const; - _FORCE_INLINE_ Quaternion operator*(const real_t &s) const; - _FORCE_INLINE_ Quaternion operator/(const real_t &s) const; + _FORCE_INLINE_ Quaternion operator*(const real_t s) const; + _FORCE_INLINE_ Quaternion operator/(const real_t s) const; _FORCE_INLINE_ bool operator==(const Quaternion &p_quat) const; _FORCE_INLINE_ bool operator!=(const Quaternion &p_quat) const; @@ -138,7 +138,7 @@ struct _NO_DISCARD_CLASS_ Quaternion { z(p_z), w(p_w) { } - Quaternion(const Vector3 &axis, const real_t &angle) { + Quaternion(const Vector3 &axis, const real_t angle) { set_axis_angle(axis, angle); } @@ -211,14 +211,14 @@ void Quaternion::operator-=(const Quaternion &p_q) { w -= p_q.w; } -void Quaternion::operator*=(const real_t &s) { +void Quaternion::operator*=(const real_t s) { x *= s; y *= s; z *= s; w *= s; } -void Quaternion::operator/=(const real_t &s) { +void Quaternion::operator/=(const real_t s) { *this *= 1 / s; } @@ -237,11 +237,11 @@ Quaternion Quaternion::operator-() const { return Quaternion(-q2.x, -q2.y, -q2.z, -q2.w); } -Quaternion Quaternion::operator*(const real_t &s) const { +Quaternion Quaternion::operator*(const real_t s) const { return Quaternion(x * s, y * s, z * s, w * s); } -Quaternion Quaternion::operator/(const real_t &s) const { +Quaternion Quaternion::operator/(const real_t s) const { return *this * (1 / s); } diff --git a/core/math/vector2i.cpp b/core/math/vector2i.cpp index 9a89dfa2c..8cfe6867d 100644 --- a/core/math/vector2i.cpp +++ b/core/math/vector2i.cpp @@ -66,10 +66,10 @@ Vector2i Vector2i::operator*(const Vector2i &p_v1) const { return Vector2i(x * p_v1.x, y * p_v1.y); }; -Vector2i Vector2i::operator*(const int &rvalue) const { +Vector2i Vector2i::operator*(const int rvalue) const { return Vector2i(x * rvalue, y * rvalue); }; -void Vector2i::operator*=(const int &rvalue) { +void Vector2i::operator*=(const int rvalue) { x *= rvalue; y *= rvalue; }; @@ -78,11 +78,11 @@ Vector2i Vector2i::operator/(const Vector2i &p_v1) const { return Vector2i(x / p_v1.x, y / p_v1.y); }; -Vector2i Vector2i::operator/(const int &rvalue) const { +Vector2i Vector2i::operator/(const int rvalue) const { return Vector2i(x / rvalue, y / rvalue); }; -void Vector2i::operator/=(const int &rvalue) { +void Vector2i::operator/=(const int rvalue) { x /= rvalue; y /= rvalue; }; diff --git a/core/math/vector2i.h b/core/math/vector2i.h index a45ce8684..3f6d609ca 100644 --- a/core/math/vector2i.h +++ b/core/math/vector2i.h @@ -98,14 +98,14 @@ struct _NO_DISCARD_CLASS_ Vector2i { void operator-=(const Vector2i &p_v); Vector2i operator*(const Vector2i &p_v1) const; - Vector2i operator*(const int &rvalue) const; - void operator*=(const int &rvalue); + Vector2i operator*(const int rvalue) const; + void operator*=(const int rvalue); Vector2i operator/(const Vector2i &p_v1) const; - Vector2i operator/(const int &rvalue) const; + Vector2i operator/(const int rvalue) const; - void operator/=(const int &rvalue); + void operator/=(const int rvalue); Vector2i operator-() const; bool operator<(const Vector2i &p_vec2) const { return (x == p_vec2.x) ? (y < p_vec2.y) : (x < p_vec2.x); }