uuugh
Some checks failed
/ build (push) Has been cancelled

This commit is contained in:
🪞👃🪞 2025-09-09 01:07:19 +03:00
parent ca862b9802
commit 3ebdf9e71f
38 changed files with 602 additions and 1108 deletions

View file

@ -1,7 +1,6 @@
use crate::*;
use Direction::*;
/// A split or layer.
/// A binary split or layer.
pub struct Bsp<Head, Tail>(
pub(crate) Direction,
/// First element.
@ -19,31 +18,79 @@ impl<Head, Tail> Bsp<Head, Tail> {
#[inline] pub const fn b (a: Head, b: Tail) -> Self { Self(Below, a, b) }
}
impl<
O: Out,
Head: Draw<O> + Layout<O>,
Tail: Draw<O> + Layout<O>
> Draw<O> for Bsp<Head, Tail> {
impl<O: Out, Head: Content<O>, Tail: Content<O>> Draw<O> for Bsp<Head, Tail> {
fn draw (&self, to: &mut O) {
let [a, b, _] = bsp_areas(to.area(), self.0, &self.1, &self.2);
if self.0 == Below {
to.place_at(a, &self.1);
to.place_at(b, &self.2);
} else {
to.place_at(b, &self.2);
to.place_at(a, &self.1);
match self.0 {
South => {
panic!("{}", self.1.h(to.area()));
let area_1 = self.1.layout(to.area());
let area_2 = self.2.layout([
to.area().x(),
to.area().y().plus(area_1.h()),
to.area().w(),
to.area().h().minus(area_1.h())
].into());
panic!("{area_1:?} {area_2:?}");
to.place_at(area_1, &self.1);
to.place_at(area_2, &self.2);
},
_ => todo!("{:?}", self.0)
}
//let [a, b, _] = bsp_areas(to.area(), self.0, &self.1, &self.2);
//panic!("{a:?} {b:?}");
//if self.0 == Below {
//to.place_at(a, &self.1);
//to.place_at(b, &self.2);
//} else {
//to.place_at(b, &self.2);
//to.place_at(a, &self.1);
//}
}
}
impl<O: Out, Head: Layout<O>, Tail: Layout<O>> Layout<O> for Bsp<Head, Tail> {
fn w (&self, area: O::Area) -> O::Unit {
match self.0 {
North | South | Above | Below => self.1.w(area).max(self.2.w(area)),
East | West => self.1.min_w(area).plus(self.2.w(area)),
}
}
fn min_w (&self, area: O::Area) -> O::Unit {
match self.0 {
North | South | Above | Below => self.1.min_w(area).max(self.2.min_w(area)),
East | West => self.1.min_w(area).plus(self.2.min_w(area)),
}
}
fn max_w (&self, area: O::Area) -> O::Unit {
match self.0 {
North | South | Above | Below => self.1.max_w(area).max(self.2.max_w(area)),
East | West => self.1.max_w(area).plus(self.2.max_w(area)),
}
}
fn h (&self, area: O::Area) -> O::Unit {
match self.0 {
East | West | Above | Below => self.1.h(area).max(self.2.h(area)),
North | South => self.1.h(area).plus(self.2.h(area)),
}
}
fn min_h (&self, area: O::Area) -> O::Unit {
match self.0 {
East | West | Above | Below => self.1.min_h(area).max(self.2.min_h(area)),
North | South => self.1.min_h(area).plus(self.2.min_h(area)),
}
}
fn max_h (&self, area: O::Area) -> O::Unit {
match self.0 {
North | South | Above | Below => self.1.max_h(area).max(self.2.max_h(area)),
East | West => self.1.max_h(area).plus(self.2.max_h(area)),
}
}
fn layout (&self, area: O::Area) -> O::Area {
bsp_areas(area, self.0, &self.1, &self.2)[2]
}
}
fn bsp_areas <O: Out> (
area: O::Area, direction: Direction, a: &impl Layout<O>, b: &impl Layout<O>,
fn bsp_areas <O: Out, A: Layout<O>, B: Layout<O>> (
area: O::Area, direction: Direction, a: &A, b: &B,
) -> [O::Area;3] {
let [x, y, w, h] = area.xywh();
let [aw, ah] = a.layout(area).wh();