diff --git a/src/agent.rs b/src/agent.rs index 53cf30d..fcbdad3 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -1,5 +1,4 @@ use crate::{buffer::Buf, util::wrap}; - use fastapprox::faster::{cos, sin}; use rand::{seq::SliceRandom, Rng}; use std::f32::consts::TAU; @@ -41,7 +40,6 @@ impl Agent { } // Tick an agent - #[inline] pub fn tick( &mut self, buf: &Buf, @@ -75,7 +73,9 @@ impl Agent { if (center > left) && (center > right) { direction = 0.0; } else if (center < left) && (center < right) { - direction = *[-1.0, 1.0].choose(&mut rng).unwrap(); + direction = *[-1.0, 1.0] + .choose(&mut rng) + .expect("unable to choose random direction"); } else if left < right { direction = 1.0; } else if right < left { diff --git a/src/blur.rs b/src/blur.rs index 1ecdc39..0735c7d 100644 --- a/src/blur.rs +++ b/src/blur.rs @@ -1,19 +1,11 @@ use itertools::multizip; use rayon::prelude::*; -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Blur { row_buffer: Vec, } -impl Clone for Blur { - fn clone(&self) -> Blur { - Blur { - row_buffer: self.row_buffer.clone(), - } - } -} - impl Blur { pub fn new(width: usize) -> Self { Blur { diff --git a/src/grid.rs b/src/grid.rs index d5c2a6c..24bc0ff 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -23,33 +23,15 @@ impl Display for PopulationConfig { } impl PopulationConfig { - const SENSOR_ANGLE_MIN: f32 = 0.0; - const SENSOR_ANGLE_MAX: f32 = 120.0; - const SENSOR_DISTANCE_MIN: f32 = 0.0; - const SENSOR_DISTANCE_MAX: f32 = 64.0; - const ROTATION_ANGLE_MIN: f32 = 0.0; - const ROTATION_ANGLE_MAX: f32 = 120.0; - const STEP_DISTANCE_MIN: f32 = 0.2; - const STEP_DISTANCE_MAX: f32 = 2.0; - const DEPOSITION_AMOUNT_MIN: f32 = 5.0; - const DEPOSITION_AMOUNT_MAX: f32 = 5.0; - const DECAY_FACTOR_MIN: f32 = 0.1; - const DECAY_FACTOR_MAX: f32 = 0.1; - // Construct a random configuration. pub fn new(rng: &mut R) -> Self { PopulationConfig { - sensor_distance: rng.gen_range(Self::SENSOR_DISTANCE_MIN..=Self::SENSOR_DISTANCE_MAX), - step_distance: rng.gen_range(Self::STEP_DISTANCE_MIN..=Self::STEP_DISTANCE_MAX), - decay_factor: rng.gen_range(Self::DECAY_FACTOR_MIN..=Self::DECAY_FACTOR_MAX), - sensor_angle: rng - .gen_range(Self::SENSOR_ANGLE_MIN..=Self::SENSOR_ANGLE_MAX) - .to_radians(), - rotation_angle: rng - .gen_range(Self::ROTATION_ANGLE_MIN..=Self::ROTATION_ANGLE_MAX) - .to_radians(), - deposition_amount: rng - .gen_range(Self::DEPOSITION_AMOUNT_MIN..=Self::DEPOSITION_AMOUNT_MAX), + sensor_distance: rng.gen_range(0.0..=64.0), + step_distance: rng.gen_range(0.2..=2.0), + decay_factor: rng.gen_range(0.1..=0.1), + sensor_angle: rng.gen_range(0.0_f32..=120.0).to_radians(), + rotation_angle: rng.gen_range(0.0_f32..=120.0).to_radians(), + deposition_amount: rng.gen_range(5.0..=5.0), } } } @@ -103,13 +85,6 @@ impl Grid { j * self.width + i } - /* - // Get the buffer value at a given position. The implementation effectively treats data as periodic, hence any finite position will produce a value. - pub fn get_buf(&self, x: f32, y: f32) -> f32 { - self.buf.buf[self.index(x, y)] - } - */ - // Add a value to the grid data at a given position. pub fn deposit(&mut self, x: f32, y: f32) { let idx = self.index(x, y); @@ -128,7 +103,6 @@ impl Grid { ); } - #[inline] pub fn tick(&mut self) { let (width, height) = (self.width, self.height); let PopulationConfig { @@ -153,33 +127,12 @@ impl Grid { self.deposit_all(); } - #[inline] pub fn deposit_all(&mut self) { let agent_list = self.agents.clone(); for agent in agent_list.iter() { self.deposit(agent.x, agent.y); } } - - // No longer needed (moved to imgdata.rs) - /* - pub fn quantile(&self, fraction: f32) -> f32 { - let index = if (fraction - 1.0_f32).abs() < f32::EPSILON { - self.data.len() - 1 - } else { - (self.data.len() as f32 * fraction) as usize - }; - let mut sorted = self.data.clone(); - sorted - .as_mut_slice() - .select_nth_unstable_by(index, |a, b| a.partial_cmp(b).unwrap()); - sorted[index] - } - - pub fn data(&self) -> &[f32] { - &self.data - } - */ } pub fn combine(grids: &mut [Grid], attraction_table: &[T])