The guiding principle for the path of light, which covers reflection and refraction, is Fermat's Principle of Least Time. This principle states that the path a light ray takes between two points is the path that can be traveled in the least amount of time.
When light travels in a uniform medium, its speed is constant, and the path of minimum time is a straight line (the minimum distance). However, when light refracts, its speed changes as it enters the new medium. To minimize the total travel time, the light bends, following a path that is not the shortest distance but is the quickest. Snell's law can be derived from this principle.