pub trait CoverObject<T> {
fn cover(&mut self, object: &T);
}
pub trait ManhattanDistance<T, O> {
fn manhattan_distance(&self, other: &Self) -> O;
}
pub trait EuclideanDistanceSquared<T, O> {
fn euclidean_distance_squared(&self, other: &Self) -> O;
}
pub trait IterateNeighboursContext {}
impl IterateNeighboursContext for () {}
pub trait IterateNeighbours<T: IterateNeighboursContext>
where
Self: std::marker::Sized,
{
fn neighbours(&self, context: &T) -> Vec<Self>;
}
pub trait Movement4Directions
where
Self: std::marker::Sized,
Self: Clone,
{
fn step_right(&self) -> Option<Self>;
fn step_up(&self) -> Option<Self>;
fn step_left(&self) -> Option<Self>;
fn step_down(&self) -> Option<Self>;
fn step_right_n(&self, n: usize) -> Option<Self> {
let mut result: Self = self.clone();
for _ in 0..n {
result = result.step_right()?;
}
Some(result)
}
fn step_up_n(&self, n: usize) -> Option<Self> {
let mut result: Self = self.clone();
for _ in 0..n {
result = result.step_up()?;
}
Some(result)
}
fn step_left_n(&self, n: usize) -> Option<Self> {
let mut result: Self = self.clone();
for _ in 0..n {
result = result.step_left()?;
}
Some(result)
}
fn step_down_n(&self, n: usize) -> Option<Self> {
let mut result: Self = self.clone();
for _ in 0..n {
result = result.step_down()?;
}
Some(result)
}
}