cleanup agent structs
This commit is contained in:
parent
f32315cb5d
commit
a0c07364d1
14
src/agent.rs
14
src/agent.rs
@ -9,9 +9,7 @@ use std::fmt::{Display, Formatter};
|
||||
pub struct Agent {
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
pub angle: f32,
|
||||
pub population_id: usize,
|
||||
pub i: usize,
|
||||
angle: f32,
|
||||
}
|
||||
|
||||
impl Display for Agent {
|
||||
@ -22,20 +20,12 @@ impl Display for Agent {
|
||||
|
||||
impl Agent {
|
||||
/// Construct a new agent with random parameters.
|
||||
pub fn new<R: Rng + ?Sized>(
|
||||
width: usize,
|
||||
height: usize,
|
||||
id: usize,
|
||||
rng: &mut R,
|
||||
i: usize,
|
||||
) -> Self {
|
||||
pub fn new<R: Rng + ?Sized>(width: usize, height: usize, rng: &mut R) -> Self {
|
||||
let (x, y, angle) = rng.gen::<(f32, f32, f32)>();
|
||||
Agent {
|
||||
x: x * width as f32,
|
||||
y: y * height as f32,
|
||||
angle: angle * TAU,
|
||||
population_id: id,
|
||||
i,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -73,9 +73,9 @@ impl Model {
|
||||
}
|
||||
|
||||
let mut grids: Vec<Grid> = Vec::new();
|
||||
for pop in 0..n_populations {
|
||||
for _ in 0..n_populations {
|
||||
let agents = (0..particles_per_grid)
|
||||
.map(|i| Agent::new(width, height, pop, &mut rng, i))
|
||||
.map(|_| Agent::new(width, height, &mut rng))
|
||||
.collect();
|
||||
grids.push(Grid::new(width, height, &mut rng, agents));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user