I have two points (a line segment) and a rectangle. I would like to know how to calculate if the line segment intersects the rectangle.
If it is 2d, then all lines are on the only plane.
So, this is basic 3-D geometry. You should be able to do this with a straightforward equation.
Check out this page:
http://local.wasp.uwa.edu.au/~pbourke/geometry/planeline/.
The second solution should be easy to implement, as long as you translate the coordinates of your rectangle into the equation of a plane.
Furthermore, check that your denominator isn't zero (line doesn't intersect or is contained in the plane).