If only we can use pattern matching instead of keeping that "bool leaf" :(
What is the variable "closest" for? I must have missed that part.
@OtB_BlueBerry The closest variable keeps track of the ray-scene intersection point closest to the ray's origin (where t=0). For example, in ray tracing, we only care about computing the first ray-scene intersection point, and do not need to keep track of any ray-scene intersections that occur for larger t values.
Regarding the question shown above ("how could this occur?"), if the bounding box intersection value, hit.t, is larger than the closest intersection point computed thus far, we know that any ray-scene intersections that occur within that bounding box occurs later in time. That means we can skip processing the primitives in the bounding box entirely.