animate_core/spring/
settled.rs1pub trait Settled {
2 fn magnitude(&self) -> f64;
3
4 #[inline]
5 fn is_within_epsilon(&self, epsilon: f32) -> bool {
6 self.magnitude() < epsilon as f64
7 }
8}
9
10#[cfg(feature = "ratatui")]
11impl Settled for [f64; 3] {
12 #[inline]
13 fn magnitude(&self) -> f64 {
14 self.iter().map(|v| v * v).sum::<f64>().sqrt()
15 }
16}
17
18macro_rules! impl_settled {
19 (s: $($t:ty),* $(,)?) => {
20 $(
21 impl Settled for $t {
22 #[inline]
23 fn magnitude(&self) -> f64 {
24 self.abs() as f64
25 }
26 }
27 )*
28 };
29
30 (u: $($t:ty),* $(,)?) => {
31 $(
32 impl Settled for $t {
33 #[inline]
34 fn magnitude(&self) -> f64 {
35 *self as f64
36 }
37 }
38 )*
39 };
40}
41
42impl_settled!(s: f64, f32, isize, i64, i32, i16, i8);
43impl_settled!(u: usize, u64, u32, u16, u8);