Skip to content

Commit 6e2d8e9

Browse files
committed
test(core/mat4): improve -0.0 diagnostics with axis+index; document angle choice and add FRAC_PI_6/FRAC_PI_3 sanity checks
1 parent d2b9a5b commit 6e2d8e9

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

crates/rmg-core/tests/mat4_mul_tests.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,36 @@ fn mat4_mul_assign_variants_work() {
5151

5252
#[test]
5353
fn rotations_do_not_produce_negative_zero() {
54+
// We target angles that should produce exact zeros in rotation matrices:
55+
// multiples of π/2 yield sin/cos values in { -1, 0, 1 }, which is where
56+
// -0.0 might accidentally appear if we don't canonicalize zeros. We also
57+
// include a couple of intermediate angles as a sanity check (these should
58+
// not introduce exact zeros but must also not yield -0.0 anywhere).
5459
let angles = [
5560
0.0,
61+
core::f32::consts::FRAC_PI_6,
62+
core::f32::consts::FRAC_PI_3,
5663
core::f32::consts::FRAC_PI_2,
5764
core::f32::consts::PI,
5865
3.0 * core::f32::consts::FRAC_PI_2,
5966
2.0 * core::f32::consts::PI,
6067
];
6168
let neg_zero = (-0.0f32).to_bits();
6269
for &a in &angles {
63-
for m in [
64-
Mat4::rotation_x(a),
65-
Mat4::rotation_y(a),
66-
Mat4::rotation_z(a),
67-
] {
68-
for &e in m.to_array().iter() {
70+
let axes = [
71+
("X", Mat4::rotation_x(a)),
72+
("Y", Mat4::rotation_y(a)),
73+
("Z", Mat4::rotation_z(a)),
74+
];
75+
for (axis, m) in axes {
76+
for (idx, &e) in m.to_array().iter().enumerate() {
6977
assert_ne!(
7078
e.to_bits(),
7179
neg_zero,
72-
"found -0.0 in rotation matrix for angle {a}"
80+
"found -0.0 in rotation_{} matrix at element [{}] for angle {}",
81+
axis,
82+
idx,
83+
a
7384
);
7485
}
7586
}

0 commit comments

Comments
 (0)