diff options
author | Julian T <julian@jtle.dk> | 2021-02-07 00:37:58 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-02-07 00:37:58 +0100 |
commit | f3f56ed5f183f8461cc91cb6430d97c725ba159c (patch) | |
tree | 32d07fc105185849b8bf6bfe1fd63bf85f976410 /src/camera | |
parent | b64c7e972c52b7d015d661866f0cf902370343e5 (diff) |
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.
Diffstat (limited to 'src/camera')
-rw-r--r-- | src/camera/film.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/camera/film.rs b/src/camera/film.rs index 2ff7239..7a7f2dc 100644 --- a/src/camera/film.rs +++ b/src/camera/film.rs @@ -132,11 +132,14 @@ impl FilmTile { pub fn add_sample(&mut self, inp: &Vector2f, c: Spectrum) { let point = Vector2i::from(inp.floor()); // Subtract the offset - let point = point - self.bounds.min; + let point = (point - self.bounds.min).cap(self.size.x-1, self.size.y-1); let index = point.x + point.y * self.size.x; - let pixel = self.pixels.get_mut(index as usize).unwrap(); - pixel.add(&c, 1.0); + if let Some(pixel) = self.pixels.get_mut(index as usize) { + pixel.add(&c, 1.0); + } else { + println!("Could not get pixel {} inp: {}, index: {}", point, inp, index); + } } } |