eazy_core/easing/exponential/
expoe.rs

1//! # The Exponent E Curve.
2//!
3//! An algebric curve of degree infinite.
4//!
5//! #### formula.
6//!
7//! `e^x`
8
9use crate::easing::Curve;
10
11use libm::powf;
12
13/// ### The [`InExpoE`] Easing Function.
14///
15/// #### examples.
16///
17/// ```rust
18/// use eazy::Curve;
19/// use eazy::exponential::expoe::InExpoE;
20///
21/// let p = InExpoE.y(0.4);
22/// ```
23#[derive(Debug)]
24pub struct InExpoE;
25
26impl Curve for InExpoE {
27  #[inline(always)]
28  fn y(&self, p: f32) -> f32 {
29    if p <= 0.0 {
30      return 0.0;
31    }
32
33    powf(core::f32::consts::E, -10.0 * (1.0 - p))
34  }
35}
36
37#[test]
38fn test_in_expoe() {
39  let p = InExpoE.y(1.0);
40
41  assert_eq!(p, 1.0);
42}
43
44/// ### The [`OutExpoE`] Easing Function.
45///
46/// #### examples.
47///
48/// ```rust
49/// use eazy::Curve;
50/// use eazy::exponential::expoe::OutExpoE;
51///
52/// let p = OutExpoE.y(0.4);
53/// ```
54#[derive(Debug)]
55pub struct OutExpoE;
56
57impl Curve for OutExpoE {
58  #[inline(always)]
59  fn y(&self, p: f32) -> f32 {
60    1.0 - InExpoE.y(1.0 - p)
61  }
62}
63
64#[test]
65fn test_out_expoe() {
66  let p = OutExpoE.y(1.0);
67
68  assert_eq!(p, 1.0);
69}
70
71/// ### The [`InOutExpoE`] Easing Function.
72///
73/// #### examples.
74///
75/// ```rust
76/// use eazy::Curve;
77/// use eazy::exponential::expoe::InOutExpoE;
78///
79/// let p = InOutExpoE.y(0.4);
80/// ```
81#[derive(Debug)]
82pub struct InOutExpoE;
83
84impl Curve for InOutExpoE {
85  #[inline(always)]
86  fn y(&self, p: f32) -> f32 {
87    let t = p * 2.0;
88
89    if t < 1.0 {
90      return 0.5 - 0.5 * OutExpoE.y(1.0 - t);
91    }
92
93    0.5 + 0.5 * OutExpoE.y(t - 1.0)
94  }
95}
96
97#[test]
98fn test_in_out_expoe() {
99  let p = InOutExpoE.y(1.0);
100
101  assert_eq!(p, 1.0);
102}