better edge case handling

This commit is contained in:
2024-03-26 10:24:35 +01:00
parent 35b7d7bab0
commit 3863e7907f

View File

@@ -49,11 +49,11 @@ float Distance(const Ray& ray, const AABB& aabb) {
// (as a result of 0.0 / 0.0). If all coordinates are NAN, this means
// that the box is reduced to a point and the ray has direction 0,
// in which case this returns -1
if (tmax < 0.0f || tmin > tmax) {
return -1.0f;
if (tmax >= 0.0f && tmin <= tmax) {
return std::fmaxf(tmin, 0.0f);
}
return std::fmaxf(tmin, 0.0f);
return -1.0f;
}
bool Intersects(const Ray& ray, const AABB& aabb) {