use crate::easing::*;
#[derive(Copy, Clone, Debug, Default)]
pub struct Linear;
impl EasingFunction for Linear {
#[inline]
fn y(&self, x: f64) -> f64 {
x
}
}
#[derive(Copy, Clone, Debug, Default)]
pub struct Step;
impl EasingFunction for Step {
#[inline]
fn y(&self, x: f64) -> f64 {
x.round()
}
}
#[derive(Copy, Clone, Debug, Default)]
pub struct Hold;
impl EasingFunction for Hold {
#[inline]
fn y(&self, _x: f64) -> f64 {
0.0
}
}
#[derive(Copy, Clone, Debug, Default)]
pub struct EaseInQuad;
impl EasingFunction for EaseInQuad {
#[inline]
fn y(&self, x: f64) -> f64 {
x * x
}
}
#[derive(Copy, Clone, Debug, Default)]
pub struct EaseOutQuad;
impl EasingFunction for EaseOutQuad {
#[inline]
fn y(&self, x: f64) -> f64 {
x * (2.0 - x)
}
}
#[derive(Copy, Clone, Debug, Default)]
pub struct EaseInOutQuad;
impl EasingFunction for EaseInOutQuad {
#[inline]
fn y(&self, x: f64) -> f64 {
if x < 0.5 {
2.0 * x * x
} else {
-1.0 + (4.0 - 2.0 * x) * x
}
}
}
#[derive(Copy, Clone, Debug, Default)]
pub struct EaseInCubic;
impl EasingFunction for EaseInCubic {
#[inline]
fn y(&self, x: f64) -> f64 {
x * x * x
}
}
#[derive(Copy, Clone, Debug, Default)]
pub struct EaseOutCubic;
impl EasingFunction for EaseOutCubic {
#[inline]
fn y(&self, x: f64) -> f64 {
let x_minus_one = x - 1.0;
1.0 + x_minus_one * x_minus_one * x_minus_one
}
}
#[derive(Copy, Clone, Debug, Default)]
pub struct EaseInOutCubic;
impl EasingFunction for EaseInOutCubic {
#[inline]
fn y(&self, x: f64) -> f64 {
if x < 0.5 {
4.0 * x * x * x
} else {
let x_minus_one = x - 1.0;
x_minus_one * (2.0 * x - 2.0) * (2.0 * x - 2.0) + 1.0
}
}
}
#[derive(Copy, Clone, Debug, Default)]
pub struct EaseInQuart;
impl EasingFunction for EaseInQuart {
#[inline]
fn y(&self, x: f64) -> f64 {
x * x * x * x
}
}
#[derive(Copy, Clone, Debug, Default)]
pub struct EaseOutQuart;
impl EasingFunction for EaseOutQuart {
#[inline]
fn y(&self, x: f64) -> f64 {
let x_minus_one = x - 1.0;
1.0 - x_minus_one * x_minus_one * x_minus_one * x_minus_one
}
}
#[derive(Copy, Clone, Debug, Default)]
pub struct EaseInOutQuart;
impl EasingFunction for EaseInOutQuart {
#[inline]
fn y(&self, x: f64) -> f64 {
if x < 0.5 {
8.0 * x * x * x * x
} else {
let x_minus_one = x - 1.0;
1.0 - 8.0 * x_minus_one * x_minus_one * x_minus_one * x_minus_one
}
}
}
#[derive(Copy, Clone, Debug, Default)]
pub struct EaseInQuint;
impl EasingFunction for EaseInQuint {
#[inline]
fn y(&self, x: f64) -> f64 {
x * x * x * x * x
}
}
#[derive(Copy, Clone, Debug, Default)]
pub struct EaseOutQuint;
impl EasingFunction for EaseOutQuint {
#[inline]
fn y(&self, x: f64) -> f64 {
let x_minus_one = x - 1.0;
1.0 + x_minus_one * x_minus_one * x_minus_one * x_minus_one * x_minus_one
}
}
#[derive(Copy, Clone, Debug, Default)]
pub struct EaseInOutQuint;
impl EasingFunction for EaseInOutQuint {
#[inline]
fn y(&self, x: f64) -> f64 {
if x < 0.5 {
16.0 * x * x * x * x * x
} else {
let x_minus_one = x - 1.0;
1.0 + 16.0 * x_minus_one * x_minus_one * x_minus_one * x_minus_one * x_minus_one
}
}
}
#[derive(Copy, Clone, Debug, Default)]
pub struct EaseIn;
impl EasingFunction for EaseIn {
#[inline]
fn y(&self, x: f64) -> f64 {
((x - 1.0) * core::f64::consts::FRAC_PI_2).sin() + 1.0
}
}
#[derive(Copy, Clone, Debug, Default)]
pub struct EaseOut;
impl EasingFunction for EaseOut {
#[inline]
fn y(&self, x: f64) -> f64 {
(x * core::f64::consts::FRAC_PI_2).sin()
}
}
#[derive(Copy, Clone, Debug, Default)]
pub struct EaseInOut;
impl EasingFunction for EaseInOut {
#[inline]
fn y(&self, x: f64) -> f64 {
0.5 * (1.0 - (x * core::f64::consts::PI).cos())
}
}