permanganate 0.2.0

Graph and Boolean SAT solver for Numberlink and Flow Free
Documentation
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)]
/// A location `(x, y)` on a board. The top left corner is `Location(0, 0)`.
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)
    }
}