Another shared library update

This commit is contained in:
Timothy Warren 2022-12-23 17:01:45 -05:00
parent 61ca75696d
commit 1d6ff7705e
3 changed files with 25 additions and 22 deletions

View File

@ -18,6 +18,10 @@ impl<T> Grid<T> {
self.vec.len()
}
pub fn is_empty(&self) -> bool {
self.vec.is_empty()
}
pub fn num_cols(&self) -> usize {
self.width
}

View File

@ -2,6 +2,25 @@ pub mod grid;
pub mod enums;
pub use grid::*;
pub use enums::*;
#[derive(Debug, Default, Copy, Clone, Eq, Hash, PartialEq)]
pub struct Location {
pub x: isize,
pub y: isize,
}
impl Location {
pub fn new(x: isize, y: isize) -> Self {
Location { x, y }
}
pub fn get_distance(self, other: Self) -> f64 {
let squares = (other.x - self.x).pow(2) + (other.y - self.y).pow(2);
(squares as f64).sqrt()
}
}
#[macro_export]
macro_rules! deref {

View File

@ -1,6 +1,6 @@
use std::collections::HashSet;
use aoc_shared::enums::*;
use aoc_shared::enums::Direction::*;
use aoc_shared::{Location, Direction};
use aoc_shared::Direction::*;
struct Move {
dir: Direction,
@ -24,24 +24,6 @@ impl Move {
}
}
#[derive(Debug, Default, Copy, Clone, Eq, Hash, PartialEq)]
struct Location {
x: isize,
y: isize,
}
impl Location {
fn new(x: isize, y: isize) -> Self {
Location { x, y }
}
fn get_distance(self, other: Self) -> f64 {
let squares = (other.x - self.x).pow(2) + (other.y - self.y).pow(2);
(squares as f64).sqrt()
}
}
// ---------------------------------------------------------------------------
#[derive(Debug, Default)]
@ -97,8 +79,6 @@ impl Rope {
for i in 1..self.knot_count {
self.move_knot(i, i - 1);
}
// self.head = to;
// self.head_visited.insert(to);
}
}