4
4
//! [easing functions]: EaseFunction
5
5
6
6
use crate :: { Dir2 , Dir3 , Dir3A , Quat , Rot2 , VectorSpace } ;
7
- use interpolation:: Ease as IEase ;
8
7
9
8
use super :: { function_curve, Curve , Interval } ;
10
9
@@ -219,6 +218,79 @@ mod easing_functions {
219
218
t
220
219
}
221
220
221
+ #[ inline]
222
+ pub ( crate ) fn quadratic_in ( t : f32 ) -> f32 {
223
+ t. squared ( )
224
+ }
225
+ #[ inline]
226
+ pub ( crate ) fn quadratic_out ( t : f32 ) -> f32 {
227
+ 1.0 - ( 1.0 - t) . squared ( )
228
+ }
229
+ #[ inline]
230
+ pub ( crate ) fn quadratic_in_out ( t : f32 ) -> f32 {
231
+ if t < 0.5 {
232
+ 2.0 * t. squared ( )
233
+ } else {
234
+ 1.0 - ( -2.0 * t + 2.0 ) . squared ( ) / 2.0
235
+ }
236
+ }
237
+
238
+ #[ inline]
239
+ pub ( crate ) fn cubic_in ( t : f32 ) -> f32 {
240
+ t. cubed ( )
241
+ }
242
+ #[ inline]
243
+ pub ( crate ) fn cubic_out ( t : f32 ) -> f32 {
244
+ 1.0 - ( 1.0 - t) . cubed ( )
245
+ }
246
+ #[ inline]
247
+ pub ( crate ) fn cubic_in_out ( t : f32 ) -> f32 {
248
+ if t < 0.5 {
249
+ 4.0 * t. cubed ( )
250
+ } else {
251
+ 1.0 - ( -2.0 * t + 2.0 ) . cubed ( ) / 2.0
252
+ }
253
+ }
254
+
255
+ #[ inline]
256
+ pub ( crate ) fn quartic_in ( t : f32 ) -> f32 {
257
+ t * t * t * t
258
+ }
259
+ #[ inline]
260
+ pub ( crate ) fn quartic_out ( t : f32 ) -> f32 {
261
+ 1.0 - ( 1.0 - t) * ( 1.0 - t) * ( 1.0 - t) * ( 1.0 - t)
262
+ }
263
+ #[ inline]
264
+ pub ( crate ) fn quartic_in_out ( t : f32 ) -> f32 {
265
+ if t < 0.5 {
266
+ 8.0 * t * t * t * t
267
+ } else {
268
+ 1.0 - ( -2.0 * t + 2.0 ) * ( -2.0 * t + 2.0 ) * ( -2.0 * t + 2.0 ) * ( -2.0 * t + 2.0 ) / 2.0
269
+ }
270
+ }
271
+
272
+ #[ inline]
273
+ pub ( crate ) fn quintic_in ( t : f32 ) -> f32 {
274
+ t * t * t * t * t
275
+ }
276
+ #[ inline]
277
+ pub ( crate ) fn quintic_out ( t : f32 ) -> f32 {
278
+ 1.0 - ( 1.0 - t) * ( 1.0 - t) * ( 1.0 - t) * ( 1.0 - t) * ( 1.0 - t)
279
+ }
280
+ #[ inline]
281
+ pub ( crate ) fn quintic_in_out ( t : f32 ) -> f32 {
282
+ if t < 0.5 {
283
+ 16.0 * t * t * t * t * t
284
+ } else {
285
+ 1.0 - ( -2.0 * t + 2.0 )
286
+ * ( -2.0 * t + 2.0 )
287
+ * ( -2.0 * t + 2.0 )
288
+ * ( -2.0 * t + 2.0 )
289
+ * ( -2.0 * t + 2.0 )
290
+ / 2.0
291
+ }
292
+ }
293
+
222
294
#[ inline]
223
295
pub ( crate ) fn sine_in ( t : f32 ) -> f32 {
224
296
1.0 - ops:: cos ( t * FRAC_PI_2 )
@@ -227,6 +299,44 @@ mod easing_functions {
227
299
pub ( crate ) fn sine_out ( t : f32 ) -> f32 {
228
300
ops:: sin ( t * FRAC_PI_2 )
229
301
}
302
+ #[ inline]
303
+ pub ( crate ) fn sine_in_out ( t : f32 ) -> f32 {
304
+ -( ops:: cos ( PI * t) - 1.0 ) / 2.0
305
+ }
306
+
307
+ #[ inline]
308
+ pub ( crate ) fn circular_in ( t : f32 ) -> f32 {
309
+ 1.0 - ( 1.0 - t. squared ( ) ) . sqrt ( )
310
+ }
311
+ #[ inline]
312
+ pub ( crate ) fn circular_out ( t : f32 ) -> f32 {
313
+ ( 1.0 - ( t - 1.0 ) . squared ( ) ) . sqrt ( )
314
+ }
315
+ #[ inline]
316
+ pub ( crate ) fn circular_in_out ( t : f32 ) -> f32 {
317
+ if t < 0.5 {
318
+ ( 1.0 - ( 1.0 - ( 2.0 * t) . squared ( ) ) . sqrt ( ) ) / 2.0
319
+ } else {
320
+ ( ( 1.0 - ( -2.0 * t + 2.0 ) . squared ( ) ) . sqrt ( ) + 1.0 ) / 2.0
321
+ }
322
+ }
323
+
324
+ #[ inline]
325
+ pub ( crate ) fn exponential_in ( t : f32 ) -> f32 {
326
+ ops:: powf ( 2.0 , 10.0 * t - 10.0 )
327
+ }
328
+ #[ inline]
329
+ pub ( crate ) fn exponential_out ( t : f32 ) -> f32 {
330
+ 1.0 - ops:: powf ( 2.0 , -10.0 * t)
331
+ }
332
+ #[ inline]
333
+ pub ( crate ) fn exponential_in_out ( t : f32 ) -> f32 {
334
+ if t < 0.5 {
335
+ ops:: powf ( 2.0 , 20.0 * t - 10.0 ) / 2.0
336
+ } else {
337
+ ( 2.0 - ops:: powf ( 2.0 , -20.0 * t + 10.0 ) ) / 2.0
338
+ }
339
+ }
230
340
231
341
#[ inline]
232
342
pub ( crate ) fn back_in ( t : f32 ) -> f32 {
@@ -271,6 +381,31 @@ mod easing_functions {
271
381
}
272
382
}
273
383
384
+ #[ inline]
385
+ pub ( crate ) fn bounce_in ( t : f32 ) -> f32 {
386
+ 1.0 - bounce_out ( 1.0 - t)
387
+ }
388
+ #[ inline]
389
+ pub ( crate ) fn bounce_out ( t : f32 ) -> f32 {
390
+ if t < 4.0 / 11.0 {
391
+ ( 121.0 * t. squared ( ) ) / 16.0
392
+ } else if t < 8.0 / 11.0 {
393
+ ( 363.0 / 40.0 * t. squared ( ) ) - ( 99.0 / 10.0 * t) + 17.0 / 5.0
394
+ } else if t < 9.0 / 10.0 {
395
+ ( 4356.0 / 361.0 * t. squared ( ) ) - ( 35442.0 / 1805.0 * t) + 16061.0 / 1805.0
396
+ } else {
397
+ ( 54.0 / 5.0 * t. squared ( ) ) - ( 513.0 / 25.0 * t) + 268.0 / 25.0
398
+ }
399
+ }
400
+ #[ inline]
401
+ pub ( crate ) fn bounce_in_out ( t : f32 ) -> f32 {
402
+ if t < 0.5 {
403
+ ( 1.0 - bounce_out ( 1.0 - 2.0 * t) ) / 2.0
404
+ } else {
405
+ ( 1.0 + bounce_out ( 2.0 * t - 1.0 ) ) / 2.0
406
+ }
407
+ }
408
+
274
409
#[ inline]
275
410
pub ( crate ) fn steps ( num_steps : usize , t : f32 ) -> f32 {
276
411
( t * num_steps as f32 ) . round ( ) / num_steps. max ( 1 ) as f32
@@ -286,36 +421,36 @@ impl EaseFunction {
286
421
fn eval ( & self , t : f32 ) -> f32 {
287
422
match self {
288
423
EaseFunction :: Linear => easing_functions:: linear ( t) ,
289
- EaseFunction :: QuadraticIn => IEase :: quadratic_in ( t) ,
290
- EaseFunction :: QuadraticOut => IEase :: quadratic_out ( t) ,
291
- EaseFunction :: QuadraticInOut => IEase :: quadratic_in_out ( t) ,
292
- EaseFunction :: CubicIn => IEase :: cubic_in ( t) ,
293
- EaseFunction :: CubicOut => IEase :: cubic_out ( t) ,
294
- EaseFunction :: CubicInOut => IEase :: cubic_in_out ( t) ,
295
- EaseFunction :: QuarticIn => IEase :: quartic_in ( t) ,
296
- EaseFunction :: QuarticOut => IEase :: quartic_out ( t) ,
297
- EaseFunction :: QuarticInOut => IEase :: quartic_in_out ( t) ,
298
- EaseFunction :: QuinticIn => IEase :: quintic_in ( t) ,
299
- EaseFunction :: QuinticOut => IEase :: quintic_out ( t) ,
300
- EaseFunction :: QuinticInOut => IEase :: quintic_in_out ( t) ,
424
+ EaseFunction :: QuadraticIn => easing_functions :: quadratic_in ( t) ,
425
+ EaseFunction :: QuadraticOut => easing_functions :: quadratic_out ( t) ,
426
+ EaseFunction :: QuadraticInOut => easing_functions :: quadratic_in_out ( t) ,
427
+ EaseFunction :: CubicIn => easing_functions :: cubic_in ( t) ,
428
+ EaseFunction :: CubicOut => easing_functions :: cubic_out ( t) ,
429
+ EaseFunction :: CubicInOut => easing_functions :: cubic_in_out ( t) ,
430
+ EaseFunction :: QuarticIn => easing_functions :: quartic_in ( t) ,
431
+ EaseFunction :: QuarticOut => easing_functions :: quartic_out ( t) ,
432
+ EaseFunction :: QuarticInOut => easing_functions :: quartic_in_out ( t) ,
433
+ EaseFunction :: QuinticIn => easing_functions :: quintic_in ( t) ,
434
+ EaseFunction :: QuinticOut => easing_functions :: quintic_out ( t) ,
435
+ EaseFunction :: QuinticInOut => easing_functions :: quintic_in_out ( t) ,
301
436
EaseFunction :: SineIn => easing_functions:: sine_in ( t) ,
302
437
EaseFunction :: SineOut => easing_functions:: sine_out ( t) ,
303
- EaseFunction :: SineInOut => IEase :: sine_in_out ( t) ,
304
- EaseFunction :: CircularIn => IEase :: circular_in ( t) ,
305
- EaseFunction :: CircularOut => IEase :: circular_out ( t) ,
306
- EaseFunction :: CircularInOut => IEase :: circular_in_out ( t) ,
307
- EaseFunction :: ExponentialIn => IEase :: exponential_in ( t) ,
308
- EaseFunction :: ExponentialOut => IEase :: exponential_out ( t) ,
309
- EaseFunction :: ExponentialInOut => IEase :: exponential_in_out ( t) ,
438
+ EaseFunction :: SineInOut => easing_functions :: sine_in_out ( t) ,
439
+ EaseFunction :: CircularIn => easing_functions :: circular_in ( t) ,
440
+ EaseFunction :: CircularOut => easing_functions :: circular_out ( t) ,
441
+ EaseFunction :: CircularInOut => easing_functions :: circular_in_out ( t) ,
442
+ EaseFunction :: ExponentialIn => easing_functions :: exponential_in ( t) ,
443
+ EaseFunction :: ExponentialOut => easing_functions :: exponential_out ( t) ,
444
+ EaseFunction :: ExponentialInOut => easing_functions :: exponential_in_out ( t) ,
310
445
EaseFunction :: ElasticIn => easing_functions:: elastic_in ( t) ,
311
446
EaseFunction :: ElasticOut => easing_functions:: elastic_out ( t) ,
312
447
EaseFunction :: ElasticInOut => easing_functions:: elastic_in_out ( t) ,
313
448
EaseFunction :: BackIn => easing_functions:: back_in ( t) ,
314
449
EaseFunction :: BackOut => easing_functions:: back_out ( t) ,
315
450
EaseFunction :: BackInOut => easing_functions:: back_in_out ( t) ,
316
- EaseFunction :: BounceIn => IEase :: bounce_in ( t) ,
317
- EaseFunction :: BounceOut => IEase :: bounce_out ( t) ,
318
- EaseFunction :: BounceInOut => IEase :: bounce_in_out ( t) ,
451
+ EaseFunction :: BounceIn => easing_functions :: bounce_in ( t) ,
452
+ EaseFunction :: BounceOut => easing_functions :: bounce_out ( t) ,
453
+ EaseFunction :: BounceInOut => easing_functions :: bounce_in_out ( t) ,
319
454
EaseFunction :: Steps ( num_steps) => easing_functions:: steps ( * num_steps, t) ,
320
455
EaseFunction :: Elastic ( omega) => easing_functions:: elastic ( * omega, t) ,
321
456
}
0 commit comments