From 83d088e842bc5cd54896361b078d1301548475bc Mon Sep 17 00:00:00 2001 From: Maurice Date: Wed, 23 Sep 2026 12:53:24 +0200 Subject: [PATCH] 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. --- shared/src/roadtrip/routeRun.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/shared/src/roadtrip/routeRun.ts b/shared/src/roadtrip/routeRun.ts index 09db903ca..2bd79ba89 100644 --- a/shared/src/roadtrip/routeRun.ts +++ b/shared/src/roadtrip/routeRun.ts @@ -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),