From 10bb2a67c5bb005b304508eb2026780531132f82 Mon Sep 17 00:00:00 2001 From: mhsn Date: Thu, 7 Aug 2025 21:35:55 +0100 Subject: 2024-06 rust p1 --- lib/rust/src/grid.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'lib/rust/src') diff --git a/lib/rust/src/grid.rs b/lib/rust/src/grid.rs index 1b43852..671c7de 100644 --- a/lib/rust/src/grid.rs +++ b/lib/rust/src/grid.rs @@ -9,8 +9,8 @@ type Point = (usize, usize); #[derive(PartialEq, Eq, Clone, Hash, Debug, Copy)] pub struct Direction { - x: i64, - y: i64, + pub x: i64, + pub y: i64, } impl From<(i64, i64)> for Direction { @@ -20,12 +20,12 @@ impl From<(i64, i64)> for Direction { } impl Direction { - fn cw(self) -> Self { - (self.y, -self.x).into() - } - fn acw(self) -> Self { + pub fn cw(self) -> Self { (-self.y, self.x).into() } + pub fn acw(self) -> Self { + (self.y, -self.x).into() + } } pub fn chebyshev_ball(n: i64) -> impl Iterator { @@ -58,6 +58,10 @@ impl Grid { (0..self.width).flat_map(|x| (0..self.height).map(move |y| (x, y))) } + pub fn enumerate(&self) -> impl Iterator { + self.points().map(|p| (p, self.at(p).unwrap())) + } + pub fn move_pos(&self, (x, y): Point, d: Direction, n: i64) -> Option { let x = (i64::try_from(x).ok()? + n * d.x).try_into().ok()?; let y = (i64::try_from(y).ok()? + n * d.y).try_into().ok()?; -- cgit v1.2.3