Use the built in macros.

This commit is contained in:
Relintai 2023-10-23 18:03:01 +02:00
parent 3e2e07a056
commit e1f7662027
9 changed files with 17 additions and 31 deletions

View File

@ -346,7 +346,7 @@ bool AABB::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *
c2[i] = (end[i] - p_from[i]) / p_dir[i]; c2[i] = (end[i] - p_from[i]) / p_dir[i];
if (c1[i] > c2[i]) { if (c1[i] > c2[i]) {
std::swap(c1, c2); SWAP(c1, c2);
} }
if (c1[i] > near) { if (c1[i] > near) {
near = c1[i]; near = c1[i];

View File

@ -106,9 +106,9 @@ bool Basis::is_rotation() const {
} }
void Basis::transpose() { void Basis::transpose() {
std::swap(elements[0][1], elements[1][0]); SWAP(elements[0][1], elements[1][0]);
std::swap(elements[0][2], elements[2][0]); SWAP(elements[0][2], elements[2][0]);
std::swap(elements[1][2], elements[2][1]); SWAP(elements[1][2], elements[2][1]);
} }
Basis Basis::inverse() const { Basis Basis::inverse() const {

View File

@ -195,11 +195,11 @@ inline bool is_equal_approx(real_t a, real_t b) {
return true; return true;
} }
// Then check for approximate equality. // Then check for approximate equality.
real_t tolerance = CMP_EPSILON * std::abs(a); real_t tolerance = CMP_EPSILON * ABS(a);
if (tolerance < CMP_EPSILON) { if (tolerance < CMP_EPSILON) {
tolerance = CMP_EPSILON; tolerance = CMP_EPSILON;
} }
return std::abs(a - b) < tolerance; return ABS(a - b) < tolerance;
} }
inline bool is_equal_approx(real_t a, real_t b, real_t tolerance) { inline bool is_equal_approx(real_t a, real_t b, real_t tolerance) {
@ -208,11 +208,11 @@ inline bool is_equal_approx(real_t a, real_t b, real_t tolerance) {
return true; return true;
} }
// Then check for approximate equality. // Then check for approximate equality.
return std::abs(a - b) < tolerance; return ABS(a - b) < tolerance;
} }
inline bool is_zero_approx(real_t s) { inline bool is_zero_approx(real_t s) {
return std::abs(s) < CMP_EPSILON; return ABS(s) < CMP_EPSILON;
} }
inline double smoothstep(double p_from, double p_to, double p_weight) { inline double smoothstep(double p_from, double p_to, double p_weight) {
@ -231,11 +231,11 @@ inline float smoothstep(float p_from, float p_to, float p_weight) {
} }
inline double move_toward(double p_from, double p_to, double p_delta) { inline double move_toward(double p_from, double p_to, double p_delta) {
return std::abs(p_to - p_from) <= p_delta ? p_to : p_from + sign(p_to - p_from) * p_delta; return ABS(p_to - p_from) <= p_delta ? p_to : p_from + sign(p_to - p_from) * p_delta;
} }
inline float move_toward(float p_from, float p_to, float p_delta) { inline float move_toward(float p_from, float p_to, float p_delta) {
return std::abs(p_to - p_from) <= p_delta ? p_to : p_from + sign(p_to - p_from) * p_delta; return ABS(p_to - p_from) <= p_delta ? p_to : p_from + sign(p_to - p_from) * p_delta;
} }
inline double linear2db(double p_linear) { inline double linear2db(double p_linear) {

View File

@ -561,7 +561,7 @@ real_t Projection::get_fov() const {
right_plane.normalize(); right_plane.normalize();
if ((matrix[8] == 0) && (matrix[9] == 0)) { if ((matrix[8] == 0) && (matrix[9] == 0)) {
return Mathp::rad2deg(acos(std::abs(right_plane.normal.x))) * 2.0; return Mathp::rad2deg(acos(ABS(right_plane.normal.x))) * 2.0;
} else { } else {
// our frustum is asymmetrical need to calculate the left planes angle separately.. // our frustum is asymmetrical need to calculate the left planes angle separately..
Plane left_plane = Plane(matrix[3] + matrix[0], Plane left_plane = Plane(matrix[3] + matrix[0],
@ -570,7 +570,7 @@ real_t Projection::get_fov() const {
matrix[15] + matrix[12]); matrix[15] + matrix[12]);
left_plane.normalize(); left_plane.normalize();
return Mathp::rad2deg(acos(std::abs(left_plane.normal.x))) + Mathp::rad2deg(acos(std::abs(right_plane.normal.x))); return Mathp::rad2deg(acos(ABS(left_plane.normal.x))) + Mathp::rad2deg(acos(ABS(right_plane.normal.x)));
} }
} }

View File

@ -39,10 +39,6 @@
#include <vector> #include <vector>
namespace {
} // namespace
struct Projection { struct Projection {
enum Planes { enum Planes {
PLANE_NEAR, PLANE_NEAR,

View File

@ -122,7 +122,7 @@ Quaternion Quaternion::normalized() const {
} }
bool Quaternion::is_normalized() const { bool Quaternion::is_normalized() const {
return std::abs(length_squared() - 1.0) < 0.00001; return ABS(length_squared() - 1.0) < 0.00001;
} }
Quaternion Quaternion::inverse() const { Quaternion Quaternion::inverse() const {

View File

@ -35,10 +35,6 @@
#include "vector3.h" #include "vector3.h"
// #include "basis.h"
class Quaternion { class Quaternion {
public: public:
static const Quaternion IDENTITY; static const Quaternion IDENTITY;
@ -120,6 +116,4 @@ public:
} }
}; };
#endif // QUAT_H #endif // QUAT_H

View File

@ -115,7 +115,7 @@ Rect2 Transform2D::xform_inv(const Rect2 &p_rect) const {
void Transform2D::invert() { void Transform2D::invert() {
// FIXME: this function assumes the basis is a rotation matrix, with no scaling. // FIXME: this function assumes the basis is a rotation matrix, with no scaling.
// Transform2D::affine_inverse can handle matrices with scaling, so GDScript should eventually use that. // Transform2D::affine_inverse can handle matrices with scaling, so GDScript should eventually use that.
std::swap(elements[0][1], elements[1][0]); SWAP(elements[0][1], elements[1][0]);
elements[2] = basis_xform(-elements[2]); elements[2] = basis_xform(-elements[2]);
} }
@ -130,7 +130,7 @@ void Transform2D::affine_invert() {
ERR_FAIL_COND(det == 0); ERR_FAIL_COND(det == 0);
real_t idet = 1.0 / det; real_t idet = 1.0 / det;
std::swap(elements[0][0], elements[1][1]); SWAP(elements[0][0], elements[1][1]);
elements[0] *= Vector2(idet, -idet); elements[0] *= Vector2(idet, -idet);
elements[1] *= Vector2(-idet, idet); elements[1] *= Vector2(-idet, idet);

View File

@ -37,8 +37,6 @@
#include <math_funcs.h> #include <math_funcs.h>
class Basis; class Basis;
class String; class String;
@ -257,7 +255,7 @@ struct Vector3 {
} }
inline real_t angle_to(const Vector3 &b) const { inline real_t angle_to(const Vector3 &b) const {
return std::atan2(cross(b).length(), dot(b)); return Mathp::atan2(cross(b).length(), dot(b));
} }
inline Vector3 direction_to(const Vector3 &p_b) const { inline Vector3 direction_to(const Vector3 &p_b) const {
@ -275,7 +273,7 @@ struct Vector3 {
} }
inline bool is_normalized() const { inline bool is_normalized() const {
return std::abs(length_squared() - 1.f) < 0.00001f; return ABS(length_squared() - 1.f) < 0.00001f;
} }
Basis outer(const Vector3 &b) const; Basis outer(const Vector3 &b) const;
@ -336,6 +334,4 @@ inline Vector3 vec3_cross(const Vector3 &p_a, const Vector3 &p_b) {
return p_a.cross(p_b); return p_a.cross(p_b);
} }
#endif // VECTOR3_H #endif // VECTOR3_H