From a7e1f1c134f9800d2be2e51d1ac46d037b973674 Mon Sep 17 00:00:00 2001 From: Matthew Gordon Date: Sat, 7 Dec 2019 10:31:55 -0500 Subject: [PATCH] Add type alias for the return type of Material::bsdf() --- src/materials.rs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/materials.rs b/src/materials.rs index d50ef96..a7b554a 100644 --- a/src/materials.rs +++ b/src/materials.rs @@ -4,10 +4,11 @@ use super::colour::{ColourRgbF, NamedColour}; use std::fmt::Debug; +type Bsdf<'a, T> = + Box, Vector3, ColourRgbF) -> ColourRgbF + 'a>; + pub trait Material: Debug { - fn bsdf<'a>( - &'a self, - ) -> Box, Vector3, ColourRgbF) -> ColourRgbF + 'a>; + fn bsdf<'a>(&'a self) -> Bsdf<'a, T>; fn sample(&self, _w_o: &Vector3) -> Vec> { vec![] @@ -30,9 +31,7 @@ impl LambertianMaterial { } impl Material for LambertianMaterial { - fn bsdf<'a>( - &'a self, - ) -> Box, Vector3, ColourRgbF) -> ColourRgbF + 'a> { + fn bsdf<'a>(&'a self) -> Bsdf<'a, T> { Box::new( move |_w_o: Vector3, _w_i: Vector3, colour_in: ColourRgbF| { self.colour * colour_in * self.diffuse_strength @@ -50,9 +49,7 @@ pub struct PhongMaterial { } impl Material for PhongMaterial { - fn bsdf<'a>( - &'a self, - ) -> Box, Vector3, ColourRgbF) -> ColourRgbF + 'a> { + fn bsdf<'a>(&'a self) -> Bsdf<'a, T> { Box::new( move |w_o: Vector3, w_i: Vector3, colour_in: ColourRgbF| { if w_i.z < T::zero() || w_o.z < T::zero() { @@ -77,9 +74,7 @@ pub struct ReflectiveMaterial { } impl Material for ReflectiveMaterial { - fn bsdf<'a>( - &'a self, - ) -> Box, Vector3, ColourRgbF) -> ColourRgbF + 'a> { + fn bsdf<'a>(&'a self) -> Bsdf<'a, T> { Box::new( move |w_o: Vector3, w_i: Vector3, colour_in: ColourRgbF| { if w_i.z < T::zero() || w_o.z < T::zero() {