mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 19:56:44 +01:00
refactor(output): group ops/ and space/
This commit is contained in:
parent
18a01b8355
commit
ec7621eff9
17 changed files with 29 additions and 13 deletions
38
output/src/space/direction.rs
Normal file
38
output/src/space/direction.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use crate::*;
|
||||
#[cfg(test)] use proptest_derive::Arbitrary;
|
||||
/// 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())
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(test)] mod test {
|
||||
use super::*;
|
||||
use proptest::prelude::*;
|
||||
proptest! {
|
||||
#[test] fn proptest_direction (
|
||||
d in prop_oneof![
|
||||
Just(North), Just(South),
|
||||
Just(East), Just(West),
|
||||
Just(Above), Just(Below)
|
||||
],
|
||||
x in u16::MIN..u16::MAX,
|
||||
y in u16::MIN..u16::MAX,
|
||||
w in u16::MIN..u16::MAX,
|
||||
h in u16::MIN..u16::MAX,
|
||||
a in u16::MIN..u16::MAX,
|
||||
) {
|
||||
let _ = d.split_fixed([x, y, w, h], a);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue