Fix: hit record selection mechanism

Because of the mutable record being used in the loop, the previous
version had a somewhat obscured way to track the nearest collision.

Switching to an optional (so I can have a non-optional Material in it)
means I'm not interrogating that value.... So it gets to be explicit
again.

I'll refactor the entire for-loop into an iterator with the min()
adapter at some point. For now: Material lifetimes!
This commit is contained in:
2023-09-23 09:27:21 -07:00
parent bdc396accf
commit 515f5b866a

View File

@@ -32,10 +32,11 @@ impl Hittable {
Hittable::HittableList { hittables } => {
let mut might_return: Option<HitRecord> = None;
let mut hit_anything = false;
let mut nearest_t = t_max;
for item in hittables {
if let Some(record) = item.hit(r, t_min, t_max){
if let Some(record) = item.hit(r, t_min, nearest_t){
hit_anything = true;
nearest_t = record.t;
might_return = Some(record);
}
}