#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct Shift {
pub(crate) dh: i8,
pub(crate) dv: i8,
}
impl std::fmt::Debug for Shift {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Shift {{ dv: {0}, dh: {1} }}", self.dv, self.dh)
}
}
impl Shift {
pub fn new(dv: i8, dh: i8) -> Self {
Self { dh, dv }
}
pub fn dh(&self) -> &i8 {
&self.dh
}
pub fn dv(&self) -> &i8 {
&self.dv
}
pub fn dh_mut(&mut self) -> &mut i8 {
&mut self.dh
}
pub fn dv_mut(&mut self) -> &mut i8 {
&mut self.dv
}
}
impl std::ops::Add for Shift {
type Output = Shift;
fn add(self, rhs: Self) -> Self::Output {
Shift {
dh: self.dh + rhs.dh,
dv: self.dv + rhs.dv,
}
}
}
impl std::ops::Neg for Shift {
type Output = Shift;
fn neg(self) -> Self::Output {
Shift {
dh: -self.dh,
dv: -self.dv,
}
}
}
impl std::ops::Sub for Shift {
type Output = Shift;
fn sub(self, rhs: Self) -> Self::Output {
Shift {
dh: self.dh - rhs.dh,
dv: self.dv - rhs.dv,
}
}
}