From 5d28e88b9bc7688e45d5c87da45b457068272b58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moses=20Palm=C3=A9r?= Date: Mon, 2 Sep 2024 16:57:14 +0200 Subject: [PATCH 1/5] Streamline results for operator overloading --- maze/src/physical.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/maze/src/physical.rs b/maze/src/physical.rs index b8a9840..864bfe4 100644 --- a/maze/src/physical.rs +++ b/maze/src/physical.rs @@ -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, @@ -121,7 +121,7 @@ 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, @@ -151,7 +151,7 @@ impl ops::Add 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, From 6547ad99472d222cedb2df1e3c22073b0d1580bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moses=20Palm=C3=A9r?= Date: Mon, 2 Sep 2024 16:58:07 +0200 Subject: [PATCH 2/5] Correct corner walls for hex maze --- maze/src/shape/hex.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maze/src/shape/hex.rs b/maze/src/shape/hex.rs index ccde91d..375c7b3 100644 --- a/maze/src/shape/hex.rs +++ b/maze/src/shape/hex.rs @@ -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: ( @@ -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!( From 6252353560edaca201567c41454b862c96c28467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moses=20Palm=C3=A9r?= Date: Mon, 2 Sep 2024 16:58:31 +0200 Subject: [PATCH 3/5] Implement multiplication and divition for physical pos --- maze/src/physical.rs | 75 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/maze/src/physical.rs b/maze/src/physical.rs index 864bfe4..7c3c902 100644 --- a/maze/src/physical.rs +++ b/maze/src/physical.rs @@ -129,6 +129,81 @@ impl ops::Sub for Pos { } } +impl ops::Mul 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 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 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 for Pos { type Output = Self; From d23287fc1231feaf58079c765d1c8ef32ef49145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moses=20Palm=C3=A9r?= Date: Mon, 2 Sep 2024 16:58:50 +0200 Subject: [PATCH 4/5] Clarify wall order for wall follower --- maze/src/walk.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/maze/src/walk.rs b/maze/src/walk.rs index bf11652..6668777 100644 --- a/maze/src/walk.rs +++ b/maze/src/walk.rs @@ -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. /// @@ -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); From 8812eab4421fe0937f1c87cd6aa37cedce20945d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moses=20Palm=C3=A9r?= Date: Mon, 2 Sep 2024 17:10:23 +0200 Subject: [PATCH 5/5] Update dependencies --- Cargo.toml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1d1bc58..e0c3ad6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,18 +4,18 @@ authors = ["Moses Palmér "] 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 = [