Core: Use Math namespace for constants

This commit is contained in:
Thaddeus Crews 2025-04-10 11:21:05 -05:00
parent 06c71fbf40
commit 94282d88f9
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
181 changed files with 812 additions and 818 deletions

View file

@ -461,7 +461,7 @@ TEST_CASE("[AABB] Expanding") {
TEST_CASE("[AABB] Finite number checks") {
constexpr Vector3 x(0, 1, 2);
const Vector3 infinite(NAN, NAN, NAN);
constexpr Vector3 infinite(Math::NaN, Math::NaN, Math::NaN);
CHECK_MESSAGE(
AABB(x, x).is_finite(),

View file

@ -280,7 +280,7 @@ TEST_CASE("[Stress][AStar3D] Find paths") {
float d[N][N];
for (int u = 0; u < N; u++) {
for (int v = 0; v < N; v++) {
d[u][v] = (u == v || adj[u][v]) ? p[u].distance_to(p[v]) : INFINITY;
d[u][v] = (u == v || adj[u][v]) ? p[u].distance_to(p[v]) : Math::INF;
}
}
for (int w = 0; w < N; w++) {

View file

@ -38,11 +38,11 @@
namespace TestBasis {
Vector3 deg_to_rad(const Vector3 &p_rotation) {
return p_rotation / 180.0 * Math_PI;
return p_rotation / 180.0 * Math::PI;
}
Vector3 rad2deg(const Vector3 &p_rotation) {
return p_rotation / Math_PI * 180.0;
return p_rotation / Math::PI * 180.0;
}
String get_rot_order_name(EulerOrder ro) {
@ -218,7 +218,7 @@ TEST_CASE("[Stress][Basis] Euler conversions") {
TEST_CASE("[Basis] Set axis angle") {
Vector3 axis;
real_t angle;
real_t pi = (real_t)Math_PI;
real_t pi = (real_t)Math::PI;
// Testing the singularity when the angle is 0°.
Basis identity(1, 0, 0, 0, 1, 0, 0, 0, 1);
@ -270,7 +270,7 @@ TEST_CASE("[Basis] Set axis angle") {
TEST_CASE("[Basis] Finite number checks") {
constexpr Vector3 x(0, 1, 2);
const Vector3 infinite(NAN, NAN, NAN);
constexpr Vector3 infinite(Math::NaN, Math::NaN, Math::NaN);
CHECK_MESSAGE(
Basis(x, x, x).is_finite(),
@ -327,7 +327,7 @@ TEST_CASE("[Basis] Is conformal checks") {
"Basis with non-uniform scale should not be conformal.");
CHECK_FALSE_MESSAGE(
Basis(Vector3(Math_SQRT12, Math_SQRT12, 0), Vector3(0, 1, 0), Vector3(0, 0, 1)).is_conformal(),
Basis(Vector3(Math::SQRT12, Math::SQRT12, 0), Vector3(0, 1, 0), Vector3(0, 0, 1)).is_conformal(),
"Basis with the X axis skewed 45 degrees should not be conformal.");
CHECK_MESSAGE(
@ -357,7 +357,7 @@ TEST_CASE("[Basis] Is orthogonal checks") {
"Basis with a flip, rotation, and uniform scale should be orthogonal.");
CHECK_FALSE_MESSAGE(
Basis(Vector3(Math_SQRT12, Math_SQRT12, 0), Vector3(0, 1, 0), Vector3(0, 0, 1)).is_orthogonal(),
Basis(Vector3(Math::SQRT12, Math::SQRT12, 0), Vector3(0, 1, 0), Vector3(0, 0, 1)).is_orthogonal(),
"Basis with the X axis skewed 45 degrees should not be orthogonal.");
CHECK_MESSAGE(
@ -387,7 +387,7 @@ TEST_CASE("[Basis] Is orthonormal checks") {
"Basis with a flip, rotation, and uniform scale should not be orthonormal.");
CHECK_FALSE_MESSAGE(
Basis(Vector3(Math_SQRT12, Math_SQRT12, 0), Vector3(0, 1, 0), Vector3(0, 0, 1)).is_orthonormal(),
Basis(Vector3(Math::SQRT12, Math::SQRT12, 0), Vector3(0, 1, 0), Vector3(0, 0, 1)).is_orthonormal(),
"Basis with the X axis skewed 45 degrees should not be orthonormal.");
CHECK_FALSE_MESSAGE(
@ -417,7 +417,7 @@ TEST_CASE("[Basis] Is rotation checks") {
"Basis with a squeeze should not be a rotation.");
CHECK_FALSE_MESSAGE(
Basis(Vector3(Math_SQRT12, Math_SQRT12, 0), Vector3(0, 1, 0), Vector3(0, 0, 1)).is_rotation(),
Basis(Vector3(Math::SQRT12, Math::SQRT12, 0), Vector3(0, 1, 0), Vector3(0, 0, 1)).is_rotation(),
"Basis with the X axis skewed 45 degrees should not be a rotation.");
CHECK_FALSE_MESSAGE(

View file

@ -53,8 +53,8 @@ TEST_CASE("[Math] C++ macros") {
CHECK(SIGN(-5) == -1.0);
CHECK(SIGN(0) == 0.0);
CHECK(SIGN(5) == 1.0);
// Check that SIGN(NAN) returns 0.0.
CHECK(SIGN(NAN) == 0.0);
// Check that SIGN(Math::NaN) returns 0.0.
CHECK(SIGN(Math::NaN) == 0.0);
}
TEST_CASE("[Math] Power of two functions") {
@ -189,7 +189,7 @@ TEST_CASE_TEMPLATE("[Math] asin/acos/atan", T, float, double) {
CHECK(Math::acos((T)0.5) == doctest::Approx((T)1.0471975512));
CHECK(Math::acos((T)1.0) == doctest::Approx((T)0.0));
CHECK(Math::acos((T)2.0) == doctest::Approx((T)0.0));
CHECK(Math::acos((T)-2.0) == doctest::Approx((T)Math_PI));
CHECK(Math::acos((T)-2.0) == doctest::Approx((T)Math::PI));
CHECK(Math::atan((T)-0.1) == doctest::Approx((T)-0.0996686525));
CHECK(Math::atan((T)0.1) == doctest::Approx((T)0.0996686525));
@ -291,10 +291,10 @@ TEST_CASE_TEMPLATE("[Math] pow/log/log2/exp/sqrt", T, float, double) {
TEST_CASE_TEMPLATE("[Math] is_nan/is_inf", T, float, double) {
CHECK(!Math::is_nan((T)0.0));
CHECK(Math::is_nan((T)NAN));
CHECK(Math::is_nan((T)Math::NaN));
CHECK(!Math::is_inf((T)0.0));
CHECK(Math::is_inf((T)INFINITY));
CHECK(Math::is_inf((T)Math::INF));
}
TEST_CASE_TEMPLATE("[Math] linear_to_db", T, float, double) {
@ -387,15 +387,15 @@ TEST_CASE_TEMPLATE("[Math] remap", T, float, double) {
TEST_CASE_TEMPLATE("[Math] angle_difference", T, float, double) {
// Loops around, should return 0.0.
CHECK(Math::angle_difference((T)0.0, (T)Math_TAU) == doctest::Approx((T)0.0));
CHECK(Math::angle_difference((T)Math_PI, (T)-Math_PI) == doctest::Approx((T)0.0));
CHECK(Math::angle_difference((T)0.0, (T)Math_TAU * (T)4.0) == doctest::Approx((T)0.0));
CHECK(Math::angle_difference((T)0.0, (T)Math::TAU) == doctest::Approx((T)0.0));
CHECK(Math::angle_difference((T)Math::PI, (T)-Math::PI) == doctest::Approx((T)0.0));
CHECK(Math::angle_difference((T)0.0, (T)Math::TAU * (T)4.0) == doctest::Approx((T)0.0));
// Rotation is clockwise, so it should return -PI.
CHECK(Math::angle_difference((T)0.0, (T)Math_PI) == doctest::Approx((T)-Math_PI));
CHECK(Math::angle_difference((T)0.0, (T)-Math_PI) == doctest::Approx((T)Math_PI));
CHECK(Math::angle_difference((T)Math_PI, (T)0.0) == doctest::Approx((T)Math_PI));
CHECK(Math::angle_difference((T)-Math_PI, (T)0.0) == doctest::Approx((T)-Math_PI));
CHECK(Math::angle_difference((T)0.0, (T)Math::PI) == doctest::Approx((T)-Math::PI));
CHECK(Math::angle_difference((T)0.0, (T)-Math::PI) == doctest::Approx((T)Math::PI));
CHECK(Math::angle_difference((T)Math::PI, (T)0.0) == doctest::Approx((T)Math::PI));
CHECK(Math::angle_difference((T)-Math::PI, (T)0.0) == doctest::Approx((T)-Math::PI));
CHECK(Math::angle_difference((T)0.0, (T)3.0) == doctest::Approx((T)3.0));
CHECK(Math::angle_difference((T)1.0, (T)-2.0) == doctest::Approx((T)-3.0));
@ -406,23 +406,23 @@ TEST_CASE_TEMPLATE("[Math] angle_difference", T, float, double) {
TEST_CASE_TEMPLATE("[Math] lerp_angle", T, float, double) {
// Counter-clockwise rotation.
CHECK(Math::lerp_angle((T)0.24 * Math_TAU, 0.75 * Math_TAU, 0.5) == doctest::Approx((T)-0.005 * Math_TAU));
CHECK(Math::lerp_angle((T)0.24 * Math::TAU, 0.75 * Math::TAU, 0.5) == doctest::Approx((T)-0.005 * Math::TAU));
// Counter-clockwise rotation.
CHECK(Math::lerp_angle((T)0.25 * Math_TAU, 0.75 * Math_TAU, 0.5) == doctest::Approx((T)0.0));
CHECK(Math::lerp_angle((T)0.25 * Math::TAU, 0.75 * Math::TAU, 0.5) == doctest::Approx((T)0.0));
// Clockwise rotation.
CHECK(Math::lerp_angle((T)0.26 * Math_TAU, 0.75 * Math_TAU, 0.5) == doctest::Approx((T)0.505 * Math_TAU));
CHECK(Math::lerp_angle((T)0.26 * Math::TAU, 0.75 * Math::TAU, 0.5) == doctest::Approx((T)0.505 * Math::TAU));
CHECK(Math::lerp_angle((T)-0.25 * Math_TAU, 1.25 * Math_TAU, 0.5) == doctest::Approx((T)-0.5 * Math_TAU));
CHECK(Math::lerp_angle((T)0.72 * Math_TAU, 1.44 * Math_TAU, 0.96) == doctest::Approx((T)0.4512 * Math_TAU));
CHECK(Math::lerp_angle((T)0.72 * Math_TAU, 1.44 * Math_TAU, 1.04) == doctest::Approx((T)0.4288 * Math_TAU));
CHECK(Math::lerp_angle((T)-0.25 * Math::TAU, 1.25 * Math::TAU, 0.5) == doctest::Approx((T)-0.5 * Math::TAU));
CHECK(Math::lerp_angle((T)0.72 * Math::TAU, 1.44 * Math::TAU, 0.96) == doctest::Approx((T)0.4512 * Math::TAU));
CHECK(Math::lerp_angle((T)0.72 * Math::TAU, 1.44 * Math::TAU, 1.04) == doctest::Approx((T)0.4288 * Math::TAU));
// Initial and final angles are effectively identical, so the value returned
// should always be the same regardless of the `weight` parameter.
CHECK(Math::lerp_angle((T)-4 * Math_TAU, 4 * Math_TAU, -1.0) == doctest::Approx((T)-4.0 * Math_TAU));
CHECK(Math::lerp_angle((T)-4 * Math_TAU, 4 * Math_TAU, 0.0) == doctest::Approx((T)-4.0 * Math_TAU));
CHECK(Math::lerp_angle((T)-4 * Math_TAU, 4 * Math_TAU, 0.5) == doctest::Approx((T)-4.0 * Math_TAU));
CHECK(Math::lerp_angle((T)-4 * Math_TAU, 4 * Math_TAU, 1.0) == doctest::Approx((T)-4.0 * Math_TAU));
CHECK(Math::lerp_angle((T)-4 * Math_TAU, 4 * Math_TAU, 500.0) == doctest::Approx((T)-4.0 * Math_TAU));
CHECK(Math::lerp_angle((T)-4 * Math::TAU, 4 * Math::TAU, -1.0) == doctest::Approx((T)-4.0 * Math::TAU));
CHECK(Math::lerp_angle((T)-4 * Math::TAU, 4 * Math::TAU, 0.0) == doctest::Approx((T)-4.0 * Math::TAU));
CHECK(Math::lerp_angle((T)-4 * Math::TAU, 4 * Math::TAU, 0.5) == doctest::Approx((T)-4.0 * Math::TAU));
CHECK(Math::lerp_angle((T)-4 * Math::TAU, 4 * Math::TAU, 1.0) == doctest::Approx((T)-4.0 * Math::TAU));
CHECK(Math::lerp_angle((T)-4 * Math::TAU, 4 * Math::TAU, 500.0) == doctest::Approx((T)-4.0 * Math::TAU));
}
TEST_CASE_TEMPLATE("[Math] move_toward", T, float, double) {
@ -436,16 +436,16 @@ TEST_CASE_TEMPLATE("[Math] move_toward", T, float, double) {
TEST_CASE_TEMPLATE("[Math] rotate_toward", T, float, double) {
// Rotate toward.
CHECK(Math::rotate_toward((T)0.0, (T)Math_PI * (T)0.75, (T)1.5) == doctest::Approx((T)1.5));
CHECK(Math::rotate_toward((T)0.0, (T)Math::PI * (T)0.75, (T)1.5) == doctest::Approx((T)1.5));
CHECK(Math::rotate_toward((T)-2.0, (T)1.0, (T)2.5) == doctest::Approx((T)0.5));
CHECK(Math::rotate_toward((T)-2.0, (T)Math_PI, (T)Math_PI) == doctest::Approx((T)-Math_PI));
CHECK(Math::rotate_toward((T)1.0, (T)Math_PI, (T)20.0) == doctest::Approx((T)Math_PI));
CHECK(Math::rotate_toward((T)-2.0, (T)Math::PI, (T)Math::PI) == doctest::Approx((T)-Math::PI));
CHECK(Math::rotate_toward((T)1.0, (T)Math::PI, (T)20.0) == doctest::Approx((T)Math::PI));
// Rotate away.
CHECK(Math::rotate_toward((T)0.0, (T)0.0, (T)-1.5) == doctest::Approx((T)-1.5));
CHECK(Math::rotate_toward((T)0.0, (T)0.0, (T)-Math_PI) == doctest::Approx((T)-Math_PI));
CHECK(Math::rotate_toward((T)3.0, (T)Math_PI, (T)-Math_PI) == doctest::Approx((T)0.0));
CHECK(Math::rotate_toward((T)2.0, (T)Math_PI, (T)-1.5) == doctest::Approx((T)0.5));
CHECK(Math::rotate_toward((T)0.0, (T)0.0, (T)-Math::PI) == doctest::Approx((T)-Math::PI));
CHECK(Math::rotate_toward((T)3.0, (T)Math::PI, (T)-Math::PI) == doctest::Approx((T)0.0));
CHECK(Math::rotate_toward((T)2.0, (T)Math::PI, (T)-1.5) == doctest::Approx((T)0.5));
CHECK(Math::rotate_toward((T)1.0, (T)2.0, (T)-0.5) == doctest::Approx((T)0.5));
CHECK(Math::rotate_toward((T)2.5, (T)2.0, (T)-0.5) == doctest::Approx((T)3.0));
CHECK(Math::rotate_toward((T)-1.0, (T)1.0, (T)-1.0) == doctest::Approx((T)-2.0));
@ -585,10 +585,10 @@ TEST_CASE_TEMPLATE("[Math] pingpong", T, float, double) {
}
TEST_CASE_TEMPLATE("[Math] deg_to_rad/rad_to_deg", T, float, double) {
CHECK(Math::deg_to_rad((T)180.0) == doctest::Approx((T)Math_PI));
CHECK(Math::deg_to_rad((T)180.0) == doctest::Approx((T)Math::PI));
CHECK(Math::deg_to_rad((T)-27.0) == doctest::Approx((T)-0.471239));
CHECK(Math::rad_to_deg((T)Math_PI) == doctest::Approx((T)180.0));
CHECK(Math::rad_to_deg((T)Math::PI) == doctest::Approx((T)180.0));
CHECK(Math::rad_to_deg((T)-1.5) == doctest::Approx((T)-85.94366927));
}
@ -607,11 +607,11 @@ TEST_CASE_TEMPLATE("[Math] cubic_interpolate", T, float, double) {
}
TEST_CASE_TEMPLATE("[Math] cubic_interpolate_angle", T, float, double) {
CHECK(Math::cubic_interpolate_angle((T)(Math_PI * (1.0 / 6.0)), (T)(Math_PI * (5.0 / 6.0)), (T)0.0, (T)Math_PI, (T)0.0) == doctest::Approx((T)Math_PI * (1.0 / 6.0)));
CHECK(Math::cubic_interpolate_angle((T)(Math_PI * (1.0 / 6.0)), (T)(Math_PI * (5.0 / 6.0)), (T)0.0, (T)Math_PI, (T)0.25) == doctest::Approx((T)0.973566));
CHECK(Math::cubic_interpolate_angle((T)(Math_PI * (1.0 / 6.0)), (T)(Math_PI * (5.0 / 6.0)), (T)0.0, (T)Math_PI, (T)0.5) == doctest::Approx((T)Math_PI / 2.0));
CHECK(Math::cubic_interpolate_angle((T)(Math_PI * (1.0 / 6.0)), (T)(Math_PI * (5.0 / 6.0)), (T)0.0, (T)Math_PI, (T)0.75) == doctest::Approx((T)2.16803));
CHECK(Math::cubic_interpolate_angle((T)(Math_PI * (1.0 / 6.0)), (T)(Math_PI * (5.0 / 6.0)), (T)0.0, (T)Math_PI, (T)1.0) == doctest::Approx((T)Math_PI * (5.0 / 6.0)));
CHECK(Math::cubic_interpolate_angle((T)(Math::PI * (1.0 / 6.0)), (T)(Math::PI * (5.0 / 6.0)), (T)0.0, (T)Math::PI, (T)0.0) == doctest::Approx((T)Math::PI * (1.0 / 6.0)));
CHECK(Math::cubic_interpolate_angle((T)(Math::PI * (1.0 / 6.0)), (T)(Math::PI * (5.0 / 6.0)), (T)0.0, (T)Math::PI, (T)0.25) == doctest::Approx((T)0.973566));
CHECK(Math::cubic_interpolate_angle((T)(Math::PI * (1.0 / 6.0)), (T)(Math::PI * (5.0 / 6.0)), (T)0.0, (T)Math::PI, (T)0.5) == doctest::Approx((T)Math::PI / 2.0));
CHECK(Math::cubic_interpolate_angle((T)(Math::PI * (1.0 / 6.0)), (T)(Math::PI * (5.0 / 6.0)), (T)0.0, (T)Math::PI, (T)0.75) == doctest::Approx((T)2.16803));
CHECK(Math::cubic_interpolate_angle((T)(Math::PI * (1.0 / 6.0)), (T)(Math::PI * (5.0 / 6.0)), (T)0.0, (T)Math::PI, (T)1.0) == doctest::Approx((T)Math::PI * (5.0 / 6.0)));
}
TEST_CASE_TEMPLATE("[Math] cubic_interpolate_in_time", T, float, double) {
@ -623,11 +623,11 @@ TEST_CASE_TEMPLATE("[Math] cubic_interpolate_in_time", T, float, double) {
}
TEST_CASE_TEMPLATE("[Math] cubic_interpolate_angle_in_time", T, float, double) {
CHECK(Math::cubic_interpolate_angle_in_time((T)(Math_PI * (1.0 / 6.0)), (T)(Math_PI * (5.0 / 6.0)), (T)0.0, (T)Math_PI, (T)0.0, (T)0.5, (T)0.0, (T)1.0) == doctest::Approx((T)0.0));
CHECK(Math::cubic_interpolate_angle_in_time((T)(Math_PI * (1.0 / 6.0)), (T)(Math_PI * (5.0 / 6.0)), (T)0.0, (T)Math_PI, (T)0.25, (T)0.5, (T)0.0, (T)1.0) == doctest::Approx((T)0.494964));
CHECK(Math::cubic_interpolate_angle_in_time((T)(Math_PI * (1.0 / 6.0)), (T)(Math_PI * (5.0 / 6.0)), (T)0.0, (T)Math_PI, (T)0.5, (T)0.5, (T)0.0, (T)1.0) == doctest::Approx((T)1.27627));
CHECK(Math::cubic_interpolate_angle_in_time((T)(Math_PI * (1.0 / 6.0)), (T)(Math_PI * (5.0 / 6.0)), (T)0.0, (T)Math_PI, (T)0.75, (T)0.5, (T)0.0, (T)1.0) == doctest::Approx((T)2.07394));
CHECK(Math::cubic_interpolate_angle_in_time((T)(Math_PI * (1.0 / 6.0)), (T)(Math_PI * (5.0 / 6.0)), (T)0.0, (T)Math_PI, (T)1.0, (T)0.5, (T)0.0, (T)1.0) == doctest::Approx((T)Math_PI * (5.0 / 6.0)));
CHECK(Math::cubic_interpolate_angle_in_time((T)(Math::PI * (1.0 / 6.0)), (T)(Math::PI * (5.0 / 6.0)), (T)0.0, (T)Math::PI, (T)0.0, (T)0.5, (T)0.0, (T)1.0) == doctest::Approx((T)0.0));
CHECK(Math::cubic_interpolate_angle_in_time((T)(Math::PI * (1.0 / 6.0)), (T)(Math::PI * (5.0 / 6.0)), (T)0.0, (T)Math::PI, (T)0.25, (T)0.5, (T)0.0, (T)1.0) == doctest::Approx((T)0.494964));
CHECK(Math::cubic_interpolate_angle_in_time((T)(Math::PI * (1.0 / 6.0)), (T)(Math::PI * (5.0 / 6.0)), (T)0.0, (T)Math::PI, (T)0.5, (T)0.5, (T)0.0, (T)1.0) == doctest::Approx((T)1.27627));
CHECK(Math::cubic_interpolate_angle_in_time((T)(Math::PI * (1.0 / 6.0)), (T)(Math::PI * (5.0 / 6.0)), (T)0.0, (T)Math::PI, (T)0.75, (T)0.5, (T)0.0, (T)1.0) == doctest::Approx((T)2.07394));
CHECK(Math::cubic_interpolate_angle_in_time((T)(Math::PI * (1.0 / 6.0)), (T)(Math::PI * (5.0 / 6.0)), (T)0.0, (T)Math::PI, (T)1.0, (T)0.5, (T)0.0, (T)1.0) == doctest::Approx((T)Math::PI * (5.0 / 6.0)));
}
TEST_CASE_TEMPLATE("[Math] bezier_interpolate", T, float, double) {

View file

@ -169,9 +169,9 @@ TEST_CASE("[Plane] Intersection") {
TEST_CASE("[Plane] Finite number checks") {
constexpr Vector3 x(0, 1, 2);
const Vector3 infinite_vec(NAN, NAN, NAN);
constexpr Vector3 infinite_vec(Math::NaN, Math::NaN, Math::NaN);
constexpr real_t y = 0;
const real_t infinite_y = NAN;
constexpr real_t infinite_y = Math::NaN;
CHECK_MESSAGE(
Plane(x, y).is_finite(),

View file

@ -411,21 +411,21 @@ TEST_CASE("[Stress][Quaternion] Many vector xforms") {
// For each trial, check that rotation by Quaternion yields same result as
// rotation by Basis.
constexpr int STEPS = 100; // Number of test steps in each dimension
constexpr double delta = 2.0 * Math_PI / STEPS; // Angle increment per step
constexpr double delta = 2.0 * Math::PI / STEPS; // Angle increment per step
constexpr double delta_vec = 20.0 / STEPS; // Vector increment per step
Vector3 vec_arb(1.0, 1.0, 1.0);
double x_angle = -Math_PI;
double y_angle = -Math_PI;
double z_angle = -Math_PI;
double x_angle = -Math::PI;
double y_angle = -Math::PI;
double z_angle = -Math::PI;
for (double i = 0; i < STEPS; ++i) {
vec_arb[0] = -10.0 + i * delta_vec;
x_angle = i * delta - Math_PI;
x_angle = i * delta - Math::PI;
for (double j = 0; j < STEPS; ++j) {
vec_arb[1] = -10.0 + j * delta_vec;
y_angle = j * delta - Math_PI;
y_angle = j * delta - Math::PI;
for (double k = 0; k < STEPS; ++k) {
vec_arb[2] = -10.0 + k * delta_vec;
z_angle = k * delta - Math_PI;
z_angle = k * delta - Math::PI;
Vector3 euler_yzx(x_angle, y_angle, z_angle);
test_quat_vec_rotate(euler_yzx, vec_arb);
}
@ -434,7 +434,7 @@ TEST_CASE("[Stress][Quaternion] Many vector xforms") {
}
TEST_CASE("[Quaternion] Finite number checks") {
const real_t x = NAN;
constexpr real_t x = Math::NaN;
CHECK_MESSAGE(
Quaternion(0, 1, 2, 3).is_finite(),

View file

@ -323,8 +323,8 @@ TEST_CASE("[Rect2] Merging") {
}
TEST_CASE("[Rect2] Finite number checks") {
const Vector2 x(0, 1);
const Vector2 infinite(NAN, NAN);
constexpr Vector2 x(0, 1);
constexpr Vector2 infinite(Math::NaN, Math::NaN);
CHECK_MESSAGE(
Rect2(x, x).is_finite(),

View file

@ -56,7 +56,7 @@ TEST_CASE("[Transform2D] Copy constructor") {
}
TEST_CASE("[Transform2D] Constructor from angle and position") {
constexpr float ROTATION = Math_PI / 4;
constexpr float ROTATION = Math::PI / 4;
constexpr Vector2 TRANSLATION = Vector2(20, -20);
const Transform2D test = Transform2D(ROTATION, TRANSLATION);
@ -65,9 +65,9 @@ TEST_CASE("[Transform2D] Constructor from angle and position") {
}
TEST_CASE("[Transform2D] Constructor from angle, scale, skew and position") {
constexpr float ROTATION = Math_PI / 2;
constexpr float ROTATION = Math::PI / 2;
constexpr Vector2 SCALE = Vector2(2, 0.5);
constexpr float SKEW = Math_PI / 4;
constexpr float SKEW = Math::PI / 4;
constexpr Vector2 TRANSLATION = Vector2(30, 0);
const Transform2D test = Transform2D(ROTATION, SCALE, SKEW, TRANSLATION);
@ -182,7 +182,7 @@ TEST_CASE("[Transform2D] Interpolation") {
TEST_CASE("[Transform2D] Finite number checks") {
constexpr Vector2 x = Vector2(0, 1);
const Vector2 infinite = Vector2(NAN, NAN);
constexpr Vector2 infinite = Vector2(Math::NaN, Math::NaN);
CHECK_MESSAGE(
Transform2D(x, x, x).is_finite(),
@ -239,7 +239,7 @@ TEST_CASE("[Transform2D] Is conformal checks") {
"Transform2D with non-uniform scale should not be conformal.");
CHECK_FALSE_MESSAGE(
Transform2D(Vector2(Math_SQRT12, Math_SQRT12), Vector2(0, 1), Vector2()).is_conformal(),
Transform2D(Vector2(Math::SQRT12, Math::SQRT12), Vector2(0, 1), Vector2()).is_conformal(),
"Transform2D with the X axis skewed 45 degrees should not be conformal.");
}

View file

@ -86,9 +86,9 @@ TEST_CASE("[Transform3D] rotation") {
TEST_CASE("[Transform3D] Finite number checks") {
constexpr Vector3 y(0, 1, 2);
const Vector3 infinite_vec(NAN, NAN, NAN);
constexpr Vector3 infinite_vec(Math::NaN, Math::NaN, Math::NaN);
constexpr Basis x(y, y, y);
const Basis infinite_basis(infinite_vec, infinite_vec, infinite_vec);
constexpr Basis infinite_basis(infinite_vec, infinite_vec, infinite_vec);
CHECK_MESSAGE(
Transform3D(x, y).is_finite(),
@ -117,7 +117,7 @@ TEST_CASE("[Transform3D] Rotate around global origin") {
expected.basis[0] = Vector3(-1, 0, 0);
expected.basis[2] = Vector3(0, 0, -1);
const Transform3D rotated_transform = transform.rotated(Vector3(0, 1, 0), Math_PI);
const Transform3D rotated_transform = transform.rotated(Vector3(0, 1, 0), Math::PI);
CHECK_MESSAGE(rotated_transform.is_equal_approx(expected), "The rotated transform should have a new orientation and basis.");
}
@ -132,7 +132,7 @@ TEST_CASE("[Transform3D] Rotate in-place (local rotation)") {
expected.basis[0] = Vector3(-1, 0, 0);
expected.basis[2] = Vector3(0, 0, -1);
const Transform3D rotated_transform = Transform3D(transform.rotated_local(Vector3(0, 1, 0), Math_PI));
const Transform3D rotated_transform = Transform3D(transform.rotated_local(Vector3(0, 1, 0), Math::PI));
CHECK_MESSAGE(rotated_transform.is_equal_approx(expected), "The rotated transform should have a new orientation but still be based on the same origin.");
}
} // namespace TestTransform3D

View file

@ -48,16 +48,16 @@ TEST_CASE("[Vector2] Angle methods") {
constexpr Vector2 vector_x = Vector2(1, 0);
constexpr Vector2 vector_y = Vector2(0, 1);
CHECK_MESSAGE(
vector_x.angle_to(vector_y) == doctest::Approx((real_t)Math_TAU / 4),
vector_x.angle_to(vector_y) == doctest::Approx((real_t)Math::TAU / 4),
"Vector2 angle_to should work as expected.");
CHECK_MESSAGE(
vector_y.angle_to(vector_x) == doctest::Approx((real_t)-Math_TAU / 4),
vector_y.angle_to(vector_x) == doctest::Approx((real_t)-Math::TAU / 4),
"Vector2 angle_to should work as expected.");
CHECK_MESSAGE(
vector_x.angle_to_point(vector_y) == doctest::Approx((real_t)Math_TAU * 3 / 8),
vector_x.angle_to_point(vector_y) == doctest::Approx((real_t)Math::TAU * 3 / 8),
"Vector2 angle_to_point should work as expected.");
CHECK_MESSAGE(
vector_y.angle_to_point(vector_x) == doctest::Approx((real_t)-Math_TAU / 8),
vector_y.angle_to_point(vector_x) == doctest::Approx((real_t)-Math::TAU / 8),
"Vector2 angle_to_point should work as expected.");
}
@ -94,7 +94,7 @@ TEST_CASE("[Vector2] Interpolation methods") {
vector1.normalized().slerp(vector2.normalized(), 1.0 / 3.0).is_equal_approx(Vector2(0.508990883827209473, 0.860771894454956055)),
"Vector2 slerp should work as expected.");
CHECK_MESSAGE(
Vector2(5, 0).slerp(Vector2(0, 5), 0.5).is_equal_approx(Vector2(5, 5) * Math_SQRT12),
Vector2(5, 0).slerp(Vector2(0, 5), 0.5).is_equal_approx(Vector2(5, 5) * Math::SQRT12),
"Vector2 slerp with non-normalized values should work as expected.");
CHECK_MESSAGE(
Vector2(1, 1).slerp(Vector2(2, 2), 0.5).is_equal_approx(Vector2(1.5, 1.5)),
@ -135,7 +135,7 @@ TEST_CASE("[Vector2] Length methods") {
vector1.length_squared() == 200,
"Vector2 length_squared should work as expected and return exact result.");
CHECK_MESSAGE(
vector1.length() == doctest::Approx(10 * (real_t)Math_SQRT2),
vector1.length() == doctest::Approx(10 * (real_t)Math::SQRT2),
"Vector2 length should work as expected.");
CHECK_MESSAGE(
vector2.length_squared() == 1300,
@ -154,10 +154,10 @@ TEST_CASE("[Vector2] Length methods") {
TEST_CASE("[Vector2] Limiting methods") {
constexpr Vector2 vector = Vector2(10, 10);
CHECK_MESSAGE(
vector.limit_length().is_equal_approx(Vector2(Math_SQRT12, Math_SQRT12)),
vector.limit_length().is_equal_approx(Vector2(Math::SQRT12, Math::SQRT12)),
"Vector2 limit_length should work as expected.");
CHECK_MESSAGE(
vector.limit_length(5).is_equal_approx(5 * Vector2(Math_SQRT12, Math_SQRT12)),
vector.limit_length(5).is_equal_approx(5 * Vector2(Math::SQRT12, Math::SQRT12)),
"Vector2 limit_length should work as expected.");
CHECK_MESSAGE(
@ -179,7 +179,7 @@ TEST_CASE("[Vector2] Normalization methods") {
Vector2(1, 0).normalized() == Vector2(1, 0),
"Vector2 normalized should return the same vector for a normalized vector.");
CHECK_MESSAGE(
Vector2(1, 1).normalized().is_equal_approx(Vector2(Math_SQRT12, Math_SQRT12)),
Vector2(1, 1).normalized().is_equal_approx(Vector2(Math::SQRT12, Math::SQRT12)),
"Vector2 normalized should work as expected.");
Vector2 vector = Vector2(3.2, -5.4);
@ -281,11 +281,11 @@ TEST_CASE("[Vector2] Operators") {
"Vector2 cast to String should work as expected.");
#ifdef REAL_T_IS_DOUBLE
CHECK_MESSAGE(
((String)Vector2(Math_PI, Math_TAU)) == "(3.14159265358979, 6.28318530717959)",
((String)Vector2(Math::PI, Math::TAU)) == "(3.14159265358979, 6.28318530717959)",
"Vector2 cast to String should print the correct amount of digits for real_t = double.");
#else
CHECK_MESSAGE(
((String)Vector2(Math_PI, Math_TAU)) == "(3.141593, 6.283185)",
((String)Vector2(Math::PI, Math::TAU)) == "(3.141593, 6.283185)",
"Vector2 cast to String should print the correct amount of digits for real_t = float.");
#endif // REAL_T_IS_DOUBLE
}
@ -300,7 +300,7 @@ TEST_CASE("[Vector2] Other methods") {
vector.direction_to(Vector2()).is_equal_approx(-vector.normalized()),
"Vector2 direction_to should work as expected.");
CHECK_MESSAGE(
Vector2(1, 1).direction_to(Vector2(2, 2)).is_equal_approx(Vector2(Math_SQRT12, Math_SQRT12)),
Vector2(1, 1).direction_to(Vector2(2, 2)).is_equal_approx(Vector2(Math::SQRT12, Math::SQRT12)),
"Vector2 direction_to should work as expected.");
CHECK_MESSAGE(
@ -317,16 +317,16 @@ TEST_CASE("[Vector2] Other methods") {
"Vector2 posmodv should work as expected.");
CHECK_MESSAGE(
vector.rotated(Math_TAU).is_equal_approx(Vector2(1.2, 3.4)),
vector.rotated(Math::TAU).is_equal_approx(Vector2(1.2, 3.4)),
"Vector2 rotated should work as expected.");
CHECK_MESSAGE(
vector.rotated(Math_TAU / 4).is_equal_approx(Vector2(-3.4, 1.2)),
vector.rotated(Math::TAU / 4).is_equal_approx(Vector2(-3.4, 1.2)),
"Vector2 rotated should work as expected.");
CHECK_MESSAGE(
vector.rotated(Math_TAU / 3).is_equal_approx(Vector2(-3.544486372867091398996, -0.660769515458673623883)),
vector.rotated(Math::TAU / 3).is_equal_approx(Vector2(-3.544486372867091398996, -0.660769515458673623883)),
"Vector2 rotated should work as expected.");
CHECK_MESSAGE(
vector.rotated(Math_TAU / 2).is_equal_approx(vector.rotated(Math_TAU / -2)),
vector.rotated(Math::TAU / 2).is_equal_approx(vector.rotated(Math::TAU / -2)),
"Vector2 rotated should work as expected.");
CHECK_MESSAGE(
@ -472,7 +472,7 @@ TEST_CASE("[Vector2] Linear algebra methods") {
}
TEST_CASE("[Vector2] Finite number checks") {
const double infinite[] = { NAN, INFINITY, -INFINITY };
constexpr double infinite[] = { Math::NaN, Math::INF, -Math::INF };
CHECK_MESSAGE(
Vector2(0, 1).is_finite(),

View file

@ -78,7 +78,7 @@ TEST_CASE("[Vector2i] Length methods") {
vector1.length_squared() == 200,
"Vector2i length_squared should work as expected and return exact result.");
CHECK_MESSAGE(
vector1.length() == doctest::Approx(10 * Math_SQRT2),
vector1.length() == doctest::Approx(10 * Math::SQRT2),
"Vector2i length should work as expected.");
CHECK_MESSAGE(
vector2.length_squared() == 1300,

View file

@ -33,9 +33,6 @@
#include "core/math/vector3.h"
#include "tests/test_macros.h"
#define Math_SQRT13 0.57735026918962576450914878050196
#define Math_SQRT3 1.7320508075688772935274463415059
namespace TestVector3 {
TEST_CASE("[Vector3] Constructor methods") {
@ -51,26 +48,26 @@ TEST_CASE("[Vector3] Angle methods") {
constexpr Vector3 vector_y = Vector3(0, 1, 0);
constexpr Vector3 vector_yz = Vector3(0, 1, 1);
CHECK_MESSAGE(
vector_x.angle_to(vector_y) == doctest::Approx((real_t)Math_TAU / 4),
vector_x.angle_to(vector_y) == doctest::Approx((real_t)Math::TAU / 4),
"Vector3 angle_to should work as expected.");
CHECK_MESSAGE(
vector_x.angle_to(vector_yz) == doctest::Approx((real_t)Math_TAU / 4),
vector_x.angle_to(vector_yz) == doctest::Approx((real_t)Math::TAU / 4),
"Vector3 angle_to should work as expected.");
CHECK_MESSAGE(
vector_yz.angle_to(vector_x) == doctest::Approx((real_t)Math_TAU / 4),
vector_yz.angle_to(vector_x) == doctest::Approx((real_t)Math::TAU / 4),
"Vector3 angle_to should work as expected.");
CHECK_MESSAGE(
vector_y.angle_to(vector_yz) == doctest::Approx((real_t)Math_TAU / 8),
vector_y.angle_to(vector_yz) == doctest::Approx((real_t)Math::TAU / 8),
"Vector3 angle_to should work as expected.");
CHECK_MESSAGE(
vector_x.signed_angle_to(vector_y, vector_y) == doctest::Approx((real_t)Math_TAU / 4),
vector_x.signed_angle_to(vector_y, vector_y) == doctest::Approx((real_t)Math::TAU / 4),
"Vector3 signed_angle_to edge case should be positive.");
CHECK_MESSAGE(
vector_x.signed_angle_to(vector_yz, vector_y) == doctest::Approx((real_t)Math_TAU / -4),
vector_x.signed_angle_to(vector_yz, vector_y) == doctest::Approx((real_t)Math::TAU / -4),
"Vector3 signed_angle_to should work as expected.");
CHECK_MESSAGE(
vector_yz.signed_angle_to(vector_x, vector_y) == doctest::Approx((real_t)Math_TAU / 4),
vector_yz.signed_angle_to(vector_x, vector_y) == doctest::Approx((real_t)Math::TAU / 4),
"Vector3 signed_angle_to should work as expected.");
}
@ -152,7 +149,7 @@ TEST_CASE("[Vector3] Length methods") {
vector1.length_squared() == 300,
"Vector3 length_squared should work as expected and return exact result.");
CHECK_MESSAGE(
vector1.length() == doctest::Approx(10 * (real_t)Math_SQRT3),
vector1.length() == doctest::Approx(10 * (real_t)Math::SQRT3),
"Vector3 length should work as expected.");
CHECK_MESSAGE(
vector2.length_squared() == 2900,
@ -171,10 +168,10 @@ TEST_CASE("[Vector3] Length methods") {
TEST_CASE("[Vector3] Limiting methods") {
constexpr Vector3 vector = Vector3(10, 10, 10);
CHECK_MESSAGE(
vector.limit_length().is_equal_approx(Vector3(Math_SQRT13, Math_SQRT13, Math_SQRT13)),
vector.limit_length().is_equal_approx(Vector3(Math::SQRT13, Math::SQRT13, Math::SQRT13)),
"Vector3 limit_length should work as expected.");
CHECK_MESSAGE(
vector.limit_length(5).is_equal_approx(5 * Vector3(Math_SQRT13, Math_SQRT13, Math_SQRT13)),
vector.limit_length(5).is_equal_approx(5 * Vector3(Math::SQRT13, Math::SQRT13, Math::SQRT13)),
"Vector3 limit_length should work as expected.");
CHECK_MESSAGE(
@ -196,10 +193,10 @@ TEST_CASE("[Vector3] Normalization methods") {
Vector3(1, 0, 0).normalized() == Vector3(1, 0, 0),
"Vector3 normalized should return the same vector for a normalized vector.");
CHECK_MESSAGE(
Vector3(1, 1, 0).normalized().is_equal_approx(Vector3(Math_SQRT12, Math_SQRT12, 0)),
Vector3(1, 1, 0).normalized().is_equal_approx(Vector3(Math::SQRT12, Math::SQRT12, 0)),
"Vector3 normalized should work as expected.");
CHECK_MESSAGE(
Vector3(1, 1, 1).normalized().is_equal_approx(Vector3(Math_SQRT13, Math_SQRT13, Math_SQRT13)),
Vector3(1, 1, 1).normalized().is_equal_approx(Vector3(Math::SQRT13, Math::SQRT13, Math::SQRT13)),
"Vector3 normalized should work as expected.");
Vector3 vector = Vector3(3.2, -5.4, 6);
@ -301,11 +298,11 @@ TEST_CASE("[Vector3] Operators") {
"Vector3 cast to String should work as expected.");
#ifdef REAL_T_IS_DOUBLE
CHECK_MESSAGE(
((String)Vector3(Math_E, Math_SQRT2, Math_SQRT3)) == "(2.71828182845905, 1.4142135623731, 1.73205080756888)",
((String)Vector3(Math::E, Math::SQRT2, Math::SQRT3)) == "(2.71828182845905, 1.4142135623731, 1.73205080756888)",
"Vector3 cast to String should print the correct amount of digits for real_t = double.");
#else
CHECK_MESSAGE(
((String)Vector3(Math_E, Math_SQRT2, Math_SQRT3)) == "(2.718282, 1.414214, 1.732051)",
((String)Vector3(Math::E, Math::SQRT2, Math::SQRT3)) == "(2.718282, 1.414214, 1.732051)",
"Vector3 cast to String should print the correct amount of digits for real_t = float.");
#endif // REAL_T_IS_DOUBLE
}
@ -316,7 +313,7 @@ TEST_CASE("[Vector3] Other methods") {
vector.direction_to(Vector3()).is_equal_approx(-vector.normalized()),
"Vector3 direction_to should work as expected.");
CHECK_MESSAGE(
Vector3(1, 1, 1).direction_to(Vector3(2, 2, 2)).is_equal_approx(Vector3(Math_SQRT13, Math_SQRT13, Math_SQRT13)),
Vector3(1, 1, 1).direction_to(Vector3(2, 2, 2)).is_equal_approx(Vector3(Math::SQRT13, Math::SQRT13, Math::SQRT13)),
"Vector3 direction_to should work as expected.");
CHECK_MESSAGE(
vector.inverse().is_equal_approx(Vector3(1 / 1.2, 1 / 3.4, 1 / 5.6)),
@ -335,16 +332,16 @@ TEST_CASE("[Vector3] Other methods") {
"Vector3 posmodv should work as expected.");
CHECK_MESSAGE(
vector.rotated(Vector3(0, 1, 0), Math_TAU).is_equal_approx(vector),
vector.rotated(Vector3(0, 1, 0), Math::TAU).is_equal_approx(vector),
"Vector3 rotated should work as expected.");
CHECK_MESSAGE(
vector.rotated(Vector3(0, 1, 0), Math_TAU / 4).is_equal_approx(Vector3(5.6, 3.4, -1.2)),
vector.rotated(Vector3(0, 1, 0), Math::TAU / 4).is_equal_approx(Vector3(5.6, 3.4, -1.2)),
"Vector3 rotated should work as expected.");
CHECK_MESSAGE(
vector.rotated(Vector3(1, 0, 0), Math_TAU / 3).is_equal_approx(Vector3(1.2, -6.54974226119285642, 0.1444863728670914)),
vector.rotated(Vector3(1, 0, 0), Math::TAU / 3).is_equal_approx(Vector3(1.2, -6.54974226119285642, 0.1444863728670914)),
"Vector3 rotated should work as expected.");
CHECK_MESSAGE(
vector.rotated(Vector3(0, 0, 1), Math_TAU / 2).is_equal_approx(vector.rotated(Vector3(0, 0, 1), Math_TAU / -2)),
vector.rotated(Vector3(0, 0, 1), Math::TAU / 2).is_equal_approx(vector.rotated(Vector3(0, 0, 1), Math::TAU / -2)),
"Vector3 rotated should work as expected.");
CHECK_MESSAGE(
@ -490,7 +487,7 @@ TEST_CASE("[Vector3] Linear algebra methods") {
}
TEST_CASE("[Vector3] Finite number checks") {
const double infinite[] = { NAN, INFINITY, -INFINITY };
constexpr double infinite[] = { Math::NaN, Math::INF, -Math::INF };
CHECK_MESSAGE(
Vector3(0, 1, 2).is_finite(),

View file

@ -33,8 +33,6 @@
#include "core/math/vector3i.h"
#include "tests/test_macros.h"
#define Math_SQRT3 1.7320508075688772935274463415059
namespace TestVector3i {
TEST_CASE("[Vector3i] Constructor methods") {
@ -83,7 +81,7 @@ TEST_CASE("[Vector3i] Length methods") {
vector1.length_squared() == 300,
"Vector3i length_squared should work as expected and return exact result.");
CHECK_MESSAGE(
vector1.length() == doctest::Approx(10 * Math_SQRT3),
vector1.length() == doctest::Approx(10 * Math::SQRT3),
"Vector3i length should work as expected.");
CHECK_MESSAGE(
vector2.length_squared() == 2900,

View file

@ -33,8 +33,6 @@
#include "core/math/vector4.h"
#include "tests/test_macros.h"
#define Math_SQRT3 1.7320508075688772935274463415059
namespace TestVector4 {
TEST_CASE("[Vector4] Constructor methods") {
@ -127,7 +125,7 @@ TEST_CASE("[Vector4] Normalization methods") {
Vector4(1, 0, 0, 0).normalized() == Vector4(1, 0, 0, 0),
"Vector4 normalized should return the same vector for a normalized vector.");
CHECK_MESSAGE(
Vector4(1, 1, 0, 0).normalized().is_equal_approx(Vector4(Math_SQRT12, Math_SQRT12, 0, 0)),
Vector4(1, 1, 0, 0).normalized().is_equal_approx(Vector4(Math::SQRT12, Math::SQRT12, 0, 0)),
"Vector4 normalized should work as expected.");
CHECK_MESSAGE(
Vector4(1, 1, 1, 1).normalized().is_equal_approx(Vector4(0.5, 0.5, 0.5, 0.5)),
@ -216,11 +214,11 @@ TEST_CASE("[Vector4] Operators") {
"Vector4 cast to String should work as expected.");
#ifdef REAL_T_IS_DOUBLE
CHECK_MESSAGE(
((String)Vector4(Math_E, Math_SQRT2, Math_SQRT3, Math_SQRT3)) == "(2.71828182845905, 1.4142135623731, 1.73205080756888, 1.73205080756888)",
((String)Vector4(Math::E, Math::SQRT2, Math::SQRT3, Math::SQRT3)) == "(2.71828182845905, 1.4142135623731, 1.73205080756888, 1.73205080756888)",
"Vector4 cast to String should print the correct amount of digits for real_t = double.");
#else
CHECK_MESSAGE(
((String)Vector4(Math_E, Math_SQRT2, Math_SQRT3, Math_SQRT3)) == "(2.718282, 1.414214, 1.732051, 1.732051)",
((String)Vector4(Math::E, Math::SQRT2, Math::SQRT3, Math::SQRT3)) == "(2.718282, 1.414214, 1.732051, 1.732051)",
"Vector4 cast to String should print the correct amount of digits for real_t = float.");
#endif // REAL_T_IS_DOUBLE
}
@ -323,7 +321,7 @@ TEST_CASE("[Vector4] Linear algebra methods") {
}
TEST_CASE("[Vector4] Finite number checks") {
const double infinite[] = { NAN, INFINITY, -INFINITY };
constexpr double infinite[] = { Math::NaN, Math::INF, -Math::INF };
CHECK_MESSAGE(
Vector4(0, 1, 2, 3).is_finite(),

View file

@ -579,12 +579,12 @@ TEST_CASE("[String] Number to string") {
#ifdef REAL_T_IS_DOUBLE
CHECK_MESSAGE(String::num_real(real_t(123.456789)) == "123.456789", "Prints the appropriate amount of digits for real_t = double.");
CHECK_MESSAGE(String::num_real(real_t(-123.456789)) == "-123.456789", "Prints the appropriate amount of digits for real_t = double.");
CHECK_MESSAGE(String::num_real(real_t(Math_PI)) == "3.14159265358979", "Prints the appropriate amount of digits for real_t = double.");
CHECK_MESSAGE(String::num_real(real_t(Math::PI)) == "3.14159265358979", "Prints the appropriate amount of digits for real_t = double.");
CHECK_MESSAGE(String::num_real(real_t(3.1415f)) == "3.1414999961853", "Prints more digits of 32-bit float when real_t = double (ones that would be reliable for double) and no trailing zero.");
#else
CHECK_MESSAGE(String::num_real(real_t(123.456789)) == "123.4568", "Prints the appropriate amount of digits for real_t = float.");
CHECK_MESSAGE(String::num_real(real_t(-123.456789)) == "-123.4568", "Prints the appropriate amount of digits for real_t = float.");
CHECK_MESSAGE(String::num_real(real_t(Math_PI)) == "3.141593", "Prints the appropriate amount of digits for real_t = float.");
CHECK_MESSAGE(String::num_real(real_t(Math::PI)) == "3.141593", "Prints the appropriate amount of digits for real_t = float.");
CHECK_MESSAGE(String::num_real(real_t(3.1415f)) == "3.1415", "Prints only reliable digits of 32-bit float when real_t = float.");
#endif // REAL_T_IS_DOUBLE
@ -690,15 +690,15 @@ TEST_CASE("[String] String to float") {
CHECK(String("-1e308").to_float() == -1e308);
// Exponent is so high that value is INFINITY/-INFINITY.
CHECK(String("1e309").to_float() == INFINITY);
CHECK(String("1e511").to_float() == INFINITY);
CHECK(String("-1e309").to_float() == -INFINITY);
CHECK(String("-1e511").to_float() == -INFINITY);
CHECK(String("1e309").to_float() == Math::INF);
CHECK(String("1e511").to_float() == Math::INF);
CHECK(String("-1e309").to_float() == -Math::INF);
CHECK(String("-1e511").to_float() == -Math::INF);
// Exponent is so high that a warning message is printed. Value is INFINITY/-INFINITY.
ERR_PRINT_OFF
CHECK(String("1e512").to_float() == INFINITY);
CHECK(String("-1e512").to_float() == -INFINITY);
CHECK(String("1e512").to_float() == Math::INF);
CHECK(String("-1e512").to_float() == -Math::INF);
ERR_PRINT_ON
}
@ -1003,7 +1003,7 @@ TEST_CASE("[String] sprintf") {
// Real (infinity) left-padded
format = "fish %11f frog";
args.clear();
args.push_back(INFINITY);
args.push_back(Math::INF);
output = format.sprintf(args, &error);
REQUIRE(error == false);
CHECK(output == String("fish inf frog"));
@ -1127,7 +1127,7 @@ TEST_CASE("[String] sprintf") {
// Vector left-padded with inf/nan
format = "fish %11v frog";
args.clear();
args.push_back(Variant(Vector2(INFINITY, NAN)));
args.push_back(Variant(Vector2(Math::INF, Math::NaN)));
output = format.sprintf(args, &error);
REQUIRE(error == false);
CHECK(output == String("fish ( inf, nan) frog"));

View file

@ -46,7 +46,7 @@ constexpr int WAV_COUNT = WAV_RATE;
float gen_wav(float frequency, float wav_rate, int wav_number) {
// formula for generating a sin wave with given frequency.
return Math::sin((Math_TAU * frequency / wav_rate) * wav_number);
return Math::sin((Math::TAU * frequency / wav_rate) * wav_number);
}
/* Generates a 440Hz sin wave in channel 0 (mono channel or left stereo channel)

View file

@ -285,7 +285,7 @@ TEST_CASE("[SceneTree][Camera2D] Transforms") {
}
SUBCASE("Rotation") {
test_camera->set_rotation(Math_PI / 2);
test_camera->set_rotation(Math::PI / 2);
Transform2D xform = mock_viewport->get_canvas_transform();
Transform2D test_xform = Transform2D(Vector2(1, 0), Vector2(0, 1), Vector2(200, 100));
CHECK(xform.is_equal_approx(test_xform));
@ -295,7 +295,7 @@ TEST_CASE("[SceneTree][Camera2D] Transforms") {
test_xform = Transform2D(Vector2(0, -1), Vector2(1, 0), Vector2(200, 100));
CHECK(xform.is_equal_approx(test_xform));
test_camera->set_rotation(-1 * Math_PI);
test_camera->set_rotation(-1 * Math::PI);
test_camera->force_update_scroll();
xform = mock_viewport->get_canvas_transform();
test_xform = Transform2D(Vector2(-1, 0), Vector2(0, -1), Vector2(200, 100));

View file

@ -36,9 +36,6 @@
#include "tests/test_macros.h"
// Constants.
#define SQRT3 (1.7320508f)
TEST_CASE("[SceneTree][Camera3D] Getters and setters") {
Camera3D *test_camera = memnew(Camera3D);
@ -246,13 +243,13 @@ TEST_CASE("[SceneTree][Camera3D] Project/Unproject position") {
CHECK(test_camera->project_position(Vector2(200, 100), 100.0f).is_equal_approx(Vector3(0, 0, -100.0f)));
CHECK(test_camera->project_position(Vector2(200, 100), test_camera->get_far()).is_equal_approx(Vector3(0, 0, -1.0f) * test_camera->get_far()));
// 3/4th way to Top left.
CHECK(test_camera->project_position(Vector2(100, 50), 0.5f).is_equal_approx(Vector3(-SQRT3 * 0.5f, SQRT3 * 0.25f, -0.5f)));
CHECK(test_camera->project_position(Vector2(100, 50), 1.0f).is_equal_approx(Vector3(-SQRT3, SQRT3 * 0.5f, -1.0f)));
CHECK(test_camera->project_position(Vector2(100, 50), test_camera->get_near()).is_equal_approx(Vector3(-SQRT3, SQRT3 * 0.5f, -1.0f) * test_camera->get_near()));
CHECK(test_camera->project_position(Vector2(100, 50), 0.5f).is_equal_approx(Vector3(-Math::SQRT3 * 0.5f, Math::SQRT3 * 0.25f, -0.5f)));
CHECK(test_camera->project_position(Vector2(100, 50), 1.0f).is_equal_approx(Vector3(-Math::SQRT3, Math::SQRT3 * 0.5f, -1.0f)));
CHECK(test_camera->project_position(Vector2(100, 50), test_camera->get_near()).is_equal_approx(Vector3(-Math::SQRT3, Math::SQRT3 * 0.5f, -1.0f) * test_camera->get_near()));
// 3/4th way to Bottom right.
CHECK(test_camera->project_position(Vector2(300, 150), 0.5f).is_equal_approx(Vector3(SQRT3 * 0.5f, -SQRT3 * 0.25f, -0.5f)));
CHECK(test_camera->project_position(Vector2(300, 150), 1.0f).is_equal_approx(Vector3(SQRT3, -SQRT3 * 0.5f, -1.0f)));
CHECK(test_camera->project_position(Vector2(300, 150), test_camera->get_far()).is_equal_approx(Vector3(SQRT3, -SQRT3 * 0.5f, -1.0f) * test_camera->get_far()));
CHECK(test_camera->project_position(Vector2(300, 150), 0.5f).is_equal_approx(Vector3(Math::SQRT3 * 0.5f, -Math::SQRT3 * 0.25f, -0.5f)));
CHECK(test_camera->project_position(Vector2(300, 150), 1.0f).is_equal_approx(Vector3(Math::SQRT3, -Math::SQRT3 * 0.5f, -1.0f)));
CHECK(test_camera->project_position(Vector2(300, 150), test_camera->get_far()).is_equal_approx(Vector3(Math::SQRT3, -Math::SQRT3 * 0.5f, -1.0f) * test_camera->get_far()));
}
}
@ -274,11 +271,11 @@ TEST_CASE("[SceneTree][Camera3D] Project/Unproject position") {
CHECK(test_camera->unproject_position(Vector3(0, 0, -0.5f)).is_equal_approx(Vector2(200, 100)));
CHECK(test_camera->unproject_position(Vector3(0, 0, -100.0f)).is_equal_approx(Vector2(200, 100)));
// 3/4th way to Top left.
WARN(test_camera->unproject_position(Vector3(-SQRT3 * 0.5f, SQRT3 * 0.25f, -0.5f)).is_equal_approx(Vector2(100, 50)));
WARN(test_camera->unproject_position(Vector3(-SQRT3, SQRT3 * 0.5f, -1.0f)).is_equal_approx(Vector2(100, 50)));
WARN(test_camera->unproject_position(Vector3(-Math::SQRT3 * 0.5f, Math::SQRT3 * 0.25f, -0.5f)).is_equal_approx(Vector2(100, 50)));
WARN(test_camera->unproject_position(Vector3(-Math::SQRT3, Math::SQRT3 * 0.5f, -1.0f)).is_equal_approx(Vector2(100, 50)));
// 3/4th way to Bottom right.
CHECK(test_camera->unproject_position(Vector3(SQRT3 * 0.5f, -SQRT3 * 0.25f, -0.5f)).is_equal_approx(Vector2(300, 150)));
CHECK(test_camera->unproject_position(Vector3(SQRT3, -SQRT3 * 0.5f, -1.0f)).is_equal_approx(Vector2(300, 150)));
CHECK(test_camera->unproject_position(Vector3(Math::SQRT3 * 0.5f, -Math::SQRT3 * 0.25f, -0.5f)).is_equal_approx(Vector2(300, 150)));
CHECK(test_camera->unproject_position(Vector3(Math::SQRT3, -Math::SQRT3 * 0.5f, -1.0f)).is_equal_approx(Vector2(300, 150)));
}
}
@ -336,9 +333,9 @@ TEST_CASE("[SceneTree][Camera3D] Project ray") {
// Center.
CHECK(test_camera->project_ray_normal(Vector2(200, 100)).is_equal_approx(Vector3(0, 0, -1)));
// Top left.
CHECK(test_camera->project_ray_normal(Vector2(0, 0)).is_equal_approx(Vector3(-SQRT3, SQRT3 / 2, -0.5f).normalized()));
CHECK(test_camera->project_ray_normal(Vector2(0, 0)).is_equal_approx(Vector3(-Math::SQRT3, Math::SQRT3 / 2, -0.5f).normalized()));
// Bottom right.
CHECK(test_camera->project_ray_normal(Vector2(400, 200)).is_equal_approx(Vector3(SQRT3, -SQRT3 / 2, -0.5f).normalized()));
CHECK(test_camera->project_ray_normal(Vector2(400, 200)).is_equal_approx(Vector3(Math::SQRT3, -Math::SQRT3 / 2, -0.5f).normalized()));
}
}
@ -360,14 +357,12 @@ TEST_CASE("[SceneTree][Camera3D] Project ray") {
// Center.
CHECK(test_camera->project_local_ray_normal(Vector2(200, 100)).is_equal_approx(Vector3(0, 0, -1)));
// Top left.
CHECK(test_camera->project_local_ray_normal(Vector2(0, 0)).is_equal_approx(Vector3(-SQRT3, SQRT3 / 2, -0.5f).normalized()));
CHECK(test_camera->project_local_ray_normal(Vector2(0, 0)).is_equal_approx(Vector3(-Math::SQRT3, Math::SQRT3 / 2, -0.5f).normalized()));
// Bottom right.
CHECK(test_camera->project_local_ray_normal(Vector2(400, 200)).is_equal_approx(Vector3(SQRT3, -SQRT3 / 2, -0.5f).normalized()));
CHECK(test_camera->project_local_ray_normal(Vector2(400, 200)).is_equal_approx(Vector3(Math::SQRT3, -Math::SQRT3 / 2, -0.5f).normalized()));
}
}
memdelete(test_camera);
memdelete(mock_viewport);
}
#undef SQRT3

View file

@ -52,9 +52,9 @@ TEST_CASE("[SceneTree][Control] Transforms") {
CHECK_EQ(test_node->get_global_transform(), Transform2D(0, Size2(4, 4), 0, Vector2(2, 2)));
test_node->set_scale(Vector2(1, 1));
test_node->set_rotation_degrees(90);
CHECK_EQ(test_node->get_global_transform(), Transform2D(Math_PI / 2, Vector2(2, 2)));
CHECK_EQ(test_node->get_global_transform(), Transform2D(Math::PI / 2, Vector2(2, 2)));
test_node->set_pivot_offset(Vector2(1, 0));
CHECK_EQ(test_node->get_global_transform(), Transform2D(Math_PI / 2, Vector2(3, 1)));
CHECK_EQ(test_node->get_global_transform(), Transform2D(Math::PI / 2, Vector2(3, 1)));
memdelete(test_child);
memdelete(test_node);

View file

@ -63,22 +63,22 @@ TEST_CASE("[SceneTree][TextureProgressBar]") {
texture_progress_bar->set_radial_initial_angle(30.5);
ERR_PRINT_OFF;
texture_progress_bar->set_radial_initial_angle(INFINITY);
texture_progress_bar->set_radial_initial_angle(Math::INF);
ERR_PRINT_ON;
CHECK(Math::is_equal_approx(texture_progress_bar->get_radial_initial_angle(), (float)30.5));
ERR_PRINT_OFF;
texture_progress_bar->set_radial_initial_angle(-INFINITY);
texture_progress_bar->set_radial_initial_angle(-Math::INF);
ERR_PRINT_ON;
CHECK(Math::is_equal_approx(texture_progress_bar->get_radial_initial_angle(), (float)30.5));
ERR_PRINT_OFF;
texture_progress_bar->set_radial_initial_angle(NAN);
texture_progress_bar->set_radial_initial_angle(Math::NaN);
ERR_PRINT_ON;
CHECK(Math::is_equal_approx(texture_progress_bar->get_radial_initial_angle(), (float)30.5));
ERR_PRINT_OFF;
texture_progress_bar->set_radial_initial_angle(-NAN);
texture_progress_bar->set_radial_initial_angle(-Math::NaN);
ERR_PRINT_ON;
CHECK(Math::is_equal_approx(texture_progress_bar->get_radial_initial_angle(), (float)30.5));
}

View file

@ -1774,7 +1774,7 @@ TEST_CASE("[SceneTree][Viewport] Physics Picking 2D") {
SUBCASE("[Viewport][Picking2D] CollisionObject in CanvasLayer") {
CanvasLayer *node_c = memnew(CanvasLayer);
node_c->set_rotation(Math_PI);
node_c->set_rotation(Math::PI);
node_c->set_offset(Point2i(100, 100));
root->add_child(node_c);