1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use interpolate;
use interpolation::{Ease, EaseFunction, Spatial};
use point::Point;
use num::{Float, NumCast};
#[derive(Clone, Copy)]
pub struct EasePoint<X, Y>
where X: PartialEq + NumCast + Clone + Copy,
Y: PartialEq + Spatial + Clone + Copy,
Y::Scalar: Float + Ease,
{
pub x: X,
pub y: Y,
pub maybe_ease_fn: Option<EaseFunction>,
}
impl<X, Y> EasePoint<X, Y>
where X: PartialEq + NumCast + Clone + Copy,
Y: PartialEq + Spatial + Clone + Copy,
Y::Scalar: Float + Ease,
{
#[inline]
pub fn new(x: X, y: Y, maybe_ease_fn: Option<EaseFunction>) -> EasePoint<X, Y> {
EasePoint {
x: x,
y: y,
maybe_ease_fn: maybe_ease_fn,
}
}
}
impl<X, Y> Point for EasePoint<X, Y>
where X: PartialEq + NumCast + Clone + Copy,
Y: PartialEq + Spatial + Clone + Copy,
Y::Scalar: Float + Ease,
{
type X = X;
type Y = Y;
#[inline(always)]
fn x_to_scalar(x: X) -> Y::Scalar {
NumCast::from(x).unwrap()
}
#[inline(always)]
fn x(&self) -> X { self.x }
#[inline(always)]
fn y(&self) -> Y { self.y }
#[inline(always)]
fn interpolate(x: X, start: &Self, end: &Self) -> Y {
match start.maybe_ease_fn {
Some(ease_fn) => interpolate::ease(x, start, end, ease_fn),
None => interpolate::linear(x, start, end),
}
}
}