use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify))]
#[cfg_attr(feature = "wasm", tsify(into_wasm_abi, from_wasm_abi))]
pub enum Direction {
Up,
Down,
Left,
Right,
}
impl Direction {
#[must_use]
pub const fn opposite(self) -> Self {
match self {
Self::Up => Self::Down,
Self::Down => Self::Up,
Self::Left => Self::Right,
Self::Right => Self::Left,
}
}
#[must_use]
pub const fn is_horizontal(self) -> bool {
matches!(self, Self::Left | Self::Right)
}
#[must_use]
pub const fn is_vertical(self) -> bool {
matches!(self, Self::Up | Self::Down)
}
#[must_use]
pub const fn as_delta(self) -> (i16, i16) {
match self {
Self::Up => (0, -1),
Self::Down => (0, 1),
Self::Left => (-1, 0),
Self::Right => (1, 0),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify))]
#[cfg_attr(feature = "wasm", tsify(into_wasm_abi, from_wasm_abi))]
pub enum SplitDirection {
Horizontal,
Vertical,
}
impl SplitDirection {
#[must_use]
pub const fn opposite(self) -> Self {
match self {
Self::Horizontal => Self::Vertical,
Self::Vertical => Self::Horizontal,
}
}
#[must_use]
pub const fn is_along(&self, direction: Direction) -> bool {
match self {
Self::Horizontal => direction.is_vertical(),
Self::Vertical => direction.is_horizontal(),
}
}
}
#[cfg(test)]
#[path = "direction_tests.rs"]
mod tests;