drone-path 0.12.1 → 1.0.0-rc1

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.
Files changed (78) hide show
  1. package/README.md +20 -74
  2. package/THIRD-PARTY-NOTICES.md +3 -82
  3. package/bin/drone-path.mjs +0 -0
  4. package/dist/cli.d.ts +14 -0
  5. package/dist/cli.js +7 -7
  6. package/dist/version.d.ts +1 -0
  7. package/package.json +21 -68
  8. package/CHANGELOG.md +0 -336
  9. package/app/ipc.d.mts +0 -43
  10. package/app/ipc.mjs +0 -216
  11. package/app/main.mjs +0 -356
  12. package/app/preload.cjs +0 -34
  13. package/app/update-policy.d.mts +0 -6
  14. package/app/update-policy.mjs +0 -6
  15. package/app/update.d.mts +0 -10
  16. package/app/update.mjs +0 -54
  17. package/dist/appassets.js +0 -35
  18. package/dist/apppaths.js +0 -20
  19. package/dist/appsession.js +0 -121
  20. package/dist/appstate.js +0 -94
  21. package/dist/assets.js +0 -60
  22. package/dist/buildinfo.js +0 -64
  23. package/dist/cammeta-decode.js +0 -237
  24. package/dist/cammeta.js +0 -92
  25. package/dist/changeset-gate.js +0 -39
  26. package/dist/config.js +0 -631
  27. package/dist/configfile.js +0 -86
  28. package/dist/decimate.js +0 -84
  29. package/dist/errors.js +0 -34
  30. package/dist/exec-tool.js +0 -13
  31. package/dist/exportjob.js +0 -90
  32. package/dist/ffmpeg-tools.js +0 -56
  33. package/dist/ffmpeg.js +0 -98
  34. package/dist/frametime.js +0 -32
  35. package/dist/geo.js +0 -60
  36. package/dist/logging.js +0 -1
  37. package/dist/manual/anchors.js +0 -17
  38. package/dist/manual/build.js +0 -67
  39. package/dist/manual/cliref.js +0 -34
  40. package/dist/manual/links.js +0 -59
  41. package/dist/manual/markdown.js +0 -98
  42. package/dist/manual/model.js +0 -1
  43. package/dist/manual/module.js +0 -5
  44. package/dist/manual/nav.js +0 -11
  45. package/dist/manual/reference.js +0 -18
  46. package/dist/paths.js +0 -16
  47. package/dist/pipeline.js +0 -402
  48. package/dist/plan.js +0 -106
  49. package/dist/png.js +0 -32
  50. package/dist/protobuf-wire.js +0 -102
  51. package/dist/range.js +0 -50
  52. package/dist/recordings.js +0 -55
  53. package/dist/render-page.js +0 -85
  54. package/dist/render.js +0 -268
  55. package/dist/renderer/boot.js +0 -7
  56. package/dist/renderer/dom.js +0 -177
  57. package/dist/renderer/framemath.js +0 -30
  58. package/dist/renderer/scene.js +0 -385
  59. package/dist/renderer/theme.js +0 -82
  60. package/dist/renderer/tilesources.js +0 -38
  61. package/dist/renderer/trail.js +0 -42
  62. package/dist/restyle.js +0 -16
  63. package/dist/serve.js +0 -27
  64. package/dist/srt.js +0 -98
  65. package/dist/telemetry-json-schema.js +0 -18
  66. package/dist/telemetry-json.js +0 -126
  67. package/dist/telemetry-math.js +0 -267
  68. package/dist/telemetry-summary.js +0 -19
  69. package/dist/telemetry.js +0 -95
  70. package/dist/tilecache.js +0 -21
  71. package/dist/tiles.js +0 -155
  72. package/dist/track-format.js +0 -13
  73. package/dist/track-geojson.js +0 -44
  74. package/dist/track-gpx.js +0 -34
  75. package/dist/track-kml.js +0 -47
  76. package/dist/track-kmz.js +0 -68
  77. package/dist/track-write.js +0 -41
  78. package/dist/track.js +0 -79
package/dist/tiles.js DELETED
@@ -1,155 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import PQueue from 'p-queue';
4
- import { errorMessage } from './errors.js';
5
- import { solidPng } from './png.js';
6
- import { tilePaths } from './tilecache.js';
7
- import { TILE_SOURCES } from './renderer/tilesources.js';
8
- import { VERSION } from './version.js';
9
- const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
10
- const USER_AGENT = `drone-path/${VERSION} (flight-path map renderer; https://github.com/MrManny/drone-path)`;
11
- const DOWNLOAD_ATTEMPTS = 2;
12
- const DOWNLOAD_WORKERS = 2;
13
- const REQUEST_INTERVAL_MS = 500;
14
- const RETRY_DELAY_MS = 500;
15
- const FETCH_TIMEOUT_MS = 20000;
16
- // p-queue starts higher priorities first, so 'now' jumps the queued pre-warm.
17
- const TASK_PRIORITY = { now: 1, background: 0 };
18
- function tileUrl(style, tile) {
19
- const source = TILE_SOURCES[style];
20
- const subdomain = source.subdomains.length
21
- ? source.subdomains[(tile.x + tile.y) % source.subdomains.length]
22
- : '';
23
- return source.url
24
- .replace('{s}', subdomain)
25
- .replace('{z}', String(tile.z))
26
- .replace('{x}', String(tile.x))
27
- .replace('{y}', String(tile.y));
28
- }
29
- function canceledError(signal) {
30
- return new Error('tile download canceled', { cause: signal.reason });
31
- }
32
- async function fetchBody(url, signal) {
33
- const res = await fetch(url, {
34
- headers: { 'User-Agent': USER_AGENT },
35
- signal: signal
36
- ? AbortSignal.any([AbortSignal.timeout(FETCH_TIMEOUT_MS), signal])
37
- : AbortSignal.timeout(FETCH_TIMEOUT_MS),
38
- });
39
- return res.ok ? Buffer.from(await res.arrayBuffer()) : null;
40
- }
41
- async function downloadTile(queue, url, priority, signal) {
42
- for (let attempt = 0; attempt < DOWNLOAD_ATTEMPTS; attempt++) {
43
- try {
44
- const body = await queue.add(() => fetchBody(url, signal), {
45
- priority: TASK_PRIORITY[priority],
46
- signal,
47
- });
48
- if (body)
49
- return body;
50
- }
51
- catch {
52
- if (signal?.aborted)
53
- throw canceledError(signal);
54
- await sleep(RETRY_DELAY_MS);
55
- }
56
- }
57
- return null;
58
- }
59
- function writeCacheFile(cachePath, data) {
60
- try {
61
- fs.mkdirSync(path.dirname(cachePath), { recursive: true });
62
- fs.writeFileSync(cachePath, data);
63
- }
64
- catch (e) {
65
- throw new Error(`cache write failed: ${cachePath}: ${errorMessage(e)}`, { cause: e });
66
- }
67
- }
68
- function createPlaceholderSource() {
69
- const cache = new Map();
70
- return (style) => {
71
- let png = cache.get(style);
72
- if (!png) {
73
- png = solidPng(TILE_SOURCES[style].placeholderBg);
74
- cache.set(style, png);
75
- }
76
- return png;
77
- };
78
- }
79
- async function fetchTileToCache(ctx, style, tile, priority, signal) {
80
- const paths = tilePaths(ctx.cacheDir, style, tile);
81
- if (fs.existsSync(paths.file))
82
- return { file: paths.file, status: 'cached' };
83
- const body = await downloadTile(ctx.queue, tileUrl(style, tile), priority, signal);
84
- if (body) {
85
- writeCacheFile(paths.file, body);
86
- return { file: paths.file, status: 'downloaded' };
87
- }
88
- writeCacheFile(paths.placeholder, ctx.placeholderPng(style));
89
- return { file: paths.placeholder, status: 'failed' };
90
- }
91
- function createDownloader(cacheDir, placeholderPng) {
92
- const queue = new PQueue({
93
- concurrency: DOWNLOAD_WORKERS,
94
- intervalCap: 1,
95
- interval: REQUEST_INTERVAL_MS,
96
- // Sliding window: no more than intervalCap starts in any interval window,
97
- // matching the old request gate's nextFreeAt semantics.
98
- strict: true,
99
- });
100
- const ctx = { cacheDir, queue, placeholderPng };
101
- const inFlight = new Map();
102
- return {
103
- enqueue(style, tile, options = {}) {
104
- const priority = options.priority ?? 'background';
105
- const key = `${priority}:${tilePaths(cacheDir, style, tile).file}`;
106
- // Share only within one stream: a canceled stream's downloads must never be handed to the next one.
107
- const shared = inFlight.get(key);
108
- if (shared && shared.signal === options.signal)
109
- return shared.promise;
110
- const task = fetchTileToCache(ctx, style, tile, priority, options.signal);
111
- const entry = { promise: task, signal: options.signal };
112
- const clear = () => {
113
- if (inFlight.get(key) === entry)
114
- inFlight.delete(key);
115
- };
116
- void task.then(clear, clear);
117
- inFlight.set(key, entry);
118
- return task;
119
- },
120
- };
121
- }
122
- export function createTileTraffic(cacheDir) {
123
- const downloader = createDownloader(cacheDir, createPlaceholderSource());
124
- return {
125
- ensure(style, tile) {
126
- return downloader.enqueue(style, tile, { priority: 'now' }).then((result) => result.file);
127
- },
128
- stream(options) {
129
- const { style, tiles, log = () => { }, onTile = () => { }, signal } = options;
130
- const missing = [];
131
- for (const tile of tiles) {
132
- if (fs.existsSync(tilePaths(cacheDir, style, tile).file))
133
- onTile('cached');
134
- else
135
- missing.push(tile);
136
- }
137
- if (missing.length === 0) {
138
- return Promise.resolve({ downloaded: 0, failed: 0, total: tiles.length });
139
- }
140
- log(`tiles: ${tiles.length} needed, ${missing.length} to download (${style})`);
141
- let downloaded = 0;
142
- let failed = 0;
143
- return Promise.all(missing.map((tile) => downloader.enqueue(style, tile, { priority: 'background', signal }).then((result) => {
144
- if (result.status === 'downloaded')
145
- downloaded++;
146
- else if (result.status === 'failed')
147
- failed++;
148
- onTile(result.status);
149
- }))).then(() => ({ downloaded, failed, total: tiles.length }));
150
- },
151
- };
152
- }
153
- export function prefetchTiles(options) {
154
- return createTileTraffic(options.cacheDir).stream(options);
155
- }
@@ -1,13 +0,0 @@
1
- // The --track-out vocabulary: the file extension alone selects the track
2
- // format, shared by the CLI writer and the desktop save request. The one
3
- // values list is both the vocabulary and the extension set.
4
- export const TRACK_FORMAT_VALUES = ['gpx', 'geojson', 'kml', 'kmz', 'json'];
5
- export function trackFormatOf(file) {
6
- const match = /\.([^.\\/]+)$/.exec(file);
7
- const ext = match ? match[1].toLowerCase() : '';
8
- const format = TRACK_FORMAT_VALUES.find((candidate) => candidate === ext);
9
- if (!format) {
10
- throw new Error(`unsupported track file extension: ${file} (use .gpx, .geojson, .kml, .kmz or .json)`);
11
- }
12
- return format;
13
- }
@@ -1,44 +0,0 @@
1
- // Pure GeoJSON serializer (RFC 7946): one MultiLineString line per track
2
- // segment, [lon, lat] or [lon, lat, altM] positions, and the QGIS
3
- // coordinateProperties.times convention only where every vertex carries
4
- // trustworthy UTC. Assembled with fixed formatting and key order, so identical
5
- // input yields identical bytes.
6
- import { isoUtc } from './track.js';
7
- function position(vertex) {
8
- return vertex.altM !== null
9
- ? `[${vertex.lon}, ${vertex.lat}, ${vertex.altM}]`
10
- : `[${vertex.lon}, ${vertex.lat}]`;
11
- }
12
- function oneLineList(items) {
13
- return items.length > 0 ? `[${items.join(', ')}]` : '[]';
14
- }
15
- function itemLines(indents, itemsBySegment) {
16
- const lines = [];
17
- itemsBySegment.forEach((items, index) => {
18
- const last = index === itemsBySegment.length - 1;
19
- lines.push(`${indents}${oneLineList(items)}${last ? '' : ','}`);
20
- });
21
- return lines;
22
- }
23
- export function serializeGeoJson(segments) {
24
- const allTimed = segments.length > 0 &&
25
- segments.every((segment) => segment.every((vertex) => vertex.timeMs !== null));
26
- const lines = [
27
- '{',
28
- ' "type": "Feature",',
29
- ' "geometry": {',
30
- ' "type": "MultiLineString",',
31
- ' "coordinates": [',
32
- ];
33
- lines.push(...itemLines(' ', segments.map((s) => s.map(position))));
34
- lines.push(' ]', ' },');
35
- if (allTimed) {
36
- lines.push(' "properties": {', ' "coordinateProperties": {', ' "times": [');
37
- lines.push(...itemLines(' ', segments.map((segment) => segment.map((vertex) => JSON.stringify(isoUtc(vertex.timeMs))))));
38
- lines.push(' ]', ' }', ' }', '}', '');
39
- }
40
- else {
41
- lines.push(' "properties": {}', '}', '');
42
- }
43
- return lines.join('\n');
44
- }
package/dist/track-gpx.js DELETED
@@ -1,34 +0,0 @@
1
- // Pure GPX 1.1 serializer: one <trkseg> per track segment, altitude as <ele>,
2
- // and a <time> only where the vertex carries trustworthy UTC. No metadata
3
- // wall-clock or version strings, so identical input yields identical bytes.
4
- import { isoUtc } from './track.js';
5
- function trkptLines(vertex) {
6
- const children = [];
7
- if (vertex.altM !== null)
8
- children.push(`<ele>${vertex.altM}</ele>`);
9
- if (vertex.timeMs !== null)
10
- children.push(`<time>${isoUtc(vertex.timeMs)}</time>`);
11
- const open = `<trkpt lat="${vertex.lat}" lon="${vertex.lon}">`;
12
- if (children.length === 0)
13
- return [` <trkpt lat="${vertex.lat}" lon="${vertex.lon}"/>`];
14
- return [
15
- ` ${open}`,
16
- ...children.map((child) => ` ${child}`),
17
- ' </trkpt>',
18
- ];
19
- }
20
- export function serializeGpx(segments) {
21
- const lines = [
22
- '<?xml version="1.0" encoding="UTF-8"?>',
23
- '<gpx version="1.1" creator="drone-path" xmlns="http://www.topografix.com/GPX/1/1">',
24
- ' <trk>',
25
- ];
26
- for (const segment of segments) {
27
- lines.push(' <trkseg>');
28
- for (const vertex of segment)
29
- lines.push(...trkptLines(vertex));
30
- lines.push(' </trkseg>');
31
- }
32
- lines.push(' </trk>', '</gpx>', '');
33
- return lines.join('\n');
34
- }
package/dist/track-kml.js DELETED
@@ -1,47 +0,0 @@
1
- // Pure KML 2.2 serializer: one placemark per track segment. A segment whose
2
- // vertices all carry trustworthy UTC becomes a timed gx:Track (the Google
3
- // Earth flythrough); anything else becomes a plain LineString. Coordinates are
4
- // always 3-tuples in meters: a segment with any unknown altitude uses 0 there
5
- // and clamps the placemark to the ground, while fully known segments fly at
6
- // absolute (mean sea level) altitude. No wall-clock or version strings, so
7
- // identical input yields identical bytes.
8
- import { isoUtc } from './track.js';
9
- function altitudeMode(segment) {
10
- return segment.every((vertex) => vertex.altM !== null) ? 'absolute' : 'clampToGround';
11
- }
12
- // One coordinate rendering for both KML spellings: space-separated inside
13
- // <gx:coord>, comma-separated inside <coordinates>.
14
- function coordOf(vertex, separator) {
15
- return `${vertex.lon}${separator}${vertex.lat}${separator}${vertex.altM ?? 0}`;
16
- }
17
- function placemarkLines(segment) {
18
- const mode = altitudeMode(segment);
19
- const timed = segment.every((vertex) => vertex.timeMs !== null);
20
- const lines = [' <Placemark>'];
21
- if (timed) {
22
- lines.push(' <gx:Track>', ` <altitudeMode>${mode}</altitudeMode>`);
23
- for (const vertex of segment) {
24
- lines.push(` <when>${isoUtc(vertex.timeMs)}</when>`);
25
- lines.push(` <gx:coord>${coordOf(vertex, ' ')}</gx:coord>`);
26
- }
27
- lines.push(' </gx:Track>');
28
- }
29
- else {
30
- lines.push(' <LineString>', ` <altitudeMode>${mode}</altitudeMode>`);
31
- lines.push(` <coordinates>${segment.map((vertex) => coordOf(vertex, ',')).join(' ')}</coordinates>`);
32
- lines.push(' </LineString>');
33
- }
34
- lines.push(' </Placemark>');
35
- return lines;
36
- }
37
- export function serializeKml(segments) {
38
- const lines = [
39
- '<?xml version="1.0" encoding="UTF-8"?>',
40
- '<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">',
41
- ' <Document>',
42
- ];
43
- for (const segment of segments)
44
- lines.push(...placemarkLines(segment));
45
- lines.push(' </Document>', '</kml>', '');
46
- return lines.join('\n');
47
- }
package/dist/track-kmz.js DELETED
@@ -1,68 +0,0 @@
1
- // Deterministic KMZ packaging: a zip archive with exactly one stored (method 0)
2
- // `doc.kml` entry and fixed zip metadata - 1980-01-01 00:00 entry timestamps,
3
- // no extra fields, no comments. Stored entries keep the bytes independent of
4
- // any compressor version, so the same KML always produces the same KMZ.
5
- import { crc32 } from 'node:zlib';
6
- const ENTRY_NAME = 'doc.kml';
7
- // The zip epoch (1980-01-01 00:00:00) in MS-DOS date/time fields.
8
- const DOS_DATE_1980_01_01 = 0x0021;
9
- const DOS_TIME_MIDNIGHT = 0x0000;
10
- function localHeader(name, data) {
11
- const header = Buffer.alloc(30);
12
- header.writeUInt32LE(0x04034b50, 0);
13
- header.writeUInt16LE(20, 4); // version needed: 2.0
14
- header.writeUInt16LE(0, 6); // flags
15
- header.writeUInt16LE(0, 8); // method: stored
16
- header.writeUInt16LE(DOS_TIME_MIDNIGHT, 10);
17
- header.writeUInt16LE(DOS_DATE_1980_01_01, 12);
18
- header.writeUInt32LE(crc32(data), 14);
19
- header.writeUInt32LE(data.length, 18);
20
- header.writeUInt32LE(data.length, 22);
21
- header.writeUInt16LE(name.length, 26);
22
- header.writeUInt16LE(0, 28); // extra field length
23
- return Buffer.concat([header, name, data]);
24
- }
25
- function centralDirectoryEntry(name, data, offset) {
26
- const entry = Buffer.alloc(46);
27
- entry.writeUInt32LE(0x02014b50, 0);
28
- entry.writeUInt16LE(20, 4); // version made by: 2.0, MS-DOS
29
- entry.writeUInt16LE(20, 6); // version needed: 2.0
30
- entry.writeUInt16LE(0, 8); // flags
31
- entry.writeUInt16LE(0, 10); // method: stored
32
- entry.writeUInt16LE(DOS_TIME_MIDNIGHT, 12);
33
- entry.writeUInt16LE(DOS_DATE_1980_01_01, 14);
34
- entry.writeUInt32LE(crc32(data), 16);
35
- entry.writeUInt32LE(data.length, 20);
36
- entry.writeUInt32LE(data.length, 24);
37
- entry.writeUInt16LE(name.length, 28);
38
- entry.writeUInt16LE(0, 30); // extra field length
39
- entry.writeUInt16LE(0, 32); // comment length
40
- entry.writeUInt16LE(0, 34); // disk number start
41
- entry.writeUInt16LE(0, 36); // internal attributes
42
- entry.writeUInt32LE(0, 38); // external attributes
43
- entry.writeUInt32LE(offset, 42);
44
- return Buffer.concat([entry, name]);
45
- }
46
- function endOfCentralDirectory(entryCount, cdSize, cdOffset) {
47
- const eocd = Buffer.alloc(22);
48
- eocd.writeUInt32LE(0x06054b50, 0);
49
- eocd.writeUInt16LE(0, 4); // disk number
50
- eocd.writeUInt16LE(0, 6); // disk with central directory
51
- eocd.writeUInt16LE(entryCount, 8);
52
- eocd.writeUInt16LE(entryCount, 10);
53
- eocd.writeUInt32LE(cdSize, 12);
54
- eocd.writeUInt32LE(cdOffset, 16);
55
- eocd.writeUInt16LE(0, 20); // comment length
56
- return eocd;
57
- }
58
- export function kmzBytes(kml) {
59
- const name = Buffer.from(ENTRY_NAME, 'utf8');
60
- const data = Buffer.from(kml, 'utf8');
61
- const local = localHeader(name, data);
62
- const central = centralDirectoryEntry(name, data, 0);
63
- return Buffer.concat([
64
- local,
65
- central,
66
- endOfCentralDirectory(1, central.length, local.length),
67
- ]);
68
- }
@@ -1,41 +0,0 @@
1
- // The imperative shell for track exports: routes one export input to the
2
- // format its file extension selects and writes the bytes. The .json format is
3
- // the existing telemetry document, byte-for-byte unchanged (it is segmented
4
- // and written by the very functions the --telemetry-json export has used);
5
- // the track formats select their records by source time against the range.
6
- import fs from 'node:fs';
7
- import path from 'node:path';
8
- import { buildTelemetryDocument, segmentTelemetryInput, serializeTelemetryDocument, writeTelemetryDocument, } from './telemetry-json.js';
9
- import { serializeGeoJson } from './track-geojson.js';
10
- import { serializeGpx } from './track-gpx.js';
11
- import { serializeKml } from './track-kml.js';
12
- import { kmzBytes } from './track-kmz.js';
13
- import { trackFormatOf } from './track-format.js';
14
- import { buildTrack, selectTrackRecords } from './track.js';
15
- export function trackFileBytes(file, input, range) {
16
- const format = trackFormatOf(file);
17
- if (format === 'json') {
18
- return serializeTelemetryDocument(buildTelemetryDocument(segmentTelemetryInput(input.document, range)));
19
- }
20
- const track = buildTrack(selectTrackRecords(input.track, range));
21
- switch (format) {
22
- case 'gpx':
23
- return serializeGpx(track);
24
- case 'geojson':
25
- return serializeGeoJson(track);
26
- case 'kml':
27
- return serializeKml(track);
28
- case 'kmz':
29
- return kmzBytes(serializeKml(track));
30
- }
31
- }
32
- export function writeTrackFile(file, input, range) {
33
- const format = trackFormatOf(file);
34
- fs.mkdirSync(path.dirname(file), { recursive: true });
35
- if (format === 'json') {
36
- // Delegated so the telemetry document bytes can never drift.
37
- writeTelemetryDocument(file, segmentTelemetryInput(input.document, range));
38
- return;
39
- }
40
- fs.writeFileSync(file, trackFileBytes(file, input, range));
41
- }
package/dist/track.js DELETED
@@ -1,79 +0,0 @@
1
- // The flight track model the pure serializers consume: vertices at decoded
2
- // GPS fixes, telemetry gaps breaking the line, absolute/GPS altitude, and a
3
- // time only where the source carries trustworthy UTC. Built from the same
4
- // per-source-frame records as the telemetry JSON document, so the CLI and the
5
- // desktop app export byte-identical tracks for the same records.
6
- import { resolveFrameRange } from './config.js';
7
- // The one rendering of a vertex's timeMs shared by the GPX, GeoJSON and KML
8
- // serializers: UTC ISO-8601, never a relative or zone-less clock.
9
- export function isoUtc(timeMs) {
10
- return new Date(timeMs).toISOString();
11
- }
12
- // Time policy: a vertex carries a time only where the source provides
13
- // trustworthy UTC. Neither telemetry source does, measured against real
14
- // footage: the DVTM gimbal device timestamp is milliseconds since power-up
15
- // (34229 ms at clip start, spanning the clip - not an epoch), and the .SRT cue
16
- // wall-clock has no time zone. A relative or zone-less clock is never exported
17
- // as UTC, so no times appear anywhere today. A future source with real UTC
18
- // epoch milliseconds turns on times here and nowhere else.
19
- function timeOf(row) {
20
- void row;
21
- return null;
22
- }
23
- function altitudeOf(row) {
24
- if (row.altAbs !== null && row.altAbs !== undefined)
25
- return row.altAbs;
26
- if (row.gpsAltMm !== null && row.gpsAltMm !== undefined)
27
- return row.gpsAltMm / 1000;
28
- return null;
29
- }
30
- function vertexOf(row) {
31
- return {
32
- lat: row.lat,
33
- lon: row.lng,
34
- altM: altitudeOf(row),
35
- timeMs: timeOf(row),
36
- };
37
- }
38
- /**
39
- * Splits decoded records into track segments: one vertex per record with a
40
- * GPS fix, a new segment after every run of records without one. Nothing is
41
- * interpolated or bridged across a gap.
42
- */
43
- export function buildTrack(rows) {
44
- const segments = [];
45
- let current = [];
46
- for (const row of rows) {
47
- const fixed = row.lat !== null && row.lat !== undefined && row.lng !== null && row.lng !== undefined;
48
- if (!fixed) {
49
- if (current.length > 0) {
50
- segments.push(current);
51
- current = [];
52
- }
53
- continue;
54
- }
55
- current.push(vertexOf(row));
56
- }
57
- if (current.length > 0)
58
- segments.push(current);
59
- return segments;
60
- }
61
- function frameOf(record, stream) {
62
- // The final sample of a spread sample stream sits at exactly the clip
63
- // duration - it belongs to the last frame, never past it.
64
- return Math.min(Math.round(record.tSec * stream.fpsValue), stream.frameCount - 1);
65
- }
66
- /**
67
- * Selects the records for a frame range (inclusive bounds) by their source
68
- * time; a null range keeps every record, however many there are per frame.
69
- * Invalid and out-of-bounds ranges are rejected like on the document path.
70
- */
71
- export function selectTrackRecords(stream, range) {
72
- const span = resolveFrameRange(range, stream.frameCount);
73
- if (!span)
74
- return stream.records;
75
- return stream.records.filter((record) => {
76
- const frame = frameOf(record, stream);
77
- return frame >= span.start && frame <= span.end;
78
- });
79
- }