Skip to content

Commit

Permalink
maybe make it more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy5909 committed May 2, 2024
1 parent fb21d16 commit 168766d
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/hittable_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ impl HittableList {

impl Hittable for HittableList {
fn hit(&self, r: &crate::ray::Ray, ray_t: Interval, rec: &mut HitRecord) -> bool {
let mut temp_rec = HitRecord::default();
let mut hit_anything = false;
let mut closest_so_far = ray_t.max;

for object in &self.objects {
if object.hit(r, Interval::new(ray_t.min, closest_so_far), &mut temp_rec) {
hit_anything = true;
closest_so_far = temp_rec.t;
*rec = temp_rec.clone();
let hit_anything = self.objects.iter().any(|object| {
if object.hit(r, Interval::new(ray_t.min, closest_so_far), rec) {
closest_so_far = rec.t;
true
} else {
false
}
}
});
hit_anything
}
}

0 comments on commit 168766d

Please sign in to comment.