TracePreparation
Turn a raw fix stream into something a map-matching provider can actually be asked about.
Two problems, both pure and both testable without a network:
Cadence. OSRM's own documented failure mode is a trace that is too dense: a tight sampling rate can fragment into several disconnected matchings instead of one continuous route. More points is not automatically better — downsample thins a trace toward a target interval instead of sending everything recorded.
Size. A long trip has more points than one request should carry. chunk splits it into windows — WITH overlap, because a matcher needs a few points either side of a boundary to place it on the right road; a hard cut at the window edge starves the matcher of exactly the context it needs there. The overlap then has to be un-double-counted on the way back out, which is what stitchMatchedDistanceM is for.
Functions
Split fixes into request-sized windows, each sharing up to overlapPoints points with the previous window.
Thin fixes so consecutive kept points are at least targetIntervalSec apart, without moving or dropping the first or last fix.
Recombine one MatchedRoute per chunks entry into a single trip distance, counting the overlap between consecutive chunks exactly once.