fix: Rect::positions() should be empty when width is 0 and height is nonzero (#1669)
Fixes #1666.
This commit is contained in:
committed by
GitHub
parent
882cc3c6c6
commit
35a86427ab
@@ -151,7 +151,7 @@ impl Iterator for Positions {
|
||||
///
|
||||
/// Returns `None` when there are no more positions to iterate through.
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.current_position.y >= self.rect.bottom() {
|
||||
if !self.rect.contains(self.current_position) {
|
||||
return None;
|
||||
}
|
||||
let position = self.current_position;
|
||||
@@ -326,4 +326,31 @@ mod tests {
|
||||
assert_eq!(positions.next(), None);
|
||||
assert_eq!(positions.size_hint(), (0, Some(0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn positions_zero_width() {
|
||||
let rect = Rect::new(0, 0, 0, 1);
|
||||
let mut positions = Positions::new(rect);
|
||||
assert_eq!(positions.size_hint(), (0, Some(0)));
|
||||
assert_eq!(positions.next(), None);
|
||||
assert_eq!(positions.size_hint(), (0, Some(0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn positions_zero_height() {
|
||||
let rect = Rect::new(0, 0, 1, 0);
|
||||
let mut positions = Positions::new(rect);
|
||||
assert_eq!(positions.size_hint(), (0, Some(0)));
|
||||
assert_eq!(positions.next(), None);
|
||||
assert_eq!(positions.size_hint(), (0, Some(0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn positions_zero_by_zero() {
|
||||
let rect = Rect::new(0, 0, 0, 0);
|
||||
let mut positions = Positions::new(rect);
|
||||
assert_eq!(positions.size_hint(), (0, Some(0)));
|
||||
assert_eq!(positions.next(), None);
|
||||
assert_eq!(positions.size_hint(), (0, Some(0)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user