From f3f56ed5f183f8461cc91cb6430d97c725ba159c Mon Sep 17 00:00:00 2001 From: Julian T Date: Sun, 7 Feb 2021 00:37:58 +0100 Subject: Move to double to avoid rounding error This rounding errors seems to happen when adding floats very close to 1 to a relatively large number. 325.0 + 0.99999034 = 326.0 This is a problem as this sample should be counted at the 325 pixel. However this will be a lesser problem when filtering is implemented. --- src/sample/uniform.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/sample/uniform.rs') diff --git a/src/sample/uniform.rs b/src/sample/uniform.rs index cc6825a..e2f0b7c 100644 --- a/src/sample/uniform.rs +++ b/src/sample/uniform.rs @@ -15,13 +15,14 @@ impl UniformSampler { pub fn new() -> Self { Self { r: Pcg32::seed_from_u64(1), - d: Uniform::from(0.0..1.0), + d: Uniform::new(0.0, 1.0), } } } impl Sampler for UniformSampler { fn get_sample(&mut self) -> Float { - self.d.sample(&mut self.r) + let sample = self.d.sample(&mut self.r); + sample } } -- cgit v1.2.3