Skip to main content

steel_utils/
axis.rs

1//! Axis types
2
3/// An axis in 3D space.
4#[derive(Copy, Clone, Debug, Eq)]
5#[derive_const(PartialEq)]
6#[expect(missing_docs, reason = "variant names are self-explanatory")]
7pub enum Axis {
8    X,
9    Y,
10    Z,
11}
12
13#[expect(missing_docs, reason = "method names are self-explanatory")]
14impl Axis {
15    #[must_use]
16    pub const fn is_horizontal(self) -> bool {
17        matches!(self, Axis::X | Axis::Z)
18    }
19
20    #[must_use]
21    pub const fn is_vertical(self) -> bool {
22        matches!(self, Axis::Y)
23    }
24
25    #[must_use]
26    pub const fn as_str(&self) -> &str {
27        match self {
28            Axis::X => "x",
29            Axis::Y => "y",
30            Axis::Z => "z",
31        }
32    }
33    #[must_use]
34    pub const fn ordinal(self) -> i32 {
35        match self {
36            Axis::X => 0,
37            Axis::Y => 1,
38            Axis::Z => 2,
39        }
40    }
41}