mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-20 19:16:08 +00:00
f745ca13c9
A hike can now be planned as a round out of one of its stops without building the loop point by point. "Round hike from here" in a stop's menu, or the round button in the head of the waypoints for the start, opens a card over the planner map: the start (any stop of the tour, picked from a list), the wished length in the traveller's unit, the window of a fifth either way it allows, and the tour's hiking limit, which every question to the router keeps to together with the hike's preferences. TREK looks for up to three different rounds itself on the hiking router it already uses. It steers loops round circles in several directions from the start, asks a loop that missed the length once more at a corrected size, and learns from each answer how much longer the paths are than straight lines. A loop that walks most of its ground twice (a way there and back), a spot too far from any path, and a round that repeats one found are left out, and nothing outside the window is offered. The rounds show up in their colours on the map and in 3D as they are found, the map frames the area they can lie in, and each lists its length, how far it lies off the wish, climb, descent and walking time once the heights are in. Fewer rounds than three, none, or a router that does not answer are said so. Showing, choosing and closing change nothing. "Take this round" puts the start, the steering spots as shaping points and the way back in place of the plan as one step of the history, with a "Round taken" note and its undo; a tour that held more than its start asks first. The round is then an ordinary tour to edit and save. A start moved or a limit changed while rounds are shown lets them go and the card says why. The card shares its frame, buttons and rows with the comparison of a section's ways, and the map corner still holds one card at a time.
76 lines
3.7 KiB
TypeScript
76 lines
3.7 KiB
TypeScript
// FE-TOUR-ROUND-GEOMETRY-001 to FE-TOUR-ROUND-GEOMETRY-005: where a round hike's loop is steered
|
|
// through, and how much of a line covers ground twice or the ground of another (RTE-03).
|
|
import { describe, expect, it } from 'vitest';
|
|
import { haversineKm } from '../../../utils/geo';
|
|
import { loopSpots, retracedShare, sharedShare, spotToward, STRAIGHT_PER_RADIUS_M } from './roundHikeGeometry';
|
|
|
|
const START = { lat: 47.5, lng: 11.1 };
|
|
const meters = (a: { lat: number; lng: number }, b: { lat: number; lng: number }) => haversineKm(a, b) * 1000;
|
|
const line = (...spots: { lat: number; lng: number }[]): [number, number][] => spots.map(({ lat, lng }) => [lat, lng]);
|
|
|
|
describe('spotToward', () => {
|
|
it('FE-TOUR-ROUND-GEOMETRY-001: lies the asked distance away in the asked direction', () => {
|
|
const north = spotToward(START, 0, 1000);
|
|
expect(meters(START, north)).toBeCloseTo(1000, 0);
|
|
expect(north.lat).toBeGreaterThan(START.lat);
|
|
expect(north.lng).toBeCloseTo(START.lng, 9);
|
|
const east = spotToward(START, 90, 2500);
|
|
expect(meters(START, east)).toBeCloseTo(2500, 0);
|
|
expect(east.lng).toBeGreaterThan(START.lng);
|
|
// Across the date line the longitude comes back into range.
|
|
expect(spotToward({ lat: 0, lng: 179.999 }, 90, 1000).lng).toBeLessThan(-179.99);
|
|
});
|
|
});
|
|
|
|
describe('loopSpots', () => {
|
|
it('FE-TOUR-ROUND-GEOMETRY-002: three corners of a square in a circle touching the start, its centre toward the bearing', () => {
|
|
const radius = 1000;
|
|
const spots = loopSpots(START, 90, radius);
|
|
expect(spots).toHaveLength(3);
|
|
const centre = spotToward(START, 90, radius);
|
|
for (const spot of spots) expect(meters(centre, spot)).toBeCloseTo(radius, 0);
|
|
// The far corner lies opposite the start, a diameter away.
|
|
expect(meters(START, spots[1])).toBeCloseTo(2 * radius, 0);
|
|
const corners = [START, ...spots, START];
|
|
let straight = 0;
|
|
for (let i = 1; i < corners.length; i += 1) straight += meters(corners[i - 1], corners[i]);
|
|
expect(straight).toBeCloseTo(STRAIGHT_PER_RADIUS_M * radius, -1);
|
|
});
|
|
});
|
|
|
|
describe('retracedShare', () => {
|
|
it('FE-TOUR-ROUND-GEOMETRY-003: a loop covers little ground twice, a way there and back all of it', () => {
|
|
const loop = line(START, ...loopSpots(START, 0, 800), START);
|
|
expect(retracedShare(loop)).toBeLessThan(0.1);
|
|
const far = spotToward(START, 45, 3000);
|
|
expect(retracedShare(line(START, far, START))).toBeGreaterThan(0.9);
|
|
// A loop with a long way in and out shares that way.
|
|
const gate = spotToward(START, 0, 1500);
|
|
const lollipop = line(START, gate, ...loopSpots(gate, 0, 300), gate, START);
|
|
expect(retracedShare(lollipop)).toBeGreaterThan(0.4);
|
|
});
|
|
|
|
it('FE-TOUR-ROUND-GEOMETRY-004: a line too short to sample shares nothing', () => {
|
|
expect(retracedShare([])).toBe(0);
|
|
expect(retracedShare(line(START))).toBe(0);
|
|
expect(retracedShare(line(START, START))).toBe(0);
|
|
});
|
|
});
|
|
|
|
describe('sharedShare', () => {
|
|
it('FE-TOUR-ROUND-GEOMETRY-005: the share of one line on the ground of another', () => {
|
|
const loop = line(START, ...loopSpots(START, 0, 800), START);
|
|
expect(sharedShare(loop, loop)).toBe(1);
|
|
const other = line(START, ...loopSpots(START, 180, 800), START);
|
|
expect(sharedShare(loop, other)).toBeLessThan(0.1);
|
|
// Half of a line lies on the other: the share says so, one way round.
|
|
const half = line(START, spotToward(START, 0, 1000));
|
|
const whole = line(START, spotToward(START, 0, 2000));
|
|
expect(sharedShare(half, whole)).toBe(1);
|
|
expect(sharedShare(whole, half)).toBeCloseTo(0.5, 1);
|
|
expect(sharedShare([], loop)).toBe(0);
|
|
expect(sharedShare(loop, line(START))).toBe(0);
|
|
expect(sharedShare(line(START, START), loop)).toBe(1);
|
|
});
|
|
});
|