@margoengine/points 0.0.0-stage → 0.1.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.
Files changed (52) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +794 -3
  4. package/dist/attributes-DNc-1pdr.js +256 -0
  5. package/dist/attributes.d.ts +48 -0
  6. package/dist/clip.d.ts +55 -0
  7. package/dist/clip.js +122 -0
  8. package/dist/cloud-B4O_G-Df.js +545 -0
  9. package/dist/cloud.d.ts +155 -0
  10. package/dist/color.d.ts +1 -0
  11. package/dist/copc.d.ts +55 -0
  12. package/dist/copc.js +130 -0
  13. package/dist/depth-video.d.ts +98 -0
  14. package/dist/depth-video.js +164 -0
  15. package/dist/e57.d.ts +163 -0
  16. package/dist/e57.js +624 -0
  17. package/dist/frame.d.ts +9 -0
  18. package/dist/index.d.ts +16 -0
  19. package/dist/index.js +1246 -0
  20. package/dist/las.d.ts +213 -0
  21. package/dist/las.js +500 -0
  22. package/dist/laz.d.ts +50 -0
  23. package/dist/laz.js +1025 -0
  24. package/dist/material.d.ts +167 -0
  25. package/dist/math.d.ts +103 -0
  26. package/dist/octree.d.ts +182 -0
  27. package/dist/octree.js +360 -0
  28. package/dist/pick.d.ts +76 -0
  29. package/dist/pick.js +192 -0
  30. package/dist/plugin.d.ts +235 -0
  31. package/dist/potree.d.ts +70 -0
  32. package/dist/potree.js +451 -0
  33. package/dist/range-BQuJAjUM.js +23 -0
  34. package/dist/range.d.ts +4 -0
  35. package/dist/screen-door-CALlYs39.js +7 -0
  36. package/dist/shaders-Deu8H36P.js +278 -0
  37. package/dist/shaders.d.ts +52 -0
  38. package/dist/shared/fog.d.ts +33 -0
  39. package/dist/shared/pass.d.ts +53 -0
  40. package/dist/shared/selection-mask.d.ts +52 -0
  41. package/dist/shared/style-expression.d.ts +18 -0
  42. package/dist/sprites.d.ts +78 -0
  43. package/dist/storage-limit.d.ts +6 -0
  44. package/dist/style.d.ts +124 -0
  45. package/dist/style.js +708 -0
  46. package/dist/surfels.d.ts +95 -0
  47. package/dist/surfels.js +538 -0
  48. package/dist/survey-DToZwkJv.js +46 -0
  49. package/dist/survey.d.ts +10 -0
  50. package/dist/tier-BcFbLPVT.js +91 -0
  51. package/dist/tier.d.ts +6 -0
  52. package/package.json +96 -6
package/dist/laz.js ADDED
@@ -0,0 +1,1025 @@
1
+ import { MargoError as e } from "@margoengine/math/errors";
2
+ //#region src/laz.ts
3
+ var t = [
4
+ "BYTE",
5
+ "SHORT",
6
+ "INT",
7
+ "LONG",
8
+ "FLOAT",
9
+ "DOUBLE",
10
+ "POINT10",
11
+ "GPSTIME11",
12
+ "RGB12",
13
+ "WAVEPACKET13",
14
+ "POINT14",
15
+ "RGB14",
16
+ "RGBNIR14",
17
+ "WAVEPACKET14",
18
+ "BYTE14"
19
+ ], n = 0, r = 6, i = 7, a = 8, o = 9, s = 10, c = 11, l = 12, u = 13, d = 14, f = 4294967295;
20
+ function p(e) {
21
+ let n = e.find((e) => e.userId === "laszip encoded" && e.recordId === 22204);
22
+ if (!n) throw TypeError("LAZ file has no LASzip record (user id \"laszip encoded\", record 22204); the file is corrupt or not LAZ");
23
+ let r = n.data, i = new DataView(r.buffer, r.byteOffset, r.byteLength);
24
+ if (r.byteLength < 34) throw TypeError("LASzip record is shorter than 34 bytes; the file is corrupt");
25
+ let a = i.getUint16(32, !0);
26
+ if (r.byteLength < 34 + a * 6) throw TypeError(`LASzip record lists ${a} items but holds fewer; the file is corrupt`);
27
+ let o = [];
28
+ for (let e = 0; e < a; e++) {
29
+ let n = i.getUint16(34 + e * 6, !0);
30
+ o.push({
31
+ type: n,
32
+ name: t[n] ?? `item ${n}`,
33
+ size: i.getUint16(36 + e * 6, !0),
34
+ version: i.getUint16(38 + e * 6, !0)
35
+ });
36
+ }
37
+ let s = i.getUint32(12, !0), c = i.getUint16(0, !0);
38
+ return {
39
+ compressor: c,
40
+ coder: i.getUint16(2, !0),
41
+ version: `${i.getUint8(4)}.${i.getUint8(5)}.${i.getUint16(6, !0)}`,
42
+ options: i.getUint32(8, !0),
43
+ chunkSize: s === f || s === 0 && c >= 2 ? "variable" : s,
44
+ items: o
45
+ };
46
+ }
47
+ function m(e, t) {
48
+ return t ? [s, ...e === 7 ? [c] : e === 8 || e === 10 ? [l] : []].concat(e === 9 || e === 10 ? [u] : []) : [
49
+ r,
50
+ ...[
51
+ 1,
52
+ 3,
53
+ 4,
54
+ 5
55
+ ].includes(e) ? [i] : [],
56
+ ...[
57
+ 2,
58
+ 3,
59
+ 5
60
+ ].includes(e) ? [a] : [],
61
+ ...e === 4 || e === 5 ? [o] : []
62
+ ];
63
+ }
64
+ var h = (t) => new e("unsupported", `LAZ ${t} is not supported by this decoder; decompress the file to LAS first (for example with laszip or PDAL)`);
65
+ function g(e, t) {
66
+ if (e.coder !== 0) throw h(`coder ${e.coder} (only arithmetic coding, 0, is defined)`);
67
+ if (e.compressor > 3) throw h(`compressor ${e.compressor}`);
68
+ if (e.compressor === 0) return;
69
+ let f = e.compressor === 3, p = t.pointFormat;
70
+ if (f !== p >= 6) throw h(`point format ${p} with compressor ${e.compressor} (formats 0 to 5 use 1 or 2, formats 6 to 10 use 3)`);
71
+ let g = m(p, f), _ = e.items.map((e) => e.type), v = _.slice(g.length), y = e.items.reduce((e, t) => e + t.size, 0), b = f ? d : n;
72
+ if (g.some((e, t) => _[t] !== e) || v.some((e) => e !== b) || y !== t.pointRecordLength) throw TypeError(`LASzip items ${e.items.map((e) => `${e.name}(${e.size})`).join(" ")} do not match point format ${p} with ${t.pointRecordLength}-byte records; the file is corrupt`);
73
+ let x = {
74
+ [r]: 20,
75
+ [i]: 8,
76
+ [a]: 6,
77
+ [s]: 30,
78
+ [c]: 6,
79
+ [l]: 8,
80
+ [o]: 29,
81
+ [u]: 29
82
+ };
83
+ for (let t of e.items) {
84
+ if (x[t.type] !== void 0 && x[t.type] !== t.size) throw TypeError(`LASzip item ${t.name} has size ${t.size}, not ${x[t.type]}; the file is corrupt`);
85
+ let e = f ? 3 : t.type === o ? 1 : 2;
86
+ if (t.version !== e) throw h(t.version === 1 && e === 2 ? `item ${t.name} version 1 (the coding of LASzip 1.0, which neither the LAZ specification 1.4 nor the LASzip paper describes, so a clean room decoder has nothing to follow)` : `item ${t.name} version ${t.version} (this decoder reads version ${e}, what LASzip 2 and 3 write)`);
87
+ }
88
+ }
89
+ var _ = 16777216, v = 13, y = 8192, b = 15, x = 32768, S = class {
90
+ constructor() {
91
+ this.prob = 0, this.zeros = 0, this.total = 0, this.cycle = 0, this.until = 0, this.reset();
92
+ }
93
+ reset() {
94
+ this.zeros = 1, this.total = 2, this.prob = 4096, this.cycle = this.until = 4;
95
+ }
96
+ update() {
97
+ (this.total += this.cycle) > y && (this.total = this.total + 1 >>> 1, this.zeros = this.zeros + 1 >>> 1, this.zeros === this.total && this.total++);
98
+ let e = Math.floor(2147483648 / this.total);
99
+ this.prob = Math.floor(this.zeros * e / 2 ** 18), this.cycle = Math.min(5 * this.cycle >>> 2, 64), this.until = this.cycle;
100
+ }
101
+ }, C = class {
102
+ constructor(e) {
103
+ if (this.total = 0, this.cycle = 0, this.until = 0, this.symbols = e, this.last = e - 1, this.dist = new Uint32Array(e), this.counts = new Uint32Array(e), e > 16) {
104
+ let t = 3;
105
+ for (; e > 1 << t + 2;) t++;
106
+ this.tableSize = 1 << t, this.tableShift = b - t, this.table = new Uint32Array(this.tableSize + 2);
107
+ } else this.tableSize = 0, this.tableShift = 0;
108
+ this.reset();
109
+ }
110
+ reset() {
111
+ this.total = 0, this.cycle = this.symbols, this.counts.fill(1), this.update(), this.cycle = this.until = this.symbols + 6 >>> 1;
112
+ }
113
+ update() {
114
+ let { counts: e, dist: t, symbols: n } = this;
115
+ if ((this.total += this.cycle) > x) {
116
+ let t = 0;
117
+ for (let r = 0; r < n; r++) t += e[r] = e[r] + 1 >>> 1;
118
+ this.total = t;
119
+ }
120
+ let r = Math.floor(2147483648 / this.total), i = 2 ** 16, a = 0, o = this.table;
121
+ if (o) {
122
+ let s = 0;
123
+ for (let c = 0; c < n; c++) {
124
+ t[c] = Math.floor(r * a / i), a += e[c];
125
+ let n = t[c] >>> this.tableShift;
126
+ for (; s < n;) o[++s] = c - 1;
127
+ }
128
+ for (o[0] = 0; s <= this.tableSize;) o[++s] = n - 1;
129
+ } else for (let o = 0; o < n; o++) t[o] = Math.floor(r * a / i), a += e[o];
130
+ this.cycle = Math.min(5 * this.cycle >>> 2, n + 6 << 3), this.until = this.cycle;
131
+ }
132
+ }, w = /* @__PURE__ */ new Uint8Array(), T = class {
133
+ constructor() {
134
+ this.bytes = w, this.at = 0, this.end = 0, this.over = 0, this.value = 0, this.length = 0, this.label = "";
135
+ }
136
+ init(e, t, n, r) {
137
+ if (this.bytes = e, this.at = t, this.end = n, this.over = 0, this.label = r, this.length = 4294967295, this.value = this.byte() * 16777216 + this.byte() * 65536 + this.byte() * 256 + this.byte(), this.value === 4294967295) throw RangeError(`LAZ ${r} starts with an invalid code; the file is corrupt`);
138
+ }
139
+ byte() {
140
+ if (this.at < this.end) return this.bytes[this.at++];
141
+ if (++this.over > 4) throw RangeError(`LAZ ${this.label} reads past its end; the file is corrupt`);
142
+ return 0;
143
+ }
144
+ renorm() {
145
+ do
146
+ this.value = this.value * 256 + this.byte(), this.length *= 256;
147
+ while (this.length < _);
148
+ }
149
+ decodeBit(e) {
150
+ let t = e.prob * (this.length >>> v), n;
151
+ return this.value < t ? (n = 0, this.length = t, e.zeros++) : (n = 1, this.value -= t, this.length -= t), this.length < _ && this.renorm(), --e.until === 0 && e.update(), n;
152
+ }
153
+ decodeSymbol(e) {
154
+ let t, n, r = this.length, i = this.length >>>= b, a = e.dist;
155
+ if (e.table) {
156
+ let o = Math.floor(this.value / i), s = Math.min(o >>> e.tableShift, e.tableSize);
157
+ t = e.table[s];
158
+ let c = e.table[s + 1] + 1;
159
+ for (; c > t + 1;) {
160
+ let e = t + c >>> 1;
161
+ a[e] > o ? c = e : t = e;
162
+ }
163
+ n = a[t] * i, t !== e.last && (r = a[t + 1] * i);
164
+ } else {
165
+ n = t = 0;
166
+ let o = e.symbols, s = o >>> 1;
167
+ do {
168
+ let e = i * a[s];
169
+ e > this.value ? (o = s, r = e) : (t = s, n = e);
170
+ } while ((s = t + o >>> 1) !== t);
171
+ }
172
+ return this.value -= n, this.length = r - n, this.length < _ && this.renorm(), e.counts[t]++, --e.until === 0 && e.update(), t;
173
+ }
174
+ readBits(e) {
175
+ if (e > 19) {
176
+ let t = this.readBits(16);
177
+ return this.readBits(e - 16) * 65536 + t;
178
+ }
179
+ let t = this.length >>>= e, n = Math.floor(this.value / t);
180
+ return this.value -= t * n, this.length < _ && this.renorm(), n;
181
+ }
182
+ readInt() {
183
+ let e = this.readBits(16);
184
+ return this.readBits(16) * 65536 + e;
185
+ }
186
+ readInt64() {
187
+ let e = this.readInt();
188
+ return BigInt(this.readInt()) << 32n | BigInt(e);
189
+ }
190
+ }, E = class {
191
+ constructor(e, t = 16, n = 1, r = 8) {
192
+ this.dec = e, this.bitsHigh = r, this.k = 0, this.zero = new S(), this.corrector = [], t && t < 32 ? (this.corrBits = t, this.corrRange = 2 ** t, this.corrMin = -(this.corrRange / 2)) : (this.corrBits = 32, this.corrRange = 0, this.corrMin = -2147483648), this.kModels = Array.from({ length: n }, () => new C(this.corrBits + 1));
193
+ for (let e = 1; e <= this.corrBits; e++) this.corrector[e] = new C(1 << Math.min(e, r));
194
+ }
195
+ reset() {
196
+ for (let e of this.kModels) e.reset();
197
+ this.zero.reset();
198
+ for (let e = 1; e <= this.corrBits; e++) this.corrector[e].reset();
199
+ }
200
+ decompress(e, t = 0) {
201
+ let n = e + this.corrector_(this.kModels[t]);
202
+ return this.corrRange ? n < 0 ? n + this.corrRange : n >= this.corrRange ? n - this.corrRange : n : n | 0;
203
+ }
204
+ corrector_(e) {
205
+ let t = this.dec, n = this.k = t.decodeSymbol(e);
206
+ if (!n) return t.decodeBit(this.zero);
207
+ if (n >= 32) return this.corrMin;
208
+ let r;
209
+ if (n <= this.bitsHigh) r = t.decodeSymbol(this.corrector[n]);
210
+ else {
211
+ let e = n - this.bitsHigh;
212
+ r = t.decodeSymbol(this.corrector[n]) * 2 ** e + t.readBits(e);
213
+ }
214
+ return r >= 2 ** (n - 1) ? r + 1 : r - (2 ** n - 1);
215
+ }
216
+ }, ee = class {
217
+ constructor() {
218
+ this.v = /* @__PURE__ */ new Int32Array(5), this.high = !0;
219
+ }
220
+ reset() {
221
+ this.v.fill(0), this.high = !0;
222
+ }
223
+ get() {
224
+ return this.v[2];
225
+ }
226
+ add(e) {
227
+ let t = this.v;
228
+ this.high ? e < t[2] ? (t[4] = t[3], t[3] = t[2], e < t[0] ? (t[2] = t[1], t[1] = t[0], t[0] = e) : e < t[1] ? (t[2] = t[1], t[1] = e) : t[2] = e) : (e < t[3] ? (t[4] = t[3], t[3] = e) : t[4] = e, this.high = !1) : t[2] < e ? (t[0] = t[1], t[1] = t[2], t[4] < e ? (t[2] = t[3], t[3] = t[4], t[4] = e) : t[3] < e ? (t[2] = t[3], t[3] = e) : t[2] = e) : (t[1] < e ? (t[0] = t[1], t[1] = e) : t[0] = e, this.high = !0);
229
+ }
230
+ }, D = (e) => Array.from({ length: e }, () => new ee()), O = (e) => e <= 0 ? 0 : e >= 255 ? 255 : e, k = (e, t, n) => e[t] ??= new C(n), A = (e) => {
231
+ for (let t of e) t?.reset();
232
+ }, te = new Uint8Array([
233
+ 15,
234
+ 14,
235
+ 13,
236
+ 12,
237
+ 11,
238
+ 10,
239
+ 9,
240
+ 8,
241
+ 14,
242
+ 0,
243
+ 1,
244
+ 3,
245
+ 6,
246
+ 10,
247
+ 10,
248
+ 9,
249
+ 13,
250
+ 1,
251
+ 2,
252
+ 4,
253
+ 7,
254
+ 11,
255
+ 11,
256
+ 10,
257
+ 12,
258
+ 3,
259
+ 4,
260
+ 5,
261
+ 8,
262
+ 12,
263
+ 12,
264
+ 11,
265
+ 11,
266
+ 6,
267
+ 7,
268
+ 8,
269
+ 9,
270
+ 13,
271
+ 13,
272
+ 12,
273
+ 10,
274
+ 10,
275
+ 11,
276
+ 12,
277
+ 13,
278
+ 14,
279
+ 14,
280
+ 13,
281
+ 9,
282
+ 10,
283
+ 11,
284
+ 12,
285
+ 13,
286
+ 14,
287
+ 15,
288
+ 14,
289
+ 8,
290
+ 9,
291
+ 10,
292
+ 11,
293
+ 12,
294
+ 13,
295
+ 14,
296
+ 15
297
+ ]), ne = (/* @__PURE__ */ new Uint8Array(64)).map((e, t) => Math.abs((t >> 3) - (t & 7))), re = new Uint8Array([
298
+ 0,
299
+ 1,
300
+ 2,
301
+ 3,
302
+ 4,
303
+ 5,
304
+ 3,
305
+ 4,
306
+ 4,
307
+ 5,
308
+ 5,
309
+ 5,
310
+ 5,
311
+ 5,
312
+ 5,
313
+ 5,
314
+ 1,
315
+ 0,
316
+ 1,
317
+ 3,
318
+ 4,
319
+ 5,
320
+ 3,
321
+ 4,
322
+ 4,
323
+ 5,
324
+ 5,
325
+ 5,
326
+ 5,
327
+ 5,
328
+ 5,
329
+ 5,
330
+ 2,
331
+ 1,
332
+ 2,
333
+ 4,
334
+ 5,
335
+ 3,
336
+ 4,
337
+ 4,
338
+ 5,
339
+ 5,
340
+ 5,
341
+ 5,
342
+ 5,
343
+ 5,
344
+ 5,
345
+ 5,
346
+ 3,
347
+ 3,
348
+ 4,
349
+ 5,
350
+ 4,
351
+ 5,
352
+ 4,
353
+ 4,
354
+ 5,
355
+ 5,
356
+ 5,
357
+ 5,
358
+ 5,
359
+ 5,
360
+ 5,
361
+ 5,
362
+ 4,
363
+ 3,
364
+ 4,
365
+ 4,
366
+ 5,
367
+ 5,
368
+ 4,
369
+ 4,
370
+ 5,
371
+ 5,
372
+ 5,
373
+ 5,
374
+ 5,
375
+ 5,
376
+ 5,
377
+ 5,
378
+ 5,
379
+ 3,
380
+ 4,
381
+ 4,
382
+ 4,
383
+ 5,
384
+ 4,
385
+ 4,
386
+ 5,
387
+ 5,
388
+ 5,
389
+ 5,
390
+ 5,
391
+ 5,
392
+ 5,
393
+ 5,
394
+ 3,
395
+ 3,
396
+ 4,
397
+ 4,
398
+ 4,
399
+ 4,
400
+ 5,
401
+ 4,
402
+ 5,
403
+ 5,
404
+ 5,
405
+ 5,
406
+ 5,
407
+ 5,
408
+ 5,
409
+ 5,
410
+ 4,
411
+ 3,
412
+ 4,
413
+ 4,
414
+ 4,
415
+ 4,
416
+ 4,
417
+ 5,
418
+ 5,
419
+ 5,
420
+ 5,
421
+ 5,
422
+ 5,
423
+ 5,
424
+ 5,
425
+ 5,
426
+ 4,
427
+ 3,
428
+ 4,
429
+ 4,
430
+ 4,
431
+ 4,
432
+ 4,
433
+ 4,
434
+ 5,
435
+ 5,
436
+ 5,
437
+ 5,
438
+ 5,
439
+ 5,
440
+ 5,
441
+ 5,
442
+ 5,
443
+ 3,
444
+ 4,
445
+ 4,
446
+ 4,
447
+ 4,
448
+ 4,
449
+ 4,
450
+ 4,
451
+ 5,
452
+ 5,
453
+ 5,
454
+ 5,
455
+ 5,
456
+ 5,
457
+ 5,
458
+ 5,
459
+ 3,
460
+ 4,
461
+ 4,
462
+ 4,
463
+ 4,
464
+ 4,
465
+ 4,
466
+ 4,
467
+ 4,
468
+ 5,
469
+ 5,
470
+ 5,
471
+ 5,
472
+ 5,
473
+ 5,
474
+ 5,
475
+ 3,
476
+ 4,
477
+ 4,
478
+ 4,
479
+ 4,
480
+ 4,
481
+ 4,
482
+ 4,
483
+ 4,
484
+ 4,
485
+ 5,
486
+ 5,
487
+ 5,
488
+ 5,
489
+ 5,
490
+ 5,
491
+ 3,
492
+ 4,
493
+ 4,
494
+ 4,
495
+ 4,
496
+ 4,
497
+ 4,
498
+ 4,
499
+ 4,
500
+ 4,
501
+ 4,
502
+ 5,
503
+ 5,
504
+ 5,
505
+ 5,
506
+ 5,
507
+ 3,
508
+ 4,
509
+ 4,
510
+ 4,
511
+ 4,
512
+ 4,
513
+ 4,
514
+ 4,
515
+ 4,
516
+ 4,
517
+ 4,
518
+ 4,
519
+ 5,
520
+ 5,
521
+ 5,
522
+ 5,
523
+ 3,
524
+ 4,
525
+ 4,
526
+ 4,
527
+ 4,
528
+ 4,
529
+ 4,
530
+ 4,
531
+ 4,
532
+ 4,
533
+ 4,
534
+ 4,
535
+ 4,
536
+ 5,
537
+ 5,
538
+ 5,
539
+ 3,
540
+ 4,
541
+ 4,
542
+ 4,
543
+ 4,
544
+ 4,
545
+ 4,
546
+ 4,
547
+ 4,
548
+ 4,
549
+ 4,
550
+ 4,
551
+ 4,
552
+ 4,
553
+ 5
554
+ ]), ie = (/* @__PURE__ */ new Uint8Array(256)).map((e, t) => Math.min(Math.abs((t >> 4) - (t & 15)), 7)), ae = class {
555
+ constructor(e) {
556
+ this.dec = e, this.size = 20, this.x = 0, this.y = 0, this.z = 0, this.intensity = 0, this.bits = 0, this.cls = 0, this.angle = 0, this.user = 0, this.psid = 0, this.lastIntensity = /* @__PURE__ */ new Uint16Array(16), this.lastHeight = /* @__PURE__ */ new Int32Array(8), this.medianX = D(16), this.medianY = D(16), this.changed = new C(64), this.angleModels = [new C(256), new C(256)], this.bitByte = [], this.classes = [], this.userData = [], this.icIntensity = new E(e, 16, 4), this.icPsid = new E(e, 16), this.icX = new E(e, 32, 2), this.icY = new E(e, 32, 22), this.icZ = new E(e, 32, 20);
557
+ }
558
+ init(e, t) {
559
+ for (let e of this.medianX) e.reset();
560
+ for (let e of this.medianY) e.reset();
561
+ this.lastIntensity.fill(0), this.lastHeight.fill(0), this.changed.reset();
562
+ for (let e of this.angleModels) e.reset();
563
+ A(this.bitByte), A(this.classes), A(this.userData);
564
+ for (let e of [
565
+ this.icIntensity,
566
+ this.icPsid,
567
+ this.icX,
568
+ this.icY,
569
+ this.icZ
570
+ ]) e.reset();
571
+ this.x = e.getInt32(t, !0), this.y = e.getInt32(t + 4, !0), this.z = e.getInt32(t + 8, !0), this.intensity = 0, this.bits = e.getUint8(t + 14), this.cls = e.getUint8(t + 15), this.angle = e.getUint8(t + 16), this.user = e.getUint8(t + 17), this.psid = e.getUint16(t + 18, !0);
572
+ }
573
+ read(e, t) {
574
+ let n = this.dec, r = n.decodeSymbol(this.changed);
575
+ r & 32 && (this.bits = n.decodeSymbol(k(this.bitByte, this.bits, 256)));
576
+ let i = this.bits & 7, a = this.bits >> 3 & 7, o = te[a * 8 + i], s = ne[a * 8 + i], c = +(a === 1);
577
+ r && (r & 16 ? (this.intensity = this.icIntensity.decompress(this.lastIntensity[o], o < 3 ? o : 3), this.lastIntensity[o] = this.intensity) : this.intensity = this.lastIntensity[o], r & 8 && (this.cls = n.decodeSymbol(k(this.classes, this.cls, 256))), r & 4 && (this.angle = n.decodeSymbol(this.angleModels[this.bits >> 6 & 1]) + this.angle & 255), r & 2 && (this.user = n.decodeSymbol(k(this.userData, this.user, 256))), r & 1 && (this.psid = this.icPsid.decompress(this.psid)));
578
+ let l = this.icX.decompress(this.medianX[o].get(), c);
579
+ this.x = this.x + l | 0, this.medianX[o].add(l);
580
+ let u = this.icX.k;
581
+ l = this.icY.decompress(this.medianY[o].get(), c + (u < 20 ? u & -2 : 20)), this.y = this.y + l | 0, this.medianY[o].add(l), u = this.icX.k + this.icY.k >>> 1, this.z = this.icZ.decompress(this.lastHeight[s], c + (u < 18 ? u & -2 : 18)), this.lastHeight[s] = this.z, e.setInt32(t, this.x, !0), e.setInt32(t + 4, this.y, !0), e.setInt32(t + 8, this.z, !0), e.setUint16(t + 12, this.intensity, !0), e.setUint8(t + 14, this.bits), e.setUint8(t + 15, this.cls), e.setUint8(t + 16, this.angle), e.setUint8(t + 17, this.user), e.setUint16(t + 18, this.psid, !0);
582
+ }
583
+ }, j = 500, M = -10, N = 511, P = class {
584
+ constructor(e, t) {
585
+ this.dec = e, this.layered = t, this.last = 0, this.next = 0, this.low = /* @__PURE__ */ new Uint32Array(4), this.high = /* @__PURE__ */ new Uint32Array(4), this.diff = /* @__PURE__ */ new Int32Array(4), this.extreme = /* @__PURE__ */ new Int32Array(4), this.fullCode = t ? N : 512, this.multi = new C(this.fullCode + 4), this.zero = new C(t ? 5 : 6), this.ic = new E(e, 32, 9);
586
+ }
587
+ reset(e, t) {
588
+ this.multi.reset(), this.zero.reset(), this.ic.reset(), this.last = this.next = 0, this.diff.fill(0), this.extreme.fill(0), this.low.fill(0), this.high.fill(0), this.low[0] = e, this.high[0] = t;
589
+ }
590
+ add(e, t) {
591
+ let n = this.low[e] + t;
592
+ this.low[e] = n, n >= 4294967296 ? this.high[e]++ : n < 0 && this.high[e]--;
593
+ }
594
+ full() {
595
+ let e = this.next = this.next + 1 & 3, t = this.ic.decompress(this.high[this.last] | 0, 8);
596
+ this.low[e] = this.dec.readInt(), this.high[e] = t, this.last = e, this.diff[e] = 0, this.extreme[e] = 0;
597
+ }
598
+ extremeDiff(e) {
599
+ ++this.extreme[this.last] > 3 && (this.diff[this.last] = e, this.extreme[this.last] = 0);
600
+ }
601
+ read() {
602
+ let e = this.dec, t = this.ic;
603
+ for (let n = 0;; n++) {
604
+ if (n > 3) throw RangeError(`LAZ ${e.label} GPS time switches sequence repeatedly; the file is corrupt`);
605
+ let r = this.last;
606
+ if (this.diff[r] === 0) {
607
+ let n = e.decodeSymbol(this.zero), i = +!this.layered;
608
+ if (n === i) {
609
+ let e = t.decompress(0, 0);
610
+ this.diff[r] = e, this.add(r, e), this.extreme[r] = 0;
611
+ } else if (n === i + 1) this.full();
612
+ else if (n > i + 1) {
613
+ this.last = r + n - i - 1 & 3;
614
+ continue;
615
+ }
616
+ return;
617
+ }
618
+ let i = e.decodeSymbol(this.multi);
619
+ if (i === 1) {
620
+ let e = t.decompress(this.diff[r], 1);
621
+ this.add(r, e), this.extreme[r] = 0;
622
+ } else if (i < N) {
623
+ let e;
624
+ i === 0 ? (e = t.decompress(0, 7), this.extremeDiff(e)) : i < j ? e = t.decompress(Math.imul(i, this.diff[r]), i < 10 ? 2 : 3) : i === j ? (e = t.decompress(Math.imul(j, this.diff[r]), 4), this.extremeDiff(e)) : (i = j - i, i > M ? e = t.decompress(Math.imul(i, this.diff[r]), 5) : (e = t.decompress(Math.imul(M, this.diff[r]), 6), this.extremeDiff(e))), this.add(r, e);
625
+ } else if (i === this.fullCode) this.full();
626
+ else if (i > this.fullCode) {
627
+ this.last = r + i - this.fullCode & 3;
628
+ continue;
629
+ }
630
+ return;
631
+ }
632
+ }
633
+ }, oe = class {
634
+ constructor(e) {
635
+ this.size = 8, this.gps = new P(e, !1);
636
+ }
637
+ init(e, t) {
638
+ this.gps.reset(e.getUint32(t, !0), e.getUint32(t + 4, !0));
639
+ }
640
+ read(e, t) {
641
+ let n = this.gps;
642
+ n.read(), e.setUint32(t, n.low[n.last], !0), e.setUint32(t + 4, n.high[n.last], !0);
643
+ }
644
+ }, F = class {
645
+ constructor() {
646
+ this.used = new C(128), this.diff = Array.from({ length: 6 }, () => new C(256));
647
+ }
648
+ reset() {
649
+ this.used.reset();
650
+ for (let e of this.diff) e.reset();
651
+ }
652
+ };
653
+ function I(e, t, n) {
654
+ let r = e.decodeSymbol(t.used), i = n[0], a = n[1], o = n[2], s = r & 1 ? e.decodeSymbol(t.diff[0]) + (i & 255) & 255 : i & 255;
655
+ s |= r & 2 ? (e.decodeSymbol(t.diff[1]) + (i >> 8) & 255) << 8 : i & 65280;
656
+ let c = s, l = s;
657
+ if (r & 64) {
658
+ let n = (s & 255) - (i & 255);
659
+ c = r & 4 ? e.decodeSymbol(t.diff[2]) + O(n + (a & 255)) & 255 : a & 255, r & 16 ? (n = Math.trunc((n + (c & 255) - (a & 255)) / 2), l = e.decodeSymbol(t.diff[4]) + O(n + (o & 255)) & 255) : l = o & 255, n = (s >> 8) - (i >> 8), c |= r & 8 ? (e.decodeSymbol(t.diff[3]) + O(n + (a >> 8)) & 255) << 8 : a & 65280, r & 32 ? (n = Math.trunc((n + (c >> 8) - (a >> 8)) / 2), l |= (e.decodeSymbol(t.diff[5]) + O(n + (o >> 8)) & 255) << 8) : l |= o & 65280;
660
+ }
661
+ n[0] = s, n[1] = c, n[2] = l;
662
+ }
663
+ var L = (e, t, n) => {
664
+ e.setUint16(t, n[0], !0), e.setUint16(t + 2, n[1], !0), e.setUint16(t + 4, n[2], !0);
665
+ }, se = class {
666
+ constructor(e) {
667
+ this.dec = e, this.size = 6, this.last = /* @__PURE__ */ new Uint16Array(3), this.models = new F();
668
+ }
669
+ init(e, t) {
670
+ this.models.reset();
671
+ for (let n = 0; n < 3; n++) this.last[n] = e.getUint16(t + n * 2, !0);
672
+ }
673
+ read(e, t) {
674
+ I(this.dec, this.models, this.last), L(e, t, this.last);
675
+ }
676
+ }, ce = class {
677
+ constructor(e, t) {
678
+ this.dec = e, this.size = t, this.last = new Uint8Array(t), this.models = Array.from({ length: t }, () => new C(256));
679
+ }
680
+ init(e, t) {
681
+ A(this.models);
682
+ for (let n = 0; n < this.size; n++) this.last[n] = e.getUint8(t + n);
683
+ }
684
+ read(e, t) {
685
+ for (let n = 0; n < this.size; n++) this.last[n] = this.last[n] + this.dec.decodeSymbol(this.models[n]) & 255, e.setUint8(t + n, this.last[n]);
686
+ }
687
+ }, R = class {
688
+ constructor() {
689
+ this.index = 0, this.offset = 0n, this.size = 0, this.location = 0, this.dx = 0, this.dy = 0, this.dz = 0;
690
+ }
691
+ readFrom(e, t) {
692
+ this.index = e.getUint8(t), this.offset = e.getBigUint64(t + 1, !0), this.size = e.getInt32(t + 9, !0), this.location = e.getInt32(t + 13, !0), this.dx = e.getInt32(t + 17, !0), this.dy = e.getInt32(t + 21, !0), this.dz = e.getInt32(t + 25, !0);
693
+ }
694
+ copy(e) {
695
+ this.index = e.index, this.offset = e.offset, this.size = e.size, this.location = e.location, this.dx = e.dx, this.dy = e.dy, this.dz = e.dz;
696
+ }
697
+ writeTo(e, t) {
698
+ e.setUint8(t, this.index), e.setBigUint64(t + 1, this.offset, !0), e.setInt32(t + 9, this.size, !0), e.setInt32(t + 13, this.location, !0), e.setInt32(t + 17, this.dx, !0), e.setInt32(t + 21, this.dy, !0), e.setInt32(t + 25, this.dz, !0);
699
+ }
700
+ }, z = class {
701
+ constructor(e) {
702
+ this.index = new C(256), this.offsetType = Array.from({ length: 4 }, () => new C(4)), this.lastType = 0, this.lastDiff = 0, this.offsetDiff = new E(e, 32), this.size = new E(e, 32), this.location = new E(e, 32), this.direction = new E(e, 32, 3);
703
+ }
704
+ reset() {
705
+ this.lastType = this.lastDiff = 0, this.index.reset(), A(this.offsetType), this.offsetDiff.reset(), this.size.reset(), this.location.reset(), this.direction.reset();
706
+ }
707
+ };
708
+ function B(e, t, n) {
709
+ n.index = e.decodeSymbol(t.index);
710
+ let r = t.lastType = e.decodeSymbol(t.offsetType[t.lastType]);
711
+ r === 1 ? n.offset = BigInt.asUintN(64, n.offset + BigInt(n.size >>> 0)) : r === 2 ? (t.lastDiff = t.offsetDiff.decompress(t.lastDiff), n.offset = BigInt.asUintN(64, n.offset + BigInt(t.lastDiff))) : r === 3 && (n.offset = e.readInt64()), n.size = t.size.decompress(n.size), n.location = t.location.decompress(n.location), n.dx = t.direction.decompress(n.dx, 0), n.dy = t.direction.decompress(n.dy, 1), n.dz = t.direction.decompress(n.dz, 2);
712
+ }
713
+ var le = class {
714
+ constructor(e) {
715
+ this.dec = e, this.size = 29, this.last = new R(), this.models = new z(e);
716
+ }
717
+ init(e, t) {
718
+ this.models.reset(), this.last.readFrom(e, t);
719
+ }
720
+ read(e, t) {
721
+ B(this.dec, this.models, this.last), this.last.writeTo(e, t);
722
+ }
723
+ }, V = class {
724
+ constructor() {
725
+ this.x = 0, this.y = 0, this.z = 0, this.intensity = 0, this.ret = 0, this.returns = 0, this.classFlags = 0, this.channel = 0, this.scanDirection = 0, this.edge = 0, this.cls = 0, this.user = 0, this.angle = 0, this.psid = 0, this.gpsLow = 0, this.gpsHigh = 0, this.gpsChange = !1;
726
+ }
727
+ copy(e) {
728
+ Object.assign(this, e);
729
+ }
730
+ readFrom(e, t) {
731
+ this.x = e.getInt32(t, !0), this.y = e.getInt32(t + 4, !0), this.z = e.getInt32(t + 8, !0), this.intensity = e.getUint16(t + 12, !0);
732
+ let n = e.getUint8(t + 14), r = e.getUint8(t + 15);
733
+ this.ret = n & 15, this.returns = n >> 4, this.classFlags = r & 15, this.channel = r >> 4 & 3, this.scanDirection = r >> 6 & 1, this.edge = r >> 7, this.cls = e.getUint8(t + 16), this.user = e.getUint8(t + 17), this.angle = e.getInt16(t + 18, !0), this.psid = e.getUint16(t + 20, !0), this.gpsLow = e.getUint32(t + 22, !0), this.gpsHigh = e.getUint32(t + 26, !0), this.gpsChange = !1;
734
+ }
735
+ writeTo(e, t) {
736
+ e.setInt32(t, this.x, !0), e.setInt32(t + 4, this.y, !0), e.setInt32(t + 8, this.z, !0), e.setUint16(t + 12, this.intensity, !0), e.setUint8(t + 14, this.ret | this.returns << 4), e.setUint8(t + 15, this.classFlags | this.channel << 4 | this.scanDirection << 6 | this.edge << 7), e.setUint8(t + 16, this.cls), e.setUint8(t + 17, this.user), e.setInt16(t + 18, this.angle, !0), e.setUint16(t + 20, this.psid, !0), e.setUint32(t + 22, this.gpsLow, !0), e.setUint32(t + 26, this.gpsHigh, !0);
737
+ }
738
+ }, H = 0, U = 1, W = 2, G = 3, K = 4, q = 5, J = 6, Y = 7, ue = 8, de = class {
739
+ constructor(e) {
740
+ this.unused = !0, this.last = new V(), this.lastIntensity = /* @__PURE__ */ new Uint16Array(8), this.lastZ = /* @__PURE__ */ new Int32Array(8), this.medianX = D(12), this.medianY = D(12), this.changed = Array.from({ length: 8 }, () => new C(128)), this.channel = new C(3), this.returns = [], this.ret = [], this.retGpsSame = new C(13), this.classes = [], this.flags = [], this.userData = [], this.icX = new E(e[H], 32, 2), this.icY = new E(e[H], 32, 22), this.icZ = new E(e[U], 32, 20), this.icIntensity = new E(e[K], 16, 4), this.icAngle = new E(e[q], 16, 2), this.icPsid = new E(e[Y], 16), this.gps = new P(e[ue], !0);
741
+ }
742
+ reset(e) {
743
+ for (let e of this.changed) e.reset();
744
+ this.channel.reset(), this.retGpsSame.reset(), A(this.returns), A(this.ret), A(this.classes), A(this.flags), A(this.userData);
745
+ for (let e of [
746
+ this.icX,
747
+ this.icY,
748
+ this.icZ,
749
+ this.icIntensity,
750
+ this.icAngle,
751
+ this.icPsid
752
+ ]) e.reset();
753
+ for (let e of this.medianX) e.reset();
754
+ for (let e of this.medianY) e.reset();
755
+ this.lastZ.fill(e.z), this.lastIntensity.fill(e.intensity), this.gps.reset(e.gpsLow, e.gpsHigh), this.last.copy(e), this.last.gpsChange = !1, this.unused = !1;
756
+ }
757
+ }, fe = class {
758
+ constructor(e) {
759
+ this.channel = e, this.size = 30, this.layers = 9, this.dec = Array.from({ length: 9 }, () => new T()), this.has = Array(9).fill(!1), this.contexts = [], this.first = new V();
760
+ }
761
+ layer(e, t, n, r, i) {
762
+ this.has[e] = e === H || r > n, this.has[e] && this.dec[e].init(t, n, r, i);
763
+ }
764
+ context(e, t) {
765
+ let n = this.contexts[e] ??= new de(this.dec);
766
+ return n.reset(t), n;
767
+ }
768
+ init(e, t) {
769
+ this.first.readFrom(e, t);
770
+ for (let e of this.contexts) e && (e.unused = !0);
771
+ this.channel.current = this.channel.item = this.first.channel, this.context(this.first.channel, this.first);
772
+ }
773
+ read(e, t) {
774
+ let n = this.dec, r = this.has, i = this.contexts[this.channel.current], a = i.last, o = +(a.ret === 1) + (a.ret >= a.returns ? 2 : 0) + (a.gpsChange ? 4 : 0), s = n[H].decodeSymbol(i.changed[o]);
775
+ if (this.channel.item = 0, s & 64) {
776
+ let e = this.channel.current + n[H].decodeSymbol(i.channel) + 1 & 3, t = this.contexts[e];
777
+ i = t && !t.unused ? t : this.context(e, a), this.channel.current = this.channel.item = e, a = i.last, a.channel = e;
778
+ }
779
+ let c = !!(s & 32), l = !!(s & 16), u = !!(s & 8), d = +!!l, f = a.returns, p = a.ret;
780
+ s & 4 && (a.returns = n[H].decodeSymbol(k(i.returns, f, 16)));
781
+ let m = s & 3;
782
+ m === 1 ? a.ret = p + 1 & 15 : m === 2 ? a.ret = p + 15 & 15 : m === 3 && (a.ret = l ? n[H].decodeSymbol(k(i.ret, p, 16)) : p + n[H].decodeSymbol(i.retGpsSame) + 2 & 15);
783
+ let h = a.returns, g = a.ret, _ = re[h * 16 + g], v = ie[h * 16 + g], y = +(h === 1), b = (g === 1 ? 2 : 0) + +(g >= h), x = i.medianX[_ << 1 | d], S = i.medianY[_ << 1 | d], C = i.icX.decompress(x.get(), y);
784
+ a.x = a.x + C | 0, x.add(C);
785
+ let w = i.icX.k;
786
+ if (C = i.icY.decompress(S.get(), y + (w < 20 ? w & -2 : 20)), a.y = a.y + C | 0, S.add(C), r[U] && (w = i.icX.k + i.icY.k >>> 1, a.z = i.icZ.decompress(i.lastZ[v], y + (w < 18 ? w & -2 : 18)), i.lastZ[v] = a.z), r[W]) {
787
+ let e = ((a.cls & 31) << 1) + +(b === 3);
788
+ a.cls = n[W].decodeSymbol(k(i.classes, e, 256));
789
+ }
790
+ if (r[G]) {
791
+ let e = a.edge << 5 | a.scanDirection << 4 | a.classFlags, t = n[G].decodeSymbol(k(i.flags, e, 64));
792
+ a.edge = t >> 5 & 1, a.scanDirection = t >> 4 & 1, a.classFlags = t & 15;
793
+ }
794
+ if (r[K]) {
795
+ let e = b << 1 | d;
796
+ a.intensity = i.icIntensity.decompress(i.lastIntensity[e], b), i.lastIntensity[e] = a.intensity;
797
+ }
798
+ r[q] && u && (a.angle = i.icAngle.decompress(a.angle, d) << 16 >> 16), r[J] && (a.user = n[J].decodeSymbol(k(i.userData, a.user >> 2, 256))), r[Y] && c && (a.psid = i.icPsid.decompress(a.psid)), r[ue] && l && (i.gps.read(), a.gpsLow = i.gps.low[i.gps.last], a.gpsHigh = i.gps.high[i.gps.last]), a.writeTo(e, t), a.gpsChange = l;
799
+ }
800
+ }, X = class {
801
+ constructor(e) {
802
+ this.channel = e, this.dec = [], this.has = [], this.contexts = [], this.current = 0;
803
+ }
804
+ layer(e, t, n, r, i) {
805
+ this.dec[e] ??= new T(), this.has[e] = r > n, this.has[e] && this.dec[e].init(t, n, r, i);
806
+ }
807
+ context(e, t, n) {
808
+ let r = this.contexts[e] ??= this.create();
809
+ return this.start(r, t, n), r.unused = !1, r;
810
+ }
811
+ init(e, t) {
812
+ for (let e of this.contexts) e && (e.unused = !0);
813
+ this.current = this.channel.current, this.context(this.current, e, t);
814
+ }
815
+ read(e, t) {
816
+ let n = this.channel.item, r = this.contexts[this.current];
817
+ if (this.current !== n) {
818
+ this.current = n;
819
+ let e = this.contexts[n];
820
+ (!e || e.unused) && (r = this.context(n, r, 0));
821
+ }
822
+ this.decode(this.contexts[n], r, e, t);
823
+ }
824
+ }, pe = class {
825
+ constructor() {
826
+ this.unused = !0, this.last = /* @__PURE__ */ new Uint16Array(4), this.rgb = new F(), this.nirUsed = new C(4), this.nir = [new C(256), new C(256)];
827
+ }
828
+ }, me = class extends X {
829
+ constructor(e, t) {
830
+ super(e), this.size = t, this.layers = t === 8 ? 2 : 1;
831
+ }
832
+ create() {
833
+ return new pe();
834
+ }
835
+ start(e, t, n) {
836
+ e.rgb.reset(), e.nirUsed.reset();
837
+ for (let t of e.nir) t.reset();
838
+ if (!(t instanceof DataView)) e.last.set(t.last);
839
+ else for (let r = 0; r < this.size / 2; r++) e.last[r] = t.getUint16(n + r * 2, !0);
840
+ }
841
+ decode(e, t, n, r) {
842
+ let i = t.last;
843
+ if (this.has[0] && I(this.dec[0], e.rgb, i), L(n, r, i), this.layers === 2) {
844
+ if (this.has[1]) {
845
+ let t = this.dec[1], n = t.decodeSymbol(e.nirUsed), r = i[3], a = n & 1 ? t.decodeSymbol(e.nir[0]) + (r & 255) & 255 : r & 255;
846
+ a |= n & 2 ? (t.decodeSymbol(e.nir[1]) + (r >> 8) & 255) << 8 : r & 65280, i[3] = a;
847
+ }
848
+ n.setUint16(r + 6, i[3], !0);
849
+ }
850
+ }
851
+ }, he = class {
852
+ constructor(e) {
853
+ this.unused = !0, this.last = new Uint8Array(e), this.models = Array.from({ length: e }, () => new C(256));
854
+ }
855
+ }, ge = class extends X {
856
+ constructor(e, t) {
857
+ super(e), this.size = t, this.layers = t;
858
+ }
859
+ create() {
860
+ return new he(this.size);
861
+ }
862
+ start(e, t, n) {
863
+ if (A(e.models), t instanceof DataView) for (let r = 0; r < this.size; r++) e.last[r] = t.getUint8(n + r);
864
+ else e.last.set(t.last);
865
+ }
866
+ decode(e, t, n, r) {
867
+ let i = t.last;
868
+ for (let t = 0; t < this.size; t++) this.has[t] && (i[t] = i[t] + this.dec[t].decodeSymbol(e.models[t]) & 255), n.setUint8(r + t, i[t]);
869
+ }
870
+ }, _e = class {
871
+ constructor(e) {
872
+ this.unused = !0, this.last = new R(), this.models = new z(e);
873
+ }
874
+ }, ve = class extends X {
875
+ constructor(...e) {
876
+ super(...e), this.size = 29, this.layers = 1;
877
+ }
878
+ create() {
879
+ return new _e(this.dec[0]);
880
+ }
881
+ start(e, t, n) {
882
+ e.models.reset(), t instanceof DataView ? e.last.readFrom(t, n) : e.last.copy(t.last);
883
+ }
884
+ decode(e, t, n, r) {
885
+ this.has[0] && B(this.dec[0], e.models, t.last), t.last.writeTo(n, r);
886
+ }
887
+ };
888
+ function ye(e, t, n) {
889
+ let r = new DataView(e.buffer, e.byteOffset, e.byteLength), i = t.pointDataOffset + 8;
890
+ if (i > e.byteLength) throw RangeError("LAZ point data is shorter than its 8-byte chunk table offset; the file is truncated");
891
+ let a = Number(r.getBigInt64(t.pointDataOffset, !0));
892
+ if (a === -1 && e.byteLength >= i + 8 && (a = Number(r.getBigInt64(e.byteLength - 8, !0))), !(a >= i && a + 8 <= e.byteLength)) throw RangeError(`LAZ chunk table offset ${a} lies outside the file; the file is truncated or corrupt (LAZ is read through its chunk table)`);
893
+ let o = r.getUint32(a, !0), s = r.getUint32(a + 4, !0), c = n.chunkSize === "variable";
894
+ if (o !== 0) throw h(`chunk table version ${o}`);
895
+ let l = c ? void 0 : Math.ceil(t.pointCount / n.chunkSize);
896
+ if (l === void 0 ? s > t.pointCount : s !== l) throw RangeError(`LAZ chunk table lists ${s} chunks for ${t.pointCount} points${l === void 0 ? "" : ` (expected ${l})`}; the file is corrupt`);
897
+ let u = [];
898
+ if (!s) return u;
899
+ let d = new T(), f = new E(d, 32, 2);
900
+ d.init(e, a + 8, e.byteLength, "chunk table");
901
+ let p = 0, m = 0, g = i, _ = 0;
902
+ for (let e = 0; e < s; e++) {
903
+ if (p = c ? f.decompress(p, 0) : Math.min(n.chunkSize, t.pointCount - _), m = f.decompress(m, 1), p < 0 || m < 0 || g + m > a || _ + p > t.pointCount) throw RangeError(`LAZ chunk ${e} (${p} points, ${m} bytes at ${g}) does not fit the point data; the file is corrupt`);
904
+ u.push({
905
+ start: g,
906
+ end: g + m,
907
+ count: p
908
+ }), g += m, _ += p;
909
+ }
910
+ if (_ !== t.pointCount) throw RangeError(`LAZ chunks hold ${_} points but the header says ${t.pointCount}; the file is corrupt`);
911
+ return u;
912
+ }
913
+ function be(e) {
914
+ let t = new T(), d = e.compressor === 3, f = {
915
+ current: 0,
916
+ item: 0
917
+ };
918
+ return {
919
+ readers: e.items.map((e) => {
920
+ switch (e.type) {
921
+ case r: return new ae(t);
922
+ case i: return new oe(t);
923
+ case a: return new se(t);
924
+ case o: return new le(t);
925
+ case n: return new ce(t, e.size);
926
+ case s: return new fe(f);
927
+ case c:
928
+ case l: return new me(f, e.size);
929
+ case u: return new ve(f);
930
+ default: return new ge(f, e.size);
931
+ }
932
+ }),
933
+ dec: t,
934
+ layered: d
935
+ };
936
+ }
937
+ function Z(e, t, n, r, i, a) {
938
+ let { readers: o, dec: s, layered: c } = i, l = `chunk ${n}`, u = new DataView(a.buffer, a.byteOffset, a.byteLength);
939
+ if (!t.count) return;
940
+ let d = t.start + r;
941
+ if (d > t.end) throw RangeError(`LAZ ${l} is shorter than its first point; the file is corrupt`);
942
+ if (a.set(e.subarray(t.start, d)), c) {
943
+ let n = new DataView(e.buffer, e.byteOffset, e.byteLength), r = o, i = r.reduce((e, t) => e + t.layers, 0);
944
+ if (d + 4 + i * 4 > t.end) throw RangeError(`LAZ ${l} is shorter than its layer table; the file is corrupt`);
945
+ let a = n.getUint32(d, !0);
946
+ if (a !== t.count) throw RangeError(`LAZ ${l} holds ${a} points but its table says ${t.count}; the file is corrupt`);
947
+ let s = d + 4, c = s + i * 4, u = 0;
948
+ for (let i of r) for (let r = 0; r < i.layers; r++, s += 4, u++) {
949
+ let a = n.getUint32(s, !0);
950
+ if (c + a > t.end) throw RangeError(`LAZ ${l} layer sizes run past the chunk; the file is corrupt`);
951
+ i.layer(r, e, c, c + a, `${l} layer ${u}`), c += a;
952
+ }
953
+ } else s.init(e, d, t.end, l);
954
+ d = 0;
955
+ for (let e of o) e.init(u, d), d += e.size;
956
+ xe(o, u, 1, t.count, r);
957
+ }
958
+ function xe(e, t, n, r, i) {
959
+ for (let a = n; a < r; a++) {
960
+ let n = a * i;
961
+ for (let r of e) r.read(t, n), n += r.size;
962
+ }
963
+ }
964
+ var Q = 5e4;
965
+ function* Se(e, t, n) {
966
+ let r = t.pointRecordLength, i = t.pointCount;
967
+ if (!i) return;
968
+ let a = Math.min(Q, i), o = new Uint8Array(a * r);
969
+ if (t.pointDataOffset + r > e.byteLength) throw RangeError("LAZ point data is shorter than its first point; the file is truncated");
970
+ Z(e, {
971
+ start: t.pointDataOffset,
972
+ end: e.byteLength,
973
+ count: a
974
+ }, 0, r, n, o), yield o;
975
+ for (let e = a; e < i;) {
976
+ let t = Math.min(Q, i - e), a = new Uint8Array(t * r);
977
+ xe(n.readers, new DataView(a.buffer), 0, t, r), e += t, yield a;
978
+ }
979
+ }
980
+ var $ = () => globalThis.performance?.now() ?? Date.now();
981
+ async function* Ce(e, t, n, r = {}) {
982
+ let i = r.signal;
983
+ if (i?.throwIfAborted(), !t.compressed) throw TypeError("LAS file is not compressed (no LAZ bit in the point format); use parseLAS");
984
+ let a = p(n);
985
+ g(a, t);
986
+ let o = t.pointRecordLength;
987
+ if (a.compressor === 0) {
988
+ yield e.subarray(t.pointDataOffset, t.pointDataOffset + t.pointCount * o);
989
+ return;
990
+ }
991
+ let s = be(a), c = $(), l = async () => {
992
+ i?.throwIfAborted(), $() - c > 30 && (await new Promise((e) => setTimeout(e, 0)), i?.throwIfAborted(), c = $());
993
+ };
994
+ if (a.compressor === 1) {
995
+ for (let n of Se(e, t, s)) yield n, await l();
996
+ return;
997
+ }
998
+ let u = ye(e, t, a);
999
+ for (let t = 0; t < u.length; t++) {
1000
+ await l();
1001
+ let n = new Uint8Array(u[t].count * o);
1002
+ Z(e, u[t], t, o, s, n), yield n;
1003
+ }
1004
+ }
1005
+ function we(e, t, n, r) {
1006
+ let i = p(r);
1007
+ g(i, n);
1008
+ let a = n.pointRecordLength;
1009
+ if (!Number.isSafeInteger(t) || t < 0) throw RangeError(`LAZ chunk point count ${t} is not a whole number of 0 or more; pass the count its index gives`);
1010
+ if (t && i.compressor === 3 && e.byteLength >= a + 4) {
1011
+ let n = new DataView(e.buffer, e.byteOffset, e.byteLength).getUint32(a, !0);
1012
+ if (n !== t) throw RangeError(`LAZ chunk 0 holds ${n} points but its table says ${t}; the file is corrupt`);
1013
+ }
1014
+ let o = new Uint8Array(t * a);
1015
+ return Z(e, {
1016
+ start: 0,
1017
+ end: e.byteLength,
1018
+ count: t
1019
+ }, 0, a, be(i), o), o;
1020
+ }
1021
+ function Te() {
1022
+ return (e, t, n, r) => Ce(e, t, n, { signal: r });
1023
+ }
1024
+ //#endregion
1025
+ export { Te as createLazDecoder, we as decodeLazChunk, Ce as lazChunks, p as lazInfo };