From 6d829bd74192900110a4702a54e43a4f6fb83540 Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Tue, 4 Jan 2022 00:10:51 +0000 Subject: [PATCH] remove the step by feature should have test to make sure it does what I want it to do --- agb/src/lib.rs | 1 - agb/src/number.rs | 23 +++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/agb/src/lib.rs b/agb/src/lib.rs index 3b973565..c806729c 100644 --- a/agb/src/lib.rs +++ b/agb/src/lib.rs @@ -7,7 +7,6 @@ #![feature(alloc_error_handler)] #![test_runner(crate::test_runner)] #![reexport_test_harness_main = "test_main"] -#![feature(step_trait)] //! # agb //! `agb` is a library for making games on the Game Boy Advance using the Rust //! programming language. It attempts to be a high level abstraction over the diff --git a/agb/src/number.rs b/agb/src/number.rs index 0524a11e..92ac260c 100644 --- a/agb/src/number.rs +++ b/agb/src/number.rs @@ -862,15 +862,22 @@ impl Rect { } } -impl Rect { +impl Rect { pub fn iter(self) -> impl Iterator { - (self.position.x..=(self.position.x + self.size.x)) - .into_iter() - .flat_map(move |x| { - (self.position.y..=(self.position.y + self.size.y)) - .into_iter() - .map(move |y| (x, y)) - }) + let mut x = self.position.x - T::one(); + let mut y = self.position.y; + core::iter::from_fn(move || { + x = x + T::one(); + if x > self.position.x + self.size.x { + x = self.position.x; + y = y + T::one(); + if y > self.position.y + self.size.y { + return None; + } + } + + Some((x, y)) + }) } }