From 8cde3ba3991cdfbb7ea3bd9d810f8c33cdab2eda Mon Sep 17 00:00:00 2001 From: Zynh0722 Date: Sat, 17 Feb 2024 02:28:05 -0800 Subject: [PATCH] switch to using a generic rect --- src/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index d227ecc..1610554 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,9 +23,7 @@ struct Model { engine: PhysicsEngine, } -fn random_vec(_app: &App) -> nalgebra::Vector2 { - let boundary = _app.window_rect(); - +fn random_vec_in_rect(boundary: &Rect) -> nalgebra::Vector2 { let x = random_range(-100., 100.); let y = random_range(-150., boundary.top()); @@ -36,13 +34,15 @@ fn fill_particles(app: &App, colliders: &mut ColliderSet, bodies: &mut RigidBody // Keeping track of already placed balls to avoid overlap // Need to look into a way to do this with rapier directly let mut positions: Vec> = Vec::new(); + let boundary = &app.window_rect(); + for _ in 0..PARTICLE_COUNT { - let mut xy = random_vec(app); + let mut xy = random_vec_in_rect(boundary); while !positions .iter() .all(|pos| pos.metric_distance(&xy) > PARTICLE_SIZE * 2.) { - xy = random_vec(app) + xy = random_vec_in_rect(boundary) } positions.push(xy);