mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 20:56:43 +01:00
fix bsp nsew centering
This commit is contained in:
parent
a8611db452
commit
6746844b7b
9 changed files with 25 additions and 15 deletions
|
|
@ -13,7 +13,7 @@ pub trait Area<N: Coordinate>: From<[N;4]> + Debug + Copy {
|
|||
Ok(self)
|
||||
}
|
||||
}
|
||||
#[inline] fn xy (&self) -> [N;2] {
|
||||
#[inline] fn xy (&self) -> [N;2] {
|
||||
[self.x(), self.y()]
|
||||
}
|
||||
#[inline] fn wh (&self) -> [N;2] {
|
||||
|
|
@ -49,18 +49,24 @@ pub trait Area<N: Coordinate>: From<[N;4]> + Debug + Copy {
|
|||
#[inline] fn center (&self) -> [N;2] {
|
||||
[self.x() + self.w()/2.into(), self.y() + self.h()/2.into()]
|
||||
}
|
||||
|
||||
#[inline] fn center_x (&self, n: N) -> [N;4] {
|
||||
let [x, y, w, h] = self.xywh();
|
||||
[(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();
|
||||
[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] {
|
||||
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]
|
||||
}
|
||||
|
||||
#[inline] fn centered (&self) -> [N;2] {
|
||||
[self.x().minus(self.w()/2.into()), self.y().minus(self.h()/2.into())]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue