use approx::assert_abs_diff_eq;
use crate::types::Position;
#[track_caller]
fn expect_array_ne(got: [f32; 3], expected: [f32; 3]) {
let eq = (0..3).filter(|&i| got[i] == expected[i]).count();
assert_ne!(eq, 3);
}
fn create_position(pos: [f32; 3]) -> Position {
Position::new(pos)
}
#[test]
#[expect(clippy::excessive_precision, reason = "the C++ test's expected values, digit for digit")]
fn calculations() {
let spherical = [2.0, 10.0, 270.0];
let mut position = Position::new(spherical);
expect_array_ne(position.cartesian(), spherical);
assert_abs_diff_eq!(&position.spherical()[..], &spherical[..], epsilon = 0.00001);
assert_abs_diff_eq!(
&position.cartesian()[..],
&[0.347_296_386_957_168_58, -1.969_615_459_442_138_7, 2.384_976_127_700_611e-08][..],
epsilon = 0.00001
);
expect_array_ne(create_position([2.0, 30.0, 10.0]).spherical(), create_position([2.0, 30.0, 370.0]).spherical());
assert_abs_diff_eq!(
&create_position([2.0, 30.0, 10.0]).cartesian()[..],
&create_position([2.0, 30.0, 370.0]).cartesian()[..],
epsilon = 0.00001
);
let new_spherical = [1.0, 80.0, 270.0];
position.set(new_spherical);
expect_array_ne(position.spherical(), spherical);
expect_array_ne(
position.cartesian(),
[0.347_296_386_957_168_58, -1.969_615_459_442_138_7, 2.384_976_127_700_611e-08],
);
assert_abs_diff_eq!(
&position.cartesian()[..],
&[0.984_807_729_721_069_34, -0.173_648_297_786_712_65, 1.192_488_063_850_305_5e-08][..],
epsilon = 0.00001
);
}