Skip to content

Commit

Permalink
Fix clippy::legacy_numeric_constants lints. (#505)
Browse files Browse the repository at this point in the history
The `std::f64::EPSILON` and similar constants are being deprecated
and it is encouraged to use the associated constants on `f32` and
`f64` instead.
  • Loading branch information
waywardmonkeys committed Apr 20, 2024
1 parent d4c4037 commit 1b243db
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 143 deletions.
4 changes: 2 additions & 2 deletions codegen/templates/quat.rs.tera
Expand Up @@ -395,7 +395,7 @@ impl {{ self_t }} {
glam_assert!(from.is_normalized());
glam_assert!(to.is_normalized());

const ONE_MINUS_EPS: {{ scalar_t }} = 1.0 - 2.0 * core::{{ scalar_t }}::EPSILON;
const ONE_MINUS_EPS: {{ scalar_t }} = 1.0 - 2.0 * {{ scalar_t }}::EPSILON;
let dot = from.dot(to);
if dot > ONE_MINUS_EPS {
// 0° singularity: from ≈ to
Expand Down Expand Up @@ -451,7 +451,7 @@ impl {{ self_t }} {
glam_assert!(from.is_normalized());
glam_assert!(to.is_normalized());

const ONE_MINUS_EPSILON: {{ scalar_t }} = 1.0 - 2.0 * core::{{ scalar_t }}::EPSILON;
const ONE_MINUS_EPSILON: {{ scalar_t }} = 1.0 - 2.0 * {{ scalar_t }}::EPSILON;
let dot = from.dot(to);
if dot > ONE_MINUS_EPSILON {
// 0° singularity: from ≈ to
Expand Down
4 changes: 2 additions & 2 deletions src/f32/coresimd/quat.rs
Expand Up @@ -282,7 +282,7 @@ impl Quat {
glam_assert!(from.is_normalized());
glam_assert!(to.is_normalized());

const ONE_MINUS_EPS: f32 = 1.0 - 2.0 * core::f32::EPSILON;
const ONE_MINUS_EPS: f32 = 1.0 - 2.0 * f32::EPSILON;
let dot = from.dot(to);
if dot > ONE_MINUS_EPS {
// 0° singularity: from ≈ to
Expand Down Expand Up @@ -338,7 +338,7 @@ impl Quat {
glam_assert!(from.is_normalized());
glam_assert!(to.is_normalized());

const ONE_MINUS_EPSILON: f32 = 1.0 - 2.0 * core::f32::EPSILON;
const ONE_MINUS_EPSILON: f32 = 1.0 - 2.0 * f32::EPSILON;
let dot = from.dot(to);
if dot > ONE_MINUS_EPSILON {
// 0° singularity: from ≈ to
Expand Down
4 changes: 2 additions & 2 deletions src/f32/scalar/quat.rs
Expand Up @@ -290,7 +290,7 @@ impl Quat {
glam_assert!(from.is_normalized());
glam_assert!(to.is_normalized());

const ONE_MINUS_EPS: f32 = 1.0 - 2.0 * core::f32::EPSILON;
const ONE_MINUS_EPS: f32 = 1.0 - 2.0 * f32::EPSILON;
let dot = from.dot(to);
if dot > ONE_MINUS_EPS {
// 0° singularity: from ≈ to
Expand Down Expand Up @@ -346,7 +346,7 @@ impl Quat {
glam_assert!(from.is_normalized());
glam_assert!(to.is_normalized());

const ONE_MINUS_EPSILON: f32 = 1.0 - 2.0 * core::f32::EPSILON;
const ONE_MINUS_EPSILON: f32 = 1.0 - 2.0 * f32::EPSILON;
let dot = from.dot(to);
if dot > ONE_MINUS_EPSILON {
// 0° singularity: from ≈ to
Expand Down
4 changes: 2 additions & 2 deletions src/f32/sse2/quat.rs
Expand Up @@ -290,7 +290,7 @@ impl Quat {
glam_assert!(from.is_normalized());
glam_assert!(to.is_normalized());

const ONE_MINUS_EPS: f32 = 1.0 - 2.0 * core::f32::EPSILON;
const ONE_MINUS_EPS: f32 = 1.0 - 2.0 * f32::EPSILON;
let dot = from.dot(to);
if dot > ONE_MINUS_EPS {
// 0° singularity: from ≈ to
Expand Down Expand Up @@ -346,7 +346,7 @@ impl Quat {
glam_assert!(from.is_normalized());
glam_assert!(to.is_normalized());

const ONE_MINUS_EPSILON: f32 = 1.0 - 2.0 * core::f32::EPSILON;
const ONE_MINUS_EPSILON: f32 = 1.0 - 2.0 * f32::EPSILON;
let dot = from.dot(to);
if dot > ONE_MINUS_EPSILON {
// 0° singularity: from ≈ to
Expand Down
4 changes: 2 additions & 2 deletions src/f32/wasm32/quat.rs
Expand Up @@ -282,7 +282,7 @@ impl Quat {
glam_assert!(from.is_normalized());
glam_assert!(to.is_normalized());

const ONE_MINUS_EPS: f32 = 1.0 - 2.0 * core::f32::EPSILON;
const ONE_MINUS_EPS: f32 = 1.0 - 2.0 * f32::EPSILON;
let dot = from.dot(to);
if dot > ONE_MINUS_EPS {
// 0° singularity: from ≈ to
Expand Down Expand Up @@ -338,7 +338,7 @@ impl Quat {
glam_assert!(from.is_normalized());
glam_assert!(to.is_normalized());

const ONE_MINUS_EPSILON: f32 = 1.0 - 2.0 * core::f32::EPSILON;
const ONE_MINUS_EPSILON: f32 = 1.0 - 2.0 * f32::EPSILON;
let dot = from.dot(to);
if dot > ONE_MINUS_EPSILON {
// 0° singularity: from ≈ to
Expand Down
4 changes: 2 additions & 2 deletions src/f64/dquat.rs
Expand Up @@ -279,7 +279,7 @@ impl DQuat {
glam_assert!(from.is_normalized());
glam_assert!(to.is_normalized());

const ONE_MINUS_EPS: f64 = 1.0 - 2.0 * core::f64::EPSILON;
const ONE_MINUS_EPS: f64 = 1.0 - 2.0 * f64::EPSILON;
let dot = from.dot(to);
if dot > ONE_MINUS_EPS {
// 0° singularity: from ≈ to
Expand Down Expand Up @@ -335,7 +335,7 @@ impl DQuat {
glam_assert!(from.is_normalized());
glam_assert!(to.is_normalized());

const ONE_MINUS_EPSILON: f64 = 1.0 - 2.0 * core::f64::EPSILON;
const ONE_MINUS_EPSILON: f64 = 1.0 - 2.0 * f64::EPSILON;
let dot = from.dot(to);
if dot > ONE_MINUS_EPSILON {
// 0° singularity: from ≈ to
Expand Down
7 changes: 2 additions & 5 deletions tests/affine2.rs
Expand Up @@ -6,9 +6,6 @@ macro_rules! impl_affine2_tests {
const MATRIX1D: [$t; 6] = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];
const MATRIX2D: [[$t; 2]; 3] = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];

use core::$t::NAN;
use core::$t::NEG_INFINITY;

glam_test!(test_affine2_identity, {
assert_eq!($affine2::IDENTITY, $affine2::IDENTITY * $affine2::IDENTITY);
assert_eq!($affine2::IDENTITY, $affine2::default());
Expand Down Expand Up @@ -260,8 +257,8 @@ macro_rules! impl_affine2_tests {
glam_test!(test_affine2_is_finite, {
assert!($affine2::from_scale($vec2::new(1.0, 1.0)).is_finite());
assert!($affine2::from_scale($vec2::new(0.0, 1.0)).is_finite());
assert!(!$affine2::from_scale($vec2::new(1.0, NAN)).is_finite());
assert!(!$affine2::from_scale($vec2::new(1.0, NEG_INFINITY)).is_finite());
assert!(!$affine2::from_scale($vec2::new(1.0, $t::NAN)).is_finite());
assert!(!$affine2::from_scale($vec2::new(1.0, $t::NEG_INFINITY)).is_finite());
});
};
}
Expand Down
9 changes: 3 additions & 6 deletions tests/affine3.rs
Expand Up @@ -13,9 +13,6 @@ macro_rules! impl_affine3_tests {
[10.0, 11.0, 12.0],
];

use core::$t::NAN;
use core::$t::NEG_INFINITY;

glam_test!(test_affine3_identity, {
assert_eq!($affine3::IDENTITY, $affine3::IDENTITY * $affine3::IDENTITY);
assert_eq!($affine3::IDENTITY, $affine3::default());
Expand Down Expand Up @@ -98,7 +95,7 @@ macro_rules! impl_affine3_tests {
});

glam_test!(test_from_rotation, {
let eps = 2.0 * core::f32::EPSILON;
let eps = 2.0 * f32::EPSILON;
let rot_x1 = $affine3::from_rotation_x(deg(180.0));
let rot_x2 = $affine3::from_axis_angle($vec3::X, deg(180.0));
assert_approx_eq!(rot_x1, rot_x2, eps);
Expand Down Expand Up @@ -345,8 +342,8 @@ macro_rules! impl_affine3_tests {
glam_test!(test_affine3_is_finite, {
assert!($affine3::from_scale($vec3::new(1.0, 1.0, 1.0)).is_finite());
assert!($affine3::from_scale($vec3::new(0.0, 1.0, 1.0)).is_finite());
assert!(!$affine3::from_scale($vec3::new(1.0, NAN, 1.0)).is_finite());
assert!(!$affine3::from_scale($vec3::new(1.0, 1.0, NEG_INFINITY)).is_finite());
assert!(!$affine3::from_scale($vec3::new(1.0, $t::NAN, 1.0)).is_finite());
assert!(!$affine3::from_scale($vec3::new(1.0, 1.0, $t::NEG_INFINITY)).is_finite());
});
};
}
Expand Down
9 changes: 3 additions & 6 deletions tests/mat2.rs
Expand Up @@ -220,13 +220,10 @@ macro_rules! impl_mat2_tests {
});

glam_test!(test_mat2_is_finite, {
use std::$t::INFINITY;
use std::$t::NAN;
use std::$t::NEG_INFINITY;
assert!($mat2::IDENTITY.is_finite());
assert!(!($mat2::IDENTITY * INFINITY).is_finite());
assert!(!($mat2::IDENTITY * NEG_INFINITY).is_finite());
assert!(!($mat2::IDENTITY * NAN).is_finite());
assert!(!($mat2::IDENTITY * $t::INFINITY).is_finite());
assert!(!($mat2::IDENTITY * $t::NEG_INFINITY).is_finite());
assert!(!($mat2::IDENTITY * $t::NAN).is_finite());
});
};
}
Expand Down
10 changes: 3 additions & 7 deletions tests/mat3.rs
Expand Up @@ -3,10 +3,6 @@ mod support;

macro_rules! impl_mat3_tests {
($t:ident, $newmat3:ident, $mat3:ident, $mat2:ident, $mat4:ident, $quat:ident, $newvec3:ident, $vec3:ident, $vec2:ident) => {
use core::$t::INFINITY;
use core::$t::NAN;
use core::$t::NEG_INFINITY;

const IDENTITY: [[$t; 3]; 3] = [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]];

const MATRIX: [[$t; 3]; 3] = [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]];
Expand Down Expand Up @@ -363,9 +359,9 @@ macro_rules! impl_mat3_tests {

glam_test!(test_mat3_is_finite, {
assert!($mat3::IDENTITY.is_finite());
assert!(!($mat3::IDENTITY * INFINITY).is_finite());
assert!(!($mat3::IDENTITY * NEG_INFINITY).is_finite());
assert!(!($mat3::IDENTITY * NAN).is_finite());
assert!(!($mat3::IDENTITY * $t::INFINITY).is_finite());
assert!(!($mat3::IDENTITY * $t::NEG_INFINITY).is_finite());
assert!(!($mat3::IDENTITY * $t::NAN).is_finite());
});
};
}
Expand Down
10 changes: 3 additions & 7 deletions tests/mat4.rs
Expand Up @@ -3,10 +3,6 @@ mod support;

macro_rules! impl_mat4_tests {
($t:ident, $newmat4:ident, $newvec4:ident, $newvec3:ident, $mat4:ident, $mat3:ident, $quat:ident, $vec4:ident, $vec3:ident) => {
use core::$t::INFINITY;
use core::$t::NAN;
use core::$t::NEG_INFINITY;

const IDENTITY: [[$t; 4]; 4] = [
[1.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 0.0, 0.0],
Expand Down Expand Up @@ -669,9 +665,9 @@ macro_rules! impl_mat4_tests {

glam_test!(test_mat4_is_finite, {
assert!($mat4::IDENTITY.is_finite());
assert!(!($mat4::IDENTITY * INFINITY).is_finite());
assert!(!($mat4::IDENTITY * NEG_INFINITY).is_finite());
assert!(!($mat4::IDENTITY * NAN).is_finite());
assert!(!($mat4::IDENTITY * $t::INFINITY).is_finite());
assert!(!($mat4::IDENTITY * $t::NEG_INFINITY).is_finite());
assert!(!($mat4::IDENTITY * $t::NAN).is_finite());
});

glam_test!(test_mat4_abs, {
Expand Down
16 changes: 6 additions & 10 deletions tests/quat.rs
Expand Up @@ -5,10 +5,6 @@ mod support;

macro_rules! impl_quat_tests {
($t:ident, $new:ident, $mat3:ident, $mat4:ident, $quat:ident, $vec2:ident, $vec3:ident, $vec4:ident) => {
use core::$t::INFINITY;
use core::$t::NAN;
use core::$t::NEG_INFINITY;

glam_test!(test_const, {
const Q0: $quat = $quat::from_xyzw(1.0, 2.0, 3.0, 4.0);
const Q1: $quat = $quat::from_array([1.0, 2.0, 3.0, 4.0]);
Expand Down Expand Up @@ -236,7 +232,7 @@ macro_rules! impl_quat_tests {

glam_test!(test_angle_between, {
const TAU: $t = 2.0 * core::$t::consts::PI;
let eps = 10.0 * core::$t::EPSILON as f32;
let eps = 10.0 * $t::EPSILON as f32;
let q1 = $quat::from_euler(EulerRot::YXZ, 0.0, 0.0, 0.0);
let q2 = $quat::from_euler(EulerRot::YXZ, TAU * 0.25, 0.0, 0.0);
let q3 = $quat::from_euler(EulerRot::YXZ, TAU * 0.5, 0.0, 0.0);
Expand Down Expand Up @@ -421,14 +417,14 @@ macro_rules! impl_quat_tests {
glam_test!(test_is_finite, {
assert!($quat::from_xyzw(0.0, 0.0, 0.0, 0.0).is_finite());
assert!($quat::from_xyzw(-1e-10, 1.0, 1e10, 42.0).is_finite());
assert!(!$quat::from_xyzw(INFINITY, 0.0, 0.0, 0.0).is_finite());
assert!(!$quat::from_xyzw(0.0, NAN, 0.0, 0.0).is_finite());
assert!(!$quat::from_xyzw(0.0, 0.0, NEG_INFINITY, 0.0).is_finite());
assert!(!$quat::from_xyzw(0.0, 0.0, 0.0, NAN).is_finite());
assert!(!$quat::from_xyzw($t::INFINITY, 0.0, 0.0, 0.0).is_finite());
assert!(!$quat::from_xyzw(0.0, $t::NAN, 0.0, 0.0).is_finite());
assert!(!$quat::from_xyzw(0.0, 0.0, $t::NEG_INFINITY, 0.0).is_finite());
assert!(!$quat::from_xyzw(0.0, 0.0, 0.0, $t::NAN).is_finite());
});

glam_test!(test_rotation_arc, {
let eps = 2.0 * core::$t::EPSILON.sqrt();
let eps = 2.0 * $t::EPSILON.sqrt();

for &from in &vec3_float_test_vectors!($vec3) {
let from = from.normalize();
Expand Down

0 comments on commit 1b243db

Please sign in to comment.