mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
introduce vector and rect abs
This commit is contained in:
parent
66ec762855
commit
20a74fe319
|
@ -759,6 +759,16 @@ impl<T: Number> SubAssign<Self> for Vector2D<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: FixedWidthSignedInteger> Vector2D<T> {
|
||||
/// Calculates the absolute value of the x and y components.
|
||||
pub fn abs(self) -> Self {
|
||||
Self {
|
||||
x: self.x.fixed_abs(),
|
||||
y: self.y.fixed_abs(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: FixedWidthUnsignedInteger, const N: usize> Vector2D<Num<I, N>> {
|
||||
#[must_use]
|
||||
/// Truncates the x and y coordinate, see [Num::trunc]
|
||||
|
@ -1073,6 +1083,20 @@ impl<T: FixedWidthUnsignedInteger> Rect<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: FixedWidthSignedInteger> Rect<T> {
|
||||
/// Makes a rectangle that represents the equivalent location in space but with a positive size
|
||||
pub fn abs(self) -> Self {
|
||||
Self {
|
||||
position: (
|
||||
self.position.x + self.size.x.min(0.into()),
|
||||
self.position.y + self.size.y.min(0.into()),
|
||||
)
|
||||
.into(),
|
||||
size: self.size.abs(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Number> Vector2D<T> {
|
||||
/// Created a vector from the given coordinates
|
||||
/// ```
|
||||
|
|
Loading…
Reference in a new issue