Files
TREK/shared/src/tours/route-corridor.spec.ts
T
Maurice 6a0c54cb2f feat(tours): compare a tour's plan with the track it was actually done with (ACT-02)
Each actual track in a tour's detail now stands beside the plan instead of
on its own: a table names the plan and the actual track as columns, each with
the line it is drawn as on the map, and sets distance, ascent, descent and the
time with breaks side by side. The difference is shown, signed and with an
arrow, only where both values are known and mean the same thing; a planned
total that leaves a stay out reads "at least" and is not subtracted from. A
value one side does not carry is named as missing ("Not in the plan", "Not in
the track", "No time stamps"), never estimated. Below the table, how far the
track left the planned line: its farthest point and the recorded stretches
more than 50 m away, or that there is no line to compare.

On the desktop plan map, "Compare on map" draws the actual track dotted in
the colour of done next to the plan, which stays picked in its own track
colour (and is put back should it be hidden on the map). The recording leaves
the map as a tour of its own meanwhile, so it is never drawn twice or in a
plan's colour. A frosted legend over the map names both lines and ends the
comparison; so do closing the detail, comparing another track, or the track
being unlinked. Comparing only reads: neither the plan nor the track changes.

The track is laid into the day's route lines the map already draws, so both
renderers show it without a layer of their own. distancesToLine in the shared
route corridor measures many points against one line laid flat once; a long
recording is measured in at most 1500 samples.
2026-10-20 15:23:18 +02:00

74 lines
2.2 KiB
TypeScript

import { distancesToLine, nearnessToLine } from './route-corridor';
import { describe, expect, it } from 'vitest';
describe('nearnessToLine', () => {
// A line running north along 11° E for about 2.2 km.
const line = [
[47, 11],
[47.01, 11],
[47.02, 11],
];
it('measures a point beside the line square to it, and how far along its foot lies', () => {
const near = nearnessToLine({ lat: 47.015, lng: 11.001 }, line);
expect(near?.distanceM).toBeGreaterThan(70);
expect(near?.distanceM).toBeLessThan(80);
expect(near?.alongM).toBeGreaterThan(1650);
expect(near?.alongM).toBeLessThan(1690);
});
it('measures a point past an end from that end', () => {
const near = nearnessToLine({ lat: 46.99, lng: 11 }, line);
expect(near?.alongM).toBe(0);
expect(near?.distanceM).toBeGreaterThan(1100);
expect(near?.distanceM).toBeLessThan(1120);
});
it('takes heights along without minding them, and answers nothing for a line too short', () => {
expect(
nearnessToLine({ lat: 47, lng: 11 }, [
[47, 11, 900],
[47.01, 11, 950],
])?.distanceM,
).toBe(0);
expect(nearnessToLine({ lat: 47, lng: 11 }, [[47, 11]])).toBeNull();
expect(
nearnessToLine({ lat: 47, lng: 11 }, [
[47, 11],
[47, 11],
])?.distanceM,
).toBe(0);
});
});
describe('distancesToLine', () => {
const line = [
[47, 11],
[47.01, 11],
[47.02, 11],
];
it('measures every point against the line, in their order, as nearnessToLine does one', () => {
const points = [
[47.015, 11.001],
[47.005, 11],
[46.99, 11, 900],
];
const distances = distancesToLine(points, line);
expect(distances).toHaveLength(3);
points.forEach((point, index) => {
expect(distances?.[index]).toBeCloseTo(
nearnessToLine({ lat: Number(point[0]), lng: Number(point[1]) }, line)?.distanceM ?? -1,
6,
);
});
expect(distances?.[1]).toBe(0);
});
it('answers nothing for a line too short, and nothing to measure for no points', () => {
expect(distancesToLine([[47, 11]], [[47, 11]])).toBeNull();
expect(distancesToLine([], line)).toEqual([]);
});
});