I am looking through this code and seeing two things which confuse me (well, the whole functions does) in the top functions.
dir * p where
p are vec3s. What does component wise multiplication of two vec3s give you in geometric terms? The function is clearly meant to give you the maximum distance along a vector to an AABB, but how we got there from a load of point-vector multiplications? I do not know.
tng = d - dot(d, N) * N. Here,
d is the shortest vector between a point and an AABB, and
N is the point's normal. I can see
tng is meant to say "tangent", but I'm not seeing how we got from a normal and an effectively random vector to a tangent to something?
Also, I have read the papers this code is derived from, and they do not explain it. If anything they would suggest that just
clamp(p, boundMin, boundMax) - p should be returned.