fix(roadtrip): a merged drive keeps its first piece ends when a leg comes without them

A leg a routing provider answers without its from and to points threw in
the merge, and the day it belonged to never finished routing. Such a leg now
keeps the first piece's ends; the texts are still written from the sums.
This commit is contained in:
Maurice
2026-09-23 12:53:24 +02:00
parent e921799580
commit 83d088e842
+9 -2
View File
@@ -27,10 +27,17 @@ export function mergeRouteSegments(parts: RouteSegment[], unit: DistanceUnit): R
const distance = parts.reduce((sum, leg) => sum + (leg.distance ?? 0), 0);
const duration = parts.reduce((sum, leg) => sum + (leg.duration ?? 0), 0);
const durationText = formatDurationShort(duration);
// A leg a provider handed over without its ends keeps the first piece's; the texts are
// what the reader was shown wrong, the ends only place the label.
const ends = first.from && last.to ? { from: first.from, to: last.to } : null;
return {
...first,
to: last.to,
mid: [(first.from[0] + last.to[0]) / 2, (first.from[1] + last.to[1]) / 2],
...(ends
? {
to: ends.to,
mid: [(ends.from[0] + ends.to[0]) / 2, (ends.from[1] + ends.to[1]) / 2] as [number, number],
}
: {}),
distance,
duration,
distanceText: formatDistance(distance / 1000, unit),