When line intersects a rectangle it means that there are corners of the tested rectangle that are above and below the line.

The LineTestIntersection function can be like this:

1. Create line equation ax+b=y from x1,y1,x2,y2
a = (y2-y1 )/(x2-x1)
b = y1-a*x1
2. for each corner of the rect calculate d = ax + b - y
where x and y are coordinates of each corner
3. Check the signs of all four d's. If they are not the same then line intersects the rect, otherwise there is no intersection.

I hope you find it usefull.