Skip to content

Commit

Permalink
Merge branch 'fixup/general'
Browse files Browse the repository at this point in the history
  • Loading branch information
moses-palmer committed Sep 2, 2024
2 parents d1e851d + 8812eab commit 3c9f4c8
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 11 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ authors = ["Moses Palmér <[email protected]>"]
edition = "2021"

[workspace.dependencies]
actix-web = "4.4"
actix-web = "4.9"
bit-set = "0.5"
clap = { version = "4.4", features = [ "cargo", "derive" ] }
clap = { version = "4.5", features = [ "cargo", "derive" ] }
futures-util = "0.3"
image = "0.24"
lazy_static = "1.4"
image = "0.25"
lazy_static = "1.5"
rand = "0.8"
rayon = "1.8"
rayon = "1.10"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_urlencoded = "0.7"
svg = "0.14"
svg = "0.17"

[workspace]
members = [
Expand Down
81 changes: 78 additions & 3 deletions maze/src/physical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl ops::Add for Pos {
///
/// # Arguments
/// * `other` - The other position to add.
fn add(self, other: Self) -> Self {
fn add(self, other: Self) -> Self::Output {
Self {
x: self.x + other.x,
y: self.y + other.y,
Expand All @@ -121,14 +121,89 @@ impl ops::Sub for Pos {
///
/// # Arguments
/// * `other` - The other position to add.
fn sub(self, other: Self) -> Self {
fn sub(self, other: Self) -> Self::Output {
Self {
x: self.x - other.x,
y: self.y - other.y,
}
}
}

impl ops::Mul<f32> for Pos {
type Output = Self;

/// Multiplies the axis values of a position.
///
/// # Example
///
/// ```
/// # use maze::physical::*;
///
/// assert_eq!(
/// Pos { x: 1.0, y: 2.5 } * 2.0,
/// Pos { x: 2.0, y: 5.0 },
/// );
/// ```
///
/// # Arguments
/// * `other` - The multiplication factor.
#[inline]
fn mul(self, other: f32) -> Self::Output {
Self {
x: other * self.x,
y: other * self.y,
}
}
}

impl ops::Mul<Pos> for f32 {
type Output = Pos;

/// Multiplies the axis values of a position.
///
/// # Example
///
/// ```
/// # use maze::physical::*;
///
/// assert_eq!(
/// 2.0 * Pos { x: 1.0, y: 2.5 },
/// Pos { x: 2.0, y: 5.0 },
/// );
/// ```
///
/// # Arguments
/// * `other` - The multiplication factor.
#[inline]
fn mul(self, other: Pos) -> Self::Output {
other * self
}
}

impl ops::Div<f32> for Pos {
type Output = Self;

/// Divides the axis values of a position.
///
/// # Example
///
/// ```
/// # use maze::physical::*;
///
/// assert_eq!(
/// Pos { x: 1.0, y: 3.0 } / 2.0,
/// Pos { x: 0.5, y: 1.5 },
/// );
/// ```
///
/// # Arguments
/// * `other` - The divisor.
#[inline]
fn div(self, other: f32) -> Self::Output {
self * (1.0 / other)
}
}

impl ops::Add<Angle> for Pos {
type Output = Self;

Expand All @@ -151,7 +226,7 @@ impl ops::Add<Angle> for Pos {
///
/// # Arguments
/// * `other` - The other position to add.
fn add(self, other: Angle) -> Self {
fn add(self, other: Angle) -> Self::Output {
Self {
x: self.x + other.dx,
y: self.y + other.dy,
Expand Down
4 changes: 2 additions & 2 deletions maze/src/shape/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ define_shape! {
UP_LEFT0(1) = {
corner_wall_offsets: &[
Offset { dx: 0, dy: -1, wall: &DOWN_LEFT1 },
Offset { dx: -1, dy: 0, wall: &UP_RIGHT0 },
Offset { dx: -1, dy: 0, wall: &RIGHT0 },
],
dir: (0, -1),
span: (
Expand Down Expand Up @@ -568,7 +568,7 @@ mod tests {
vec![
(matrix_pos(1, 2), &walls::UP_LEFT0),
(matrix_pos(1, 1), &walls::DOWN_LEFT1),
(matrix_pos(0, 2), &walls::UP_RIGHT0),
(matrix_pos(0, 2), &walls::RIGHT0),
],
);
assert_eq!(
Expand Down
18 changes: 18 additions & 0 deletions maze/src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ where
/// This method will follow a wall without passing through any walls. When
/// the starting wall is encountered, no more walls will be returned.
///
/// The direction of walking along a wall is from the point where its span
/// starts to where it ends.
///
/// If the starting position is an open wall, the iterator will contain no
/// elements.
///
Expand Down Expand Up @@ -514,6 +517,21 @@ mod tests {
);
}

#[maze_test]
fn follow_wall_order(maze: TestMaze) {
let start =
maze.wall_positions((0isize, 0isize).into()).next().unwrap();

for (a, b) in maze.follow_wall(start) {
if let Some(b) = b {
assert!(is_close(
maze.center(a.0) + a.1.span.1,
maze.center(b.0) + b.1.span.0,
));
}
}
}

#[test]
fn pop_empty() {
let mut os = OpenSet::new(10, 10);
Expand Down

0 comments on commit 3c9f4c8

Please sign in to comment.