use std::time::Duration;
use crate::easing::Easing;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Tween {
pub duration: Duration,
pub easing: Easing,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Spring {
pub stiffness: f32,
pub damping: f32,
pub mass: f32,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Curve {
Tween(Tween),
Spring(Spring),
}
pub fn tween(duration: Duration, easing: Easing) -> Tween {
Tween { duration, easing }
}
pub fn spring(stiffness: f32, damping: f32) -> Spring {
Spring {
stiffness,
damping,
mass: 1.0,
}
}
impl Spring {
pub fn gentle() -> Spring {
spring(120.0, 14.0)
}
pub fn snappy() -> Spring {
spring(210.0, 20.0)
}
pub fn bouncy() -> Spring {
spring(180.0, 12.0)
}
}
impl From<Tween> for Curve {
fn from(t: Tween) -> Self {
Curve::Tween(t)
}
}
impl From<Spring> for Curve {
fn from(s: Spring) -> Self {
Curve::Spring(s)
}
}