eazy_data/easing/trigonometric/
sine.rs1use crate::easing::Curve;
4
5use libm::{cosf, sinf};
6
7use core::f32::consts::PI;
8
9#[derive(Debug)]
22pub struct InSine;
23
24impl Curve for InSine {
25 #[inline(always)]
26 fn y(&self, p: f32) -> f32 {
27 1.0 - cosf(p * PI * 0.5)
28 }
29}
30
31#[test]
32fn test_in_sine() {
33 let p = InSine.y(0.5);
34
35 assert_eq!(p, 0.29289323);
36}
37
38#[derive(Debug)]
53pub struct OutSine;
54
55impl Curve for OutSine {
56 #[inline(always)]
57 fn y(&self, p: f32) -> f32 {
58 sinf(p * PI * 0.5)
59 }
60}
61
62#[test]
63fn test_out_sine() {
64 let p = OutSine.y(0.1264);
65
66 assert_eq!(p, 0.1972467);
67}
68
69#[derive(Debug)]
82pub struct InOutSine;
83
84impl Curve for InOutSine {
85 #[inline(always)]
86 fn y(&self, p: f32) -> f32 {
87 0.5 * (1.0 - cosf(p * PI))
88 }
89}
90
91#[test]
92fn test_in_out_sine() {
93 let p = InOutSine.y(0.248608);
94
95 assert_eq!(p, 0.14490387);
96}