use std::collections::HashSet;
use grid::Grid;
use super::EXPECT_WAVE_GRID_BOUNDS;
pub trait VisitedCoordsTracker {
fn mark_visited_coords(&mut self, coords: (u32, u32));
fn has_visited_coords(&self, coords: &(u32, u32)) -> bool;
}
impl VisitedCoordsTracker for HashSet<(u32, u32)> {
fn mark_visited_coords(&mut self, coords: (u32, u32)) {
self.insert(coords);
}
fn has_visited_coords(&self, coords: &(u32, u32)) -> bool {
self.contains(coords)
}
}
impl VisitedCoordsTracker for Grid<bool> {
fn mark_visited_coords(&mut self, coords: (u32, u32)) {
let cell = self.get_mut(coords.1 as usize, coords.0 as usize)
.expect(EXPECT_WAVE_GRID_BOUNDS);
*cell = true
}
fn has_visited_coords(&self, coords: &(u32, u32)) -> bool {
*self.get(coords.1 as usize, coords.0 as usize)
.expect(EXPECT_WAVE_GRID_BOUNDS)
}
}