Add support for ND systems
This commit is contained in:
parent
1c49bf92c8
commit
7cfa5092e8
@ -8,6 +8,7 @@ use crate::system::{GriddedPosition, Position};
|
||||
use crate::system::storage::{Storage, VectorStorage};
|
||||
use crate::system::walker::{LocalRandomWalker, Walker};
|
||||
use serde::{Serialize, Deserialize};
|
||||
use crate::system::nd::{NDPosition, NDVectorStorage};
|
||||
|
||||
pub struct DLASystem<R: Rng, P: GriddedPosition, S: Storage<P>, W: Walker<P>> {
|
||||
rng: R,
|
||||
@ -55,6 +56,31 @@ impl<R: Rng, P: GriddedPosition, S: Storage<P>, W: Walker<P>> DLASystem<R, P, S,
|
||||
sys
|
||||
}
|
||||
|
||||
pub fn new_nd<const DIM: usize>(rng: R, max_particles: usize, stick_probability: f32) -> DLASystem<R, NDPosition<DIM>, NDVectorStorage<DIM>, LocalRandomWalker> {
|
||||
let mut sys: DLASystem<R, NDPosition<DIM>, NDVectorStorage<DIM>, LocalRandomWalker> = DLASystem {
|
||||
rng,
|
||||
stick_probability,
|
||||
max_particles,
|
||||
running: true,
|
||||
|
||||
space: NDVectorStorage::new(1600),
|
||||
walker: LocalRandomWalker,
|
||||
particles: vec![],
|
||||
active_particle: None,
|
||||
|
||||
add_ratio: 1.2,
|
||||
kill_ratio: 1.7,
|
||||
|
||||
add_circle: 10.0,
|
||||
kill_circle: 20.0,
|
||||
cluster_radius: 0.0,
|
||||
};
|
||||
|
||||
sys.deposit(&NDPosition::zero());
|
||||
|
||||
sys
|
||||
}
|
||||
|
||||
pub fn update(&mut self) {
|
||||
if self.active_particle.is_some() {
|
||||
self.move_particle();
|
||||
|
||||
@ -10,6 +10,12 @@ pub struct NDVectorStorage<const DIM: usize> {
|
||||
grid_size: u32,
|
||||
}
|
||||
|
||||
impl<const DIM: usize> NDVectorStorage<DIM> {
|
||||
pub fn new(grid_size: u32) -> Self {
|
||||
Self { grid_size, backing: vec![false; grid_size.pow(DIM as u32) as usize] }
|
||||
}
|
||||
}
|
||||
|
||||
impl<const DIM: usize> Storage<NDPosition<DIM>> for NDVectorStorage<DIM> {
|
||||
fn at(&self, position: &NDPosition<DIM>) -> bool {
|
||||
return self.backing[position.linear_index(self.grid_size)];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user