Files
TREK/client/src/components/Tours/paddle/lakeStyleAdvice.ts
T
Maurice 1bc82f97fd feat(tours): route paddle tours on the water, shaping points and auto-loaded regions
Paddle tours are planned on the water by TREK's own router: a water network
per paddle region, built from the same Geofabrik extract as the obstacles and
searched in a worker thread of the server (no sidecar). Rivers, canals and
lakes (direct or along the shore), portages round weirs, locks by policy,
whitewater by boat, gaps marked. Found portages and locks become points of
their own; an unplannable leg says why and offers a way out.

- Shaping points: a click on the line sets a point that steers the route
  without being a stop (hikes and paddle tours); recompute a single leg.
- Lake style direct/shore, suggested from the wind forecast.
- Regions load by themselves where a paddler plans (admin setting: automatic,
  on request, off; size cap and a daily count), with requests for the admins,
  a notification, and the load followed on the leg.
- Portage from the last point, portages follow footways via the walking
  router (or stay straight), "put in here" on slipways and put-ins.
- MCP plan_paddle_route with the REST route's rules.
2026-10-18 21:21:32 +00:00

33 lines
1.5 KiB
TypeScript

import type { WindForecastResponse } from '@trek/shared';
import type { PaddleTourRoute } from '../planner/paddleRouting';
/** The hours a day tour is out on the water, as the wind strip shows them. */
const FIRST_HOUR = 6;
const LAST_HOUR = 21;
/**
* Wind from which open water gets rough for a small boat: a moderate breeze
* (Beaufort 4 from 20 km/h) or gusts of 30 km/h, where a crossing turns into
* work and a capsize far from the bank into a long swim.
*/
const MEAN_KMH = 20;
const GUSTS_KMH = 30;
/** Whether the route as planned crosses a lake, so its lake style changes anything. */
export function crossesLake(route: Pick<PaddleTourRoute, 'legs'> | null): boolean {
return !!route?.legs.some((leg) => leg?.status === 'ok' && leg.segments.some((segment) => segment.kind === 'lake'));
}
/**
* PAD-11 with PAD-08: the strongest wind of the paddling hours when it is
* enough to keep near the shores on the lakes, else null. Lakes are crossed
* straight over as a rule and along the shore only in wind; this says when.
*/
export function windForShore(forecast: WindForecastResponse): { meanKmh: number; gustsKmh: number } | null {
const hours = forecast.hours.filter((hour) => hour.hour >= FIRST_HOUR && hour.hour <= LAST_HOUR);
const meanKmh = Math.max(0, ...hours.map((hour) => hour.speed_kmh ?? 0));
const gustsKmh = Math.max(0, ...hours.map((hour) => hour.gusts_kmh ?? 0));
if (meanKmh < MEAN_KMH && gustsKmh < GUSTS_KMH) return null;
return { meanKmh: Math.round(meanKmh), gustsKmh: Math.round(gustsKmh) };
}