@Roa, that's not true, it does matter if it is in 2D or 3D.
You could for example use a basic operation in 2D to look at what side of a line a certain point lies.
This can very efficiently be done in 2D and can be used for creating the algorithm to this problem.
In 3D however, there is boolean concept of side of a line, which makes that method unusable (without extra care).
Now, as to your suggested method, it sounds like it would be more complicated and less performant than could be,
as you need to calculate multiple intersections and do axis aligned checks and such.
I'm not an expert yet with ray casting algorithms yet though, so I might be wrong.