Katharine/pebble-caltrain — pull request #3 by dwfreed (2014-09-23 04:43:31+00:00)
Title: stop_list.c: avoid integer overflows

The previous method resulted in integer overflows for nearly all
stations, and so the "closest" station after overflow wraparound could
end up being one really far away, even if you're standing at a station.
This method mostly preserves the spirit of the previous method, while
avoiding integer overflows. The algorithm prefers a shorter leg sum
over actual shortest distance, so it can result in ordering a station
that is slightly farther away before a station that is slightly closer.
However, as the common case is that you're standing at the station, or
are otherwise nearby, the end result will end up matching the spirit of
the previous method.

I didn't change the name of the function, because I wanted the actual change to be as minimal as possible, and I couldn't think of a suitable name anyway.