rust_rocket/
interpolation.rs1#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
7#[derive(Debug, Copy, Clone)]
8pub enum Interpolation {
9 Step = 0,
11 Linear = 1,
13 Smooth = 2,
15 Ramp = 3,
17}
18
19impl From<u8> for Interpolation {
20 fn from(raw: u8) -> Interpolation {
21 match raw {
22 0 => Interpolation::Step,
23 1 => Interpolation::Linear,
24 2 => Interpolation::Smooth,
25 3 => Interpolation::Ramp,
26 _ => Interpolation::Step,
27 }
28 }
29}
30
31impl Interpolation {
32 pub fn interpolate(&self, t: f32) -> f32 {
46 match *self {
47 Interpolation::Step => 0.0,
48 Interpolation::Linear => t,
49 Interpolation::Smooth => t * t * (3.0 - 2.0 * t),
50 Interpolation::Ramp => t.powi(2),
51 }
52 }
53}