Refactor some method code

This commit is contained in:
bijan2005 2021-03-20 17:48:03 -04:00
parent 6ef2c65009
commit 0d3500ceb5
9 changed files with 38 additions and 50 deletions

View file

@ -11,9 +11,9 @@ use crate::object::*;
fn trace(ray: Ray, objects: &Vec<Object>) -> Option<(&Object, f32)> {
objects.iter()
.filter_map(|obj| obj.intersect(ray)
.filter_map(|&obj| obj.intersect(ray)
.map(|x| (obj, x)))
.min_by(|a, b| a.1.partial_cmp(&b.1).unwrap_or(Ordering::Equal))
.min_by(|&a, &b| a.1.partial_cmp(&b.1).unwrap_or(Ordering::Equal))
}
fn light_point(objects: &Vec<Object>, obj: &Object, point: Point3f, light: &dyn Light) -> Color {
@ -34,7 +34,7 @@ pub fn cast_ray(ray: Ray, scene: &Scene) -> Color {
let surface_color = obj.gettexture(point).color;
scene.lights.iter()
.map(|light| light_point(&scene.objects, obj, point, &**light))
.map(|&light| light_point(&scene.objects, obj, point, &*light))
.fold(Color::black(), |acc, c| acc + c) * surface_color
}
else { scene.background }