1pub const MAX_LANES: usize = 4;
5
6pub type Lanes = [f32; MAX_LANES];
8
9pub trait Animatable: Copy {
11 const LANES: usize;
13 fn to_lanes(self) -> Lanes;
15 fn from_lanes(lanes: Lanes) -> Self;
17}
18
19impl Animatable for f32 {
20 const LANES: usize = 1;
21 fn to_lanes(self) -> Lanes {
22 [self, 0.0, 0.0, 0.0]
23 }
24 fn from_lanes([x, ..]: Lanes) -> Self {
25 x
26 }
27}
28
29impl Animatable for [f32; 2] {
30 const LANES: usize = 2;
31 fn to_lanes(self) -> Lanes {
32 let [x, y] = self;
33 [x, y, 0.0, 0.0]
34 }
35 fn from_lanes([x, y, ..]: Lanes) -> Self {
36 [x, y]
37 }
38}
39
40impl Animatable for [f32; 3] {
41 const LANES: usize = 3;
42 fn to_lanes(self) -> Lanes {
43 let [x, y, z] = self;
44 [x, y, z, 0.0]
45 }
46 fn from_lanes([x, y, z, _]: Lanes) -> Self {
47 [x, y, z]
48 }
49}
50
51impl Animatable for [f32; 4] {
52 const LANES: usize = 4;
53 fn to_lanes(self) -> Lanes {
54 self
55 }
56 fn from_lanes(lanes: Lanes) -> Self {
57 lanes
58 }
59}
60
61#[derive(Clone, Copy, Debug, PartialEq, Default)]
64pub struct Edges {
65 pub left: f32,
67 pub top: f32,
69 pub right: f32,
71 pub bottom: f32,
73}
74
75impl Edges {
76 pub const fn new(left: f32, top: f32, right: f32, bottom: f32) -> Edges {
78 Edges { left, top, right, bottom }
79 }
80}
81
82impl Animatable for Edges {
83 const LANES: usize = 4;
84 fn to_lanes(self) -> Lanes {
85 [self.left, self.top, self.right, self.bottom]
86 }
87 fn from_lanes([left, top, right, bottom]: Lanes) -> Self {
88 Edges { left, top, right, bottom }
89 }
90}
91
92pub(crate) const fn lane_count<T: Animatable>() -> usize {
94 if T::LANES < MAX_LANES { T::LANES } else { MAX_LANES }
95}