use super::*; #[derive(Copy, Clone, Eq, PartialEq)] pub enum Axis { X, Y, } impl std::ops::Not for Axis { type Output = Self; fn not(self) -> Self::Output { match self { Self::X => Self::Y, Self::Y => Self::X, } } } #[derive(Clone, Copy, Eq, PartialEq)] pub struct Dir { pub axis: Axis, pub sign: Sign, } impl Dir { pub const fn new(axis: Axis, dir: Sign) -> Self { Self { axis, sign: dir } } pub const LEFT: Self = Self::new(Axis::X, Sign::Neg); pub const RIGHT: Self = Self::new(Axis::X, Sign::Pos); pub const UP: Self = Self::new(Axis::Y, Sign::Neg); pub const DOWN: Self = Self::new(Axis::Y, Sign::Pos); } #[derive(Clone, Copy, Eq, PartialEq)] pub enum Sign { Neg, Pos, } impl Vec2 { pub fn axis(&self, axis: Axis) -> f32 { match axis { Axis::X => self.x, Axis::Y => self.y, } } pub fn axis_mut(&mut self, axis: Axis) -> &mut f32 { match axis { Axis::X => &mut self.x, Axis::Y => &mut self.y, } } pub const fn from_axis(axis: Axis, aligned: f32, ortho: f32) -> Self { Self { x: match axis { Axis::X => aligned, Axis::Y => ortho, }, y: match axis { Axis::Y => aligned, Axis::X => ortho, }, } } }