eazy_core/interpolation/rational/
cubic.rs

1//! The Cubic Interpolating Rational Curve.
2
3use crate::easing::Curve;
4
5use libm::powf;
6
7/// The [`InRationalCubic`] Curve.
8#[derive(Debug)]
9pub struct InRationalCubic;
10
11impl Curve for InRationalCubic {
12  #[inline(always)]
13  fn y(&self, p: f32) -> f32 {
14    p * p * p / (3.0 * p * p - 3.0 * p + 1.0)
15  }
16}
17
18#[test]
19fn test_in_rational_cubic() {
20  let p = InRationalCubic.y(0.2);
21
22  assert_eq!(p, 0.015384616);
23}
24
25/// The [`OutRationalCubic`] Curve.
26#[derive(Debug)]
27pub struct OutRationalCubic;
28
29impl Curve for OutRationalCubic {
30  #[inline(always)]
31  fn y(&self, p: f32) -> f32 {
32    let a = powf(p, 1.0 / 3.0);
33    let b = powf(1.0 - p, 1.0 / 3.0);
34
35    a / (a + b)
36  }
37}
38
39#[test]
40fn test_out_rational_cubic() {
41  let p = OutRationalCubic.y(0.42);
42
43  assert_eq!(p, 0.47312814);
44}