eazy_core/easing/
bezier.rs

1pub mod cubic_bezier;
2
3use crate::easing::Curve;
4
5/// The Unit Bezier.
6#[derive(Copy, Clone, Debug, Default)]
7pub enum Bezier {
8  /// CSS `ease` timing function.
9  /// Equivalent to `cubic-bezier(0.25, 0.1, 0.25, 1)`.
10  #[default]
11  Ease,
12  /// CSS `ease-in` timing function.
13  /// Equivalent to `cubic-bezier(0.42, 0, 1, 1)`.
14  InEase,
15  /// CSS `ease-out` timing function.
16  /// Equivalent to `cubic-bezier(0, 0, 0.58, 1)`.
17  OutEase,
18  /// CSS `ease-in-out` timing function.
19  /// Equivalent to `cubic-bezier(0.42, 0, 0.58, 1)`.
20  InOutEase,
21  /// Specifies the unit Bézier control points — `p1` and `p2`.
22  ///
23  /// i.e Curve(p1x, p1y, p2x, p2y).
24  Curve(f32, f32, f32, f32),
25}
26
27impl Curve for Bezier {
28  #[inline(always)]
29  fn y(&self, p: f32) -> f32 {
30    match self {
31      Self::Ease => cubic_bezier::CubicBezier::ease().y(p),
32      Self::InEase => cubic_bezier::CubicBezier::in_ease().y(p),
33      Self::OutEase => cubic_bezier::CubicBezier::out_ease().y(p),
34      Self::InOutEase => cubic_bezier::CubicBezier::in_out_ease().y(p),
35      Self::Curve(p1x, p1y, p2x, p2y) => {
36        cubic_bezier::CubicBezier::curve(*p1x, *p1y, *p2x, *p2y).y(p)
37      }
38    }
39  }
40}