utility_games 0.1.1

utils to make games and more
Documentation
use mint::Point2;
pub type Pos = Point2<f32>;
pub type Size = Point2<f32>;

pub fn new_pos(x: f32, y: f32) -> Pos {
    Pos { x, y }
}

pub fn get_corners(pos: Pos, size: Size) -> [Pos; 4] {
    [
        pos,
        new_pos(pos.x + size.x, pos.y),
        new_pos(pos.x + size.x, pos.y + size.y),
        new_pos(pos.x, pos.y + size.y),
    ]
}
pub fn get_corners_fmiddle(pos: Pos, size: Size) -> [Pos; 4] {
    [
        new_pos(pos.x - size.x/2.0, pos.y - size.y/2.0),
        new_pos(pos.x + size.x/2.0, pos.y - size.y/2.0),
        new_pos(pos.x + size.x/2.0, pos.y + size.y/2.0),
        new_pos(pos.x - size.x/2.0, pos.y + size.y/2.0),
    ]
}
pub fn get_middle(pos: Pos, size: Size) -> Pos {
    new_pos(pos.x + size.x / 2.0, pos.y + size.y / 2.0)
}

#[cfg(feature = "rand")]
pub fn random_zone(default_pos: Pos, r: f32) -> Pos {
    use rand::Rng;

    let mut rng = rand::thread_rng();
    let random_x: f32 = rng.gen_range(0.0..r);
    let random_y: f32 = rng.gen_range(0.0..r);
    new_pos(default_pos.x + random_x, default_pos.y + random_y)
}