diff --git a/Cargo.toml b/Cargo.toml index c27a1f8..0f35711 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,14 @@ path = "src/main.rs" name = "ui" path = "src/ui.rs" +# Set the default for crate. +[profile.dev] +opt-level = 1 + +# Set the default for dependencies. +[profile.dev.package."*"] +opt-level = 3 + [dependencies] clap = { version = "4.1.8", features = ["derive"] } bevy = { version = "0.9.1", features = ["dynamic"] } diff --git a/src/main.rs b/src/main.rs index acb8b06..7344996 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use std::fs::File; use std::io; use std::io::Write; use std::ops::Add; +use std::path::PathBuf; use nd_array::Array; use rand::prelude::*; @@ -22,7 +23,7 @@ struct Cli { seed: u64, max_particles: usize, stick_probability: f32, - csv_path: String, + csv_path: PathBuf, } fn main() { @@ -38,6 +39,6 @@ fn main() { sys.update(); } - sys.export_data() + sys.export_data(&cli.csv_path) .expect("Failed to write"); } diff --git a/src/system/model.rs b/src/system/model.rs index 98dc69d..a50e63a 100644 --- a/src/system/model.rs +++ b/src/system/model.rs @@ -1,6 +1,7 @@ use std::fs::File; use std::io::Write; use std::io; +use std::path::Path; use rand::prelude::*; use crate::system::{DIM, Position}; use crate::system::storage::{Storage, VectorStorage}; @@ -34,7 +35,7 @@ impl> DLASystem { max_particles, running: true, - storage: VectorStorage::new(1600, 2), + storage: VectorStorage::new(6000, 2), walker: LocalRandomWalker, particles: vec![], active_particle: None, @@ -68,19 +69,19 @@ impl> DLASystem { .clone() .expect("No active particle"); - if self.check_stick(current_position) { - self.deposit(current_position); - self.active_particle = None; - return; - } - let next_position = self.walker.walk(&mut self.rng, current_position); let distance = next_position.abs(); if distance > self.kill_circle { self.active_particle = None; } else if !self.storage.at(&next_position) { - self.active_particle.replace(next_position); + if self.check_stick(&next_position) { + self.deposit(&next_position); + self.active_particle = None; + return; + } else { + self.active_particle.replace(next_position); + } } } @@ -123,8 +124,8 @@ impl> DLASystem { } } - pub fn export_data(&self) -> io::Result<()> { - let mut file = File::create("out.csv")?; + pub fn export_data(&self, path: &Path) -> io::Result<()> { + let mut file = File::create(path)?; writeln!(&mut file, "x, y")?; for particle in &self.particles {