eazy_data/easing/polynomial/
sextic.rs

1//! # The Sextic Curve.
2//!
3//! An algebric curve of degree six.
4//!
5//! #### formula.
6//!
7//! `p^6`
8
9use crate::easing::Curve;
10
11/// ### The [`InSextic`] Easing Function.
12///
13/// #### examples.
14///
15/// ```
16/// use eazy::Curve;
17/// use eazy::polynomial::sextic::InSextic;
18///
19/// let p = InSextic.y(1.0);
20/// ```
21#[derive(Debug)]
22pub struct InSextic;
23
24impl Curve for InSextic {
25  #[inline(always)]
26  fn y(&self, p: f32) -> f32 {
27    p * p * p * p * p * p
28  }
29}
30
31#[test]
32fn test_in_sextic() {
33  let p = InSextic.y(1.0);
34
35  assert_eq!(p, 1.0);
36}
37
38/// ### The [`OutSextic`] Easing Function.
39///
40/// #### examples.
41///
42/// ```
43/// use eazy::Curve;
44/// use eazy::polynomial::sextic::OutSextic;
45///
46/// let p = OutSextic.y(1.0);
47/// ```
48#[derive(Debug)]
49pub struct OutSextic;
50
51impl Curve for OutSextic {
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
57  }
58}
59
60#[test]
61fn test_out_sextic() {
62  let p = OutSextic.y(1.0);
63
64  assert_eq!(p, 1.0);
65}
66
67/// ### [`InOutSextic`] Easing Function.
68///
69/// #### examples.
70///
71/// ```
72/// use eazy::Curve;
73/// use eazy::polynomial::sextic::InOutSextic;
74///
75/// let p = InOutSextic.y(1.0);
76/// ```
77#[derive(Debug)]
78pub struct InOutSextic;
79
80impl Curve for InOutSextic {
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;
88    }
89
90    1.0 - m * m * m * m * m * m * 32.0
91  }
92}
93
94#[test]
95fn test_in_out_sextic() {
96  let p = InOutSextic.y(1.0);
97
98  assert_eq!(p, 1.0);
99}