makinacorpus/Leaflet.GeometryUtil — pull request #16 by manleyjster (2014-06-21 02:45:32+00:00)
Title: Make sure that interpolateOnLine always returns a LatLng object.

The signature of interpolateOnLine declares that it will return an object structured like so: { latLng: {{LatLng}}, predecessor: {{int}} }. That is, the latLng property of interpolateOnLine should be a LatLng object. When the ratio is 0 (or 1), interpolateOnLine just returned the first (or last, respectively) element of the array of coordinates.

This is fine if the polyline is supplied as an array of LatLng objects - but the type signature of interpolateOnLine says that it also takes an array of [lat, lng] arrays. If an array of [lat, lng] arrays is supplied, the interpolateOnLine returns a flat [lat, lng] array on ratio = 0 or 1, NOT a LatLng object.

I added a check for the type of the first and last coordinates. If they are LatLng objects, they are returned immediately. If they are not LatLng objects, then a LatLng object with the same coordinates is returned.

This ensures that the return value of interpolateOnLine is consistent, since for values in the open interval (0,1) it ALWAYS already returns a LatLng object, not a [lat, lng] array.

I added a test verifying the presence of this bug. With my code changes, this test is satisfied.