rustbatch 0.4.0

purely game dewelopment crate that offers simple but powerfull 2D rendering and some fast solutions for game world bottle necks
Documentation
/// module contains some basic helper functions for working with angles
use std::f32::consts::PI;

pub const PI2: f32 = 2.0 * PI;

/// returns smallest number needed to get from a to b, absolute value of result newer exceeds 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
}

/// linear interpolation for angles, it can lerp clockwise of counterclockwise depends on what is
/// shorter
#[inline]
pub fn lerp(a: f32, b: f32, t: f32) -> f32 {
    a + to(a, b) * t
}

/// move_to takes starting angle, destination angle and velocity and it moves to the destination in
/// most effective direction.
#[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))
    }
}