summaryrefslogtreecommitdiffstats
path: root/src/grid.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2022-12-15 02:29:48 -0500
committerJesse Luehrs <doy@tozt.net>2022-12-15 02:29:48 -0500
commit71b0f797ae1d5d224e2ec0856b8f80f414156573 (patch)
treebdac7b6f327155ce1ab88593738ff1a373509e88 /src/grid.rs
parent8c2d4fdbc6dac9d568b32d853baf698b84aca68f (diff)
downloadadvent-of-code-71b0f797ae1d5d224e2ec0856b8f80f414156573.tar.gz
advent-of-code-71b0f797ae1d5d224e2ec0856b8f80f414156573.zip
simplify
Diffstat (limited to 'src/grid.rs')
-rw-r--r--src/grid.rs78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/grid.rs b/src/grid.rs
index f099189..96ac933 100644
--- a/src/grid.rs
+++ b/src/grid.rs
@@ -76,6 +76,84 @@ impl std::ops::Sub<Col> for usize {
}
}
+#[derive(
+ Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd, Debug, Default,
+)]
+pub struct IRow(pub isize);
+
+#[derive(
+ Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd, Debug, Default,
+)]
+pub struct ICol(pub isize);
+
+impl IRow {
+ pub fn abs_diff(self, other: Self) -> Row {
+ Row(self.0.abs_diff(other.0))
+ }
+}
+
+impl ICol {
+ pub fn abs_diff(self, other: Self) -> Col {
+ Col(self.0.abs_diff(other.0))
+ }
+}
+
+impl std::ops::Add<isize> for IRow {
+ type Output = Self;
+ fn add(self, other: isize) -> Self::Output {
+ Self(self.0 + other)
+ }
+}
+
+impl std::ops::Add<IRow> for isize {
+ type Output = IRow;
+ fn add(self, other: IRow) -> Self::Output {
+ IRow(self + other.0)
+ }
+}
+
+impl std::ops::Add<isize> for ICol {
+ type Output = Self;
+ fn add(self, other: isize) -> Self::Output {
+ Self(self.0 + other)
+ }
+}
+
+impl std::ops::Add<ICol> for isize {
+ type Output = ICol;
+ fn add(self, other: ICol) -> Self::Output {
+ ICol(self + other.0)
+ }
+}
+
+impl std::ops::Sub<isize> for IRow {
+ type Output = Self;
+ fn sub(self, other: isize) -> Self::Output {
+ Self(self.0 - other)
+ }
+}
+
+impl std::ops::Sub<IRow> for isize {
+ type Output = IRow;
+ fn sub(self, other: IRow) -> Self::Output {
+ IRow(self - other.0)
+ }
+}
+
+impl std::ops::Sub<isize> for ICol {
+ type Output = Self;
+ fn sub(self, other: isize) -> Self::Output {
+ Self(self.0 - other)
+ }
+}
+
+impl std::ops::Sub<ICol> for isize {
+ type Output = ICol;
+ fn sub(self, other: ICol) -> Self::Output {
+ ICol(self - other.0)
+ }
+}
+
#[derive(Default, Clone, Debug, Eq, PartialEq)]
pub struct GridRow<T: Default + Clone + Eq + PartialEq> {
cells: Vec<T>,