eazy_core/easing/polynomial/
decic.rs

1//! # The Decic Curve.
2//!
3//! An algebric curve of degree ten.
4//!
5//! #### formula.
6//!
7//! `p^10`
8
9use crate::easing::Curve;
10
11/// ### The [`InDecic`] Easing Function.
12///
13/// #### examples.
14///
15/// ```
16/// use eazy::Curve;
17/// use eazy::polynomial::decic::InDecic;
18///
19/// let p = InDecic.y(1.0);
20/// ```
21#[derive(Debug)]
22pub struct InDecic;
23
24impl Curve for InDecic {
25  #[inline(always)]
26  fn y(&self, p: f32) -> f32 {
27    p * p * p * p * p * p * p * p * p * p
28  }
29}
30
31#[test]
32fn test_in_decic() {
33  let p = InDecic.y(1.0);
34
35  assert_eq!(p, 1.0);
36}
37
38/// ### The [`OutDecic`] Easing Function.
39///
40/// #### examples.
41///
42/// ```
43/// use eazy::Curve;
44/// use eazy::polynomial::decic::OutDecic;
45///
46/// let p = OutDecic.y(1.0);
47/// ```
48#[derive(Debug)]
49pub struct OutDecic;
50
51impl Curve for OutDecic {
52  #[inline(always)]
53  fn y(&self, p: f32) -> f32 {
54    let m = p - 1.0;
55
56    1.0 - m * m * m * m * m * m * m * m * m * m
57  }
58}
59
60#[test]
61fn test_out_decic() {
62  let p = OutDecic.y(1.0);
63
64  assert_eq!(p, 1.0);
65}
66
67/// ### The [`InOutDecic`] Easing Function.
68///
69/// #### examples.
70///
71/// ```
72/// use eazy::Curve;
73/// use eazy::polynomial::decic::InOutDecic;
74///
75/// let p = InOutDecic.y(1.0);
76/// ```
77#[derive(Debug)]
78pub struct InOutDecic;
79
80impl Curve for InOutDecic {
81  #[inline(always)]
82  fn y(&self, p: f32) -> f32 {
83    let m = p - 1.0;
84    let t = p * 2.0;
85
86    if t < 1.0 {
87      return p * t * t * t * t * t * t * t * t;
88    }
89
90    1.0 - m * m * m * m * m * m * m * m * m * m * 512.0
91  }
92}
93
94#[test]
95fn test_in_out_decic() {
96  let p = InOutDecic.y(1.0);
97
98  assert_eq!(p, 1.0);
99}