mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 16:21:33 +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)]
|
||||
#![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
|
||||
|
|
|
@ -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)> {
|
||||
(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))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[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> {
|
||||
pub fn new(x: T, y: T) -> Self {
|
||||
Vector2D { x, y }
|
||||
|
|
Loading…
Reference in a new issue