-
Notifications
You must be signed in to change notification settings - Fork 945
Closed
Description
raytracing.github.io/src/TheRestOfYourLife/aarect.h
Lines 124 to 126 in 7b92650
auto t = (k-r.origin().y()) / r.direction().y(); | |
if (t < t0 || t > t1) | |
return false; |
If
r.direction().y()
happens to be zero, you'll get t=infinity
. This infinity will get passed along, because infinity > infinity
is false
so the if
branch is not taken.
Additionally, if k-r.origin().y()
happens to be 0
as well, you'll get 0.0 / 0.0
resulting in a NaN
that again gets passed along.
This exists in all three cases of rect
, with different axes being the culprit.
Caveat emptor: I bumped into this in my Rust implementation, so some specific details may be slightly different, including in case infinity & NaN semantics are slightly different in C++. But I think this should be applicable.
Offtopic sidenote: wonder if it would be worth it to make the distance be named something else than t
, considering some other functions in the book use t
or t0, t1
for time