eazy_core/easing/polynomial/
cubic.rs1use wide::f32x8;
10
11use crate::easing::Curve;
12
13#[derive(Debug)]
25pub struct InCubic;
26
27impl Curve for InCubic {
28 #[inline(always)]
29 fn y(&self, p: f32) -> f32 {
30 p * p * p
31 }
32}
33
34#[test]
35fn test_in_cubic() {
36 let p = InCubic.y(1.0);
37
38 assert_eq!(p, 1.0);
39}
40
41#[derive(Debug)]
52pub struct OutCubic;
53
54impl Curve for OutCubic {
55 #[inline(always)]
56 fn y(&self, p: f32) -> f32 {
57 let m = p - 1.0;
58
59 1.0 + m * m * m
60 }
61}
62
63#[test]
64fn test_out_cubic() {
65 let p = OutCubic.y(1.0);
66
67 assert_eq!(p, 1.0);
68}
69
70#[derive(Debug)]
81pub struct InOutCubic;
82
83impl Curve for InOutCubic {
84 #[inline(always)]
85 fn y(&self, p: f32) -> f32 {
86 let m = p - 1.0;
87 let t = p * 2.0;
88
89 if t < 1.0 {
90 p * t * t
91 } else {
92 1.0 + m * m * m * 4.0
93 }
94 }
95}
96
97use wide::CmpLt;
98
99pub fn in_out_cubic_simd(p: f32x8) -> f32x8 {
100 let one = f32x8::splat(1.0);
101 let two = f32x8::splat(2.0);
102 let four = f32x8::splat(4.0);
103
104 let m = p - one;
105 let t = p * two;
106
107 let t_branch = p * t * t;
108 let m_branch = one + m * m * m * four;
109
110 let mask = t.simd_lt(one);
111
112 mask.blend(t_branch, m_branch)
113}
114
115#[test]
116fn test_in_out_cubic() {
117 let p = InOutCubic.y(1.0);
118
119 assert_eq!(p, 1.0);
120}