more built-in centering

This commit is contained in:
🪞👃🪞 2025-01-01 17:43:48 +01:00
parent 8454b95df8
commit a6a4eb80fd
5 changed files with 33 additions and 17 deletions

View file

@ -126,6 +126,18 @@ pub trait Area<N: Coordinate> {
#[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() - n, y + h / 2.into(), n, 1.into()]
}
#[inline] fn center_y (&self, m: N) -> [N;4] {
let [x, y, w, h] = self.xywh();
[x + w / 2.into(), y + h / 2.into() - m, 1.into(), m]
}
#[inline] fn center_xy (&self, [n, m]: [N;2]) -> [N;4] {
let [x, y, w, h] = self.xywh();
[x + w / 2.into() - n, y + h / 2.into() - n - m, n, m]
}
#[inline] fn centered (&self) -> [N;2] {
[self.x().minus(self.w()/2.into()), self.y().minus(self.h()/2.into())]
}