A snippet code to use when you need to test if a line segment intersects with an Axis-Aligned Bounding box (AABB) This uses only 46 operations which means it's quite efficient. (it can probably be done in even less but this is good enough for now)
How it works: We first convert the line segment to parametric coordinates with parameter t. Then we check for each edge of the AABB whether the x/y value lies within the t bound of the line segment.