From c1801a7a78193431f93ebeb37fa903bae25d6f1d Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 6 Apr 2020 15:07:43 +0200 Subject: [PATCH] library: render: pathtracer: use map_or_else --- pathtracer/src/render/pathtrace/pathtracer.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pathtracer/src/render/pathtrace/pathtracer.rs b/pathtracer/src/render/pathtrace/pathtracer.rs index 8c4a8b7..cc26265 100644 --- a/pathtracer/src/render/pathtrace/pathtracer.rs +++ b/pathtracer/src/render/pathtrace/pathtracer.rs @@ -59,11 +59,12 @@ impl Pathtracer { fn pixel_ray(&self, x: f32, y: f32) -> LinearColor { let (x, y) = self.scene.camera.film().pixel_ratio(x, y); let ray = self.scene.camera.ray_with_ratio(x, y); - if let Some(_) = self.cast_ray(ray) { - LinearColor::new(1., 1., 1.) // FIXME: calculate real color - } else { - LinearColor::black() - } + self.cast_ray(ray).map_or_else( + || self.scene.background.clone(), + |(t, obj)| { + LinearColor::new(1., 1., 1.) // FIXME: calculate real color + }, + ) } fn cast_ray(&self, ray: Ray) -> Option<(f32, &Object)> {