diff --git a/crates/whiskers/src/context.rs b/crates/whiskers/src/context.rs index 562d36d..e86101b 100644 --- a/crates/whiskers/src/context.rs +++ b/crates/whiskers/src/context.rs @@ -1,6 +1,6 @@ use rand::distributions::uniform::SampleUniform; use rand::Rng; -use rand_distr::{Distribution, WeightedAliasIndex}; +use rand_distr::{Distribution, Normal, WeightedAliasIndex}; use std::{fmt::Debug, ops::Range}; use vsvg::Point; @@ -100,6 +100,17 @@ impl<'a> Context<'a> { Point::new(x, y) } + /// Helper function to return a number with a Gaussian (normal) distribution + /// + /// # Panics + /// + /// Panics when the `rand_distr` can't create a Normal distribution struct instance. + pub fn rng_gaussian(&mut self, mean: f64, std_dev: f64) -> f64 { + let normal = Normal::new(mean, std_dev).expect("Failed to create normal distribution"); + + normal.sample(&mut self.rng) + } + /// Helper function to display an inspect parameter in the inspect variables UI pub fn inspect(&mut self, key: impl AsRef, value: impl Debug) { self.inspect_variables