#![warn(missing_debug_implementations)]
#![warn(missing_docs)]
use std::collections;
use super::gridbool::Gridbool;
use super::pos::Pos;
pub trait SetPos<const W: u16, const H: u16, const WORDS: usize, const SIZE: usize> {
fn contains(&self, pos: &Pos<W, H>) -> bool;
fn insert(&mut self, pos: &Pos<W, H>);
fn remove(&mut self, pos: &Pos<W, H>);
fn set(&mut self, pos: &Pos<W, H>, add: bool) {
if add {
self.insert(pos);
} else {
self.remove(pos);
}
}
}
impl<const W: u16, const H: u16, const WORDS: usize, const SIZE: usize> SetPos<W, H, WORDS, SIZE>
for Gridbool<W, H, WORDS>
{
fn contains(&self, pos: &Pos<W, H>) -> bool {
self.get(pos)
}
fn insert(&mut self, pos: &Pos<W, H>) {
self.set_t(pos)
}
fn remove(&mut self, pos: &Pos<W, H>) {
self.set_f(pos)
}
}
impl<const W: u16, const H: u16, const WORDS: usize, const SIZE: usize> SetPos<W, H, WORDS, SIZE>
for collections::HashSet<Pos<W, H>>
{
fn contains(&self, pos: &Pos<W, H>) -> bool {
self.contains(pos)
}
fn insert(&mut self, pos: &Pos<W, H>) {
self.insert(*pos);
}
fn remove(&mut self, pos: &Pos<W, H>) {
self.remove(pos);
}
}
impl<const W: u16, const H: u16, const WORDS: usize, const SIZE: usize> SetPos<W, H, WORDS, SIZE>
for collections::BTreeSet<Pos<W, H>>
{
fn contains(&self, pos: &Pos<W, H>) -> bool {
self.contains(pos)
}
fn insert(&mut self, pos: &Pos<W, H>) {
self.insert(*pos);
}
fn remove(&mut self, pos: &Pos<W, H>) {
self.remove(pos);
}
}