fix bsp nsew centering

This commit is contained in:
🪞👃🪞 2025-01-10 19:20:48 +01:00
parent a8611db452
commit 6746844b7b
9 changed files with 25 additions and 15 deletions

View file

@ -49,18 +49,24 @@ pub trait Area<N: Coordinate>: From<[N;4]> + Debug + Copy {
#[inline] fn center (&self) -> [N;2] { #[inline] fn center (&self) -> [N;2] {
[self.x() + self.w()/2.into(), self.y() + self.h()/2.into()] [self.x() + self.w()/2.into(), self.y() + self.h()/2.into()]
} }
#[inline] fn center_x (&self, n: N) -> [N;4] { #[inline] fn center_x (&self, n: N) -> [N;4] {
let [x, y, w, h] = self.xywh(); let [x, y, w, h] = self.xywh();
[(x + w / 2.into()).minus(n / 2.into()), y + h / 2.into(), n, 1.into()] [(x + w / 2.into()).minus(n / 2.into()), y + h / 2.into(), n, 1.into()]
} }
#[inline] fn center_y (&self, m: N) -> [N;4] { #[inline] fn center_xw (&self, n: N, m: N) -> [N;4] {
let [x, y, w, h] = self.xywh(); let [x, y, w, h] = self.xywh();
[x + w / 2.into(), (y + h / 2.into()).minus(m / 2.into()), 1.into(), m] [(x + w / 2.into()).minus(n / 2.into()), y + h / 2.into(), n, 1.into()]
}
#[inline] fn center_y (&self, n: N) -> [N;4] {
let [x, y, w, h] = self.xywh();
[x + w / 2.into(), (y + h / 2.into()).minus(n / 2.into()), 1.into(), n]
} }
#[inline] fn center_xy (&self, [n, m]: [N;2]) -> [N;4] { #[inline] fn center_xy (&self, [n, m]: [N;2]) -> [N;4] {
let [x, y, w, h] = self.xywh(); let [x, y, w, h] = self.xywh();
[(x + w / 2.into()).minus(n / 2.into()), (y + h / 2.into()).minus(m / 2.into()), n, m] [(x + w / 2.into()).minus(n / 2.into()), (y + h / 2.into()).minus(m / 2.into()), n, m]
} }
#[inline] fn centered (&self) -> [N;2] { #[inline] fn centered (&self) -> [N;2] {
[self.x().minus(self.w()/2.into()), self.y().minus(self.h()/2.into())] [self.x().minus(self.w()/2.into()), self.y().minus(self.h()/2.into())]
} }

View file

@ -69,26 +69,26 @@ pub trait BspAreas<E: Output, A: Content<E>, B: Content<E>> {
}, },
South => { South => {
let [x, y, w, h] = outer.center_xy([aw.max(bw), ah + bh]); let [x, y, w, h] = outer.center_xy([aw.max(bw), ah + bh]);
let a = [x, y, aw, ah]; let a = [(x + w/2.into()).minus(aw/2.into()), y, aw, ah];
let b = [x, y + ah, bw, bh]; let b = [(x + w/2.into()).minus(bw/2.into()), y + ah, bw, bh];
[a.into(), b.into(), [x, y, w, h].into()] [a.into(), b.into(), [x, y, w, h].into()]
}, },
North => { North => {
let [x, y, w, h] = outer.center_xy([aw.max(bw), ah + bh]); let [x, y, w, h] = outer.center_xy([aw.max(bw), ah + bh]);
let a = [x, y + bh, aw, ah]; let a = [(x + (w/2.into())).minus(aw/2.into()), y + bh, aw, ah];
let b = [x, y, bw, bh]; let b = [(x + (w/2.into())).minus(bw/2.into()), y, bw, bh];
[a.into(), b.into(), [x, y, w, h].into()] [a.into(), b.into(), [x, y, w, h].into()]
}, },
East => { East => {
let [x, y, w, h] = outer.center_xy([aw + bw, ah.max(bh)]); let [x, y, w, h] = outer.center_xy([aw + bw, ah.max(bh)]);
let a = [x, y, aw, ah]; let a = [x, (y + h/2.into()).minus(ah/2.into()), aw, ah];
let b = [x + aw, y, bw, bh]; let b = [x + aw, (y + h/2.into()).minus(bh/2.into()), bw, bh];
[a.into(), b.into(), [x, y, w, h].into()] [a.into(), b.into(), [x, y, w, h].into()]
}, },
West => { West => {
let [x, y, w, h] = outer.center_xy([aw + bw, ah.max(bh)]); let [x, y, w, h] = outer.center_xy([aw + bw, ah.max(bh)]);
let a = [x + bw, y, aw, ah]; let a = [x + bw, (y + h/2.into()).minus(ah/2.into()), aw, ah];
let b = [x, y, bw, bh]; let b = [x, (y + h/2.into()).minus(bh/2.into()), bw, bh];
[a.into(), b.into(), [x, y, w, h].into()] [a.into(), b.into(), [x, y, w, h].into()]
}, },
} }

View file

@ -12,6 +12,8 @@ const EDN: &'static [&'static str] = &[
include_str!("edn06.edn"), include_str!("edn06.edn"),
include_str!("edn07.edn"), include_str!("edn07.edn"),
include_str!("edn08.edn"), include_str!("edn08.edn"),
include_str!("edn09.edn"),
include_str!("edn10.edn"),
]; ];
fn main () -> Usually<()> { fn main () -> Usually<()> {

View file

@ -1 +1 @@
(fixed/xy 30 20 (bsp/s (fixed/xy 5 5 :hello) (fixed/xy 5 5 :world))) (fixed/xy 30 20 (bsp/s (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world)))

View file

@ -1 +1 @@
(fixed/xy 30 20 (bsp/e (fixed/xy 5 5 :hello) (fixed/xy 5 5 :world))) (fixed/xy 30 20 (bsp/e (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world)))

View file

@ -1 +1 @@
(fixed/xy 30 20 (bsp/n (fixed/xy 5 5 :hello) (fixed/xy 5 5 :world))) (fixed/xy 30 20 (bsp/n (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world)))

View file

@ -1 +1 @@
(fixed/xy 30 20 (bsp/w (fixed/xy 5 5 :hello) (fixed/xy 5 5 :world))) (fixed/xy 30 20 (bsp/w (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world)))

1
tek/examples/edn09.edn Normal file
View file

@ -0,0 +1 @@
(fixed/xy 30 20 (bsp/a (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world)))

1
tek/examples/edn10.edn Normal file
View file

@ -0,0 +1 @@
(fixed/xy 30 20 (bsp/b (fixed/xy 5 6 :hello) (fixed/xy 7 8 :world)))