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);