+
+ pub fn to_grid_coordinate<C>(&self, c: C) -> Option<Point<usize>>
+ where C: Into<(isize, isize)>
+ {
+ let c = c.into();
+ if c.0 >= 0 && c.0 < self.size.width as isize && c.1 >= 0 && c.1 < self.size.height as isize {
+ Some(point!(c.0 as usize, c.1 as usize))
+ } else {
+ None
+ }
+ }
+
+ /// Returns a list of grid coordinates that a line in world coordinates passes through.
+ pub fn grid_coordinates_on_line(&self, p1: Point<f64>, p2: Point<f64>) -> Vec<Point<usize>> {
+ let scale = (self.cell_size.width as f64, self.cell_size.height as f64);
+ supercover_line(p1 / scale, p2 / scale)
+ .iter()
+ .map(|c| self.to_grid_coordinate(*c))
+ .flatten()
+ .collect()
+ }