mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
trying to get new Bsp to work; update docs
This commit is contained in:
parent
c9b81edb45
commit
62ce1776c0
11 changed files with 301 additions and 157 deletions
|
|
@ -89,28 +89,28 @@ impl Direction {
|
|||
|
||||
pub enum Bsp<E: Engine, X: Content<E>, Y: Content<E>> {
|
||||
/// X is north of Y
|
||||
N(Option<f64>, Option<X>, Option<Y>),
|
||||
North(Option<f64>, Option<X>, Option<Y>),
|
||||
/// X is south of Y
|
||||
S(Option<f64>, Option<X>, Option<Y>),
|
||||
South(Option<f64>, Option<X>, Option<Y>),
|
||||
/// X is east of Y
|
||||
E(Option<f64>, Option<X>, Option<Y>),
|
||||
East(Option<f64>, Option<X>, Option<Y>),
|
||||
/// X is west of Y
|
||||
W(Option<f64>, Option<X>, Option<Y>),
|
||||
West(Option<f64>, Option<X>, Option<Y>),
|
||||
/// X is above Y
|
||||
A(Option<X>, Option<Y>),
|
||||
Above(Option<X>, Option<Y>),
|
||||
/// X is below Y
|
||||
B(Option<X>, Option<Y>),
|
||||
Below(Option<X>, Option<Y>),
|
||||
/// Should be avoided.
|
||||
Null(PhantomData<E>),
|
||||
}
|
||||
|
||||
impl<E: Engine, X: Content<E>, Y: Content<E>> Bsp<E, X, Y> {
|
||||
pub fn n (x: X, y: Y) -> Self { Self::N(None, Some(x), Some(y)) }
|
||||
pub fn s (x: X, y: Y) -> Self { Self::S(None, Some(x), Some(y)) }
|
||||
pub fn e (x: X, y: Y) -> Self { Self::E(None, Some(x), Some(y)) }
|
||||
pub fn w (x: X, y: Y) -> Self { Self::W(None, Some(x), Some(y)) }
|
||||
pub fn a (x: X, y: Y) -> Self { Self::A(Some(x), Some(y)) }
|
||||
pub fn b (x: X, y: Y) -> Self { Self::B(Some(x), Some(y)) }
|
||||
pub fn n (x: X, y: Y) -> Self { Self::North(None, Some(x), Some(y)) }
|
||||
pub fn s (x: X, y: Y) -> Self { Self::South(None, Some(x), Some(y)) }
|
||||
pub fn e (x: X, y: Y) -> Self { Self::East(None, Some(x), Some(y)) }
|
||||
pub fn w (x: X, y: Y) -> Self { Self::West(None, Some(x), Some(y)) }
|
||||
pub fn a (x: X, y: Y) -> Self { Self::Above(Some(x), Some(y)) }
|
||||
pub fn b (x: X, y: Y) -> Self { Self::Below(Some(x), Some(y)) }
|
||||
}
|
||||
|
||||
impl<E: Engine, X: Content<E>, Y: Content<E>> Default for Bsp<E, X, Y> {
|
||||
|
|
@ -123,17 +123,27 @@ impl<E: Engine, X: Content<E>, Y: Content<E>> Content<E> for Bsp<E, X, Y> {
|
|||
fn area (&self, outer: E::Area) -> E::Area {
|
||||
match self {
|
||||
Self::Null(_) => [0.into(), 0.into(), 0.into(), 0.into()].into(),
|
||||
Self::N(_, a, b) | Self::S(_, a, b) => {
|
||||
Self::North(_, a, b) => {
|
||||
let a = a.area(outer);
|
||||
let b = b.area(outer);
|
||||
let b = b.area(North.split_fixed(outer, a.y() + a.h()).1.into());
|
||||
[a.x().min(b.x()), a.y().min(b.y()), a.w().max(b.w()), a.h() + b.h()].into()
|
||||
}
|
||||
Self::South(_, a, b) => {
|
||||
let a = a.area(outer);
|
||||
let b = b.area(South.split_fixed(outer, a.y() + a.h()).1.into());
|
||||
[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) => {
|
||||
Self::East(_, a, b) => {
|
||||
let a = a.area(outer);
|
||||
let b = b.area(outer);
|
||||
let b = b.area(East.split_fixed(outer, a.x() + a.w()).1.into());
|
||||
[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) => {
|
||||
Self::West(_, a, b) => {
|
||||
let a = a.area(outer);
|
||||
let b = b.area(West.split_fixed(outer, a.x() + a.w()).1.into());
|
||||
[a.x().min(b.x()), a.y().min(b.y()), a.w() + b.w(), a.h().max(b.h())].into()
|
||||
},
|
||||
Self::Above(a, b) | Self::Below(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()
|
||||
|
|
@ -141,38 +151,45 @@ 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::Area::zero();
|
||||
let area = to.area();
|
||||
let area = to.area().clone();
|
||||
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::North(_, a, b) => {
|
||||
let area_a = a.area(area);
|
||||
let area_b = b.area(North.split_fixed(area, area_a.y() + area_a.h()).1.into());
|
||||
to.place(area_a, a);
|
||||
to.place(area_b, 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::South(_, a, b) => {
|
||||
let area_a = a.area(area).clone();
|
||||
let area_b = b.area(South.split_fixed(area, area_a.y() + area_a.h()).1.into()).clone();
|
||||
to.place(area_a, a);
|
||||
to.place(area_b, 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::East(_, a, b) => {
|
||||
let area_a = a.area(area);
|
||||
let area_b = b.area(East.split_fixed(area, area_a.x() + area_a.w()).1.into());
|
||||
to.place(area_a, a);
|
||||
to.place(area_b, 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);
|
||||
Self::West(_, a, b) => {
|
||||
let area_a = a.area(area);
|
||||
let area_b = b.area(West.split_fixed(area, area_a.x() + area_a.w()).1.into());
|
||||
to.place(area_a, a);
|
||||
to.place(area_b, b);
|
||||
},
|
||||
_ => todo!()
|
||||
Self::Above(a, b) => {
|
||||
let area_a = a.area(area);
|
||||
let area_b = b.area(area);
|
||||
to.place(area_b, b);
|
||||
to.place(area_a, a);
|
||||
},
|
||||
Self::Below(a, b) => {
|
||||
let area_a = a.area(area);
|
||||
let area_b = b.area(area);
|
||||
to.place(area_a, a);
|
||||
to.place(area_b, b);
|
||||
},
|
||||
Self::Null(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue