cargo fmt

This commit is contained in:
2025-03-24 16:27:11 -04:00
parent 3a9940dfba
commit f0d4e883f6
7 changed files with 313 additions and 86 deletions

View File

@@ -1,11 +1,8 @@
use crate::{
util::wrap,
buffer::Buf,
};
use crate::{buffer::Buf, util::wrap};
use fastapprox::faster::{cos, sin};
use rand::{seq::SliceRandom, Rng};
use std::f32::consts::TAU;
use fastapprox::faster::{cos, sin};
use std::fmt::{Display, Formatter};
// A single Physarum agent. The x and y positions are continuous, hence we use floating point numbers instead of integers.
@@ -30,7 +27,13 @@ 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,
id: usize,
rng: &mut R,
i: usize,
) -> Self {
let (x, y, angle) = rng.gen::<(f32, f32, f32)>();
Agent {
x: x * width as f32,
@@ -43,7 +46,16 @@ impl Agent {
// Tick an agent
#[inline]
pub fn tick(&mut self, buf: &Buf, sensor_distance: f32, sensor_angle: f32, rotation_angle: f32, step_distance: f32, width: usize, height: usize) {
pub fn tick(
&mut self,
buf: &Buf,
sensor_distance: f32,
sensor_angle: f32,
rotation_angle: f32,
step_distance: f32,
width: usize,
height: usize,
) {
let xc = self.x + cos(self.angle) * sensor_distance;
let yc = self.y + sin(self.angle) * sensor_distance;
@@ -77,14 +89,8 @@ impl Agent {
let delta_angle = rotation_angle * direction;
self.angle = wrap(self.angle + delta_angle, TAU);
self.x = wrap(
self.x + step_distance * cos(self.angle),
width as f32,
);
self.y = wrap(
self.y + step_distance * sin(self.angle),
height as f32,
);
self.x = wrap(self.x + step_distance * cos(self.angle), width as f32);
self.y = wrap(self.y + step_distance * sin(self.angle), height as f32);
}
}
@@ -108,4 +114,4 @@ impl PartialEq for Agent {
&& self.population_id == other.population_id
&& self.i == other.i
}
}
}