Skip to content

Commit

Permalink
fix: warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jortrr committed Nov 17, 2024
1 parent 43e71b5 commit c712ba0
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 98 deletions.
1 change: 1 addition & 0 deletions src/day08.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl Parse for Instructions {

#[derive(Debug)]
struct Node {
#[allow(dead_code)]
from_string: String,
label: String,
left: String,
Expand Down
98 changes: 0 additions & 98 deletions src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,10 @@ impl<T> Map<T> {
x >= 0 && x < self.get_columns() as Int && y >= 0 && y < self.get_rows() as Int
}

/// Wrap around bounds: keep x and y within the desired range x: [0, self.get_rows()) and y: [0, self.get_columns()).
pub fn wrapped_point_get(&self, point: &Point) -> Option<&T> {
let point = self.point_wrap_around_bounds(*point);
self.get(point.x, point.y)
}

pub fn point_get(&self, point: &Point) -> Option<&T> {
self.get(point.x, point.y)
}

pub fn point_get_mut(&mut self, point: &Point) -> Option<&mut T> {
self.get_mut(point.x, point.y)
}

/// Wrap around bounds: keep x and y within the desired range x: [0, self.get_rows()) and y: [0, self.get_columns()).
pub fn point_wrap_around_bounds(&self, point: Point) -> Point {
point.point_wrap_around_bounds(self.get_columns() as Int, self.get_rows() as Int)
}

/// Wrap around bounds: keep x and y within the desired range x: [0, self.get_rows()) and y: [0, self.get_columns()).
pub fn wrap(&self, x: Int, y: Int) -> Point {
self.point_wrap_around_bounds(Point::new(x, y))
}

pub fn wrapped_get(&self, x: Int, y: Int) -> Option<&T> {
self.point_get(&self.point_wrap_around_bounds(Point::new(x, y)))
}

pub fn get(&self, x: Int, y: Int) -> Option<&T> {
return if self.within(x, y) {
Some(&self.grid[y as usize][x as usize])
Expand All @@ -62,14 +38,6 @@ impl<T> Map<T> {
};
}

pub fn get_mut(&mut self, x: Int, y: Int) -> Option<&mut T> {
return if self.within(x, y) {
Some(&mut self.grid[y as usize][x as usize])
} else {
None
};
}

/// Return a list of Points for which the Predicate on T hold
pub fn find(&self, predicate: impl Fn(&T) -> bool) -> Vec<Point> {
let mut result = Vec::new();
Expand Down Expand Up @@ -136,35 +104,6 @@ define_convertable_enum! {
}
}

impl Direction {
pub fn move_left(&self) -> Direction {
match &self {
North => West,
East => North,
South => East,
West => South,
}
}

pub fn move_right(&self) -> Direction {
match &self {
North => East,
East => South,
South => West,
West => North,
}
}

pub fn move_back(&self) -> Direction {
match &self {
North => South,
East => West,
South => North,
West => East,
}
}
}

impl Display for Direction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
Expand Down Expand Up @@ -215,47 +154,10 @@ impl Point {
}
}

pub fn moved_from(&self, direction: &Direction) -> Point {
match direction {
North => Point {
x: self.x,
y: self.y + 1,
},
East => Point {
x: self.x - 1,
y: self.y,
},
South => Point {
x: self.x,
y: self.y - 1,
},
West => Point {
x: self.x + 1,
y: self.y,
},
}
}

pub fn new(x: Int, y: Int) -> Point {
Point { x, y }
}

/// Wrap around bounds: keep x and y within the desired range [0, max_x) and [0, max_y).
pub fn point_wrap_around_bounds(mut self, max_x: Int, max_y: Int) -> Point {
self.x = if self.x >= 0 {
self.x % max_x
} else {
(self.x % max_x + max_x) % max_x
};

self.y = if self.y >= 0 {
self.y % max_y
} else {
(self.y % max_y + max_y) % max_y
};
self
}

pub fn translate(mut self, x: Int, y: Int) -> Point {
self.x += x;
self.y += y;
Expand Down

0 comments on commit c712ba0

Please sign in to comment.