From 21c934623d0a58cc58cc06709c8c0a1cec25a5e7 Mon Sep 17 00:00:00 2001 From: GBA bot Date: Sat, 1 Jan 2022 11:20:30 +0000 Subject: [PATCH 1/4] Import the new asm macro required in newer versions of nightly --- agb/src/syscall.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/agb/src/syscall.rs b/agb/src/syscall.rs index 83b44b1c..b4357c58 100644 --- a/agb/src/syscall.rs +++ b/agb/src/syscall.rs @@ -1,3 +1,5 @@ +use core::arch::asm; + use crate::display::object::AffineMatrixAttributes; use crate::number::Num; From afe69b98b8de222375b3bc4dff8ea1d161e4c4a7 Mon Sep 17 00:00:00 2001 From: GBA bot Date: Sat, 1 Jan 2022 11:34:43 +0000 Subject: [PATCH 2/4] Add a bunch of `must_use` now requested by clippy --- agb/src/number.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/agb/src/number.rs b/agb/src/number.rs index 2e91c6a9..c81786f9 100644 --- a/agb/src/number.rs +++ b/agb/src/number.rs @@ -59,6 +59,7 @@ pub trait FixedWidthUnsignedInteger: } pub trait FixedWidthSignedInteger: FixedWidthUnsignedInteger + Neg { + #[must_use] fn fixed_abs(self) -> Self; } @@ -276,6 +277,7 @@ impl Num { self.0 / (I::one() << N) } + #[must_use] pub fn rem_euclid(self, rhs: Self) -> Self { let r = self % rhs; if r < I::zero().into() { @@ -307,6 +309,7 @@ impl Num { } impl Num { + #[must_use] pub fn sqrt(self) -> Self { assert_eq!(N % 2, 0, "N must be even to be able to square root"); assert!(self.0 >= 0, "sqrt is only valid for positive numbers"); @@ -387,6 +390,7 @@ impl Num { /// domain of [0, 1]. /// see https://github.com/tarcieri/micromath/blob/24584465b48ff4e87cffb709c7848664db896b4f/src/float/cos.rs#L226 + #[must_use] pub fn cos(self) -> Self { let one: Self = I::one().into(); let mut x = self; @@ -402,6 +406,7 @@ impl Num { x } + #[must_use] pub fn sin(self) -> Self { let one: Self = I::one().into(); let four: I = 4.into(); @@ -697,12 +702,15 @@ impl SubAssign for Vector2D { } impl Vector2D> { + #[must_use] pub fn trunc(self) -> Vector2D { Vector2D { x: self.x.trunc(), y: self.y.trunc(), } } + + #[must_use] pub fn floor(self) -> Vector2D { Vector2D { x: self.x.floor(), @@ -712,14 +720,17 @@ impl Vector2D> { } impl Vector2D> { + #[must_use] pub fn magnitude_squared(self) -> Num { self.x * self.x + self.y * self.y } + #[must_use] pub fn manhattan_distance(self) -> Num { self.x.abs() + self.y.abs() } + #[must_use] pub fn magnitude(self) -> Num { self.magnitude_squared().sqrt() } @@ -728,6 +739,7 @@ impl Vector2D> { // algorithm https://en.wikipedia.org/wiki/Alpha_max_plus_beta_min_algorithm // this has a maximum error of less than 4% of the true magnitude, probably // depending on the size of your fixed point approximation + #[must_use] pub fn fast_magnitude(self) -> Num { let max = core::cmp::max(self.x, self.y); let min = core::cmp::min(self.x, self.y); @@ -735,10 +747,12 @@ impl Vector2D> { max * num!(0.960433870103) + min * num!(0.397824734759) } + #[must_use] pub fn normalise(self) -> Self { self / self.magnitude() } + #[must_use] pub fn fast_normalise(self) -> Self { self / self.fast_magnitude() } @@ -790,6 +804,7 @@ pub struct Rect { } impl Rect { + #[must_use] pub fn new(position: Vector2D, size: Vector2D) -> Self { Rect { position, size } } @@ -808,7 +823,8 @@ impl Rect { && self.position.y + self.size.y > other.position.y } - pub fn overlapping_rect(&self, other: Rect) -> Rect { + #[must_use] + pub fn overlapping_rect(&self, other: Rect) -> Self { fn max(x: E, y: E) -> E { if x > y { x @@ -862,15 +878,20 @@ impl Vector2D { pub fn new(x: T, y: T) -> Self { Vector2D { x, y } } + pub fn get(self) -> (T, T) { (self.x, self.y) } + + #[must_use] pub fn hadamard(self, other: Self) -> Self { Self { x: self.x * other.x, y: self.y * other.y, } } + + #[must_use] pub fn swap(self) -> Self { Self { x: self.y, From 5f13c69fcfe5d12e9fe426b7ff589f8bb6a58bc3 Mon Sep 17 00:00:00 2001 From: GBA bot Date: Sat, 1 Jan 2022 11:35:17 +0000 Subject: [PATCH 3/4] Replace .map.flatten with .flat_map --- agb/src/number.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/agb/src/number.rs b/agb/src/number.rs index c81786f9..ad27a738 100644 --- a/agb/src/number.rs +++ b/agb/src/number.rs @@ -865,12 +865,11 @@ impl Rect { pub fn iter(self) -> impl Iterator { (self.position.x..=(self.position.x + self.size.x)) .into_iter() - .map(move |x| { + .flat_map(move |x| { (self.position.y..=(self.position.y + self.size.y)) .into_iter() .map(move |y| (x, y)) }) - .flatten() } } From fa88bc40c625ebe9ba8034097f853183c7bc96de Mon Sep 17 00:00:00 2001 From: GBA bot Date: Sat, 1 Jan 2022 11:35:49 +0000 Subject: [PATCH 4/4] Add another missing must_use --- agb/src/number.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/agb/src/number.rs b/agb/src/number.rs index ad27a738..0524a11e 100644 --- a/agb/src/number.rs +++ b/agb/src/number.rs @@ -384,6 +384,7 @@ fn test_macro_conversion(_gba: &mut super::Gba) { } impl Num { + #[must_use] pub fn abs(self) -> Self { Num(self.0.fixed_abs()) }