Skip to content

Commit

Permalink
apply more functional programming
Browse files Browse the repository at this point in the history
  • Loading branch information
makeecat committed Aug 12, 2024
1 parent f678cf4 commit bfcd71f
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,18 +1022,16 @@ impl Maze {
/// # Arguments
/// * `dt` - The time step
fn update_obstacles(&mut self, dt: f32) {
for obstacle in self.obstacles.iter_mut() {
// Update position
self.obstacles.iter_mut().for_each(|obstacle| {
obstacle.position += obstacle.velocity * dt;
// Bounce off boundaries
for i in 0..3 {
if obstacle.position[i] - obstacle.radius < self.lower_bounds[i]
|| obstacle.position[i] + obstacle.radius > self.upper_bounds[i]
{
obstacle.velocity[i] = -obstacle.velocity[i];
obstacle.velocity[i] *= -1.0;
}
}
}
});
}
}

Expand Down Expand Up @@ -1296,23 +1294,20 @@ fn log_maze_tube(rec: &rerun::RecordingStream, maze: &Maze) {
/// * `rec` - The rerun::RecordingStream instance
/// * `maze` - The maze instance
fn log_maze_obstacles(rec: &rerun::RecordingStream, maze: &Maze) {
let positions: Vec<(f32, f32, f32)> = maze
let (positions, radii): (Vec<_>, Vec<_>) = maze
.obstacles
.iter()
.map(|obstacle| {
(
obstacle.position.x,
obstacle.position.y,
obstacle.position.z,
(
obstacle.position.x,
obstacle.position.y,
obstacle.position.z,
),
obstacle.radius,
)
})
.collect();

let radii: Vec<f32> = maze
.obstacles
.iter()
.map(|obstacle| obstacle.radius)
.collect();
.unzip();

rec.log(
"maze/obstacles",
Expand Down

0 comments on commit bfcd71f

Please sign in to comment.