1pub mod backtracking;
21pub mod bezier;
22pub mod exponential;
23pub mod logarithmic;
24pub mod oscillatory;
25pub mod polynomial;
26pub mod root;
27pub mod trigonometric;
28
29use wide::f32x8;
30
31pub trait Curve {
35 fn y(&self, p: f32) -> f32;
63}
64
65impl<T: Curve + ?Sized> Curve for &T {
67 #[inline(always)]
68 fn y(&self, p: f32) -> f32 {
69 (**self).y(p)
70 }
71}
72
73pub trait CurveSIMD {
75 fn y(&self, p: f32x8) -> f32x8;
103}
104
105pub trait Ease {
107 fn ease(p: f32, a: f32, b: f32) -> f32;
127}
128
129#[derive(Debug, Default, Clone)]
133pub enum Easing {
134 None,
136 #[default]
138 Linear,
139 InQuadratic,
141 InCubic,
142 InQuartic,
143 InQuintic,
144 InSextic,
145 InSeptic,
146 InOctic,
147 InNonic,
148 InDecic,
149 InHectic,
150 OutQuadratic,
152 OutCubic,
153 OutQuartic,
154 OutQuintic,
155 OutSextic,
156 OutSeptic,
157 OutOctic,
158 OutNonic,
159 OutDecic,
160 OutHectic,
161 InOutQuadratic,
163 InOutCubic,
164 InOutQuartic,
165 InOutQuintic,
166 InOutSextic,
167 InOutSeptic,
168 InOutOctic,
169 InOutNonic,
170 InOutDecic,
171 InOutHectic,
172 InSine,
174 InCircle,
175 OutSine,
177 OutCircle,
178 InOutSine,
180 InOutCircle,
181 InExpo2,
183 InExpoE,
184 OutExpo2,
186 OutExpoE,
187 InOutExpo2,
189 InOutExpoE,
190 InLog10,
192 OutLog10,
194 InOutLog10,
196 InSqrt,
198 OutSqrt,
200 InOutSqrt,
202 InElastic,
204 InBounce,
205 OutElastic,
207 OutBounce,
208 InOutElastic,
210 InOutBounce,
211 Spring,
213 InBack,
215 OutBack,
217 InOutBack,
219 CubicBezier(bezier::Bezier),
221 Interpolation(crate::interpolation::Interpolation),
223 }
226
227impl Curve for Easing {
228 #[inline(always)]
229 fn y(&self, p: f32) -> f32 {
230 match self {
231 Self::None => polynomial::none::None.y(p),
232 Self::Linear => polynomial::linear::Linear.y(p),
233 Self::InQuadratic => polynomial::quadratic::InQuadratic.y(p),
234 Self::InCubic => polynomial::cubic::InCubic.y(p),
235 Self::InQuartic => polynomial::quartic::InQuartic.y(p),
236 Self::InQuintic => polynomial::quintic::InQuintic.y(p),
237 Self::InSextic => polynomial::sextic::InSextic.y(p),
238 Self::InSeptic => polynomial::septic::InSeptic.y(p),
239 Self::InOctic => polynomial::octic::InOctic.y(p),
240 Self::InNonic => polynomial::nonic::InNonic.y(p),
241 Self::InDecic => polynomial::decic::InDecic.y(p),
242 Self::InHectic => polynomial::hectic::InHectic.y(p),
243 Self::OutQuadratic => polynomial::quadratic::OutQuadratic.y(p),
244 Self::OutCubic => polynomial::cubic::OutCubic.y(p),
245 Self::OutQuartic => polynomial::quartic::OutQuartic.y(p),
246 Self::OutQuintic => polynomial::quintic::OutQuintic.y(p),
247 Self::OutSextic => polynomial::sextic::OutSextic.y(p),
248 Self::OutSeptic => polynomial::septic::OutSeptic.y(p),
249 Self::OutOctic => polynomial::octic::OutOctic.y(p),
250 Self::OutNonic => polynomial::nonic::OutNonic.y(p),
251 Self::OutDecic => polynomial::decic::OutDecic.y(p),
252 Self::OutHectic => polynomial::hectic::OutHectic.y(p),
253 Self::InOutQuadratic => polynomial::quadratic::InOutQuadratic.y(p),
254 Self::InOutCubic => polynomial::cubic::InOutCubic.y(p),
255 Self::InOutQuartic => polynomial::quartic::InOutQuartic.y(p),
256 Self::InOutQuintic => polynomial::quintic::InOutQuintic.y(p),
257 Self::InOutSextic => polynomial::sextic::InOutSextic.y(p),
258 Self::InOutSeptic => polynomial::septic::InOutSeptic.y(p),
259 Self::InOutOctic => polynomial::octic::InOutOctic.y(p),
260 Self::InOutNonic => polynomial::nonic::InOutNonic.y(p),
261 Self::InOutDecic => polynomial::decic::InOutDecic.y(p),
262 Self::InOutHectic => polynomial::hectic::InOutHectic.y(p),
263 Self::InSine => trigonometric::sine::InSine.y(p),
264 Self::InCircle => trigonometric::circle::InCircle.y(p),
265 Self::OutSine => trigonometric::sine::OutSine.y(p),
266 Self::OutCircle => trigonometric::circle::OutCircle.y(p),
267 Self::InOutSine => trigonometric::sine::InOutSine.y(p),
268 Self::InOutCircle => trigonometric::circle::InOutCircle.y(p),
269 Self::InExpo2 => exponential::expo2::InExpo2.y(p),
270 Self::InExpoE => exponential::expoe::InExpoE.y(p),
271 Self::OutExpo2 => exponential::expo2::OutExpo2.y(p),
272 Self::OutExpoE => exponential::expoe::InExpoE.y(p),
273 Self::InOutExpo2 => exponential::expo2::InOutExpo2.y(p),
274 Self::InOutExpoE => exponential::expoe::InOutExpoE.y(p),
275 Self::InLog10 => logarithmic::log10::InLog10.y(p),
276 Self::OutLog10 => logarithmic::log10::OutLog10.y(p),
277 Self::InOutLog10 => logarithmic::log10::InOutLog10.y(p),
278 Self::InSqrt => root::sqrt::InSqrt.y(p),
279 Self::OutSqrt => root::sqrt::OutSqrt.y(p),
280 Self::InOutSqrt => root::sqrt::InOutSqrt.y(p),
281 Self::InElastic => oscillatory::elastic::InElastic.y(p),
282 Self::InBounce => oscillatory::bounce::InBounce.y(p),
283 Self::OutElastic => oscillatory::elastic::OutElastic.y(p),
284 Self::OutBounce => oscillatory::bounce::OutBounce.y(p),
285 Self::InOutElastic => oscillatory::elastic::InOutElastic.y(p),
286 Self::InOutBounce => oscillatory::bounce::InOutBounce.y(p),
287 Self::Spring => oscillatory::spring::Spring.y(p),
288 Self::InBack => backtracking::back::InBack.y(p),
289 Self::OutBack => backtracking::back::OutBack.y(p),
290 Self::InOutBack => backtracking::back::InOutBack.y(p),
291 Self::CubicBezier(bezier) => bezier.y(p),
292 Self::Interpolation(interpolation) => interpolation.y(p),
293 }
296 }
297}
298
299#[inline(always)]
327pub fn ease(curve: impl Curve, time: f32, start: f32, end: f32) -> f32 {
328 start + (end - start) * curve.y(time)
329}