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/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/sample/mod.rs') diff --git a/src/sample/mod.rs b/src/sample/mod.rs index 84ac755..5095501 100644 --- a/src/sample/mod.rs +++ b/src/sample/mod.rs @@ -1,6 +1,5 @@ -use crate::Float; +use crate::{M_PI, Float}; use crate::core::{Vector3f, Vector2f}; -use std::f32::consts::PI; mod uniform; @@ -20,7 +19,7 @@ pub trait Sampler { fn get_unit_vector(&mut self) -> Vector3f { let s2d = self.get_sample_2d(); - let lambda = distribute_between(s2d.x, -PI, PI); + let lambda = distribute_between(s2d.x, -M_PI, M_PI); let costheta = 2.0 * s2d.y - 1.0; let sintheta = costheta.acos().sin(); -- cgit v1.2.3