use std::f64;
use std::f64::consts::PI;
use rand::{Rand, Rng};
use radians::Radians;
use {Distance};
#[derive(Debug, Clone, Copy, PartialOrd, Ord, PartialEq, Eq)]
pub enum Speed {
One,
Two,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine,
Ten,
Instant,
}
impl Speed {
pub fn to_absolute(self) -> Distance {
use self::Speed::*;
match self {
One => 50.,
Two => 100.,
Three => 150.,
Four => 200.,
Five => 250.,
Six => 300.,
Seven => 350.,
Eight => 400.,
Nine => 450.,
Ten => 500.,
Instant => f64::INFINITY,
}
}
pub fn to_rotation(self) -> Radians {
use self::Speed::*;
Radians::from_radians_value(match self {
One => 0.7 * PI,
Two => 0.9 * PI,
Three => 1.1 * PI,
Four => 1.3 * PI,
Five => 1.5 * PI,
Six => 2.5 * PI,
Seven => 3.5 * PI,
Eight => 4.0 * PI,
Nine => 8.0 * PI,
Ten => 12.0 * PI,
Instant => f64::INFINITY,
})
}
}
impl Rand for Speed {
fn rand<R: Rng>(rng: &mut R) -> Self {
(rng.gen::<i32>() % 10).into()
}
}
impl<'a> From<&'a str> for Speed {
fn from(s: &'a str) -> Self {
use Speed::*;
match s {
"slowest" => One,
"slow" => Three,
"normal" => Six,
"fast" => Eight,
"fastest" => Ten,
"instant" => Instant,
_ => panic!("Invalid speed specified, use one of the words: 'slowest', 'slow', 'normal', 'fast', 'fastest', 'instant'"),
}
}
}
impl From<i32> for Speed {
fn from(n: i32) -> Self {
use Speed::*;
match n {
1 => One,
2 => Two,
3 => Three,
4 => Four,
5 => Five,
6 => Six,
7 => Seven,
8 => Eight,
9 => Nine,
10 => Ten,
_ => Instant,
}
}
}