diff --git a/agb-fixnum/src/lib.rs b/agb-fixnum/src/lib.rs index 9d912bff..7df4964c 100644 --- a/agb-fixnum/src/lib.rs +++ b/agb-fixnum/src/lib.rs @@ -759,6 +759,16 @@ impl SubAssign for Vector2D { } } +impl Vector2D { + /// 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 Vector2D> { #[must_use] /// Truncates the x and y coordinate, see [Num::trunc] @@ -1073,6 +1083,20 @@ impl Rect { } } +impl Rect { + /// 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 Vector2D { /// Created a vector from the given coordinates /// ```