summaryrefslogtreecommitdiff
path: root/lib/rust/src
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rust/src')
-rw-r--r--lib/rust/src/grid.rs16
1 files changed, 10 insertions, 6 deletions
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<Item = Direction> {
@@ -58,6 +58,10 @@ impl<T> Grid<T> {
(0..self.width).flat_map(|x| (0..self.height).map(move |y| (x, y)))
}
+ pub fn enumerate(&self) -> impl Iterator<Item = (Point, &T)> {
+ self.points().map(|p| (p, self.at(p).unwrap()))
+ }
+
pub fn move_pos(&self, (x, y): Point, d: Direction, n: i64) -> Option<Point> {
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()?;