1use std::f32::consts::PI;
9
10#[inline]
11fn powf(base: f32, exp: f32) -> f32 {
12 base.powf(exp)
13}
14
15#[inline]
17pub fn linear(t: f32) -> f32 {
18 t
19}
20
21#[inline]
25pub fn quadratic_in(t: f32) -> f32 {
26 t * t
27}
28
29#[inline]
33pub fn quadratic_out(t: f32) -> f32 {
34 -(t * (t - 2.))
35}
36
37#[inline]
39pub fn quadratic_in_out(t: f32) -> f32 {
40 if t < 0.5 {
41 2. * t * t
42 } else {
43 (-2. * t * t) + (4. * t) - 1.
44 }
45}
46
47#[inline]
51pub fn cubic_in(t: f32) -> f32 {
52 t * t * t
53}
54
55#[inline]
57pub fn cubic_out(t: f32) -> f32 {
58 let f = t - 1.;
59 f * f * f + 1.
60}
61
62#[inline]
64pub fn cubic_in_out(t: f32) -> f32 {
65 if t < 0.5 {
66 4. * t * t * t
67 } else {
68 let f = (2. * t) - 2.;
69 0.5 * f * f * f + 1.
70 }
71}
72
73#[inline]
77pub fn sin_in(t: f32) -> f32 {
78 ((t - 1.) * 2. * PI).sin() + 1.
79}
80
81#[inline]
85pub fn sin_out(t: f32) -> f32 {
86 (t * 2. * PI).sin()
87}
88
89#[inline]
93pub fn sin_in_out(t: f32) -> f32 {
94 0.5 * (1. - (t * PI).cos())
95}
96
97#[inline]
101pub fn circular_in(t: f32) -> f32 {
102 1. - (1. - t * t).sqrt()
103}
104
105#[inline]
109pub fn circular_out(t: f32) -> f32 {
110 (2. - t).sqrt() * t
111}
112
113#[inline]
115pub fn circular_in_out(t: f32) -> f32 {
116 if t < 0.5 {
117 0.5 * (1. - (1. - 4. * t * t).sqrt())
118 } else {
119 0.5 * ((-(2. * t - 3.) * (2. * t - 1.)).sqrt() + 1.)
120 }
121}
122
123#[inline]
127pub fn exponential_in(t: f32) -> f32 {
128 if t == 0. {
129 t
130 } else {
131 powf(2.0, 10. * (t - 1.))
132 }
133}
134
135#[inline]
139pub fn exponential_out(t: f32) -> f32 {
140 if t == 1. { t } else { 1. - powf(2.0, -10. * t) }
141}
142
143#[inline]
147pub fn exponential_in_out(t: f32) -> f32 {
148 if t == 0. || t == 1. {
149 t
150 } else if t < 0.5 {
151 0.5 * powf(2.0, 20. * t - 10.)
152 } else {
153 0.5 * powf(2.0, -20. * t + 10.) + 1.
154 }
155}
156
157#[inline]
159pub fn back_in(t: f32) -> f32 {
160 t * t * t - t * (t * PI).sin()
161}
162
163#[inline]
165pub fn back_out(t: f32) -> f32 {
166 let f = 1. - t;
167 1. - (f * f * f - f * (f * PI).sin())
168}
169
170#[inline]
172pub fn back_in_out(t: f32) -> f32 {
173 if t < 0.5 {
174 let f = 2. * t;
175 0.5 * (f * f * f - f * (f * PI).sin())
176 } else {
177 let f = 1. - (2. * t - 1.);
178 0.5 * (1. - (f * f * f - f * (f * PI).sin())) + 0.5
179 }
180}
181
182#[inline]
186pub fn bounce_in(t: f32) -> f32 {
187 1. - bounce_out(1. - t)
188}
189
190#[inline]
194pub fn bounce_out(t: f32) -> f32 {
195 if t < 4. / 11. {
196 const T2: f32 = 121. / 16.;
197 T2 * t * t
198 } else if t < 8. / 11. {
199 const T2: f32 = 363. / 40.;
200 const T1: f32 = -99. / 10.;
201 const T0: f32 = 17. / 5.;
202 T2 * t * t + T1 * t + T0
203 } else if t < 9. / 10. {
204 const T2: f32 = 4356. / 361.;
205 const T1: f32 = -35442. / 1805.;
206 const T0: f32 = 16061. / 1805.;
207 T2 * t * t + T1 * t + T0
208 } else {
209 const T2: f32 = 54. / 5.;
210 const T1: f32 = -513. / 25.;
211 const T0: f32 = 268. / 25.;
212 T2 * t * t + T1 * t + T0
213 }
214}
215
216#[inline]
220pub fn bounce_in_out(t: f32) -> f32 {
221 if t < 0.5 {
222 0.5 * bounce_in(t * 2.)
223 } else {
224 0.5 * bounce_out(t * 2. - 1.) + 0.5
225 }
226}