mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 09:31:34 +11:00
Merge pull request #153 from corwinkuiper/remove-step
remove the step feature
This commit is contained in:
commit
039bc0acb1
|
@ -6,7 +6,6 @@
|
||||||
#![feature(alloc_error_handler)]
|
#![feature(alloc_error_handler)]
|
||||||
#![test_runner(crate::test_runner)]
|
#![test_runner(crate::test_runner)]
|
||||||
#![reexport_test_harness_main = "test_main"]
|
#![reexport_test_harness_main = "test_main"]
|
||||||
#![feature(step_trait)]
|
|
||||||
//! # agb
|
//! # agb
|
||||||
//! `agb` is a library for making games on the Game Boy Advance using the Rust
|
//! `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
|
//! programming language. It attempts to be a high level abstraction over the
|
||||||
|
|
|
@ -862,18 +862,52 @@ impl<T: Number> Rect<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: FixedWidthUnsignedInteger + core::iter::Step> Rect<T> {
|
impl<T: FixedWidthUnsignedInteger> Rect<T> {
|
||||||
pub fn iter(self) -> impl Iterator<Item = (T, T)> {
|
pub fn iter(self) -> impl Iterator<Item = (T, T)> {
|
||||||
(self.position.x..=(self.position.x + self.size.x))
|
let mut x = self.position.x - T::one();
|
||||||
.into_iter()
|
let mut y = self.position.y;
|
||||||
.flat_map(move |x| {
|
core::iter::from_fn(move || {
|
||||||
(self.position.y..=(self.position.y + self.size.y))
|
x = x + T::one();
|
||||||
.into_iter()
|
if x > self.position.x + self.size.x {
|
||||||
.map(move |y| (x, y))
|
x = self.position.x;
|
||||||
})
|
y = y + T::one();
|
||||||
|
if y > self.position.y + self.size.y {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Some((x, y))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[test_case]
|
||||||
|
fn test_rect_iter(_gba: &mut crate::Gba) {
|
||||||
|
let rect: Rect<i32> = Rect::new((5_i32, 5_i32).into(), (3_i32, 3_i32).into());
|
||||||
|
assert_eq!(
|
||||||
|
rect.iter().collect::<alloc::vec::Vec<_>>(),
|
||||||
|
&[
|
||||||
|
(5, 5),
|
||||||
|
(6, 5),
|
||||||
|
(7, 5),
|
||||||
|
(8, 5),
|
||||||
|
(5, 6),
|
||||||
|
(6, 6),
|
||||||
|
(7, 6),
|
||||||
|
(8, 6),
|
||||||
|
(5, 7),
|
||||||
|
(6, 7),
|
||||||
|
(7, 7),
|
||||||
|
(8, 7),
|
||||||
|
(5, 8),
|
||||||
|
(6, 8),
|
||||||
|
(7, 8),
|
||||||
|
(8, 8),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: Number> Vector2D<T> {
|
impl<T: Number> Vector2D<T> {
|
||||||
pub fn new(x: T, y: T) -> Self {
|
pub fn new(x: T, y: T) -> Self {
|
||||||
Vector2D { x, y }
|
Vector2D { x, y }
|
||||||
|
|
Loading…
Reference in a new issue