cell_grid/legacy/
rect.rs

1use crate::Coord;
2
3/// A rectangle of coordinates
4#[derive(Debug, Copy, Clone, Eq, PartialEq)]
5#[deprecated(since = "0.1.4", note = "Use `DynamicGrid` instead")]
6pub struct Rect {
7    min: Coord,
8    max: Coord,
9}
10
11impl Rect {
12    /// Create rectangle from the `min` and `max` coordinates
13    ///
14    /// In a typical screen-space system (x = right, y = down)
15    /// `min` is the top-left, and `max` is the bottom right
16    pub fn from_min_max(min: impl Into<Coord>, max: impl Into<Coord>) -> Self {
17        Self {
18            min: min.into(),
19            max: max.into(),
20        }
21    }
22
23    /// Returns an iterator over the coordinates contained in the rectangle
24    pub fn coords(self) -> impl Iterator<Item = Coord> {
25        (self.min.x..=self.max.x)
26            .flat_map(move |x| (self.min.y..=self.max.y).map(move |y| Coord::new(x, y)))
27    }
28}