1use ranim_core::animation::Eval;
2
3pub trait FuncRequirement: Clone {}
6impl<T: Clone> FuncRequirement for T {}
7
8pub trait FuncAnim: FuncRequirement + 'static {
11 fn func(&mut self, f: impl Fn(&Self, f64) -> Self + 'static) -> Func<Self>;
13}
14
15impl<T: FuncRequirement + 'static> FuncAnim for T {
16 fn func(&mut self, f: impl Fn(&Self, f64) -> Self + 'static) -> Func<Self> {
17 Func::new(self.clone(), f).apply_to(self)
18 }
19}
20
21pub struct Func<T: FuncRequirement> {
26 src: T,
27 #[allow(clippy::type_complexity)]
28 f: Box<dyn Fn(&T, f64) -> T>,
29}
30
31impl<T: FuncRequirement> Func<T> {
32 pub fn new(target: T, f: impl Fn(&T, f64) -> T + 'static) -> Self {
34 Self {
35 src: target,
36 f: Box::new(f),
37 }
38 }
39}
40
41impl<T: FuncRequirement> Eval for Func<T> {
42 type Output = T;
43
44 fn eval_alpha(&self, alpha: f64) -> Self::Output {
45 (self.f)(&self.src, alpha)
46 }
47}