cleanup agent structs

This commit is contained in:
Simon Gardling 2025-03-27 23:54:02 -04:00
parent f32315cb5d
commit a0c07364d1
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D
2 changed files with 4 additions and 14 deletions

View File

@ -9,9 +9,7 @@ use std::fmt::{Display, Formatter};
pub struct Agent { pub struct Agent {
pub x: f32, pub x: f32,
pub y: f32, pub y: f32,
pub angle: f32, angle: f32,
pub population_id: usize,
pub i: usize,
} }
impl Display for Agent { impl Display for Agent {
@ -22,20 +20,12 @@ impl Display for Agent {
impl Agent { impl Agent {
/// Construct a new agent with random parameters. /// Construct a new agent with random parameters.
pub fn new<R: Rng + ?Sized>( pub fn new<R: Rng + ?Sized>(width: usize, height: usize, rng: &mut R) -> Self {
width: usize,
height: usize,
id: usize,
rng: &mut R,
i: usize,
) -> Self {
let (x, y, angle) = rng.gen::<(f32, f32, f32)>(); let (x, y, angle) = rng.gen::<(f32, f32, f32)>();
Agent { Agent {
x: x * width as f32, x: x * width as f32,
y: y * height as f32, y: y * height as f32,
angle: angle * TAU, angle: angle * TAU,
population_id: id,
i,
} }
} }

View File

@ -73,9 +73,9 @@ impl Model {
} }
let mut grids: Vec<Grid> = Vec::new(); let mut grids: Vec<Grid> = Vec::new();
for pop in 0..n_populations { for _ in 0..n_populations {
let agents = (0..particles_per_grid) let agents = (0..particles_per_grid)
.map(|i| Agent::new(width, height, pop, &mut rng, i)) .map(|_| Agent::new(width, height, &mut rng))
.collect(); .collect();
grids.push(Grid::new(width, height, &mut rng, agents)); grids.push(Grid::new(width, height, &mut rng, agents));
} }