remove uses of Split, implement Bsp::area

This commit is contained in:
🪞👃🪞 2024-12-31 17:01:24 +01:00
parent 9f7b23a252
commit aa910540c0
5 changed files with 79 additions and 57 deletions

View file

@ -1,6 +1,6 @@
//! Groupings of elements.
mod split; pub use self::split::*;
//mod split; pub use self::split::*;
//mod stack; pub use self::stack::*;
use crate::*;
@ -82,7 +82,7 @@ impl<E: Engine, A: Content<E>, B: Content<E>> Content<E> for Either<E, A, B> {
}
}
pub trait Render<E: Engine> {
trait Render<E: Engine> {
fn area (&self, to: E::Area) -> E::Area;
fn render (&self, to: &mut E::Output);
}

View file

@ -120,39 +120,58 @@ impl<E: Engine, X: Content<E>, Y: Content<E>> Default for Bsp<E, X, Y> {
}
impl<E: Engine, X: Content<E>, Y: Content<E>> Content<E> for Bsp<E, X, Y> {
fn render (&self, to: &mut E::Output) {
let _n = E::Size::zero();
let _s = to.wh();
fn area (&self, outer: E::Area) -> E::Area {
match self {
Self::Null(_) => {},
//Self::S(p, a, b) => {
//let s_a = a.min_size(s)?.unwrap_or(n);
//let _ = b.min_size(s)?.unwrap_or(n);
//let h = s_a.h().into();
//to.render_in(to.area().clip_h(h).into(), a);
//to.render_in(to.area().shrink_y(h).push_y(h).into(), b);
//},
//Self::E(p, a, b) => {
//let s_a = a.min_size(s)?.unwrap_or(n);
//let _ = b.min_size(s)?.unwrap_or(n);
//let w = s_a.w().into();
//to.render_in(to.area().clip_w(w).into(), a);
//to.render_in(to.area().push_x(w).shrink_x(w).into(), b);
//},
//Self::W(p, a, b) => {
//let s_a = a.min_size(s)?.unwrap_or(n);
//let _ = b.min_size(s)?.unwrap_or(n);
//let w = (to.area().w() - s_a.w()).into();
//to.render_in(to.area().push_x(w).into(), a);
//to.render_in(to.area().shrink_x(w).into(), b);
//},
//Self::N(p, a, b) => {
//let s_a = a.min_size(s)?.unwrap_or(n);
//let _ = b.min_size(s)?.unwrap_or(n);
//let h = to.area().h() - s_a.h();
//to.render_in(to.area().push_y(h).into(), a);
//to.render_in(to.area().shrink_y(h).into(), b);
//},
Self::Null(_) => [0.into(), 0.into(), 0.into(), 0.into()].into(),
Self::N(_, a, b) | Self::S(_, a, b) => {
let a = a.area(outer);
let b = b.area(outer);
[a.x().min(b.x()), a.y().min(b.y()), a.w().max(b.w()), a.h() + b.h()].into()
},
Self::E(_, a, b) | Self::W(_, a, b) => {
let a = a.area(outer);
let b = b.area(outer);
[a.x().min(b.x()), a.y().min(b.y()), a.w() + b.w(), a.h().max(b.h())].into()
},
Self::A(a, b) | Self::B(a, b) => {
let a = a.area(outer);
let b = b.area(outer);
[a.x().min(b.x()), a.y().min(b.y()), a.w().max(b.w()), a.h().max(b.h())].into()
}
}
}
fn render (&self, to: &mut E::Output) {
let n = E::Area::zero();
let area = to.area();
match self {
Self::S(p, a, b) => {
let s_a = a.area(area);
let _ = b.area(area);
let h = s_a.h().into();
to.place(to.area().clip_h(h).into(), a);
to.place(to.area().shrink_y(h).push_y(h).into(), b);
},
Self::E(p, a, b) => {
let s_a = a.area(area);
let _ = b.area(area);
let w = s_a.w().into();
to.place(to.area().clip_w(w).into(), a);
to.place(to.area().push_x(w).shrink_x(w).into(), b);
},
Self::W(p, a, b) => {
let s_a = a.area(area);
let _ = b.area(area);
let w = (to.area().w() - s_a.w()).into();
to.place(to.area().push_x(w).into(), a);
to.place(to.area().shrink_x(w).into(), b);
},
Self::N(p, a, b) => {
let s_a = a.area(area);
let _ = b.area(area);
let h = to.area().h() - s_a.h();
to.place(to.area().push_y(h).into(), a);
to.place(to.area().shrink_y(h).into(), b);
},
_ => todo!()
}
}