openskidata-format 13.0.0 → 15.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ElevationProfile.d.ts +1 -0
- package/dist/ElevationProfile.d.ts.map +1 -0
- package/dist/ElevationProfile.js +15 -24
- package/dist/ElevationProfile.js.map +1 -1
- package/dist/FeatureType.d.ts +1 -0
- package/dist/FeatureType.d.ts.map +1 -0
- package/dist/FeatureType.js +2 -5
- package/dist/FeatureType.js.map +1 -1
- package/dist/Lift.d.ts +10 -8
- package/dist/Lift.d.ts.map +1 -0
- package/dist/Lift.js +22 -29
- package/dist/Lift.js.map +1 -1
- package/dist/LiftNameFormatter.d.ts +2 -1
- package/dist/LiftNameFormatter.d.ts.map +1 -0
- package/dist/LiftNameFormatter.js +11 -14
- package/dist/LiftNameFormatter.js.map +1 -1
- package/dist/Place.d.ts +1 -0
- package/dist/Place.d.ts.map +1 -0
- package/dist/Place.js +1 -2
- package/dist/Run.d.ts +10 -9
- package/dist/Run.d.ts.map +1 -0
- package/dist/Run.js +23 -30
- package/dist/Run.js.map +1 -1
- package/dist/RunDifficultyConvention.d.ts +2 -1
- package/dist/RunDifficultyConvention.d.ts.map +1 -0
- package/dist/RunDifficultyConvention.js +10 -15
- package/dist/RunDifficultyConvention.js.map +1 -1
- package/dist/SkiArea.d.ts +12 -10
- package/dist/SkiArea.d.ts.map +1 -0
- package/dist/SkiArea.js +2 -5
- package/dist/SkiArea.js.map +1 -1
- package/dist/SkiPass.d.ts +32 -7
- package/dist/SkiPass.d.ts.map +1 -0
- package/dist/SkiPass.js +1 -2
- package/dist/SlopeGradingScale.d.ts +3 -2
- package/dist/SlopeGradingScale.d.ts.map +1 -0
- package/dist/SlopeGradingScale.js +21 -26
- package/dist/SlopeGradingScale.js.map +1 -1
- package/dist/SnowCoverHistory.d.ts +1 -0
- package/dist/SnowCoverHistory.d.ts.map +1 -0
- package/dist/SnowCoverHistory.js +9 -8
- package/dist/SnowCoverHistory.js.map +1 -1
- package/dist/Source.d.ts +1 -0
- package/dist/Source.d.ts.map +1 -0
- package/dist/Source.js +11 -17
- package/dist/Source.js.map +1 -1
- package/dist/Spot.d.ts +6 -5
- package/dist/Spot.d.ts.map +1 -0
- package/dist/Spot.js +6 -9
- package/dist/Spot.js.map +1 -1
- package/dist/Status.d.ts +1 -0
- package/dist/Status.d.ts.map +1 -0
- package/dist/Status.js +2 -5
- package/dist/Status.js.map +1 -1
- package/dist/ViewportHint.d.ts +1 -0
- package/dist/ViewportHint.d.ts.map +1 -0
- package/dist/ViewportHint.js +4 -10
- package/dist/ViewportHint.js.map +1 -1
- package/dist/index.d.ts +16 -15
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -18
- package/dist/index.js.map +1 -1
- package/dist/util/exhaustiveMatchingGuard.d.ts +1 -0
- package/dist/util/exhaustiveMatchingGuard.d.ts.map +1 -0
- package/dist/util/exhaustiveMatchingGuard.js +1 -5
- package/dist/util/exhaustiveMatchingGuard.js.map +1 -1
- package/package.json +35 -23
- package/dist/testUtils.d.ts +0 -2
- package/dist/testUtils.js +0 -7
- package/dist/testUtils.js.map +0 -1
- package/src/ElevationProfile.test.ts +0 -738
- package/src/ElevationProfile.ts +0 -452
- package/src/FeatureType.ts +0 -6
- package/src/Lift.test.ts +0 -195
- package/src/Lift.ts +0 -219
- package/src/LiftNameFormatter.ts +0 -116
- package/src/Place.ts +0 -11
- package/src/Run.ts +0 -242
- package/src/RunDifficultyConvention.test.ts +0 -79
- package/src/RunDifficultyConvention.ts +0 -335
- package/src/SkiArea.ts +0 -128
- package/src/SkiPass.ts +0 -62
- package/src/SlopeGradingScale.test.ts +0 -151
- package/src/SlopeGradingScale.ts +0 -96
- package/src/SnowCoverHistory.test.ts +0 -103
- package/src/SnowCoverHistory.ts +0 -107
- package/src/Source.test.ts +0 -50
- package/src/Source.ts +0 -72
- package/src/Spot.ts +0 -140
- package/src/Status.ts +0 -20
- package/src/ViewportHint.ts +0 -208
- package/src/index.ts +0 -15
- package/src/testUtils.ts +0 -5
- package/src/util/exhaustiveMatchingGuard.ts +0 -3
package/src/ViewportHint.ts
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import * as GeoJSON from 'geojson'
|
|
2
|
-
import distance from '@turf/distance'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Pre-computed viewport positioning data stored on every feature's properties.
|
|
6
|
-
* Camera space: Y axis points uphill (along bearing), X axis points screen-right.
|
|
7
|
-
* Metric values are in that rotated frame with elevation-adjusted Y positions
|
|
8
|
-
* (at 45° pitch, Δe metres above mean elevation shifts Y by Δe metres).
|
|
9
|
-
*/
|
|
10
|
-
export type ViewportHint = {
|
|
11
|
-
/** Geographic centre of the rotated bounding box as [lng, lat]. */
|
|
12
|
-
center: [number, number]
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Uphill bearing in degrees clockwise from north. null when elevation variation is
|
|
16
|
-
* insufficient to determine orientation — client should use top-down view (pitch 0, bearing 0).
|
|
17
|
-
*/
|
|
18
|
-
bearing: number | null
|
|
19
|
-
|
|
20
|
-
/** Bounding box width along the camera X axis, in metres. */
|
|
21
|
-
rotatedWidthMeters: number
|
|
22
|
-
|
|
23
|
-
/** Bounding box height along the camera Y axis, in metres (elevation-adjusted). */
|
|
24
|
-
rotatedHeightMeters: number
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Most-downhill edge of the elevation-adjusted bounding box in camera-Y metres, relative
|
|
28
|
-
* to mean feature elevation. Used to compute the perspective centre shift at 45° pitch:
|
|
29
|
-
* look-at point = minCameraY + nearFraction * rotatedHeightMeters, where
|
|
30
|
-
* nearFraction = nearGround / (nearGround + farGround) from camera pitch and vFOV.
|
|
31
|
-
*/
|
|
32
|
-
minCameraY: number
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Computes a ViewportHint from one or more GeoJSON geometries.
|
|
37
|
-
* All geometry types are accepted; elevation is read from the Z coordinate (defaults to 0).
|
|
38
|
-
* Throws if no coordinates are found.
|
|
39
|
-
*/
|
|
40
|
-
export function computeViewportHint(
|
|
41
|
-
geometries: GeoJSON.Geometry[],
|
|
42
|
-
): ViewportHint {
|
|
43
|
-
// Collect all coordinates (for bbox + elevation stats) and consecutive segment pairs
|
|
44
|
-
// (for the downhill bearing calculation).
|
|
45
|
-
const allCoords: [number, number, number][] = []
|
|
46
|
-
const bearingSegments: [[number, number, number], [number, number, number]][] =
|
|
47
|
-
[]
|
|
48
|
-
|
|
49
|
-
for (const geom of geometries) {
|
|
50
|
-
collectGeometry(geom, allCoords, bearingSegments)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (allCoords.length === 0) throw new Error('computeViewportHint: no coordinates found in provided geometries')
|
|
54
|
-
|
|
55
|
-
let minLng = Infinity,
|
|
56
|
-
maxLng = -Infinity
|
|
57
|
-
let minLat = Infinity,
|
|
58
|
-
maxLat = -Infinity
|
|
59
|
-
for (const [lng, lat] of allCoords) {
|
|
60
|
-
if (lng < minLng) minLng = lng
|
|
61
|
-
if (lng > maxLng) maxLng = lng
|
|
62
|
-
if (lat < minLat) minLat = lat
|
|
63
|
-
if (lat > maxLat) maxLat = lat
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const centerLng = (minLng + maxLng) / 2
|
|
67
|
-
const centerLat = (minLat + maxLat) / 2
|
|
68
|
-
|
|
69
|
-
// Weight each segment's downhill direction by length to find dominant bearing.
|
|
70
|
-
let sumSin = 0,
|
|
71
|
-
sumCos = 0
|
|
72
|
-
for (const [[lng0, lat0, elev0], [lng1, lat1, elev1]] of bearingSegments) {
|
|
73
|
-
if (elev0 === elev1) continue
|
|
74
|
-
const [fromLng, fromLat, toLng, toLat] =
|
|
75
|
-
elev0 > elev1
|
|
76
|
-
? [lng0, lat0, lng1, lat1]
|
|
77
|
-
: [lng1, lat1, lng0, lat0]
|
|
78
|
-
const bear = greatCircleBearing(fromLat, fromLng, toLat, toLng)
|
|
79
|
-
const len = distance([lng0, lat0], [lng1, lat1], { units: 'meters' })
|
|
80
|
-
const bearingRad = (bear * Math.PI) / 180
|
|
81
|
-
sumSin += Math.sin(bearingRad) * len
|
|
82
|
-
sumCos += Math.cos(bearingRad) * len
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Uphill bearing = downhill + 180°; null if no elevation variation found.
|
|
86
|
-
// A small offset is added so the camera is angled slightly to the side of the fall line,
|
|
87
|
-
// giving a better 3-D profile of the terrain rather than pointing straight uphill.
|
|
88
|
-
const bearingSideOffsetDeg = 30
|
|
89
|
-
let mapBearing: number | null = null
|
|
90
|
-
if (sumSin !== 0 || sumCos !== 0) {
|
|
91
|
-
const dominantDownhill = (Math.atan2(sumSin, sumCos) * 180) / Math.PI
|
|
92
|
-
const normalizedDownhill = ((dominantDownhill % 360) + 360) % 360
|
|
93
|
-
mapBearing = (normalizedDownhill + 180 + bearingSideOffsetDeg) % 360
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const metersPerDeg = 111320
|
|
97
|
-
const cosLat = Math.cos(centerLat * (Math.PI / 180))
|
|
98
|
-
const bearingRad = ((mapBearing ?? 0) * Math.PI) / 180
|
|
99
|
-
|
|
100
|
-
let elevationSum = 0
|
|
101
|
-
for (const [, , elev] of allCoords) elevationSum += elev
|
|
102
|
-
const meanElevation = elevationSum / allCoords.length
|
|
103
|
-
|
|
104
|
-
let minCameraX = Infinity,
|
|
105
|
-
maxCameraX = -Infinity
|
|
106
|
-
let minCameraY = Infinity,
|
|
107
|
-
maxCameraY = -Infinity
|
|
108
|
-
|
|
109
|
-
for (const [lng, lat, elev] of allCoords) {
|
|
110
|
-
const dx = (lng - centerLng) * cosLat * metersPerDeg
|
|
111
|
-
const dy = (lat - centerLat) * metersPerDeg
|
|
112
|
-
const cx = dx * Math.cos(bearingRad) - dy * Math.sin(bearingRad)
|
|
113
|
-
const cy = dx * Math.sin(bearingRad) + dy * Math.cos(bearingRad)
|
|
114
|
-
// At 45° pitch, elevation above mean shifts apparent Y by the same amount (tan 45° = 1).
|
|
115
|
-
const cyEffective = cy + (elev - meanElevation)
|
|
116
|
-
if (cx < minCameraX) minCameraX = cx
|
|
117
|
-
if (cx > maxCameraX) maxCameraX = cx
|
|
118
|
-
if (cyEffective < minCameraY) minCameraY = cyEffective
|
|
119
|
-
if (cyEffective > maxCameraY) maxCameraY = cyEffective
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return {
|
|
123
|
-
center: [centerLng, centerLat],
|
|
124
|
-
bearing: mapBearing,
|
|
125
|
-
rotatedWidthMeters: maxCameraX - minCameraX,
|
|
126
|
-
rotatedHeightMeters: maxCameraY - minCameraY,
|
|
127
|
-
minCameraY,
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/** Recursively extracts coordinates and segment pairs from a geometry. */
|
|
132
|
-
function collectGeometry(
|
|
133
|
-
geom: GeoJSON.Geometry,
|
|
134
|
-
allCoords: [number, number, number][],
|
|
135
|
-
bearingSegments: [[number, number, number], [number, number, number]][],
|
|
136
|
-
): void {
|
|
137
|
-
switch (geom.type) {
|
|
138
|
-
case 'Point': {
|
|
139
|
-
const [lng, lat, elev = 0] = geom.coordinates
|
|
140
|
-
allCoords.push([lng, lat, elev])
|
|
141
|
-
break
|
|
142
|
-
}
|
|
143
|
-
case 'MultiPoint': {
|
|
144
|
-
for (const pos of geom.coordinates) {
|
|
145
|
-
const [lng, lat, elev = 0] = pos
|
|
146
|
-
allCoords.push([lng, lat, elev])
|
|
147
|
-
}
|
|
148
|
-
break
|
|
149
|
-
}
|
|
150
|
-
case 'LineString':
|
|
151
|
-
collectPositions(geom.coordinates, allCoords, bearingSegments)
|
|
152
|
-
break
|
|
153
|
-
case 'MultiLineString':
|
|
154
|
-
for (const line of geom.coordinates) {
|
|
155
|
-
collectPositions(line, allCoords, bearingSegments)
|
|
156
|
-
}
|
|
157
|
-
break
|
|
158
|
-
case 'Polygon':
|
|
159
|
-
for (const ring of geom.coordinates) {
|
|
160
|
-
collectPositions(ring, allCoords, bearingSegments)
|
|
161
|
-
}
|
|
162
|
-
break
|
|
163
|
-
case 'MultiPolygon':
|
|
164
|
-
for (const polygon of geom.coordinates) {
|
|
165
|
-
for (const ring of polygon) {
|
|
166
|
-
collectPositions(ring, allCoords, bearingSegments)
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
break
|
|
170
|
-
case 'GeometryCollection':
|
|
171
|
-
for (const g of geom.geometries) {
|
|
172
|
-
collectGeometry(g, allCoords, bearingSegments)
|
|
173
|
-
}
|
|
174
|
-
break
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/** Adds positions to allCoords and consecutive pairs to bearingSegments. Z defaults to 0. */
|
|
179
|
-
function collectPositions(
|
|
180
|
-
positions: GeoJSON.Position[],
|
|
181
|
-
allCoords: [number, number, number][],
|
|
182
|
-
bearingSegments: [[number, number, number], [number, number, number]][],
|
|
183
|
-
): void {
|
|
184
|
-
const elevated: [number, number, number][] = positions.map(
|
|
185
|
-
([lng, lat, elev = 0]) => [lng, lat, elev],
|
|
186
|
-
)
|
|
187
|
-
for (const coord of elevated) allCoords.push(coord)
|
|
188
|
-
for (let i = 0; i < elevated.length - 1; i++) {
|
|
189
|
-
bearingSegments.push([elevated[i], elevated[i + 1]])
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/** Great-circle bearing from (lat1, lng1) to (lat2, lng2), in degrees 0–360. */
|
|
194
|
-
function greatCircleBearing(
|
|
195
|
-
lat1: number,
|
|
196
|
-
lng1: number,
|
|
197
|
-
lat2: number,
|
|
198
|
-
lng2: number,
|
|
199
|
-
): number {
|
|
200
|
-
const toRad = (d: number) => (d * Math.PI) / 180
|
|
201
|
-
const φ1 = toRad(lat1)
|
|
202
|
-
const φ2 = toRad(lat2)
|
|
203
|
-
const Δλ = toRad(lng2 - lng1)
|
|
204
|
-
const y = Math.sin(Δλ) * Math.cos(φ2)
|
|
205
|
-
const x =
|
|
206
|
-
Math.cos(φ1) * Math.sin(φ2) - Math.sin(φ1) * Math.cos(φ2) * Math.cos(Δλ)
|
|
207
|
-
return ((Math.atan2(y, x) * 180) / Math.PI + 360) % 360
|
|
208
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export * from './ElevationProfile'
|
|
2
|
-
export * from './FeatureType'
|
|
3
|
-
export * from './Lift'
|
|
4
|
-
export * from './LiftNameFormatter'
|
|
5
|
-
export * from './Place'
|
|
6
|
-
export * from './Run'
|
|
7
|
-
export * from './RunDifficultyConvention'
|
|
8
|
-
export * from './SlopeGradingScale'
|
|
9
|
-
export * from './SkiArea'
|
|
10
|
-
export * from './SkiPass'
|
|
11
|
-
export * from './SnowCoverHistory'
|
|
12
|
-
export * from './Source'
|
|
13
|
-
export * from './Spot'
|
|
14
|
-
export * from './Status'
|
|
15
|
-
export * from './ViewportHint'
|
package/src/testUtils.ts
DELETED