AABB::overlaps false negative for edge cases
jallmenroeder opened this issue · 0 comments
jallmenroeder commented
The AABB::overlaps function misses overlaps when one of the AABBs is 0 in one dimension.
Example:
AABB a(float3(-1, -1, -1), float3(1, 1, 1));
AABB b(float3(-1, -1, 0), float3(1, 1, 0));
assert(a.overlaps(b));
Since the overlaps
function relies on the volume of the intersection of the two AABBs, which is 0 in this case, the assert fails.
This can happen in practice, if you have an axis aligned triangle, create its AABB and use it to "early out" of an intersection test.
One solution could be to only check if the intersection AABB is valid.
/// Returns true if the two AABBs have any overlap.
bool overlaps(AABB b)
{
b.intersection(*this);
return b.valid();
}
However, this would return true for "touching" AABBs. Depending on the definition of "overlaps", this might be a problem.
Would love to hear your thoughts on that.