eazy_data/easing/oscillatory/
bounce.rs1use crate::easing::Curve;
4
5#[derive(Debug)]
16pub struct InBounce;
17
18impl Curve for InBounce {
19 #[inline(always)]
20 fn y(&self, p: f32) -> f32 {
21 1.0 - OutBounce.y(1.0 - p)
22 }
23}
24
25#[test]
26fn test_in_bounce() {
27 let p = InBounce.y(1.0);
28
29 assert_eq!(p, 1.0);
30}
31
32#[derive(Debug)]
42pub struct OutBounce;
43
44impl Curve for OutBounce {
45 #[inline(always)]
46 fn y(&self, p: f32) -> f32 {
47 let t;
48 let r = 1.0 / 2.75; let k1 = r; let k2 = 2.0 * r; let k3 = 1.5 * r; let k4 = 2.5 * r; let k5 = 2.25 * r; let k6 = 2.625 * r; let k0 = 7.5625;
56
57 if p < k1 {
58 k0 * p * p
59 } else if p < k2 {
60 t = p - k3;
61
62 k0 * t * t + 0.75 } else if p < k4 {
64 t = p - k5;
65
66 k0 * t * t + 0.9375 } else {
68 t = p - k6;
69
70 k0 * t * t + 0.984375 }
72 }
73}
74
75#[test]
76fn test_out_bounce() {
77 let p = OutBounce.y(1.0);
78
79 assert_eq!(p, 1.0);
80}
81
82#[derive(Debug)]
93pub struct InOutBounce;
94
95impl Curve for InOutBounce {
96 #[inline(always)]
97 fn y(&self, p: f32) -> f32 {
98 let t = p * 2.0;
99
100 if t < 1.0 {
101 return 0.5 - 0.5 * OutBounce.y(1.0 - t);
102 }
103
104 0.5 + 0.5 * OutBounce.y(t - 1.0)
105 }
106}
107
108#[test]
109fn test_in_out_bounce() {
110 let p = InOutBounce.y(1.0);
111
112 assert_eq!(p, 1.0);
113}