Replace generic macros with math equivalents
parent
c414c2b37d
commit
48ec701507
|
@ -55,27 +55,31 @@ namespace godot {
|
|||
#undef MAX
|
||||
#undef CLAMP
|
||||
|
||||
// Generic ABS function, for math uses please use Math::abs.
|
||||
// DEPRECATED. Use `Math::abs` instead.
|
||||
template <typename T>
|
||||
constexpr T ABS(T m_v) {
|
||||
return m_v < 0 ? -m_v : m_v;
|
||||
}
|
||||
|
||||
// DEPRECATED. Use `Math::sign` instead.
|
||||
template <typename T>
|
||||
constexpr const T SIGN(const T m_v) {
|
||||
return m_v == 0 ? 0.0f : (m_v < 0 ? -1.0f : +1.0f);
|
||||
}
|
||||
|
||||
// DEPRECATED. Use `Math::min` instead.
|
||||
template <typename T, typename T2>
|
||||
constexpr auto MIN(const T m_a, const T2 m_b) {
|
||||
return m_a < m_b ? m_a : m_b;
|
||||
}
|
||||
|
||||
// DEPRECATED. Use `Math::max` instead.
|
||||
template <typename T, typename T2>
|
||||
constexpr auto MAX(const T m_a, const T2 m_b) {
|
||||
return m_a > m_b ? m_a : m_b;
|
||||
}
|
||||
|
||||
// DEPRECATED. Use `Math::clamp` instead.
|
||||
template <typename T, typename T2, typename T3>
|
||||
constexpr auto CLAMP(const T m_a, const T2 m_min, const T3 m_max) {
|
||||
return m_a < m_min ? m_min : (m_a > m_max ? m_max : m_a);
|
||||
|
@ -539,34 +543,28 @@ inline float bezier_interpolate(float p_start, float p_control_1, float p_contro
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
inline T clamp(T x, T minv, T maxv) {
|
||||
if (x < minv) {
|
||||
return minv;
|
||||
}
|
||||
if (x > maxv) {
|
||||
return maxv;
|
||||
}
|
||||
return x;
|
||||
constexpr T clamp(T x, T minv, T maxv) {
|
||||
return x < minv ? minv : (x > maxv ? maxv : x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T min(T a, T b) {
|
||||
constexpr T min(T a, T b) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T max(T a, T b) {
|
||||
constexpr T max(T a, T b) {
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T sign(T x) {
|
||||
return static_cast<T>(SIGN(x));
|
||||
constexpr T sign(T x) {
|
||||
return x > T(0) ? T(1) : (x < T(0) ? T(-1) : T(0));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T abs(T x) {
|
||||
return std::abs(x);
|
||||
constexpr T abs(T x) {
|
||||
return x == T(0) ? T(0) : (x < T(0) ? -x : x);
|
||||
}
|
||||
|
||||
inline double deg_to_rad(double p_y) {
|
||||
|
|
|
@ -160,7 +160,7 @@ private:
|
|||
uint32_t old_capacity = hash_table_size_primes[capacity_index];
|
||||
|
||||
// Capacity can't be 0.
|
||||
capacity_index = MAX((uint32_t)MIN_CAPACITY_INDEX, p_new_capacity_index);
|
||||
capacity_index = Math::max((uint32_t)MIN_CAPACITY_INDEX, p_new_capacity_index);
|
||||
|
||||
uint32_t capacity = hash_table_size_primes[capacity_index];
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ private:
|
|||
|
||||
void _resize_and_rehash(uint32_t p_new_capacity_index) {
|
||||
// Capacity can't be 0.
|
||||
capacity_index = MAX((uint32_t)MIN_CAPACITY_INDEX, p_new_capacity_index);
|
||||
capacity_index = Math::max((uint32_t)MIN_CAPACITY_INDEX, p_new_capacity_index);
|
||||
|
||||
uint32_t capacity = hash_table_size_primes[capacity_index];
|
||||
|
||||
|
|
|
@ -165,11 +165,11 @@ public:
|
|||
|
||||
const Size s = size();
|
||||
|
||||
Size begin = CLAMP(p_begin, -s, s);
|
||||
Size begin = Math::clamp(p_begin, -s, s);
|
||||
if (begin < 0) {
|
||||
begin += s;
|
||||
}
|
||||
Size end = CLAMP(p_end, -s, s);
|
||||
Size end = Math::clamp(p_end, -s, s);
|
||||
if (end < 0) {
|
||||
end += s;
|
||||
}
|
||||
|
|
|
@ -135,13 +135,13 @@ struct _NO_DISCARD_ Color {
|
|||
|
||||
float sharedexp = 65408.000f; // Result of: ((pow2to9 - 1.0f) / pow2to9) * powf(2.0f, 31.0f - 15.0f)
|
||||
|
||||
float cRed = MAX(0.0f, MIN(sharedexp, r));
|
||||
float cGreen = MAX(0.0f, MIN(sharedexp, g));
|
||||
float cBlue = MAX(0.0f, MIN(sharedexp, b));
|
||||
float cRed = Math::max(0.0f, Math::min(sharedexp, r));
|
||||
float cGreen = Math::max(0.0f, Math::min(sharedexp, g));
|
||||
float cBlue = Math::max(0.0f, Math::min(sharedexp, b));
|
||||
|
||||
float cMax = MAX(cRed, MAX(cGreen, cBlue));
|
||||
float cMax = Math::max(cRed, Math::max(cGreen, cBlue));
|
||||
|
||||
float expp = MAX(-B - 1.0f, floor(Math::log(cMax) / (real_t)Math_LN2)) + 1.0f + B;
|
||||
float expp = Math::max<float>(-B - 1.0f, floor(Math::log(cMax) / (real_t)Math_LN2)) + 1.0f + B;
|
||||
|
||||
float sMax = (float)floor((cMax / Math::pow(2.0f, expp - B - N)) + 0.5f);
|
||||
|
||||
|
@ -204,14 +204,14 @@ struct _NO_DISCARD_ Color {
|
|||
operator String() const;
|
||||
|
||||
// For the binder.
|
||||
_FORCE_INLINE_ void set_r8(int32_t r8) { r = (CLAMP(r8, 0, 255) / 255.0f); }
|
||||
_FORCE_INLINE_ int32_t get_r8() const { return int32_t(CLAMP(Math::round(r * 255.0f), 0.0f, 255.0f)); }
|
||||
_FORCE_INLINE_ void set_g8(int32_t g8) { g = (CLAMP(g8, 0, 255) / 255.0f); }
|
||||
_FORCE_INLINE_ int32_t get_g8() const { return int32_t(CLAMP(Math::round(g * 255.0f), 0.0f, 255.0f)); }
|
||||
_FORCE_INLINE_ void set_b8(int32_t b8) { b = (CLAMP(b8, 0, 255) / 255.0f); }
|
||||
_FORCE_INLINE_ int32_t get_b8() const { return int32_t(CLAMP(Math::round(b * 255.0f), 0.0f, 255.0f)); }
|
||||
_FORCE_INLINE_ void set_a8(int32_t a8) { a = (CLAMP(a8, 0, 255) / 255.0f); }
|
||||
_FORCE_INLINE_ int32_t get_a8() const { return int32_t(CLAMP(Math::round(a * 255.0f), 0.0f, 255.0f)); }
|
||||
_FORCE_INLINE_ void set_r8(int32_t r8) { r = (Math::clamp(r8, 0, 255) / 255.0f); }
|
||||
_FORCE_INLINE_ int32_t get_r8() const { return int32_t(Math::clamp(Math::round(r * 255.0f), 0.0f, 255.0f)); }
|
||||
_FORCE_INLINE_ void set_g8(int32_t g8) { g = (Math::clamp(g8, 0, 255) / 255.0f); }
|
||||
_FORCE_INLINE_ int32_t get_g8() const { return int32_t(Math::clamp(Math::round(g * 255.0f), 0.0f, 255.0f)); }
|
||||
_FORCE_INLINE_ void set_b8(int32_t b8) { b = (Math::clamp(b8, 0, 255) / 255.0f); }
|
||||
_FORCE_INLINE_ int32_t get_b8() const { return int32_t(Math::clamp(Math::round(b * 255.0f), 0.0f, 255.0f)); }
|
||||
_FORCE_INLINE_ void set_a8(int32_t a8) { a = (Math::clamp(a8, 0, 255) / 255.0f); }
|
||||
_FORCE_INLINE_ int32_t get_a8() const { return int32_t(Math::clamp(Math::round(a * 255.0f), 0.0f, 255.0f)); }
|
||||
|
||||
_FORCE_INLINE_ void set_h(float p_h) { set_hsv(p_h, get_s(), get_v(), a); }
|
||||
_FORCE_INLINE_ void set_s(float p_s) { set_hsv(get_h(), p_s, get_v(), a); }
|
||||
|
|
|
@ -88,19 +88,19 @@ struct _NO_DISCARD_ Vector2 {
|
|||
Vector2 limit_length(const real_t p_len = 1.0) const;
|
||||
|
||||
Vector2 min(const Vector2 &p_vector2) const {
|
||||
return Vector2(MIN(x, p_vector2.x), MIN(y, p_vector2.y));
|
||||
return Vector2(Math::min(x, p_vector2.x), Math::min(y, p_vector2.y));
|
||||
}
|
||||
|
||||
Vector2 minf(real_t p_scalar) const {
|
||||
return Vector2(MIN(x, p_scalar), MIN(y, p_scalar));
|
||||
return Vector2(Math::min(x, p_scalar), Math::min(y, p_scalar));
|
||||
}
|
||||
|
||||
Vector2 max(const Vector2 &p_vector2) const {
|
||||
return Vector2(MAX(x, p_vector2.x), MAX(y, p_vector2.y));
|
||||
return Vector2(Math::max(x, p_vector2.x), Math::max(y, p_vector2.y));
|
||||
}
|
||||
|
||||
Vector2 maxf(real_t p_scalar) const {
|
||||
return Vector2(MAX(x, p_scalar), MAX(y, p_scalar));
|
||||
return Vector2(Math::max(x, p_scalar), Math::max(y, p_scalar));
|
||||
}
|
||||
|
||||
real_t distance_to(const Vector2 &p_vector2) const;
|
||||
|
|
|
@ -80,19 +80,19 @@ struct _NO_DISCARD_ Vector2i {
|
|||
}
|
||||
|
||||
Vector2i min(const Vector2i &p_vector2i) const {
|
||||
return Vector2i(MIN(x, p_vector2i.x), MIN(y, p_vector2i.y));
|
||||
return Vector2i(Math::min(x, p_vector2i.x), Math::min(y, p_vector2i.y));
|
||||
}
|
||||
|
||||
Vector2i mini(int32_t p_scalar) const {
|
||||
return Vector2i(MIN(x, p_scalar), MIN(y, p_scalar));
|
||||
return Vector2i(Math::min(x, p_scalar), Math::min(y, p_scalar));
|
||||
}
|
||||
|
||||
Vector2i max(const Vector2i &p_vector2i) const {
|
||||
return Vector2i(MAX(x, p_vector2i.x), MAX(y, p_vector2i.y));
|
||||
return Vector2i(Math::max(x, p_vector2i.x), Math::max(y, p_vector2i.y));
|
||||
}
|
||||
|
||||
Vector2i maxi(int32_t p_scalar) const {
|
||||
return Vector2i(MAX(x, p_scalar), MAX(y, p_scalar));
|
||||
return Vector2i(Math::max(x, p_scalar), Math::max(y, p_scalar));
|
||||
}
|
||||
|
||||
Vector2i operator+(const Vector2i &p_v) const;
|
||||
|
@ -129,7 +129,7 @@ struct _NO_DISCARD_ Vector2i {
|
|||
double distance_to(const Vector2i &p_to) const;
|
||||
|
||||
real_t aspect() const { return width / (real_t)height; }
|
||||
Vector2i sign() const { return Vector2i(SIGN(x), SIGN(y)); }
|
||||
Vector2i sign() const { return Vector2i(Math::sign(x), Math::sign(y)); }
|
||||
Vector2i abs() const { return Vector2i(Math::abs(x), Math::abs(y)); }
|
||||
Vector2i snapped(const Vector2i &p_step) const;
|
||||
Vector2i snappedi(int32_t p_step) const;
|
||||
|
|
|
@ -79,19 +79,19 @@ struct _NO_DISCARD_ Vector3 {
|
|||
}
|
||||
|
||||
Vector3 min(const Vector3 &p_vector3) const {
|
||||
return Vector3(MIN(x, p_vector3.x), MIN(y, p_vector3.y), MIN(z, p_vector3.z));
|
||||
return Vector3(Math::min(x, p_vector3.x), Math::min(y, p_vector3.y), Math::min(z, p_vector3.z));
|
||||
}
|
||||
|
||||
Vector3 minf(real_t p_scalar) const {
|
||||
return Vector3(MIN(x, p_scalar), MIN(y, p_scalar), MIN(z, p_scalar));
|
||||
return Vector3(Math::min(x, p_scalar), Math::min(y, p_scalar), Math::min(z, p_scalar));
|
||||
}
|
||||
|
||||
Vector3 max(const Vector3 &p_vector3) const {
|
||||
return Vector3(MAX(x, p_vector3.x), MAX(y, p_vector3.y), MAX(z, p_vector3.z));
|
||||
return Vector3(Math::max(x, p_vector3.x), Math::max(y, p_vector3.y), Math::max(z, p_vector3.z));
|
||||
}
|
||||
|
||||
Vector3 maxf(real_t p_scalar) const {
|
||||
return Vector3(MAX(x, p_scalar), MAX(y, p_scalar), MAX(z, p_scalar));
|
||||
return Vector3(Math::max(x, p_scalar), Math::max(y, p_scalar), Math::max(z, p_scalar));
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ real_t length() const;
|
||||
|
@ -213,7 +213,7 @@ Vector3 Vector3::abs() const {
|
|||
}
|
||||
|
||||
Vector3 Vector3::sign() const {
|
||||
return Vector3(SIGN(x), SIGN(y), SIGN(z));
|
||||
return Vector3(Math::sign(x), Math::sign(y), Math::sign(z));
|
||||
}
|
||||
|
||||
Vector3 Vector3::floor() const {
|
||||
|
|
|
@ -72,19 +72,19 @@ struct _NO_DISCARD_ Vector3i {
|
|||
Vector3i::Axis max_axis_index() const;
|
||||
|
||||
Vector3i min(const Vector3i &p_vector3i) const {
|
||||
return Vector3i(MIN(x, p_vector3i.x), MIN(y, p_vector3i.y), MIN(z, p_vector3i.z));
|
||||
return Vector3i(Math::min(x, p_vector3i.x), Math::min(y, p_vector3i.y), Math::min(z, p_vector3i.z));
|
||||
}
|
||||
|
||||
Vector3i mini(int32_t p_scalar) const {
|
||||
return Vector3i(MIN(x, p_scalar), MIN(y, p_scalar), MIN(z, p_scalar));
|
||||
return Vector3i(Math::min(x, p_scalar), Math::min(y, p_scalar), Math::min(z, p_scalar));
|
||||
}
|
||||
|
||||
Vector3i max(const Vector3i &p_vector3i) const {
|
||||
return Vector3i(MAX(x, p_vector3i.x), MAX(y, p_vector3i.y), MAX(z, p_vector3i.z));
|
||||
return Vector3i(Math::max(x, p_vector3i.x), Math::max(y, p_vector3i.y), Math::max(z, p_vector3i.z));
|
||||
}
|
||||
|
||||
Vector3i maxi(int32_t p_scalar) const {
|
||||
return Vector3i(MAX(x, p_scalar), MAX(y, p_scalar), MAX(z, p_scalar));
|
||||
return Vector3i(Math::max(x, p_scalar), Math::max(y, p_scalar), Math::max(z, p_scalar));
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ int64_t length_squared() const;
|
||||
|
@ -163,7 +163,7 @@ Vector3i Vector3i::abs() const {
|
|||
}
|
||||
|
||||
Vector3i Vector3i::sign() const {
|
||||
return Vector3i(SIGN(x), SIGN(y), SIGN(z));
|
||||
return Vector3i(Math::sign(x), Math::sign(y), Math::sign(z));
|
||||
}
|
||||
|
||||
/* Operators */
|
||||
|
|
|
@ -71,19 +71,19 @@ struct _NO_DISCARD_ Vector4 {
|
|||
Vector4::Axis max_axis_index() const;
|
||||
|
||||
Vector4 min(const Vector4 &p_vector4) const {
|
||||
return Vector4(MIN(x, p_vector4.x), MIN(y, p_vector4.y), MIN(z, p_vector4.z), MIN(w, p_vector4.w));
|
||||
return Vector4(Math::min(x, p_vector4.x), Math::min(y, p_vector4.y), Math::min(z, p_vector4.z), Math::min(w, p_vector4.w));
|
||||
}
|
||||
|
||||
Vector4 minf(real_t p_scalar) const {
|
||||
return Vector4(MIN(x, p_scalar), MIN(y, p_scalar), MIN(z, p_scalar), MIN(w, p_scalar));
|
||||
return Vector4(Math::min(x, p_scalar), Math::min(y, p_scalar), Math::min(z, p_scalar), Math::min(w, p_scalar));
|
||||
}
|
||||
|
||||
Vector4 max(const Vector4 &p_vector4) const {
|
||||
return Vector4(MAX(x, p_vector4.x), MAX(y, p_vector4.y), MAX(z, p_vector4.z), MAX(w, p_vector4.w));
|
||||
return Vector4(Math::max(x, p_vector4.x), Math::max(y, p_vector4.y), Math::max(z, p_vector4.z), Math::max(w, p_vector4.w));
|
||||
}
|
||||
|
||||
Vector4 maxf(real_t p_scalar) const {
|
||||
return Vector4(MAX(x, p_scalar), MAX(y, p_scalar), MAX(z, p_scalar), MAX(w, p_scalar));
|
||||
return Vector4(Math::max(x, p_scalar), Math::max(y, p_scalar), Math::max(z, p_scalar), Math::max(w, p_scalar));
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ real_t length_squared() const;
|
||||
|
|
|
@ -74,19 +74,19 @@ struct _NO_DISCARD_ Vector4i {
|
|||
Vector4i::Axis max_axis_index() const;
|
||||
|
||||
Vector4i min(const Vector4i &p_vector4i) const {
|
||||
return Vector4i(MIN(x, p_vector4i.x), MIN(y, p_vector4i.y), MIN(z, p_vector4i.z), MIN(w, p_vector4i.w));
|
||||
return Vector4i(Math::min(x, p_vector4i.x), Math::min(y, p_vector4i.y), Math::min(z, p_vector4i.z), Math::min(w, p_vector4i.w));
|
||||
}
|
||||
|
||||
Vector4i mini(int32_t p_scalar) const {
|
||||
return Vector4i(MIN(x, p_scalar), MIN(y, p_scalar), MIN(z, p_scalar), MIN(w, p_scalar));
|
||||
return Vector4i(Math::min(x, p_scalar), Math::min(y, p_scalar), Math::min(z, p_scalar), Math::min(w, p_scalar));
|
||||
}
|
||||
|
||||
Vector4i max(const Vector4i &p_vector4i) const {
|
||||
return Vector4i(MAX(x, p_vector4i.x), MAX(y, p_vector4i.y), MAX(z, p_vector4i.z), MAX(w, p_vector4i.w));
|
||||
return Vector4i(Math::max(x, p_vector4i.x), Math::max(y, p_vector4i.y), Math::max(z, p_vector4i.z), Math::max(w, p_vector4i.w));
|
||||
}
|
||||
|
||||
Vector4i maxi(int32_t p_scalar) const {
|
||||
return Vector4i(MAX(x, p_scalar), MAX(y, p_scalar), MAX(z, p_scalar), MAX(w, p_scalar));
|
||||
return Vector4i(Math::max(x, p_scalar), Math::max(y, p_scalar), Math::max(z, p_scalar), Math::max(w, p_scalar));
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ int64_t length_squared() const;
|
||||
|
|
|
@ -292,7 +292,7 @@ Vector3 Basis::get_scale_abs() const {
|
|||
}
|
||||
|
||||
Vector3 Basis::get_scale_local() const {
|
||||
real_t det_sign = SIGN(determinant());
|
||||
real_t det_sign = Math::sign(determinant());
|
||||
return det_sign * Vector3(rows[0].length(), rows[1].length(), rows[2].length());
|
||||
}
|
||||
|
||||
|
@ -318,7 +318,7 @@ Vector3 Basis::get_scale() const {
|
|||
// matrix elements.
|
||||
//
|
||||
// The rotation part of this decomposition is returned by get_rotation* functions.
|
||||
real_t det_sign = SIGN(determinant());
|
||||
real_t det_sign = Math::sign(determinant());
|
||||
return det_sign * get_scale_abs();
|
||||
}
|
||||
|
||||
|
@ -416,7 +416,7 @@ void Basis::rotate_to_align(Vector3 p_start_direction, Vector3 p_end_direction)
|
|||
const Vector3 axis = p_start_direction.cross(p_end_direction).normalized();
|
||||
if (axis.length_squared() != 0) {
|
||||
real_t dot = p_start_direction.dot(p_end_direction);
|
||||
dot = CLAMP(dot, -1.0f, 1.0f);
|
||||
dot = Math::clamp<real_t>(dot, -1, 1);
|
||||
const real_t angle_rads = Math::acos(dot);
|
||||
set_axis_angle(axis, angle_rads);
|
||||
}
|
||||
|
@ -829,7 +829,7 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const {
|
|||
|
||||
r_axis = Vector3(x, y, z);
|
||||
// CLAMP to avoid NaN if the value passed to acos is not in [0,1].
|
||||
r_angle = Math::acos(CLAMP((rows[0][0] + rows[1][1] + rows[2][2] - 1) / 2, (real_t)0.0, (real_t)1.0));
|
||||
r_angle = Math::acos(Math::clamp((rows[0][0] + rows[1][1] + rows[2][2] - 1) / 2, (real_t)0.0, (real_t)1.0));
|
||||
}
|
||||
|
||||
void Basis::set_quaternion(const Quaternion &p_quaternion) {
|
||||
|
|
|
@ -109,7 +109,7 @@ uint64_t Color::to_rgba64() const {
|
|||
|
||||
String _to_hex(float p_val) {
|
||||
int v = Math::round(p_val * 255.0f);
|
||||
v = CLAMP(v, 0, 255);
|
||||
v = Math::clamp(v, 0, 255);
|
||||
String ret;
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
|
@ -246,10 +246,10 @@ bool Color::is_equal_approx(const Color &p_color) const {
|
|||
|
||||
Color Color::clamp(const Color &p_min, const Color &p_max) const {
|
||||
return Color(
|
||||
CLAMP(r, p_min.r, p_max.r),
|
||||
CLAMP(g, p_min.g, p_max.g),
|
||||
CLAMP(b, p_min.b, p_max.b),
|
||||
CLAMP(a, p_min.a, p_max.a));
|
||||
Math::clamp(r, p_min.r, p_max.r),
|
||||
Math::clamp(g, p_min.g, p_max.g),
|
||||
Math::clamp(b, p_min.b, p_max.b),
|
||||
Math::clamp(a, p_min.a, p_max.a));
|
||||
}
|
||||
|
||||
void Color::invert() {
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace godot {
|
|||
|
||||
real_t Quaternion::angle_to(const Quaternion &p_to) const {
|
||||
real_t d = dot(p_to);
|
||||
return Math::acos(CLAMP(d * d * 2 - 1, -1, 1));
|
||||
return Math::acos(Math::clamp<real_t>(d * d * 2 - 1, -1, 1));
|
||||
}
|
||||
|
||||
// get_euler_xyz returns a vector containing the Euler angles in the format
|
||||
|
|
|
@ -73,12 +73,12 @@ void Transform2D::rotate(const real_t p_angle) {
|
|||
|
||||
real_t Transform2D::get_skew() const {
|
||||
real_t det = basis_determinant();
|
||||
return Math::acos(columns[0].normalized().dot(SIGN(det) * columns[1].normalized())) - (real_t)Math_PI * 0.5f;
|
||||
return Math::acos(columns[0].normalized().dot(Math::sign(det) * columns[1].normalized())) - (real_t)Math_PI * 0.5f;
|
||||
}
|
||||
|
||||
void Transform2D::set_skew(const real_t p_angle) {
|
||||
real_t det = basis_determinant();
|
||||
columns[1] = SIGN(det) * columns[0].rotated(((real_t)Math_PI * 0.5f + p_angle)).normalized() * columns[1].length();
|
||||
columns[1] = Math::sign(det) * columns[0].rotated(((real_t)Math_PI * 0.5f + p_angle)).normalized() * columns[1].length();
|
||||
}
|
||||
|
||||
real_t Transform2D::get_rotation() const {
|
||||
|
|
|
@ -96,7 +96,7 @@ real_t Vector2::cross(const Vector2 &p_other) const {
|
|||
}
|
||||
|
||||
Vector2 Vector2::sign() const {
|
||||
return Vector2(SIGN(x), SIGN(y));
|
||||
return Vector2(Math::sign(x), Math::sign(y));
|
||||
}
|
||||
|
||||
Vector2 Vector2::floor() const {
|
||||
|
@ -133,14 +133,14 @@ Vector2 Vector2::project(const Vector2 &p_to) const {
|
|||
|
||||
Vector2 Vector2::clamp(const Vector2 &p_min, const Vector2 &p_max) const {
|
||||
return Vector2(
|
||||
CLAMP(x, p_min.x, p_max.x),
|
||||
CLAMP(y, p_min.y, p_max.y));
|
||||
Math::clamp(x, p_min.x, p_max.x),
|
||||
Math::clamp(y, p_min.y, p_max.y));
|
||||
}
|
||||
|
||||
Vector2 Vector2::clampf(real_t p_min, real_t p_max) const {
|
||||
return Vector2(
|
||||
CLAMP(x, p_min, p_max),
|
||||
CLAMP(y, p_min, p_max));
|
||||
Math::clamp(x, p_min, p_max),
|
||||
Math::clamp(y, p_min, p_max));
|
||||
}
|
||||
|
||||
Vector2 Vector2::snapped(const Vector2 &p_step) const {
|
||||
|
|
|
@ -49,14 +49,14 @@ Vector2i Vector2i::snappedi(int32_t p_step) const {
|
|||
|
||||
Vector2i Vector2i::clamp(const Vector2i &p_min, const Vector2i &p_max) const {
|
||||
return Vector2i(
|
||||
CLAMP(x, p_min.x, p_max.x),
|
||||
CLAMP(y, p_min.y, p_max.y));
|
||||
Math::clamp(x, p_min.x, p_max.x),
|
||||
Math::clamp(y, p_min.y, p_max.y));
|
||||
}
|
||||
|
||||
Vector2i Vector2i::clampi(int32_t p_min, int32_t p_max) const {
|
||||
return Vector2i(
|
||||
CLAMP(x, p_min, p_max),
|
||||
CLAMP(y, p_min, p_max));
|
||||
Math::clamp(x, p_min, p_max),
|
||||
Math::clamp(y, p_min, p_max));
|
||||
}
|
||||
|
||||
int64_t Vector2i::length_squared() const {
|
||||
|
|
|
@ -49,16 +49,16 @@ Vector3 Vector3::rotated(const Vector3 &p_axis, const real_t p_angle) const {
|
|||
|
||||
Vector3 Vector3::clamp(const Vector3 &p_min, const Vector3 &p_max) const {
|
||||
return Vector3(
|
||||
CLAMP(x, p_min.x, p_max.x),
|
||||
CLAMP(y, p_min.y, p_max.y),
|
||||
CLAMP(z, p_min.z, p_max.z));
|
||||
Math::clamp(x, p_min.x, p_max.x),
|
||||
Math::clamp(y, p_min.y, p_max.y),
|
||||
Math::clamp(z, p_min.z, p_max.z));
|
||||
}
|
||||
|
||||
Vector3 Vector3::clampf(real_t p_min, real_t p_max) const {
|
||||
return Vector3(
|
||||
CLAMP(x, p_min, p_max),
|
||||
CLAMP(y, p_min, p_max),
|
||||
CLAMP(z, p_min, p_max));
|
||||
Math::clamp(x, p_min, p_max),
|
||||
Math::clamp(y, p_min, p_max),
|
||||
Math::clamp(z, p_min, p_max));
|
||||
}
|
||||
|
||||
void Vector3::snap(const Vector3 p_step) {
|
||||
|
@ -122,7 +122,7 @@ Vector2 Vector3::octahedron_encode() const {
|
|||
Vector3 Vector3::octahedron_decode(const Vector2 &p_oct) {
|
||||
Vector2 f(p_oct.x * 2.0f - 1.0f, p_oct.y * 2.0f - 1.0f);
|
||||
Vector3 n(f.x, f.y, 1.0f - Math::abs(f.x) - Math::abs(f.y));
|
||||
float t = CLAMP(-n.z, 0.0f, 1.0f);
|
||||
float t = Math::clamp<real_t>(-n.z, 0, 1);
|
||||
n.x += n.x >= 0 ? -t : t;
|
||||
n.y += n.y >= 0 ? -t : t;
|
||||
return n.normalized();
|
||||
|
|
|
@ -59,16 +59,16 @@ Vector3i::Axis Vector3i::max_axis_index() const {
|
|||
|
||||
Vector3i Vector3i::clamp(const Vector3i &p_min, const Vector3i &p_max) const {
|
||||
return Vector3i(
|
||||
CLAMP(x, p_min.x, p_max.x),
|
||||
CLAMP(y, p_min.y, p_max.y),
|
||||
CLAMP(z, p_min.z, p_max.z));
|
||||
Math::clamp(x, p_min.x, p_max.x),
|
||||
Math::clamp(y, p_min.y, p_max.y),
|
||||
Math::clamp(z, p_min.z, p_max.z));
|
||||
}
|
||||
|
||||
Vector3i Vector3i::clampi(int32_t p_min, int32_t p_max) const {
|
||||
return Vector3i(
|
||||
CLAMP(x, p_min, p_max),
|
||||
CLAMP(y, p_min, p_max),
|
||||
CLAMP(z, p_min, p_max));
|
||||
Math::clamp(x, p_min, p_max),
|
||||
Math::clamp(y, p_min, p_max),
|
||||
Math::clamp(z, p_min, p_max));
|
||||
}
|
||||
|
||||
Vector3i::operator String() const {
|
||||
|
|
|
@ -198,18 +198,18 @@ Vector4 Vector4::inverse() const {
|
|||
|
||||
Vector4 Vector4::clamp(const Vector4 &p_min, const Vector4 &p_max) const {
|
||||
return Vector4(
|
||||
CLAMP(x, p_min.x, p_max.x),
|
||||
CLAMP(y, p_min.y, p_max.y),
|
||||
CLAMP(z, p_min.z, p_max.z),
|
||||
CLAMP(w, p_min.w, p_max.w));
|
||||
Math::clamp(x, p_min.x, p_max.x),
|
||||
Math::clamp(y, p_min.y, p_max.y),
|
||||
Math::clamp(z, p_min.z, p_max.z),
|
||||
Math::clamp(w, p_min.w, p_max.w));
|
||||
}
|
||||
|
||||
Vector4 Vector4::clampf(real_t p_min, real_t p_max) const {
|
||||
return Vector4(
|
||||
CLAMP(x, p_min, p_max),
|
||||
CLAMP(y, p_min, p_max),
|
||||
CLAMP(z, p_min, p_max),
|
||||
CLAMP(w, p_min, p_max));
|
||||
Math::clamp(x, p_min, p_max),
|
||||
Math::clamp(y, p_min, p_max),
|
||||
Math::clamp(z, p_min, p_max),
|
||||
Math::clamp(w, p_min, p_max));
|
||||
}
|
||||
|
||||
Vector4::operator String() const {
|
||||
|
|
|
@ -77,18 +77,18 @@ Vector4i::Axis Vector4i::max_axis_index() const {
|
|||
|
||||
Vector4i Vector4i::clamp(const Vector4i &p_min, const Vector4i &p_max) const {
|
||||
return Vector4i(
|
||||
CLAMP(x, p_min.x, p_max.x),
|
||||
CLAMP(y, p_min.y, p_max.y),
|
||||
CLAMP(z, p_min.z, p_max.z),
|
||||
CLAMP(w, p_min.w, p_max.w));
|
||||
Math::clamp(x, p_min.x, p_max.x),
|
||||
Math::clamp(y, p_min.y, p_max.y),
|
||||
Math::clamp(z, p_min.z, p_max.z),
|
||||
Math::clamp(w, p_min.w, p_max.w));
|
||||
}
|
||||
|
||||
Vector4i Vector4i::clampi(int32_t p_min, int32_t p_max) const {
|
||||
return Vector4i(
|
||||
CLAMP(x, p_min, p_max),
|
||||
CLAMP(y, p_min, p_max),
|
||||
CLAMP(z, p_min, p_max),
|
||||
CLAMP(w, p_min, p_max));
|
||||
Math::clamp(x, p_min, p_max),
|
||||
Math::clamp(y, p_min, p_max),
|
||||
Math::clamp(z, p_min, p_max),
|
||||
Math::clamp(w, p_min, p_max));
|
||||
}
|
||||
|
||||
Vector4i::operator String() const {
|
||||
|
|
Loading…
Reference in New Issue