Need some help with my flawed rotation logic...

I am currently trying to line trace from the top-back-right corner of a cube regardless of it’s rotation, but am having a bit of trouble. Here is my trace code:

This works fine when the cube’s rotation is a divisor of 90, but is off when the rotation is a divisor of 90 + 45. Here is a screenshot of what I want:
5f515c55a0ff44db3788411074930aa87e5e4486.jpeg

That is the result when the cube is at 0/90/180/270 degrees rotation. Here is the result when it is at 45/135/215/315 degrees of rotation:
e63f80771d9e65264f212d064eb57b3b3903be32.jpeg
As you can see, the trace is clearly off, but I have no clue why. I am rotating the box extent vector, so in my mind it should be working. Can anyone give me some pointers?

Use the Bounds visualisation and you will understand why this occurs.

Heres a picture with reference to a similar thing im attempting as well.

Just to clarify, the Bounds of the Object have a static rotation and just scale accordingly.

I originally didn’t have any better understanding from seeing the bounds, but then I decided to add a constant rotation to my mesh to see the line trace pattern, and I now do understand what is happening.

It turns out that the box extent was in world space. Thanks DevilsD, and in case it helps you, here is what I figured out to get the box extent relative to the object, which is what I am now using and works:

I was attempting to do the same but I was using the bounds of a volume, so to fix my problem i just used the actual volume box extent vector instead of its bounds.