use std::cmp::Ordering;
use std::num::NonZero;
use ndarray::Ix;
pub type Coord = usize;
pub type Dimension = NonZero<Coord>;
#[derive(Clone, Eq, Hash, Copy, PartialEq, PartialOrd, Debug)]
pub struct Location(pub Coord, pub Coord);
impl Ord for Location {
fn cmp(&self, other: &Self) -> Ordering {
self.as_index().cmp(&other.as_index())
}
}
impl Location {
pub(crate) fn as_index(&self) -> (Coord, Coord) {
(self.1, self.0)
}
pub(crate) fn offset_by(self, rhs: (isize, isize)) -> Self {
Self(self.0.wrapping_add_signed(rhs.0), self.1.wrapping_add_signed(rhs.1))
}
}
impl From<(Ix, Ix)> for Location {
fn from(value: (Ix, Ix)) -> Self {
Self(value.1, value.0)
}
}