Skip to content

Commit 57fb04f

Browse files
committed
Trips 019 (T026): trace each leg of a multi-stop trip on the map
tripArcs now emits one great-circle arc per consecutive leg of a multi-stop trip (Paris → Tokyo → Osaka draws both hops), instead of a single from → to shortcut across the middle. Single-leg trips are unchanged; a leg touching a coordinate-less stop is skipped. Two new unit tests (per-leg count; unresolvable-leg skip). 443 unit green.
1 parent 8d02768 commit 57fb04f

3 files changed

Lines changed: 47 additions & 12 deletions

File tree

‎apps/postcards/src/features/map/visitedLayers.ts‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -204,21 +204,26 @@ function greatCircle(
204204
}
205205

206206
/**
207-
* Great-circle arcs for logged trips whose endpoints resolve to coordinates,
208-
* tagged with the travel mode so the map can colour them. Trips with a
209-
* coordinate-less endpoint (e.g. a whole country) are skipped — nothing invented.
207+
* Great-circle arcs for logged trips, tagged with the travel mode so the map can
208+
* colour them. A MULTI-STOP trip (spec 019) draws one arc per consecutive leg, so
209+
* the line traces the actual route (Paris → Tokyo → Osaka), not a single endpoint
210+
* shortcut; a single-leg trip draws its one `from → to` arc. Any leg touching a
211+
* coordinate-less stop (e.g. a whole country) is skipped — nothing invented.
210212
*/
211213
export function tripArcs(trips: Trip[], ref: ReferenceData): FeatureCollection<LineString> {
212214
const features: Feature<LineString>[] = [];
213215
for (const t of trips) {
214-
const from = coordsOf(t.from, ref);
215-
const to = coordsOf(t.to, ref);
216-
if (!from || !to) continue;
217-
features.push({
218-
type: "Feature",
219-
geometry: { type: "LineString", coordinates: greatCircle(from, to) },
220-
properties: { mode: t.mode },
221-
});
216+
const chain = t.stops && t.stops.length >= 2 ? t.stops : [t.from, t.to];
217+
for (let i = 0; i < chain.length - 1; i++) {
218+
const from = coordsOf(chain[i]!, ref);
219+
const to = coordsOf(chain[i + 1]!, ref);
220+
if (!from || !to) continue;
221+
features.push({
222+
type: "Feature",
223+
geometry: { type: "LineString", coordinates: greatCircle(from, to) },
224+
properties: { mode: t.mode },
225+
});
226+
}
222227
}
223228
return { type: "FeatureCollection", features };
224229
}

‎apps/postcards/tests/unit/visitedLayers.spec.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,34 @@ describe("trip arcs", () => {
238238
const fc = tripArcs([trip(country, airport("JFK"))], ref);
239239
expect(fc.features).toHaveLength(0);
240240
});
241+
242+
it("draws one arc PER LEG for a multi-stop trip (spec 019)", () => {
243+
// CDG → JFK → LHR: two legs, so two arc features (not one endpoint shortcut).
244+
const multi: Trip = {
245+
...trip(airport("CDG"), airport("LHR")),
246+
stops: [airport("CDG"), airport("JFK"), airport("LHR")],
247+
};
248+
const fc = tripArcs([multi], ref);
249+
expect(fc.features).toHaveLength(2);
250+
// Each leg is its own great-circle arc, tagged with the mode.
251+
for (const f of fc.features) expect(f.properties?.mode).toBe("flight");
252+
// Leg 1 starts at CDG, leg 2 ends at LHR — the route is traced through JFK.
253+
const cdg = ref.airportById("CDG")!;
254+
const lhr = ref.airportById("LHR")!;
255+
const first = fc.features[0]!.geometry.coordinates;
256+
const last = fc.features[1]!.geometry.coordinates;
257+
expect(first[0]![0]).toBeCloseTo(cdg.lon, 3);
258+
expect(last[last.length - 1]![1]).toBeCloseTo(lhr.lat, 3);
259+
});
260+
261+
it("skips only the unresolvable leg of a multi-stop trip", () => {
262+
const country: PlaceRef = { kind: "country", id: "FR", name: "France", countryId: "FR" };
263+
// CDG → [country] → JFK: both legs touch the coordinate-less country → 0 arcs;
264+
// but CDG → JFK → LHR with a good middle keeps both.
265+
const withGap: Trip = {
266+
...trip(airport("CDG"), airport("JFK")),
267+
stops: [airport("CDG"), country, airport("JFK")],
268+
};
269+
expect(tripArcs([withGap], ref).features).toHaveLength(0);
270+
});
241271
});

‎specs/019-trip-reconstruction/tasks.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ stations affordance; the stop model (PlaceRef) would accept a `"station"` kind u
116116
- [x] T024 [P] Verify en/fr/ko key parity (tsc) for every new string; no missing keys.
117117
- [x] T025 [P] a11y: extend `tests/e2e/a11y.spec.ts` to cover the composer (axe WCAG 2.1 AA) + full
118118
keyboard traversal (add/reorder/remove stops, date, save/cancel).
119-
- [ ] T026 [P] (Optional nice-to-have, DEFERRED) In `src/features/map/MapScreen.tsx`/`MapView.tsx`,
119+
- [x] T026 [P] [US2] Draw each LEG of a multi-stop trip's arc on the map (not only from → to), reusing greatCircle in tripArcs; one arc feature per consecutive resolvable leg.
120120
draw each **leg** of a multi-stop trip's arc (not only `from → to`), reusing `tripArcs`. Left for a
121121
follow-up — the map still draws the endpoint arc for multi-stop trips, so nothing is broken.
122122
- [x] T027 Full gate: `pnpm typecheck && pnpm test && pnpm test:e2e trip-reconstruction a11y smoke`

0 commit comments

Comments
 (0)