prevent crash in split_fixed

This commit is contained in:
🪞👃🪞 2024-11-03 17:29:11 +02:00
parent be7501b08c
commit d94aa8c8ac

View file

@ -133,16 +133,16 @@ pub trait Area<N: Coordinate>: Copy {
#[inline] fn split_fixed (&self, direction: Direction, a: N) -> ([N;4],[N;4]) { #[inline] fn split_fixed (&self, direction: Direction, a: N) -> ([N;4],[N;4]) {
match direction { match direction {
Direction::Up => ( Direction::Up => (
[self.x(), self.y() + self.h() - a, self.w(), a], [self.x(), (self.y()+self.h()).minus(a), self.w(), a],
[self.x(), self.y(), self.w(), self.h() - a], [self.x(), self.y(), self.w(), self.h().minus(a)],
), ),
Direction::Down => ( Direction::Down => (
[self.x(), self.y(), self.w(), a], [self.x(), self.y(), self.w(), a],
[self.x(), self.y() + a, self.w(), self.h() - a], [self.x(), self.y() + a, self.w(), self.h().minus(a)],
), ),
Direction::Right => ( Direction::Right => (
[self.x(), self.y(), a, self.h()], [self.x(), self.y(), a, self.h()],
[self.x() + a, self.y(), self.w() - a, self.h()], [self.x() + a, self.y(), self.w().minus(a), self.h()],
), ),
_ => todo!(), _ => todo!(),
} }
@ -290,24 +290,14 @@ where
} }
} }
//`Layers<_, impl (Fn(&mut dyn FnMut(&dyn Widget<Engine = _>) -> Result<(), Box<...>>) -> ... ) + Send + Sync>` #[derive(Copy, Clone, PartialEq)]
//`Layers<Tui, impl (Fn(&mut dyn FnMut(&dyn Widget<Engine = Tui>) -> Result<(), Box<(dyn std::error::Error + 'static)>>) -> Result<(), Box<(dyn std::error::Error + 'static)>>) + Send + Sync + '_>` pub enum Direction { Up, Down, Left, Right, }
#[derive(Copy, Clone)]
pub enum Direction {
Up,
Down,
Left,
Right,
}
impl Direction { impl Direction {
pub fn is_down (&self) -> bool { pub fn is_up (&self) -> bool { match self { Self::Up => true, _ => false } }
match self { Self::Down => true, _ => false } pub fn is_down (&self) -> bool { match self { Self::Down => true, _ => false } }
} pub fn is_left (&self) -> bool { match self { Self::Left => true, _ => false } }
pub fn is_right (&self) -> bool { pub fn is_right (&self) -> bool { match self { Self::Right => true, _ => false } }
match self { Self::Right => true, _ => false } /// Return next direction clockwise
}
pub fn cw (&self) -> Self { pub fn cw (&self) -> Self {
match self { match self {
Self::Up => Self::Right, Self::Up => Self::Right,
@ -316,6 +306,7 @@ impl Direction {
Self::Right => Self::Down, Self::Right => Self::Down,
} }
} }
/// Return next direction counterclockwise
pub fn ccw (&self) -> Self { pub fn ccw (&self) -> Self {
match self { match self {
Self::Up => Self::Left, Self::Up => Self::Left,