mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
dcc1c18fa9
The region load and obstacle helpers move out of their component files (paddleRegionLoad.ts, paddleObstaclePlace.ts), so those files export components only (react-refresh). TourPlannerMapStage takes the take-from-card rule out into paddlePlaceFromCard and works out the cards' end inset once (complexity 24, back under 20). The tour tests reach list items through at() and must() instead of non-null assertions, a position change in the shaping test is voided rather than left floating, and PLOAD-004 seeds its regions with Promise.all.
24 lines
886 B
TypeScript
24 lines
886 B
TypeScript
import type { PaddleGeometry } from '@trek/shared';
|
|
|
|
/**
|
|
* The spot a waypoint goes to: the place itself, the middle of a way (a
|
|
* slipway drawn as a ramp), or the middle of an area's outline.
|
|
*/
|
|
export function placeOf(geometry: PaddleGeometry): { lat: number; lng: number } | null {
|
|
const line =
|
|
geometry.type === 'Point'
|
|
? [geometry.coordinates]
|
|
: geometry.type === 'LineString'
|
|
? geometry.coordinates
|
|
: geometry.coordinates[0];
|
|
if (!line?.length) return null;
|
|
if (geometry.type === 'Polygon') {
|
|
const ring = line.slice(0, -1);
|
|
const lng = ring.reduce((sum, [x]) => sum + x, 0) / ring.length;
|
|
const lat = ring.reduce((sum, [, y]) => sum + y, 0) / ring.length;
|
|
return { lat, lng };
|
|
}
|
|
const [lng, lat] = line[Math.floor((line.length - 1) / 2)] ?? [];
|
|
return lat === undefined || lng === undefined ? null : { lat, lng };
|
|
}
|