mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 23:50:08 +00:00
64445a5204
A routed section of a hike between two neighbouring points can now be compared with the other ways the router knows between the same two points, under the same limit and preferences. "Compare ways for the next leg" in a waypoint's menu opens a card over the planner map: the way taken now and up to three others, each drawn on the map in its own colour, with length, climb, descent and walking time by the signposts' rule. Figures without heights stay unknown, and the differences to the current way are shown only where both are known. When the router knows no other way, or does not answer, the card says so. Showing, hovering and choosing change nothing. Only "Take this way" does: the router is first asked whether a few shaping points hold the chosen way (the check the road trip's picker already uses), and only then are they set into that one leg as a single step of the history, with a "Way taken" note and its undo at the foot of the map. Other legs, fixed lines, days and points stay as they were, the totals follow from the replanned route, and the shaping points can be dragged like any other. A section that changed while the router was asked, or a way it does not keep to, is not written, and the card says why. The ways are drawn in 3D too.
54 lines
2.3 KiB
TypeScript
54 lines
2.3 KiB
TypeScript
// FE-ROUTE-LEG-AT-001 to FE-ROUTE-LEG-AT-005: which leg a click on the drawn route lands in (P2A-03),
|
|
// and the stretch of the route a leg spans (RTE-02).
|
|
import { describe, expect, it } from 'vitest';
|
|
import { legSpanOf, legStartAt } from './routeLegAt';
|
|
|
|
const A = { id: 'a', lat: 49.0, lng: 12.0 };
|
|
const B = { id: 'b', lat: 49.0, lng: 12.1 };
|
|
const C = { id: 'c', lat: 49.1, lng: 12.1 };
|
|
// The route bends between the points, as a river does.
|
|
const LINE: [number, number][] = [
|
|
[49.0, 12.0],
|
|
[49.01, 12.05],
|
|
[49.0, 12.1],
|
|
[49.05, 12.11],
|
|
[49.1, 12.1],
|
|
];
|
|
|
|
describe('legStartAt', () => {
|
|
it('FE-ROUTE-LEG-AT-001: a spot on the line belongs to the leg whose two points enclose it', () => {
|
|
expect(legStartAt([A, B, C], LINE, 49.009, 12.05)).toBe('a');
|
|
expect(legStartAt([A, B, C], LINE, 49.05, 12.11)).toBe('b');
|
|
});
|
|
|
|
it('FE-ROUTE-LEG-AT-002: a loop keeps its order, so a spot near the start on the way back is the last leg', () => {
|
|
const back = { id: 'back', lat: A.lat, lng: A.lng };
|
|
const loop: [number, number][] = [...LINE, [49.05, 12.02], [49.0, 12.0]];
|
|
expect(legStartAt([A, B, C, back], loop, 49.05, 12.02)).toBe('c');
|
|
});
|
|
|
|
it('FE-ROUTE-LEG-AT-003: without a line or a leg there is nothing to shape', () => {
|
|
expect(legStartAt([A, B], null, 49, 12.05)).toBeNull();
|
|
expect(legStartAt([A], LINE, 49, 12.05)).toBeNull();
|
|
expect(legStartAt([A, B], [[49, 12]], 49, 12.05)).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe('legSpanOf', () => {
|
|
it('FE-ROUTE-LEG-AT-004: a leg spans the vertices from where its point lies to where the next one does', () => {
|
|
expect(legSpanOf([A, B, C], LINE, 0)).toEqual({ from: 0, to: 2 });
|
|
expect(legSpanOf([A, B, C], LINE, 1)).toEqual({ from: 2, to: 4 });
|
|
// The way back of a loop ends on the line's end, not on the start it shares a spot with.
|
|
const back = { lat: A.lat, lng: A.lng };
|
|
const loop: [number, number][] = [...LINE, [49.05, 12.02], [49.0, 12.0]];
|
|
expect(legSpanOf([A, B, C, back], loop, 2)).toEqual({ from: 4, to: 6 });
|
|
});
|
|
|
|
it('FE-ROUTE-LEG-AT-005: no span without a line, past the last point, or for two points on one spot', () => {
|
|
expect(legSpanOf([A, B], null, 0)).toBeNull();
|
|
expect(legSpanOf([A, B], LINE, 1)).toBeNull();
|
|
expect(legSpanOf([A, B], LINE, -1)).toBeNull();
|
|
expect(legSpanOf([A, A], LINE, 0)).toBeNull();
|
|
});
|
|
});
|