tengri/output/src/space/direction.rs
unspeaker f1b24d436a
Some checks are pending
/ build (push) Waiting to run
wip: ast/cst
2025-05-25 22:48:29 +03:00

22 lines
744 B
Rust

use crate::*;
use crate::Direction::*;
/// A cardinal direction.
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(test, derive(Arbitrary))]
pub enum Direction {
North, South, East, West, Above, Below
}
impl Direction {
pub fn split_fixed <N: Coordinate> (self, area: impl Area<N>, a: N) -> ([N;4],[N;4]) {
let [x, y, w, h] = area.xywh();
match self {
North => ([x, y.plus(h).minus(a), w, a], [x, y, w, h.minus(a)]),
South => ([x, y, w, a], [x, y.plus(a), w, h.minus(a)]),
East => ([x, y, a, h], [x.plus(a), y, w.minus(a), h]),
West => ([x.plus(w).minus(a), y, a, h], [x, y, w.minus(a), h]),
Above | Below => (area.xywh(), area.xywh())
}
}
}