light travels the fastest path of two points, how do you determine those two points? so in this diagram from Richard Feynman's book: QED Strange Theory of Light and Mater
the light takes the fastest path from S to P and the lens makes it so that there are many fastest paths that go through the lens. how does light 'choose' to follow the S to P paths, why not S to P where p is 5 more cm to the right?
 A: There are two ways to look at this. One way is that the surface of the lens bends a ray of light. By carefully choosing the shape of the left surface, you can make rays that spread out from S all bend to become parallel. By carefully choosing the shape of the right hand surface, you can bend the parallel rays so they all pass through P. 
The second way to look at it is time of flight. Light travels slower in glass than in air. Rays that travel a shorter path spend more of that path in glass. The result is that all take the same time to reach P.  
Starting over, you could move P 5 cm to the right. You would then design a shape that bent the rays just enough to pass through the new P. You would find it is a flatter curve. And again the times of flight would be all the same. 
A: In the book Feynman talks at some length about how some set of putative paths will all contribute little arrows in the same direction and therefore not cancel out other paths, right?
Well, that only actually happens for certain pairs of point: those for which light actually goes from one point to the other.
If you choose starting and ending points for which there is no physical path on which light travels you get a negligible final result (essentially everything cancels out).

As a practical matter it is you may be able to deduce a set of rules for knowing in advance what pairs of points will "work". For ray optics those rules are


*

*Light travels in straight lines unless it is reflected, refracted, scattered or absorbed.

*On reflection the angle of reflection is equal to the angle of incidence

*On refraction the light bends as it passes through an interface according to Snell's Law: $n_1 \sin \theta_1 = n_2 \sin \theta_2$
and thereby avoid an endless set of "well, it doesn't go from here to there" computations.
