Skip to content

Commit

Permalink
Combine from_angle and to_angle tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-blackbird committed Oct 10, 2023
1 parent f2b8f4c commit c00feb7
Showing 1 changed file with 21 additions and 29 deletions.
50 changes: 21 additions & 29 deletions tests/vec2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -896,35 +896,27 @@ macro_rules! impl_vec2_float_tests {
);
});

glam_test!(test_from_angle, {
assert_approx_eq!($vec2::from_angle(0.0), $vec2::new(1.0, 0.0));
assert_approx_eq!(
$vec2::from_angle(core::$t::consts::FRAC_PI_2),
$vec2::new(0.0, 1.0)
);
assert_approx_eq!(
$vec2::from_angle(core::$t::consts::PI),
$vec2::new(-1.0, 0.0)
);
assert_approx_eq!(
$vec2::from_angle(-core::$t::consts::FRAC_PI_2),
$vec2::new(0.0, -1.0)
);
});

glam_test!(test_to_angle, {
assert_approx_eq!($vec2::new(1.0, 0.0).to_angle(), 0.0);
assert_approx_eq!(
$vec2::new(0.0, 1.0).to_angle(),
core::$t::consts::FRAC_PI_2,
1e-6
);
assert_approx_eq!($vec2::new(-1.0, 0.0).to_angle(), core::$t::consts::PI, 1e-6);
assert_approx_eq!(
$vec2::new(0.0, -1.0).to_angle(),
-core::$t::consts::FRAC_PI_2,
1e-6
);
glam_test!(test_angle_conversion, {
let angle = 0.;
let vec = $vec2::from_angle(angle);
assert_approx_eq!(vec, $vec2::new(1.0, 0.0));
assert_approx_eq!(vec.to_angle(), angle);

let angle = core::$t::consts::FRAC_PI_2;
let vec = $vec2::from_angle(angle);
assert_approx_eq!(vec, $vec2::new(0.0, 1.0));
assert_approx_eq!(vec.to_angle(), angle);

let angle = core::$t::consts::PI;
let vec = $vec2::from_angle(angle);
assert_approx_eq!(vec, $vec2::new(-1.0, 0.0));
// The sign of the angle PI gets flipped and is slightly less precise but correct
assert_approx_eq!(vec.to_angle().abs(), angle, 1e-6);

let angle = -core::$t::consts::FRAC_PI_2;
let vec = $vec2::from_angle(angle);
assert_approx_eq!(vec, $vec2::new(0.0, -1.0));
assert_approx_eq!(vec.to_angle(), angle);
});
};
}
Expand Down

0 comments on commit c00feb7

Please sign in to comment.