rely on deriving traits instead

This commit is contained in:
2025-03-24 16:42:14 -04:00
parent f1b9f9ad30
commit 7da5541169
3 changed files with 8 additions and 63 deletions

View File

@@ -6,7 +6,7 @@ use std::f32::consts::TAU;
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.
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq)]
pub struct Agent {
pub x: f32,
pub y: f32,
@@ -17,11 +17,7 @@ pub struct Agent {
impl Display for Agent {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{{\n(x,y): ({},{})\nangle: {}\npopulation id: {}\ni: {}}}",
self.x, self.y, self.angle, self.population_id, self.i,
)
write!(f, "{:?}", self)
}
}
@@ -93,25 +89,3 @@ impl Agent {
self.y = wrap(self.y + step_distance * sin(self.angle), height as f32);
}
}
impl Clone for Agent {
fn clone(&self) -> Agent {
Agent {
x: self.x,
y: self.y,
angle: self.angle,
population_id: self.population_id,
i: self.i,
}
}
}
impl PartialEq for Agent {
fn eq(&self, other: &Self) -> bool {
self.x == other.x
&& self.y == other.y
&& self.angle == other.angle
&& self.population_id == other.population_id
&& self.i == other.i
}
}

View File

@@ -1,22 +1,12 @@
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Buf {
pub width: usize,
pub height: usize,
pub buf: Vec<f32>,
}
impl Clone for Buf {
fn clone(&self) -> Buf {
Buf {
width: self.width,
height: self.height,
buf: self.buf.clone(),
}
}
}
impl Buf {
pub fn new(width: usize, height: usize, buf: Vec<f32>) -> Self {
pub const fn new(width: usize, height: usize, buf: Vec<f32>) -> Self {
Buf { width, height, buf }
}

View File

@@ -2,23 +2,14 @@ use crate::{grid::Grid, palette::Palette};
use itertools::multizip;
// Stores data that is located in grids that is used for image generation
/// Stores data that is located in grids that is used for image generation
#[derive(Clone)]
pub struct ThinGridData {
pub width: usize,
pub height: usize,
pub data: Vec<f32>,
}
impl Clone for ThinGridData {
fn clone(&self) -> ThinGridData {
ThinGridData {
width: self.width,
height: self.height,
data: self.data.clone(),
}
}
}
impl ThinGridData {
// Convert Grid to ThinGridData
pub fn new_from_grid(in_grid: &Grid) -> Self {
@@ -69,23 +60,14 @@ impl ThinGridData {
}
}
// Class for storing data that will be used to create images
/// Class for storing data that will be used to create images
#[derive(Clone)]
pub struct ImgData {
pub grids: Vec<ThinGridData>,
pub palette: Palette,
pub iteration: i32,
}
impl Clone for ImgData {
fn clone(&self) -> ImgData {
ImgData {
grids: self.grids.clone(),
palette: self.palette,
iteration: self.iteration,
}
}
}
impl ImgData {
pub fn new(in_grids: Vec<ThinGridData>, in_palette: Palette, in_iteration: i32) -> Self {
ImgData {
@@ -105,7 +87,6 @@ impl ImgData {
output
}
#[inline]
pub fn save_to_image(&self) {
let (width, height) = (self.grids[0].width, self.grids[0].height);
let mut img = image::RgbImage::new(width as u32, height as u32);