eazy_data/easing/exponential/
expo2.rs1use crate::easing::Curve;
9
10use libm::exp2f;
11
12#[derive(Debug)]
23pub struct InExpo2;
24
25impl Curve for InExpo2 {
26 #[inline(always)]
27 fn y(&self, p: f32) -> f32 {
28 if p <= 0.0 {
29 return 0.0;
30 }
31
32 exp2f(10.0 * (p - 1.0))
33 }
34}
35
36#[test]
37fn test_in_expo2() {
38 let p = InExpo2.y(1.0);
39
40 assert_eq!(p, 1.0);
41}
42
43#[derive(Debug)]
54pub struct OutExpo2;
55
56impl Curve for OutExpo2 {
57 #[inline(always)]
58 fn y(&self, p: f32) -> f32 {
59 if p >= 1.0 {
60 return 1.0;
61 }
62
63 1.0 - exp2f(-10.0 * p)
64 }
65}
66
67#[test]
68fn test_out_expo2() {
69 let p = OutExpo2.y(1.0);
70
71 assert_eq!(p, 1.0);
72}
73
74#[derive(Debug)]
85pub struct InOutExpo2;
86
87impl Curve for InOutExpo2 {
88 #[inline(always)]
89 fn y(&self, p: f32) -> f32 {
90 if p <= 0.0 {
91 return 0.0;
92 }
93
94 if p >= 1.0 {
95 return 1.0;
96 }
97
98 if p < 0.5 {
99 return exp2f(10.0 * (2.0 * p - 1.0) - 1.0);
100 }
101
102 1.0 - exp2f(-10.0 * (2.0 * p - 1.0) - 1.0)
103 }
104}
105
106#[test]
107fn test_in_out_expo2() {
108 let p = InOutExpo2.y(1.0);
109
110 assert_eq!(p, 1.0);
111}