use std::f32::consts::PI;
pub const PI2: f32 = 2.0 * PI;
#[inline]
pub fn to(a: f32, b: f32) -> f32 {
let d = (b - a) % PI2;
if d < -PI {
return d + PI2;
}
if d > PI {
return d - PI2;
}
d
}
#[inline]
pub fn lerp(a: f32, b: f32, t: f32) -> f32 {
a + to(a, b) * t
}
#[inline]
pub fn move_to(s: f32, d: f32, v: f32) -> f32 {
let to = to(s, d);
if to.abs() < v {
return d;
}
if to < 0.0 {
return s - v;
}
s + v
}
#[cfg(test)]
mod tests {
use crate::math::angle;
use crate::math::angle::PI2;
#[test]
fn to_test() {
assert!(angle::to(10.0, 400.0).abs() <= PI2);
assert!(angle::to(10.0, -400.0).abs() <= PI2);
assert_eq!(-1.0 ,angle::to(1.0, PI2))
}
}