diff --git a/utils/grid/lib.rs b/utils/grid/lib.rs index ff75b74..6fe07dc 100644 --- a/utils/grid/lib.rs +++ b/utils/grid/lib.rs @@ -39,6 +39,16 @@ impl Add for &Coord2d { } } +impl Add<&T> for Coord2d { + type Output = Coord2d; + fn add(self, rhs: &T) -> Self::Output { + Coord2d { + x: self.x() + rhs.x(), + y: self.y() + rhs.y(), + } + } +} + impl AsCoord2d for Coord2d { fn to_coord(self) -> Coord2d { self @@ -82,6 +92,25 @@ where } } +impl AsCoord2d for &(T, T) +where + T: Copy + TryInto, + >::Error: Debug, +{ + fn to_coord(self) -> Coord2d { + Coord2d { + x: self.0.try_into().unwrap(), + y: self.1.try_into().unwrap(), + } + } + fn x(&self) -> i64 { + self.0.try_into().unwrap() + } + fn y(&self) -> i64 { + self.1.try_into().unwrap() + } +} + impl From for (i64, i64) { fn from(value: Coord2d) -> Self { (value.x, value.y)