switch to using a generic rect

main
Zynh0722 2024-02-17 02:28:05 -08:00
parent 1e90b2c514
commit 8cde3ba399
1 changed files with 5 additions and 5 deletions

View File

@ -23,9 +23,7 @@ struct Model {
engine: PhysicsEngine, engine: PhysicsEngine,
} }
fn random_vec(_app: &App) -> nalgebra::Vector2<f32> { fn random_vec_in_rect(boundary: &Rect) -> nalgebra::Vector2<f32> {
let boundary = _app.window_rect();
let x = random_range(-100., 100.); let x = random_range(-100., 100.);
let y = random_range(-150., boundary.top()); 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 // Keeping track of already placed balls to avoid overlap
// Need to look into a way to do this with rapier directly // Need to look into a way to do this with rapier directly
let mut positions: Vec<nalgebra::Vector2<f32>> = Vec::new(); let mut positions: Vec<nalgebra::Vector2<f32>> = Vec::new();
let boundary = &app.window_rect();
for _ in 0..PARTICLE_COUNT { for _ in 0..PARTICLE_COUNT {
let mut xy = random_vec(app); let mut xy = random_vec_in_rect(boundary);
while !positions while !positions
.iter() .iter()
.all(|pos| pos.metric_distance(&xy) > PARTICLE_SIZE * 2.) .all(|pos| pos.metric_distance(&xy) > PARTICLE_SIZE * 2.)
{ {
xy = random_vec(app) xy = random_vec_in_rect(boundary)
} }
positions.push(xy); positions.push(xy);