alecjacobson/computer-graphics-bounding-volume-hierarchy

About pseudo-code for distance queries

Opened this issue · 1 comments

I read the pseudo-code for distance queries and was wondering why do we have the if statement "if d_s < d". Wouldn't the first leaf to be dequeued by the priority queue be the closest object to the query point? We could just do a break statement when we encounter the first leaf and record it. Wouldn't this aslo be more efficient since I wouldn't have to pop all the content in the priority queue. I have tested out both implementations and they work the same. Is there a particular reason that the pseudo-code is written that way with the if statement "if d_s < d"?

I think you're right here - great catch! I think it's written that way for simplicity, since the early return is a bit unintuitive. In terms of performance, I don't expect a huge difference since the queue should only have O(tree depth) elements in it, and since that check basically flushes out the queue, it only needs to remove a few elements.