mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 17:41:51 +00:00
feat(roadtrip): move a stop reached after midnight onto the day it is reached
A day that runs past midnight used to keep every one of its stops on its own card, so day one ended at 03:12 with three places nobody reaches on day one and day two began with a drive that had already happened. The rail now lays the stops out by the date they are actually reached: when the clock goes backwards between two arrivals the ones after it move to the following day, into a block that says where they came from, and the night drive and its kilometres go with them. It is an arrangement, not a write — the day planner beside it is untouched, nothing reaches the database, and a shorter stay the evening before puts everything back on its own. The map follows the same arrangement, because a boundary drawn in the rail and not on the map is two answers to one question. Day one now ends where its last reachable stop is and the line, the legs and the totals are cut to match. Two switches in the driving settings, off by default. "Connect the days" routes the gap between one day's last stop and the next day's first, which is real driving the rail has never drawn, and counts it. "A colour per day" then puts the days back into a line that has become continuous, and tints each day header to match. Collapsing a day from its header takes its route and its places off the map as well as out of the rail, and the categories in the corridor panel fold the same way. The refuel band is one full-width red band with the pump as its button, the results are chips, and the driving dialog is two columns of panels with the figures on one right edge. Also fixes a via that would not adjust the route once dragged. Five separate causes, all measured rather than guessed: leg threading used the card index instead of the owning day's, the anchor lookup returned chain indices, it filtered by the card rather than by the anchor's owner, seams were routed without their vias, and a seam once routed was never re-fetched.
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
haversineKm,
|
||||
pointAtMeters,
|
||||
projectOntoRoute,
|
||||
sliceAtMeters,
|
||||
simplifyLine,
|
||||
type LatLng,
|
||||
} from './corridor'
|
||||
@@ -214,3 +215,49 @@ describe('boxAround', () => {
|
||||
expect(tromso.east - tromso.west).toBeGreaterThan(berlin.east - berlin.west)
|
||||
})
|
||||
})
|
||||
|
||||
describe('sliceAtMeters', () => {
|
||||
// A degree of latitude is about 111 km, so this line is roughly 111 km long and every
|
||||
// figure below can be read off it without a calculator.
|
||||
const line: LatLng[] = [{ lat: 52, lng: 13 }, { lat: 53, lng: 13 }]
|
||||
|
||||
it('cuts a stretch out of the middle and interpolates both ends', () => {
|
||||
const out = sliceAtMeters(line, 30_000, 60_000)
|
||||
expect(out).toHaveLength(2)
|
||||
expect(haversineKm(out[0], out[1]) * 1000).toBeGreaterThan(29_000)
|
||||
expect(haversineKm(out[0], out[1]) * 1000).toBeLessThan(31_000)
|
||||
})
|
||||
|
||||
it('two adjacent slices meet exactly, so the parts rebuild the whole', () => {
|
||||
// The reason this exists: a day's line is its legs end to end, and a night drive
|
||||
// takes its own leg to the next card. A gap at the join would draw as a break in
|
||||
// the road.
|
||||
const first = sliceAtMeters(line, 0, 40_000)
|
||||
const second = sliceAtMeters(line, 40_000, 80_000)
|
||||
const end = first[first.length - 1]
|
||||
expect(haversineKm(end, second[0])).toBeLessThan(0.001)
|
||||
})
|
||||
|
||||
it('clamps to the line rather than running past its end', () => {
|
||||
const out = sliceAtMeters(line, 0, 999_000_000)
|
||||
expect(out[out.length - 1]).toEqual(line[line.length - 1])
|
||||
})
|
||||
|
||||
it('is empty for a zero-length or backwards range', () => {
|
||||
expect(sliceAtMeters(line, 50_000, 50_000)).toEqual([])
|
||||
expect(sliceAtMeters(line, 60_000, 30_000)).toEqual([])
|
||||
})
|
||||
|
||||
it('is empty for a line that is not one', () => {
|
||||
expect(sliceAtMeters([], 0, 100)).toEqual([])
|
||||
expect(sliceAtMeters([{ lat: 52, lng: 13 }], 0, 100)).toEqual([])
|
||||
})
|
||||
|
||||
it('survives a repeated vertex without producing NaN', () => {
|
||||
// A concatenated route line really does contain these, and dividing by a zero-length
|
||||
// segment is how a route full of NaN reaches the map.
|
||||
const doubled: LatLng[] = [{ lat: 52, lng: 13 }, { lat: 52, lng: 13 }, { lat: 53, lng: 13 }]
|
||||
const out = sliceAtMeters(doubled, 10_000, 20_000)
|
||||
expect(out.every(p => Number.isFinite(p.lat) && Number.isFinite(p.lng))).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user