diff --git a/core/color.cpp b/core/color.cpp index e8cd7896200..2357392588b 100644 --- a/core/color.cpp +++ b/core/color.cpp @@ -496,12 +496,12 @@ Color Color::operator*(const Color &p_color) const { a * p_color.a); } -Color Color::operator*(const real_t &rvalue) const { +Color Color::operator*(real_t p_scalar) const { return Color( - r * rvalue, - g * rvalue, - b * rvalue, - a * rvalue); + r * p_scalar, + g * p_scalar, + b * p_scalar, + a * p_scalar); } void Color::operator*=(const Color &p_color) { @@ -511,11 +511,11 @@ void Color::operator*=(const Color &p_color) { a = a * p_color.a; } -void Color::operator*=(const real_t &rvalue) { - r = r * rvalue; - g = g * rvalue; - b = b * rvalue; - a = a * rvalue; +void Color::operator*=(real_t p_scalar) { + r = r * p_scalar; + g = g * p_scalar; + b = b * p_scalar; + a = a * p_scalar; } Color Color::operator/(const Color &p_color) const { @@ -526,12 +526,12 @@ Color Color::operator/(const Color &p_color) const { a / p_color.a); } -Color Color::operator/(const real_t &rvalue) const { +Color Color::operator/(real_t p_scalar) const { return Color( - r / rvalue, - g / rvalue, - b / rvalue, - a / rvalue); + r / p_scalar, + g / p_scalar, + b / p_scalar, + a / p_scalar); } void Color::operator/=(const Color &p_color) { @@ -541,19 +541,19 @@ void Color::operator/=(const Color &p_color) { a = a / p_color.a; } -void Color::operator/=(const real_t &rvalue) { - if (rvalue == 0) { +void Color::operator/=(real_t p_scalar) { + if (p_scalar == 0) { r = 1.0; g = 1.0; b = 1.0; a = 1.0; } else { - r = r / rvalue; - g = g / rvalue; - b = b / rvalue; - a = a / rvalue; + r = r / p_scalar; + g = g / p_scalar; + b = b / p_scalar; + a = a / p_scalar; } -}; +} Color Color::operator-() const { return Color( diff --git a/core/color.h b/core/color.h index e5192776824..0399c5d454f 100644 --- a/core/color.h +++ b/core/color.h @@ -60,11 +60,11 @@ struct _NO_DISCARD_CLASS_ Color { float get_v() const; void set_hsv(float p_h, float p_s, float p_v, float p_alpha = 1.0); - _FORCE_INLINE_ float &operator[](int idx) { - return components[idx]; + _FORCE_INLINE_ float &operator[](int p_idx) { + return components[p_idx]; } - _FORCE_INLINE_ const float &operator[](int idx) const { - return components[idx]; + _FORCE_INLINE_ const float &operator[](int p_idx) const { + return components[p_idx]; } Color operator+(const Color &p_color) const; @@ -75,14 +75,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*(real_t p_scalar) const; void operator*=(const Color &p_color); - void operator*=(const real_t &rvalue); + void operator*=(real_t p_scalar); Color operator/(const Color &p_color) const; - Color operator/(const real_t &rvalue) const; + Color operator/(real_t p_scalar) const; void operator/=(const Color &p_color); - void operator/=(const real_t &rvalue); + void operator/=(real_t p_scalar); bool is_equal_approx(const Color &p_color) const; diff --git a/core/hashfuncs.h b/core/hashfuncs.h index a06c5d0f8a6..5ae8142017e 100644 --- a/core/hashfuncs.h +++ b/core/hashfuncs.h @@ -73,7 +73,7 @@ static inline uint32_t hash_djb2_one_32(uint32_t p_in, uint32_t p_prev = 5381) { return ((p_prev << 5) + p_prev) + p_in; } -static inline uint32_t hash_one_uint64(const uint64_t p_int) { +static inline uint32_t hash_one_uint64(uint64_t p_int) { uint64_t v = p_int; v = (~v) + (v << 18); // v = (v << 18) - v - 1; v = v ^ (v >> 31); @@ -132,18 +132,18 @@ static inline uint64_t make_uint64_t(T p_in) { struct HashMapHasherDefault { static _FORCE_INLINE_ uint32_t hash(const String &p_string) { return p_string.hash(); } static _FORCE_INLINE_ uint32_t hash(const char *p_cstr) { return hash_djb2(p_cstr); } - static _FORCE_INLINE_ uint32_t hash(const uint64_t p_int) { return hash_one_uint64(p_int); } + static _FORCE_INLINE_ uint32_t hash(uint64_t p_int) { return hash_one_uint64(p_int); } - static _FORCE_INLINE_ uint32_t hash(const int64_t p_int) { return hash(uint64_t(p_int)); } - static _FORCE_INLINE_ uint32_t hash(const float p_float) { return hash_djb2_one_float(p_float); } - static _FORCE_INLINE_ uint32_t hash(const double p_double) { return hash_djb2_one_float(p_double); } - static _FORCE_INLINE_ uint32_t hash(const uint32_t p_int) { return p_int; } - static _FORCE_INLINE_ uint32_t hash(const int32_t p_int) { return (uint32_t)p_int; } - static _FORCE_INLINE_ uint32_t hash(const uint16_t p_int) { return p_int; } - static _FORCE_INLINE_ uint32_t hash(const int16_t p_int) { return (uint32_t)p_int; } - static _FORCE_INLINE_ uint32_t hash(const uint8_t p_int) { return p_int; } - static _FORCE_INLINE_ uint32_t hash(const int8_t p_int) { return (uint32_t)p_int; } - static _FORCE_INLINE_ uint32_t hash(const wchar_t p_wchar) { return (uint32_t)p_wchar; } + static _FORCE_INLINE_ uint32_t hash(int64_t p_int) { return hash(uint64_t(p_int)); } + static _FORCE_INLINE_ uint32_t hash(float p_float) { return hash_djb2_one_float(p_float); } + static _FORCE_INLINE_ uint32_t hash(double p_double) { return hash_djb2_one_float(p_double); } + static _FORCE_INLINE_ uint32_t hash(uint32_t p_int) { return p_int; } + static _FORCE_INLINE_ uint32_t hash(int32_t p_int) { return (uint32_t)p_int; } + static _FORCE_INLINE_ uint32_t hash(uint16_t p_int) { return p_int; } + static _FORCE_INLINE_ uint32_t hash(int16_t p_int) { return (uint32_t)p_int; } + static _FORCE_INLINE_ uint32_t hash(uint8_t p_int) { return p_int; } + static _FORCE_INLINE_ uint32_t hash(int8_t p_int) { return (uint32_t)p_int; } + static _FORCE_INLINE_ uint32_t hash(wchar_t p_wchar) { return (uint32_t)p_wchar; } static _FORCE_INLINE_ uint32_t hash(const StringName &p_string_name) { return p_string_name.hash(); } static _FORCE_INLINE_ uint32_t hash(const NodePath &p_path) { return p_path.hash(); } @@ -157,11 +157,11 @@ struct HashMapComparatorDefault { return p_lhs == p_rhs; } - bool compare(const float &p_lhs, const float &p_rhs) { + bool compare(float p_lhs, float p_rhs) { return (p_lhs == p_rhs) || (Math::is_nan(p_lhs) && Math::is_nan(p_rhs)); } - bool compare(const double &p_lhs, const double &p_rhs) { + bool compare(double p_lhs, double p_rhs) { return (p_lhs == p_rhs) || (Math::is_nan(p_lhs) && Math::is_nan(p_rhs)); } }; diff --git a/core/math/basis.cpp b/core/math/basis.cpp index f4ef32a4843..f202391fb64 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -278,7 +278,7 @@ Vector3 Basis::get_scale() const { // Decomposes a Basis into a rotation-reflection matrix (an element of the group O(3)) and a positive scaling matrix as B = O.S. // Returns the rotation-reflection matrix via reference argument, and scaling information is returned as a Vector3. // This (internal) function is too specific and named too ugly to expose to users, and probably there's no need to do so. -Vector3 Basis::rotref_posscale_decomposition(Basis &rotref) const { +Vector3 Basis::rotref_posscale_decomposition(Basis &r_rotref) const { #ifdef MATH_CHECKS ERR_FAIL_COND_V(determinant() == 0, Vector3()); @@ -287,10 +287,10 @@ Vector3 Basis::rotref_posscale_decomposition(Basis &rotref) const { #endif Vector3 scale = get_scale(); Basis inv_scale = Basis().scaled(scale.inverse()); // this will also absorb the sign of scale - rotref = (*this) * inv_scale; + r_rotref = (*this) * inv_scale; #ifdef MATH_CHECKS - ERR_FAIL_COND_V(!rotref.is_orthogonal(), Vector3()); + ERR_FAIL_COND_V(!r_rotref.is_orthogonal(), Vector3()); #endif return scale.abs(); } @@ -1009,7 +1009,7 @@ void Basis::set_diagonal(const Vector3 &p_diag) { elements[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, real_t p_weight) const { //consider scale Quat from(*this); Quat to(p_to); diff --git a/core/math/basis.h b/core/math/basis.h index b786a3549cb..f294e1da8fc 100644 --- a/core/math/basis.h +++ b/core/math/basis.h @@ -42,11 +42,11 @@ public: Vector3(0, 0, 1) }; - _FORCE_INLINE_ const Vector3 &operator[](int axis) const { - return elements[axis]; + _FORCE_INLINE_ const Vector3 &operator[](int p_axis) const { + return elements[p_axis]; } - _FORCE_INLINE_ Vector3 &operator[](int axis) { - return elements[axis]; + _FORCE_INLINE_ Vector3 &operator[](int p_axis) { + return elements[p_axis]; } void invert(); @@ -60,11 +60,11 @@ public: void from_z(const Vector3 &p_z); _FORCE_INLINE_ Vector3 get_axis(int p_axis) const { - // get actual basis axis (elements is transposed for performance) + // Get actual basis axis (elements is transposed for performance). return Vector3(elements[0][p_axis], elements[1][p_axis], elements[2][p_axis]); } _FORCE_INLINE_ void set_axis(int p_axis, const Vector3 &p_value) { - // get actual basis axis (elements is transposed for performance) + // Get actual basis axis (elements is transposed for performance). elements[0][p_axis] = p_value.x; elements[1][p_axis] = p_value.y; elements[2][p_axis] = p_value.z; @@ -86,9 +86,9 @@ public: void get_rotation_axis_angle(Vector3 &p_axis, real_t &p_angle) const; void get_rotation_axis_angle_local(Vector3 &p_axis, real_t &p_angle) const; Quat get_rotation_quat() const; - Vector3 get_rotation() const { return get_rotation_euler(); }; + Vector3 get_rotation() const { return get_rotation_euler(); } - Vector3 rotref_posscale_decomposition(Basis &rotref) const; + Vector3 rotref_posscale_decomposition(Basis &r_rotref) const; Vector3 get_euler_xyz() const; void set_euler_xyz(const Vector3 &p_euler); @@ -132,20 +132,20 @@ public: void set_quat_scale(const Quat &p_quat, const Vector3 &p_scale); // transposed dot products - _FORCE_INLINE_ real_t tdotx(const Vector3 &v) const { - return elements[0][0] * v[0] + elements[1][0] * v[1] + elements[2][0] * v[2]; + _FORCE_INLINE_ real_t tdotx(const Vector3 &p_v) const { + return elements[0][0] * p_v[0] + elements[1][0] * p_v[1] + elements[2][0] * p_v[2]; } - _FORCE_INLINE_ real_t tdoty(const Vector3 &v) const { - return elements[0][1] * v[0] + elements[1][1] * v[1] + elements[2][1] * v[2]; + _FORCE_INLINE_ real_t tdoty(const Vector3 &p_v) const { + return elements[0][1] * p_v[0] + elements[1][1] * p_v[1] + elements[2][1] * p_v[2]; } - _FORCE_INLINE_ real_t tdotz(const Vector3 &v) const { - return elements[0][2] * v[0] + elements[1][2] * v[1] + elements[2][2] * v[2]; + _FORCE_INLINE_ real_t tdotz(const Vector3 &p_v) const { + return elements[0][2] * p_v[0] + elements[1][2] * p_v[1] + elements[2][2] * p_v[2]; } bool is_equal_approx(const Basis &p_basis) const; // For complicated reasons, the second argument is always discarded. See #45062. - bool is_equal_approx(const Basis &a, const Basis &b) const { return is_equal_approx(a); } - bool is_equal_approx_ratio(const Basis &a, const Basis &b, real_t p_epsilon = UNIT_EPSILON) const; + bool is_equal_approx(const Basis &p_a, const Basis &p_b) const { return is_equal_approx(p_a); } + bool is_equal_approx_ratio(const Basis &p_a, const Basis &p_b, real_t p_epsilon = UNIT_EPSILON) const; bool operator==(const Basis &p_matrix) const; bool operator!=(const Basis &p_matrix) const; @@ -170,44 +170,44 @@ public: 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, real_t p_weight) const; + _FORCE_INLINE_ Basis lerp(const Basis &p_to, real_t p_weight) const; operator String() const; /* create / set */ - _FORCE_INLINE_ void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) { - elements[0][0] = xx; - elements[0][1] = xy; - elements[0][2] = xz; - elements[1][0] = yx; - elements[1][1] = yy; - elements[1][2] = yz; - elements[2][0] = zx; - elements[2][1] = zy; - elements[2][2] = zz; + _FORCE_INLINE_ void set(real_t p_xx, real_t p_xy, real_t p_xz, real_t p_yx, real_t p_yy, real_t p_yz, real_t p_zx, real_t p_zy, real_t p_zz) { + elements[0][0] = p_xx; + elements[0][1] = p_xy; + elements[0][2] = p_xz; + elements[1][0] = p_yx; + elements[1][1] = p_yy; + elements[1][2] = p_yz; + elements[2][0] = p_zx; + elements[2][1] = p_zy; + elements[2][2] = p_zz; } _FORCE_INLINE_ void set(const Vector3 &p_x, const Vector3 &p_y, const Vector3 &p_z) { set_axis(0, p_x); set_axis(1, p_y); set_axis(2, p_z); } - _FORCE_INLINE_ Vector3 get_column(int i) const { - return Vector3(elements[0][i], elements[1][i], elements[2][i]); + _FORCE_INLINE_ Vector3 get_column(int p_i) const { + return Vector3(elements[0][p_i], elements[1][p_i], elements[2][p_i]); } - _FORCE_INLINE_ Vector3 get_row(int i) const { - return Vector3(elements[i][0], elements[i][1], elements[i][2]); + _FORCE_INLINE_ Vector3 get_row(int p_i) const { + return Vector3(elements[p_i][0], elements[p_i][1], elements[p_i][2]); } _FORCE_INLINE_ Vector3 get_main_diagonal() const { return Vector3(elements[0][0], elements[1][1], elements[2][2]); } - _FORCE_INLINE_ void set_row(int i, const Vector3 &p_row) { - elements[i][0] = p_row.x; - elements[i][1] = p_row.y; - elements[i][2] = p_row.z; + _FORCE_INLINE_ void set_row(int p_i, const Vector3 &p_row) { + elements[p_i][0] = p_row.x; + elements[p_i][1] = p_row.y; + elements[p_i][2] = p_row.z; } _FORCE_INLINE_ void set_zero() { @@ -216,20 +216,20 @@ public: elements[2].zero(); } - _FORCE_INLINE_ Basis transpose_xform(const Basis &m) const { + _FORCE_INLINE_ Basis transpose_xform(const Basis &p_m) const { return Basis( - elements[0].x * m[0].x + elements[1].x * m[1].x + elements[2].x * m[2].x, - elements[0].x * m[0].y + elements[1].x * m[1].y + elements[2].x * m[2].y, - elements[0].x * m[0].z + elements[1].x * m[1].z + elements[2].x * m[2].z, - elements[0].y * m[0].x + elements[1].y * m[1].x + elements[2].y * m[2].x, - elements[0].y * m[0].y + elements[1].y * m[1].y + elements[2].y * m[2].y, - elements[0].y * m[0].z + elements[1].y * m[1].z + elements[2].y * m[2].z, - elements[0].z * m[0].x + elements[1].z * m[1].x + elements[2].z * m[2].x, - elements[0].z * m[0].y + elements[1].z * m[1].y + elements[2].z * m[2].y, - elements[0].z * m[0].z + elements[1].z * m[1].z + elements[2].z * m[2].z); + elements[0].x * p_m[0].x + elements[1].x * p_m[1].x + elements[2].x * p_m[2].x, + elements[0].x * p_m[0].y + elements[1].x * p_m[1].y + elements[2].x * p_m[2].y, + elements[0].x * p_m[0].z + elements[1].x * p_m[1].z + elements[2].x * p_m[2].z, + elements[0].y * p_m[0].x + elements[1].y * p_m[1].x + elements[2].y * p_m[2].x, + elements[0].y * p_m[0].y + elements[1].y * p_m[1].y + elements[2].y * p_m[2].y, + elements[0].y * p_m[0].z + elements[1].y * p_m[1].z + elements[2].y * p_m[2].z, + elements[0].z * p_m[0].x + elements[1].z * p_m[1].x + elements[2].z * p_m[2].x, + elements[0].z * p_m[0].y + elements[1].z * p_m[1].y + elements[2].z * p_m[2].y, + elements[0].z * p_m[0].z + elements[1].z * p_m[1].z + elements[2].z * p_m[2].z); } - Basis(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) { - set(xx, xy, xz, yx, yy, yz, zx, zy, zz); + Basis(real_t p_xx, real_t p_xy, real_t p_xz, real_t p_yx, real_t p_yy, real_t p_yz, real_t p_zx, real_t p_zy, real_t p_zz) { + set(p_xx, p_xy, p_xz, p_yx, p_yy, p_yz, p_zx, p_zy, p_zz); } void orthonormalize(); @@ -263,10 +263,10 @@ public: Basis(const Vector3 &p_axis, real_t p_angle) { set_axis_angle(p_axis, p_angle); } Basis(const Vector3 &p_axis, real_t p_angle, const Vector3 &p_scale) { set_axis_angle_scale(p_axis, p_angle, p_scale); } - _FORCE_INLINE_ Basis(const Vector3 &row0, const Vector3 &row1, const Vector3 &row2) { - elements[0] = row0; - elements[1] = row1; - elements[2] = row2; + _FORCE_INLINE_ Basis(const Vector3 &p_row0, const Vector3 &p_row1, const Vector3 &p_row2) { + elements[0] = p_row0; + elements[1] = p_row1; + elements[2] = p_row2; } _FORCE_INLINE_ Basis() {} @@ -342,7 +342,7 @@ real_t Basis::determinant() const { elements[2][0] * (elements[0][1] * elements[1][2] - elements[1][1] * elements[0][2]); } -Basis Basis::lerp(const Basis &p_to, const real_t &p_weight) const { +Basis Basis::lerp(const Basis &p_to, real_t p_weight) const { Basis b; b.elements[0] = elements[0].linear_interpolate(p_to.elements[0], p_weight); b.elements[1] = elements[1].linear_interpolate(p_to.elements[1], p_weight); diff --git a/core/math/quat.cpp b/core/math/quat.cpp index 600c60e1f1c..5640c274d5f 100644 --- a/core/math/quat.cpp +++ b/core/math/quat.cpp @@ -153,7 +153,7 @@ Quat Quat::inverse() const { return Quat(-x, -y, -z, w); } -Quat Quat::slerp(const Quat &p_to, const real_t &p_weight) const { +Quat Quat::slerp(const Quat &p_to, real_t p_weight) const { #ifdef MATH_CHECKS ERR_FAIL_COND_V_MSG(!is_normalized(), Quat(), "The start quaternion must be normalized."); ERR_FAIL_COND_V_MSG(!p_to.is_normalized(), Quat(), "The end quaternion must be normalized."); @@ -200,7 +200,7 @@ Quat Quat::slerp(const Quat &p_to, const real_t &p_weight) const { scale0 * w + scale1 * to1.w); } -Quat Quat::slerpni(const Quat &p_to, const real_t &p_weight) const { +Quat Quat::slerpni(const Quat &p_to, real_t p_weight) const { #ifdef MATH_CHECKS ERR_FAIL_COND_V_MSG(!is_normalized(), Quat(), "The start quaternion must be normalized."); ERR_FAIL_COND_V_MSG(!p_to.is_normalized(), Quat(), "The end quaternion must be normalized."); @@ -224,7 +224,7 @@ Quat Quat::slerpni(const Quat &p_to, const real_t &p_weight) const { invFactor * from.w + newFactor * p_to.w); } -Quat Quat::cubic_slerp(const Quat &p_b, const Quat &p_pre_a, const Quat &p_post_b, const real_t &p_weight) const { +Quat Quat::cubic_slerp(const Quat &p_b, const Quat &p_pre_a, const Quat &p_post_b, real_t p_weight) const { #ifdef MATH_CHECKS ERR_FAIL_COND_V_MSG(!is_normalized(), Quat(), "The start quaternion must be normalized."); ERR_FAIL_COND_V_MSG(!p_b.is_normalized(), Quat(), "The end quaternion must be normalized."); @@ -240,18 +240,18 @@ Quat::operator String() const { return String::num(x) + ", " + String::num(y) + ", " + String::num(z) + ", " + String::num(w); } -void Quat::set_axis_angle(const Vector3 &axis, const real_t &angle) { +void Quat::set_axis_angle(const Vector3 &p_axis, real_t p_angle) { #ifdef MATH_CHECKS - ERR_FAIL_COND_MSG(!axis.is_normalized(), "The axis Vector3 must be normalized."); + ERR_FAIL_COND_MSG(!p_axis.is_normalized(), "The axis Vector3 must be normalized."); #endif - real_t d = axis.length(); + real_t d = p_axis.length(); if (d == 0) { set(0, 0, 0, 0); } else { - real_t sin_angle = Math::sin(angle * 0.5f); - real_t cos_angle = Math::cos(angle * 0.5f); + real_t sin_angle = Math::sin(p_angle * 0.5f); + real_t cos_angle = Math::cos(p_angle * 0.5f); real_t s = sin_angle / d; - set(axis.x * s, axis.y * s, axis.z * s, + set(p_axis.x * s, p_axis.y * s, p_axis.z * s, cos_angle); } } diff --git a/core/math/quat.h b/core/math/quat.h index fdde52a5bf7..809ebf4e3fc 100644 --- a/core/math/quat.h +++ b/core/math/quat.h @@ -55,14 +55,14 @@ public: void set_euler_yxz(const Vector3 &p_euler); Vector3 get_euler_yxz() const; - void set_euler(const Vector3 &p_euler) { set_euler_yxz(p_euler); }; - Vector3 get_euler() const { return get_euler_yxz(); }; + void set_euler(const Vector3 &p_euler) { set_euler_yxz(p_euler); } + Vector3 get_euler() const { return get_euler_yxz(); } - Quat slerp(const Quat &p_to, const real_t &p_weight) const; - Quat slerpni(const Quat &p_to, const real_t &p_weight) const; - Quat cubic_slerp(const Quat &p_b, const Quat &p_pre_a, const Quat &p_post_b, const real_t &p_weight) const; + Quat slerp(const Quat &p_to, real_t p_weight) const; + Quat slerpni(const Quat &p_to, real_t p_weight) const; + Quat cubic_slerp(const Quat &p_b, const Quat &p_pre_a, const Quat &p_post_b, real_t p_weight) const; - void set_axis_angle(const Vector3 &axis, const real_t &angle); + void set_axis_angle(const Vector3 &p_axis, real_t p_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); @@ -74,31 +74,31 @@ public: void operator*=(const Quat &p_q); Quat operator*(const Quat &p_q) const; - Quat operator*(const Vector3 &v) const { - return Quat(w * v.x + y * v.z - z * v.y, - w * v.y + z * v.x - x * v.z, - w * v.z + x * v.y - y * v.x, - -x * v.x - y * v.y - z * v.z); + Quat operator*(const Vector3 &p_v) const { + return Quat(w * p_v.x + y * p_v.z - z * p_v.y, + w * p_v.y + z * p_v.x - x * p_v.z, + w * p_v.z + x * p_v.y - y * p_v.x, + -x * p_v.x - y * p_v.y - z * p_v.z); } - _FORCE_INLINE_ Vector3 xform(const Vector3 &v) const { + _FORCE_INLINE_ Vector3 xform(const Vector3 &p_v) const { #ifdef MATH_CHECKS - ERR_FAIL_COND_V_MSG(!is_normalized(), v, "The quaternion must be normalized."); + ERR_FAIL_COND_V_MSG(!is_normalized(), p_v, "The quaternion must be normalized."); #endif Vector3 u(x, y, z); - Vector3 uv = u.cross(v); - return v + ((uv * w) + u.cross(uv)) * ((real_t)2); + Vector3 uv = u.cross(p_v); + return p_v + ((uv * w) + u.cross(uv)) * ((real_t)2); } _FORCE_INLINE_ void operator+=(const Quat &p_q); _FORCE_INLINE_ void operator-=(const Quat &p_q); - _FORCE_INLINE_ void operator*=(const real_t &s); - _FORCE_INLINE_ void operator/=(const real_t &s); - _FORCE_INLINE_ Quat operator+(const Quat &q2) const; - _FORCE_INLINE_ Quat operator-(const Quat &q2) const; + _FORCE_INLINE_ void operator*=(real_t p_s); + _FORCE_INLINE_ void operator/=(real_t p_s); + _FORCE_INLINE_ Quat operator+(const Quat &p_q2) const; + _FORCE_INLINE_ Quat operator-(const Quat &p_q2) const; _FORCE_INLINE_ Quat operator-() const; - _FORCE_INLINE_ Quat operator*(const real_t &s) const; - _FORCE_INLINE_ Quat operator/(const real_t &s) const; + _FORCE_INLINE_ Quat operator*(real_t p_s) const; + _FORCE_INLINE_ Quat operator/(real_t p_s) const; _FORCE_INLINE_ bool operator==(const Quat &p_quat) const; _FORCE_INLINE_ bool operator!=(const Quat &p_quat) const; @@ -117,9 +117,9 @@ public: z(p_z), w(p_w) { } - Quat(const Vector3 &axis, const real_t &angle) { set_axis_angle(axis, angle); } + Quat(const Vector3 &p_axis, real_t p_angle) { set_axis_angle(p_axis, p_angle); } - Quat(const Vector3 &euler) { set_euler(euler); } + Quat(const Vector3 &p_euler) { set_euler(p_euler); } Quat(const Quat &p_q) : x(p_q.x), y(p_q.y), @@ -135,10 +135,10 @@ public: return *this; } - Quat(const Vector3 &v0, const Vector3 &v1) // shortest arc + Quat(const Vector3 &p_v0, const Vector3 &p_v1) // shortest arc { - Vector3 c = v0.cross(v1); - real_t d = v0.dot(v1); + Vector3 c = p_v0.cross(p_v1); + real_t d = p_v0.dot(p_v1); if (d < -1 + (real_t)CMP_EPSILON) { x = 0; @@ -186,25 +186,25 @@ void Quat::operator-=(const Quat &p_q) { w -= p_q.w; } -void Quat::operator*=(const real_t &s) { - x *= s; - y *= s; - z *= s; - w *= s; +void Quat::operator*=(real_t p_s) { + x *= p_s; + y *= p_s; + z *= p_s; + w *= p_s; } -void Quat::operator/=(const real_t &s) { - *this *= 1 / s; +void Quat::operator/=(real_t p_s) { + *this *= 1 / p_s; } -Quat Quat::operator+(const Quat &q2) const { +Quat Quat::operator+(const Quat &p_q2) const { const Quat &q1 = *this; - return Quat(q1.x + q2.x, q1.y + q2.y, q1.z + q2.z, q1.w + q2.w); + return Quat(q1.x + p_q2.x, q1.y + p_q2.y, q1.z + p_q2.z, q1.w + p_q2.w); } -Quat Quat::operator-(const Quat &q2) const { +Quat Quat::operator-(const Quat &p_q2) const { const Quat &q1 = *this; - return Quat(q1.x - q2.x, q1.y - q2.y, q1.z - q2.z, q1.w - q2.w); + return Quat(q1.x - p_q2.x, q1.y - p_q2.y, q1.z - p_q2.z, q1.w - p_q2.w); } Quat Quat::operator-() const { @@ -212,12 +212,12 @@ Quat Quat::operator-() const { return Quat(-q2.x, -q2.y, -q2.z, -q2.w); } -Quat Quat::operator*(const real_t &s) const { - return Quat(x * s, y * s, z * s, w * s); +Quat Quat::operator*(real_t p_s) const { + return Quat(x * p_s, y * p_s, z * p_s, w * p_s); } -Quat Quat::operator/(const real_t &s) const { - return *this * (1 / s); +Quat Quat::operator/(real_t p_s) const { + return *this * (1 / p_s); } bool Quat::operator==(const Quat &p_quat) const { diff --git a/core/math/rect2.h b/core/math/rect2.h index f05aae4b472..951f008e4d6 100644 --- a/core/math/rect2.h +++ b/core/math/rect2.h @@ -48,7 +48,7 @@ struct _NO_DISCARD_CLASS_ Rect2 { _FORCE_INLINE_ Vector2 get_center() const { return position + (size * 0.5f); } - inline bool intersects(const Rect2 &p_rect, const bool p_include_borders = false) const { + inline bool intersects(const Rect2 &p_rect, bool p_include_borders = false) const { if (p_include_borders) { if (position.x > (p_rect.position.x + p_rect.size.width)) { return false; diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp index 9fa2d02633b..953a207df68 100644 --- a/core/math/vector2.cpp +++ b/core/math/vector2.cpp @@ -109,7 +109,7 @@ Vector2 Vector2::rotated(real_t p_by) const { return v; } -Vector2 Vector2::posmod(const real_t p_mod) const { +Vector2 Vector2::posmod(real_t p_mod) const { return Vector2(Math::fposmod(x, p_mod), Math::fposmod(y, p_mod)); } @@ -139,7 +139,7 @@ Vector2 Vector2::clamped(real_t p_len) const { return v; } -Vector2 Vector2::limit_length(const real_t p_len) const { +Vector2 Vector2::limit_length(real_t p_len) const { const real_t l = length(); Vector2 v = *this; if (l > 0 && p_len < l) { @@ -169,7 +169,7 @@ Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, c return out; } -Vector2 Vector2::move_toward(const Vector2 &p_to, const real_t p_delta) const { +Vector2 Vector2::move_toward(const Vector2 &p_to, real_t p_delta) const { Vector2 v = *this; Vector2 vd = p_to - v; real_t len = vd.length(); @@ -216,30 +216,30 @@ void Vector2i::operator-=(const Vector2i &p_v) { y -= p_v.y; } -Vector2i Vector2i::operator*(const Vector2i &p_v1) const { - return Vector2i(x * p_v1.x, y * p_v1.y); -}; +Vector2i Vector2i::operator*(const Vector2i &p_v) const { + return Vector2i(x * p_v.x, y * p_v.y); +} -Vector2i Vector2i::operator*(const int &rvalue) const { - return Vector2i(x * rvalue, y * rvalue); -}; -void Vector2i::operator*=(const int &rvalue) { - x *= rvalue; - y *= rvalue; -}; +Vector2i Vector2i::operator*(int p_scalar) const { + return Vector2i(x * p_scalar, y * p_scalar); +} +void Vector2i::operator*=(int p_scalar) { + x *= p_scalar; + y *= p_scalar; +} -Vector2i Vector2i::operator/(const Vector2i &p_v1) const { - return Vector2i(x / p_v1.x, y / p_v1.y); -}; +Vector2i Vector2i::operator/(const Vector2i &p_v) const { + return Vector2i(x / p_v.x, y / p_v.y); +} -Vector2i Vector2i::operator/(const int &rvalue) const { - return Vector2i(x / rvalue, y / rvalue); -}; +Vector2i Vector2i::operator/(int p_scalar) const { + return Vector2i(x / p_scalar, y / p_scalar); +} -void Vector2i::operator/=(const int &rvalue) { - x /= rvalue; - y /= rvalue; -}; +void Vector2i::operator/=(int p_scalar) { + x /= p_scalar; + y /= p_scalar; +} Vector2i Vector2i::operator-() const { return Vector2i(-x, -y); diff --git a/core/math/vector2.h b/core/math/vector2.h index 336135b70b4..10765d0a6bf 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -95,20 +95,20 @@ struct _NO_DISCARD_CLASS_ Vector2 { real_t dot(const Vector2 &p_other) const; real_t cross(const Vector2 &p_other) const; - Vector2 posmod(const real_t p_mod) const; + Vector2 posmod(real_t p_mod) const; Vector2 posmodv(const Vector2 &p_modv) const; Vector2 project(const Vector2 &p_to) const; Vector2 plane_project(real_t p_d, const Vector2 &p_vec) const; Vector2 clamped(real_t p_len) const; - Vector2 limit_length(const real_t p_len = 1.0) const; + Vector2 limit_length(real_t p_len = 1.0) const; _FORCE_INLINE_ static Vector2 linear_interpolate(const Vector2 &p_a, const Vector2 &p_b, real_t p_weight); _FORCE_INLINE_ Vector2 linear_interpolate(const Vector2 &p_to, real_t p_weight) const; _FORCE_INLINE_ Vector2 slerp(const Vector2 &p_to, real_t p_weight) const; Vector2 cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_weight) const; - Vector2 move_toward(const Vector2 &p_to, const real_t p_delta) const; + Vector2 move_toward(const Vector2 &p_to, real_t p_delta) const; Vector2 slide(const Vector2 &p_normal) const; Vector2 bounce(const Vector2 &p_normal) const; @@ -120,18 +120,18 @@ struct _NO_DISCARD_CLASS_ Vector2 { void operator+=(const Vector2 &p_v); Vector2 operator-(const Vector2 &p_v) const; void operator-=(const Vector2 &p_v); - Vector2 operator*(const Vector2 &p_v1) const; + Vector2 operator*(const Vector2 &p_v) const; - Vector2 operator*(const real_t &rvalue) const; - void operator*=(const real_t &rvalue); - void operator*=(const Vector2 &rvalue) { *this = *this * rvalue; } + Vector2 operator*(real_t p_scalar) const; + void operator*=(real_t p_scalar); + void operator*=(const Vector2 &p_v) { *this = *this * p_v; } - Vector2 operator/(const Vector2 &p_v1) const; + Vector2 operator/(const Vector2 &p_v) const; - Vector2 operator/(const real_t &rvalue) const; + Vector2 operator/(real_t p_scalar) const; - void operator/=(const real_t &rvalue); - void operator/=(const Vector2 &rvalue) { *this = *this / rvalue; } + void operator/=(real_t p_scalar); + void operator/=(const Vector2 &p_v) { *this = *this / p_v; } Vector2 operator-() const; @@ -198,30 +198,30 @@ _FORCE_INLINE_ void Vector2::operator-=(const Vector2 &p_v) { y -= p_v.y; } -_FORCE_INLINE_ Vector2 Vector2::operator*(const Vector2 &p_v1) const { - return Vector2(x * p_v1.x, y * p_v1.y); -}; +_FORCE_INLINE_ Vector2 Vector2::operator*(const Vector2 &p_v) const { + return Vector2(x * p_v.x, y * p_v.y); +} -_FORCE_INLINE_ Vector2 Vector2::operator*(const real_t &rvalue) const { - return Vector2(x * rvalue, y * rvalue); -}; -_FORCE_INLINE_ void Vector2::operator*=(const real_t &rvalue) { - x *= rvalue; - y *= rvalue; -}; +_FORCE_INLINE_ Vector2 Vector2::operator*(real_t p_scalar) const { + return Vector2(x * p_scalar, y * p_scalar); +} +_FORCE_INLINE_ void Vector2::operator*=(real_t p_scalar) { + x *= p_scalar; + y *= p_scalar; +} -_FORCE_INLINE_ Vector2 Vector2::operator/(const Vector2 &p_v1) const { - return Vector2(x / p_v1.x, y / p_v1.y); -}; +_FORCE_INLINE_ Vector2 Vector2::operator/(const Vector2 &p_v) const { + return Vector2(x / p_v.x, y / p_v.y); +} -_FORCE_INLINE_ Vector2 Vector2::operator/(const real_t &rvalue) const { - return Vector2(x / rvalue, y / rvalue); -}; +_FORCE_INLINE_ Vector2 Vector2::operator/(real_t p_scalar) const { + return Vector2(x / p_scalar, y / p_scalar); +} -_FORCE_INLINE_ void Vector2::operator/=(const real_t &rvalue) { - x /= rvalue; - y /= rvalue; -}; +_FORCE_INLINE_ void Vector2::operator/=(real_t p_scalar) { + x /= p_scalar; + y /= p_scalar; +} _FORCE_INLINE_ Vector2 Vector2::operator-() const { return Vector2(-x, -y); @@ -305,16 +305,16 @@ struct _NO_DISCARD_CLASS_ Vector2i { void operator+=(const Vector2i &p_v); Vector2i operator-(const Vector2i &p_v) const; void operator-=(const Vector2i &p_v); - Vector2i operator*(const Vector2i &p_v1) const; + Vector2i operator*(const Vector2i &p_v) const; - Vector2i operator*(const int &rvalue) const; - void operator*=(const int &rvalue); + Vector2i operator*(int p_scalar) const; + void operator*=(int p_scalar); - Vector2i operator/(const Vector2i &p_v1) const; + Vector2i operator/(const Vector2i &p_v) const; - Vector2i operator/(const int &rvalue) const; + Vector2i operator/(int p_scalar) const; - void operator/=(const int &rvalue); + void operator/=(int p_scalar); Vector2i operator-() const; bool operator<(const Vector2i &p_vec2) const { return (x == p_vec2.x) ? (y < p_vec2.y) : (x < p_vec2.x); } diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp index 685747ef006..4c4841a32cd 100644 --- a/core/math/vector3.cpp +++ b/core/math/vector3.cpp @@ -51,18 +51,18 @@ real_t Vector3::get_axis(int p_axis) const { return operator[](p_axis); } -void Vector3::snap(Vector3 p_val) { +void Vector3::snap(const Vector3 &p_val) { x = Math::stepify(x, p_val.x); y = Math::stepify(y, p_val.y); z = Math::stepify(z, p_val.z); } -Vector3 Vector3::snapped(Vector3 p_val) const { +Vector3 Vector3::snapped(const Vector3 &p_val) const { Vector3 v = *this; v.snap(p_val); return v; } -Vector3 Vector3::limit_length(const real_t p_len) const { +Vector3 Vector3::limit_length(real_t p_len) const { const real_t l = length(); Vector3 v = *this; if (l > 0 && p_len < l) { @@ -126,7 +126,7 @@ Vector3 Vector3::cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, c return out; } -Vector3 Vector3::move_toward(const Vector3 &p_to, const real_t p_delta) const { +Vector3 Vector3::move_toward(const Vector3 &p_to, real_t p_delta) const { Vector3 v = *this; Vector3 vd = p_to - v; real_t len = vd.length(); diff --git a/core/math/vector3.h b/core/math/vector3.h index 6a66a737ded..9fd74391bd5 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -87,12 +87,12 @@ struct _NO_DISCARD_CLASS_ Vector3 { _FORCE_INLINE_ Vector3 normalized() const; _FORCE_INLINE_ bool is_normalized() const; _FORCE_INLINE_ Vector3 inverse() const; - Vector3 limit_length(const real_t p_len = 1.0) const; + Vector3 limit_length(real_t p_len = 1.0) const; _FORCE_INLINE_ void zero(); - void snap(Vector3 p_val); - Vector3 snapped(Vector3 p_val) const; + void snap(const Vector3 &p_val); + Vector3 snapped(const Vector3 &p_val) const; void rotate(const Vector3 &p_axis, real_t p_angle); Vector3 rotated(const Vector3 &p_axis, real_t p_angle) const; @@ -103,7 +103,7 @@ struct _NO_DISCARD_CLASS_ Vector3 { _FORCE_INLINE_ Vector3 slerp(const Vector3 &p_to, real_t p_weight) const; Vector3 cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_weight) const; Vector3 cubic_interpolaten(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_weight) const; - Vector3 move_toward(const Vector3 &p_to, const real_t p_delta) const; + Vector3 move_toward(const Vector3 &p_to, real_t p_delta) const; _FORCE_INLINE_ Vector3 cross(const Vector3 &p_b) const; _FORCE_INLINE_ real_t dot(const Vector3 &p_b) const; @@ -119,7 +119,7 @@ struct _NO_DISCARD_CLASS_ Vector3 { _FORCE_INLINE_ real_t distance_to(const Vector3 &p_to) const; _FORCE_INLINE_ real_t distance_squared_to(const Vector3 &p_to) const; - _FORCE_INLINE_ Vector3 posmod(const real_t p_mod) const; + _FORCE_INLINE_ Vector3 posmod(real_t p_mod) const; _FORCE_INLINE_ Vector3 posmodv(const Vector3 &p_modv) const; _FORCE_INLINE_ Vector3 project(const Vector3 &p_to) const; @@ -222,7 +222,7 @@ real_t Vector3::distance_squared_to(const Vector3 &p_to) const { return (p_to - *this).length_squared(); } -Vector3 Vector3::posmod(const real_t p_mod) const { +Vector3 Vector3::posmod(real_t p_mod) const { return Vector3(Math::fposmod(x, p_mod), Math::fposmod(y, p_mod), Math::fposmod(z, p_mod)); }