pierro/core/math/
axis.rs

1
2#[derive(Clone, Copy, PartialEq, Eq, Debug)]
3pub enum Axis {
4    X,
5    Y
6}
7
8pub const AXES: [Axis; 2] = [Axis::X, Axis::Y];
9
10impl Axis {
11
12    pub fn other(&self) -> Self {
13        match self {
14            Axis::X => Axis::Y,
15            Axis::Y => Axis::X,
16        }
17    }
18
19}
20
21#[derive(Clone, Copy)]
22pub struct PerAxis<T> {
23    pub x: T,
24    pub y: T
25}
26
27impl<T> PerAxis<T> {
28
29    pub const fn new(x: T, y: T) -> Self {
30        Self {
31            x,
32            y
33        }
34    }
35
36    pub const fn along_across(axis: Axis, along: T, across: T) -> Self {
37        match axis {
38            Axis::X => Self::new(along, across),
39            Axis::Y => Self::new(across, along)
40        }
41    }
42
43    pub fn splat(val: T) -> Self where T: Clone {
44        Self {
45            x: val.clone(),
46            y: val 
47        }
48    }
49
50    pub fn on_axis(&self, axis: Axis) -> &T {
51        match axis {
52            Axis::X => &self.x,
53            Axis::Y => &self.y,
54        } 
55    }
56
57}