Skip to content

Bug: rect hit returning NaN's, Infinities #681

@Walther

Description

@Walther

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions