eazy_data/easing/polynomial/
hectic.rs

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