Last active
May 16, 2022 22:00
-
-
Save AnthonyMikh/a50a5a00c1844d9c5ad19c900b79d7f5 to your computer and use it in GitHub Desktop.
Revisions
-
AnthonyMikh revised this gist
May 16, 2022 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,7 +27,7 @@ impl Bounds { put(row, col + 1); } if row + 1 < self.rows { put(row + 1, col); } &buf[..i] } @@ -54,6 +54,7 @@ impl Bounds { put(row, col + 1); } if row + 1 < self.rows { let row = row + 1; if let Some(col) = col.checked_sub(1) { put(row, col); } -
AnthonyMikh revised this gist
May 16, 2022 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,10 +24,10 @@ impl Bounds { put(row, col); } if col + 1 < self.cols { put(row, col + 1); } if row + 1 < self.rows { put(row, col + 1); } &buf[..i] } @@ -44,22 +44,22 @@ impl Bounds { } put(row, col); if col + 1 < self.cols { put(row, col + 1); } } if let Some(col) = col.checked_sub(1) { put(row, col); } if col + 1 < self.cols { put(row, col + 1); } if row + 1 < self.rows { if let Some(col) = col.checked_sub(1) { put(row, col); } put(row, col); if col + 1 < self.cols { put(row, col + 1); } } &buf[..i] -
AnthonyMikh created this gist
Apr 29, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,67 @@ #[derive(Clone, Copy)] pub struct Bounds { rows: usize, cols: usize, } type Pos = (usize, usize); impl Bounds { pub fn around_neumann( self, buf: &mut [Pos; 4], (row, col): Pos ) -> &[Pos] { let mut i = 0; let mut put = |r, c| { buf[i] = (r, c); i += 1; }; if let Some(row) = row.checked_sub(1) { put(row, col); } if let Some(col) = col.checked_sub(1) { put(row, col); } if col + 1 < self.cols { put(row, col); } if row + 1 < self.rows { put(row, col); } &buf[..i] } pub fn around_moore(self, buf: &mut [Pos; 8], (row, col): Pos) -> &[Pos] { let mut i = 0; let mut put = |r, c| { buf[i] = (r, c); i += 1; }; if let Some(row) = row.checked_sub(1) { if let Some(col) = col.checked_sub(1) { put(row, col); } put(row, col); if col + 1 < self.cols { put(row, col); } } if let Some(col) = col.checked_sub(1) { put(row, col); } if col + 1 < self.cols { put(row, col); } if row + 1 < self.rows { if let Some(col) = col.checked_sub(1) { put(row, col); } put(row, col); if col + 1 < self.cols { put(row, col); } } &buf[..i] } }