mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
add proptests to some layout ops
This commit is contained in:
parent
1004c6a4d6
commit
ad1abf6ec8
7 changed files with 206 additions and 57 deletions
|
|
@ -38,29 +38,29 @@ pub trait Area<N: Coordinate>: From<[N;4]> + Debug + Copy {
|
|||
[self.x(), self.y(), self.w(), h]
|
||||
}
|
||||
#[inline] fn x2 (&self) -> N {
|
||||
self.x() + self.w()
|
||||
self.x().plus(self.w())
|
||||
}
|
||||
#[inline] fn y2 (&self) -> N {
|
||||
self.y() + self.h()
|
||||
self.y().plus(self.h())
|
||||
}
|
||||
#[inline] fn lrtb (&self) -> [N;4] {
|
||||
[self.x(), self.x2(), self.y(), self.y2()]
|
||||
}
|
||||
#[inline] fn center (&self) -> [N;2] {
|
||||
[self.x() + self.w()/2.into(), self.y() + self.h()/2.into()]
|
||||
[self.x().plus(self.w()/2.into()), self.y().plus(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()]
|
||||
[(x.plus(w / 2.into())).minus(n / 2.into()), y.plus(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]
|
||||
[x.plus(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]
|
||||
[(x.plus(w / 2.into())).minus(n / 2.into()), (y.plus(h / 2.into())).minus(m / 2.into()), n, m]
|
||||
}
|
||||
|
||||
#[inline] fn centered (&self) -> [N;2] {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue