@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/las.js ADDED
@@ -0,0 +1,500 @@
1
+ import { MargoError as e } from "@margoengine/math/errors";
2
+ //#region src/las.ts
3
+ var t = [
4
+ 20,
5
+ 28,
6
+ 26,
7
+ 34,
8
+ 57,
9
+ 63,
10
+ 30,
11
+ 36,
12
+ 38,
13
+ 59,
14
+ 67
15
+ ], n = [
16
+ -1,
17
+ 20,
18
+ -1,
19
+ 20,
20
+ 20,
21
+ 20,
22
+ 22,
23
+ 22,
24
+ 22,
25
+ 22,
26
+ 22
27
+ ], r = [
28
+ -1,
29
+ -1,
30
+ 20,
31
+ 28,
32
+ -1,
33
+ 28,
34
+ -1,
35
+ 30,
36
+ 30,
37
+ -1,
38
+ 30
39
+ ], i = [
40
+ 0,
41
+ 1,
42
+ 1,
43
+ 2,
44
+ 2,
45
+ 4,
46
+ 4,
47
+ 8,
48
+ 8,
49
+ 4,
50
+ 8
51
+ ], a = [
52
+ -1,
53
+ -1,
54
+ -1,
55
+ -1,
56
+ 28,
57
+ 34,
58
+ -1,
59
+ -1,
60
+ -1,
61
+ 30,
62
+ 38
63
+ ], o = (e, t, n = RangeError) => Object.assign(new n(t), { code: e }), s = /* @__PURE__ */ new TextDecoder("latin1"), c = (e, t, n) => {
64
+ let r = e.subarray(t, t + n), i = r.indexOf(0);
65
+ return s.decode(i < 0 ? r : r.subarray(0, i)).trimEnd();
66
+ };
67
+ function l(e) {
68
+ let n = e instanceof Uint8Array ? e : new Uint8Array(e);
69
+ if (n.byteLength < 227) throw o("header", "LAS file shorter than its 227-byte header; the file is truncated");
70
+ if (c(n, 0, 4) !== "LASF") throw o("header", "Not a LAS file (no LASF signature); pass a .las or .laz file", TypeError);
71
+ let r = new DataView(n.buffer, n.byteOffset, n.byteLength), i = (e) => r.getUint8(e), a = (e) => r.getUint16(e, !0), s = (e) => r.getUint32(e, !0), l = (e) => r.getFloat64(e, !0), u = (e) => Number(r.getBigUint64(e, !0)), d = i(24), f = i(25), p = a(94), m = s(96), h = s(100), g = i(104), _ = a(105);
72
+ if (d !== 1 || f > 5) throw o("unsupported", `Unsupported LAS version ${d}.${f}; read LAS 1.0 to 1.5`, TypeError);
73
+ if (p < 227 || p > n.byteLength || m < p) throw o("header", `LAS header size ${p} or point offset ${m} is invalid; the file is corrupt`);
74
+ if (m > n.byteLength) throw o("header", `LAS points start at ${m}, past the end of the file; the file is corrupt`);
75
+ let v = g & 63, y = !!(g & 192);
76
+ if (v > 10) throw o("unsupported", `Unsupported LAS point format ${v}; formats 0 to 10 exist`, TypeError);
77
+ if (_ < t[v]) throw o("header", `LAS record length ${_} is shorter than format ${v}'s ${t[v]} bytes; the file is corrupt`);
78
+ let b = s(107), x = [
79
+ 0,
80
+ 1,
81
+ 2,
82
+ 3,
83
+ 4
84
+ ].map((e) => s(111 + e * 4)), S = f >= 4 && p >= 375, C = f >= 5 && p >= 393;
85
+ if (S) {
86
+ b ||= u(247);
87
+ let e = x;
88
+ x = Array.from({ length: 15 }, (t, n) => n < 5 && e[n] || u(255 + n * 8));
89
+ }
90
+ let w = {
91
+ versionMajor: d,
92
+ versionMinor: f,
93
+ fileSourceId: a(4),
94
+ globalEncoding: a(6),
95
+ projectId: [...n.subarray(8, 24)].map((e) => e.toString(16).padStart(2, "0")).join(""),
96
+ systemIdentifier: c(n, 26, 32),
97
+ generatingSoftware: c(n, 58, 32),
98
+ creationDay: a(90),
99
+ creationYear: a(92),
100
+ headerSize: p,
101
+ pointDataOffset: m,
102
+ pointFormat: v,
103
+ compressed: y,
104
+ pointRecordLength: _,
105
+ pointCount: b,
106
+ pointsByReturn: x,
107
+ scale: [
108
+ l(131),
109
+ l(139),
110
+ l(147)
111
+ ],
112
+ offset: [
113
+ l(155),
114
+ l(163),
115
+ l(171)
116
+ ],
117
+ max: [
118
+ l(179),
119
+ l(195),
120
+ l(211)
121
+ ],
122
+ min: [
123
+ l(187),
124
+ l(203),
125
+ l(219)
126
+ ],
127
+ waveformDataOffset: f >= 3 && p >= 235 ? u(227) : 0,
128
+ timeOffset: C ? a(391) : 0,
129
+ ...C ? { gpsTimeRange: [l(383), l(375)] } : {}
130
+ };
131
+ if (!w.scale.every((e) => Number.isFinite(e) && e !== 0) || !w.offset.every(Number.isFinite)) throw o("range", "LAS scale or offset is zero or not finite; the file is corrupt");
132
+ let T = [], E = p;
133
+ for (let e = 0; e < h; e++) {
134
+ if (E + 54 > m || E + 54 > n.byteLength) throw o("truncated", `LAS VLR ${e} header runs past the point data offset; the file is corrupt`);
135
+ let t = a(E + 20);
136
+ if (E + 54 + t > m || E + 54 + t > n.byteLength) throw o("truncated", `LAS VLR ${e} data runs past the point data offset; the file is corrupt`);
137
+ T.push({
138
+ userId: c(n, E + 2, 16),
139
+ recordId: a(E + 18),
140
+ description: c(n, E + 22, 32),
141
+ data: n.subarray(E + 54, E + 54 + t),
142
+ extended: !1
143
+ }), E += 54 + t;
144
+ }
145
+ if (S) {
146
+ let e = u(235), t = s(243);
147
+ for (let r = 0; r < t && e && !(e + 60 > n.byteLength); r++) {
148
+ let t = u(e + 20);
149
+ if (e + 60 + t > n.byteLength) break;
150
+ T.push({
151
+ userId: c(n, e + 2, 16),
152
+ recordId: a(e + 18),
153
+ description: c(n, e + 28, 32),
154
+ data: n.subarray(e + 60, e + 60 + t),
155
+ extended: !0
156
+ }), e += 60 + t;
157
+ }
158
+ }
159
+ return {
160
+ header: w,
161
+ records: T
162
+ };
163
+ }
164
+ function u(e, n) {
165
+ let r = n.pointRecordLength - t[n.pointFormat], a = [], s = 0;
166
+ for (let t of e) {
167
+ if (t.userId !== "LASF_Spec" || t.recordId !== 4) continue;
168
+ let e = new DataView(t.data.buffer, t.data.byteOffset, t.data.byteLength);
169
+ for (let n = 0; n + 192 <= t.data.byteLength; n += 192) {
170
+ let l = e.getUint8(n + 2), u = e.getUint8(n + 3), d = c(t.data, n + 4, 32);
171
+ if (l > 30) throw o("header", `Extra bytes data type ${l} of ${d} is reserved; the file is corrupt`, TypeError);
172
+ let f = l > 10 ? (l - 1) % 10 + 1 : l, p = l > 20 ? 3 : l > 10 ? 2 : 1, m = f ? i[f] : u;
173
+ if (s + m * p > r) throw o("header", `Extra bytes ${d} pass the record length; the file is corrupt`);
174
+ for (let r = 0; r < p; r++) {
175
+ let i = n + 40 + r * 8;
176
+ a.push({
177
+ name: p > 1 ? `${d}[${r}]` : d,
178
+ description: c(t.data, n + 160, 32),
179
+ dataType: f,
180
+ offset: s,
181
+ size: m,
182
+ scale: u & 8 ? e.getFloat64(n + 112 + r * 8, !0) : 1,
183
+ addOffset: u & 16 ? e.getFloat64(n + 136 + r * 8, !0) : 0,
184
+ noData: u & 1 ? f >= 9 ? e.getFloat64(i, !0) : f % 2 == 0 && f ? Number(e.getBigInt64(i, !0)) : Number(e.getBigUint64(i, !0)) : void 0
185
+ }), s += m;
186
+ }
187
+ }
188
+ }
189
+ return a;
190
+ }
191
+ function d(e) {
192
+ let t = (t) => e.find((e) => e.userId === "LASF_Projection" && e.recordId === t), n = t(2112), r = t(34735);
193
+ if (!n && !r) return;
194
+ let i = n ? c(n.data, 0, n.data.byteLength) : void 0, a, o, l;
195
+ if (r && r.data.byteLength >= 8) {
196
+ let e = new DataView(r.data.buffer, r.data.byteOffset, r.data.byteLength), n = e.getUint16(6, !0), i = t(34736), c = t(34737);
197
+ a = /* @__PURE__ */ new Map();
198
+ for (let t = 0; t < n && 8 + t * 8 + 8 <= r.data.byteLength; t++) {
199
+ let n = 8 + t * 8, r = e.getUint16(n, !0), o = e.getUint16(n + 2, !0), l = e.getUint16(n + 4, !0), u = e.getUint16(n + 6, !0);
200
+ if (o === 0) a.set(r, u);
201
+ else if (o === 34736 && i) {
202
+ let e = new DataView(i.data.buffer, i.data.byteOffset, i.data.byteLength), t = [];
203
+ for (let n = 0; n < l && (u + n) * 8 + 8 <= i.data.byteLength; n++) t.push(e.getFloat64((u + n) * 8, !0));
204
+ a.set(r, l === 1 ? t[0] : t);
205
+ } else o === 34737 && c && a.set(r, s.decode(c.data.subarray(u, u + l)).replace(/[|\0]+$/, ""));
206
+ }
207
+ let u = a.get(3072), d = a.get(2048), f = a.get(4096), p = (e) => typeof e == "number" && e > 0 && e < 32767 ? e : void 0;
208
+ o = p(u) ?? p(d), l = p(f);
209
+ }
210
+ if (o === void 0 && i) {
211
+ let e = [...i.matchAll(/(?:AUTHORITY|ID)\[\s*"EPSG"\s*,\s*"?(\d+)"?\s*\]/g)];
212
+ e.length && (o = Number(e[e.length - 1][1]));
213
+ }
214
+ return {
215
+ wkt: i,
216
+ epsg: o,
217
+ verticalEpsg: l,
218
+ geoKeys: a
219
+ };
220
+ }
221
+ function f(e) {
222
+ let t = /* @__PURE__ */ new Map();
223
+ for (let n of e) {
224
+ if (n.userId !== "LASF_Spec" || n.recordId < 100 || n.recordId > 354 || n.data.byteLength < 26) continue;
225
+ let e = new DataView(n.data.buffer, n.data.byteOffset, n.data.byteLength);
226
+ t.set(n.recordId - 99, {
227
+ bitsPerSample: e.getUint8(0),
228
+ compression: e.getUint8(1),
229
+ samples: e.getUint32(2, !0),
230
+ spacing: e.getUint32(6, !0),
231
+ gain: e.getFloat64(10, !0),
232
+ offset: e.getFloat64(18, !0)
233
+ });
234
+ }
235
+ return t;
236
+ }
237
+ function p(t, n, r) {
238
+ let i = t.wavePackets, a = i?.descriptor[n];
239
+ if (!i || !a) return;
240
+ let s = f(t.records).get(a);
241
+ if (!s) throw o("header", `LAS point ${n} names wave packet descriptor ${a}, which the file lacks`);
242
+ let { bitsPerSample: c, samples: l, compression: u, gain: d, offset: p, spacing: m } = s;
243
+ if (u !== 0 || ![
244
+ 8,
245
+ 16,
246
+ 32
247
+ ].includes(c)) throw new e("unsupported", `LAS waveform samples of ${c} bits with compression ${u} are not read; 8, 16 and 32 uncompressed are`);
248
+ let h = (t.header.globalEncoding & 4 ? 0 : t.header.waveformDataOffset) + i.offset[n], g = Math.min(l, Math.floor(i.size[n] * 8 / c));
249
+ if (h + g * c / 8 > r.byteLength) throw o("truncated", `LAS waveform of point ${n} runs past the ${r.byteLength} bytes given`);
250
+ let _ = new DataView(r.buffer, r.byteOffset, r.byteLength), v = new Uint32Array(g), y = new Float64Array(g);
251
+ for (let e = 0; e < g; e++) {
252
+ let t = h + e * c / 8;
253
+ v[e] = c === 8 ? _.getUint8(t) : c === 16 ? _.getUint16(t, !0) : _.getUint32(t, !0), y[e] = p + d * v[e];
254
+ }
255
+ return {
256
+ raw: v,
257
+ volts: y,
258
+ spacing: m
259
+ };
260
+ }
261
+ async function m(e, t = {}) {
262
+ t.signal?.throwIfAborted();
263
+ let n = e instanceof Uint8Array ? e : new Uint8Array(e), { header: r, records: i } = l(n);
264
+ if (!r.compressed) return h(r, i, n.subarray(r.pointDataOffset), t);
265
+ let a = await (t.laz ?? (await import("./laz.js")).createLazDecoder())(n, r, i, t.signal);
266
+ if (t.signal?.throwIfAborted(), a instanceof Uint8Array) return h(r, i, a, t);
267
+ let s = g(r, i, t), c = r.pointRecordLength, u = s.stride, d = 0, f = 0;
268
+ for await (let e of a) {
269
+ t.signal?.throwIfAborted();
270
+ let n = new DataView(e.buffer, e.byteOffset, e.byteLength), r = Math.floor(e.byteLength / c);
271
+ for (let e = (u - d % u) % u; e < r && f < s.count; e += u) s.put(n, e * c, f++);
272
+ if (d += r, f >= s.count) break;
273
+ }
274
+ if (f < s.count && !t.partial) throw o("truncated", `LAZ decoder returned ${d} of ${r.pointCount} records; the file is truncated (pass partial: true to read what is there)`);
275
+ return s.finish(f);
276
+ }
277
+ function h(e, t, n, r = {}) {
278
+ let i = e.pointRecordLength, a = Math.floor(n.byteLength / i), s = g(e, t, r, Math.min(e.pointCount, a));
279
+ if (a < e.pointCount && !r.partial) throw o("truncated", `LAS point data holds ${a} of ${e.pointCount} records; the file is truncated (pass partial: true to read what is there)`);
280
+ let c = new DataView(n.buffer, n.byteOffset, n.byteLength);
281
+ for (let e = 0; e < s.count; e++) s.put(c, e * s.stride * i, e);
282
+ return s.finish(s.count);
283
+ }
284
+ function g(e, i, o, s = e.pointCount) {
285
+ let c = e.pointFormat, l = o.stride ?? 1, f = o.maxPoints ?? Infinity;
286
+ if (!Number.isInteger(l) || l < 1) throw RangeError("Invalid stride; pass a whole number of 1 or more");
287
+ if (!(f >= 0)) throw RangeError("Invalid maxPoints; pass a number of 0 or more");
288
+ let p = Math.min(Math.ceil(s / l), f), m = u(i, e), h = d(i), g = o.origin, _ = g === void 0 || g === "min", v = _ ? g === "min" ? e.min : [
289
+ 0,
290
+ 1,
291
+ 2
292
+ ].map((t) => (e.min[t] + e.max[t]) / 2) : g, y = c >= 6, b = n[c] >= 0, x = r[c] >= 0, S = c === 8 || c === 10, C = a[c], w = new Float32Array(p * 3), T = new Uint16Array(p), E = new Uint8Array(p), D = new Uint8Array(p), O = new Uint8Array(p), k = new Uint8Array(p), A = new Uint8Array(p), j = new Uint8Array(p), M = new Float32Array(p), N = new Uint8Array(p), P = new Uint16Array(p), F = y ? new Uint8Array(p) : void 0, I = b ? new Float64Array(p) : void 0, L = x ? new Uint16Array(p * 3) : void 0, R = S ? new Uint16Array(p) : void 0, z = C >= 0 ? new Uint8Array(p) : void 0, B = C >= 0 ? new Float64Array(p) : void 0, V = C >= 0 ? new Uint32Array(p) : void 0, H = C >= 0 ? new Float32Array(p) : void 0, U = C >= 0 ? new Float32Array(p * 3) : void 0, W = {};
293
+ for (let e of m) e.dataType && (W[e.name] = new Float64Array(p));
294
+ let [G, K, q] = e.scale, [J, Y, X] = e.offset, Z = t[c];
295
+ return {
296
+ count: p,
297
+ stride: l,
298
+ put: (t, i, a) => {
299
+ if (a === 0 && _) {
300
+ let n = [
301
+ t.getInt32(i, !0) * G + J,
302
+ t.getInt32(i + 4, !0) * K + Y,
303
+ t.getInt32(i + 8, !0) * q + X
304
+ ];
305
+ n.every((t, n) => t >= e.min[n] - e.scale[n] && t <= e.max[n] + e.scale[n]) || (v = n);
306
+ }
307
+ w[a * 3] = t.getInt32(i, !0) * G + J - v[0], w[a * 3 + 1] = t.getInt32(i + 4, !0) * K + Y - v[1], w[a * 3 + 2] = t.getInt32(i + 8, !0) * q + X - v[2], T[a] = t.getUint16(i + 12, !0);
308
+ let o = t.getUint8(i + 14);
309
+ if (y) {
310
+ E[a] = o & 15, D[a] = o >> 4;
311
+ let e = t.getUint8(i + 15);
312
+ k[a] = e & 15, F[a] = e >> 4 & 3, A[a] = e >> 6 & 1, j[a] = e >> 7, O[a] = t.getUint8(i + 16), N[a] = t.getUint8(i + 17), M[a] = t.getInt16(i + 18, !0) * .006, P[a] = t.getUint16(i + 20, !0);
313
+ } else {
314
+ E[a] = o & 7, D[a] = o >> 3 & 7, A[a] = o >> 6 & 1, j[a] = o >> 7;
315
+ let e = t.getUint8(i + 15);
316
+ O[a] = e & 31, k[a] = e >> 5 & 7, M[a] = t.getInt8(i + 16), N[a] = t.getUint8(i + 17), P[a] = t.getUint16(i + 18, !0);
317
+ }
318
+ if (I && (I[a] = t.getFloat64(i + n[c], !0)), L) {
319
+ let e = i + r[c];
320
+ L[a * 3] = t.getUint16(e, !0), L[a * 3 + 1] = t.getUint16(e + 2, !0), L[a * 3 + 2] = t.getUint16(e + 4, !0);
321
+ }
322
+ if (R && (R[a] = t.getUint16(i + 36, !0)), z) {
323
+ let e = i + C;
324
+ z[a] = t.getUint8(e), B[a] = Number(t.getBigUint64(e + 1, !0)), V[a] = t.getUint32(e + 9, !0), H[a] = t.getFloat32(e + 13, !0);
325
+ for (let n = 0; n < 3; n++) U[a * 3 + n] = t.getFloat32(e + 17 + n * 4, !0);
326
+ }
327
+ for (let e of m) {
328
+ if (!e.dataType) continue;
329
+ let n = i + Z + e.offset, r;
330
+ switch (e.dataType) {
331
+ case 1:
332
+ r = t.getUint8(n);
333
+ break;
334
+ case 2:
335
+ r = t.getInt8(n);
336
+ break;
337
+ case 3:
338
+ r = t.getUint16(n, !0);
339
+ break;
340
+ case 4:
341
+ r = t.getInt16(n, !0);
342
+ break;
343
+ case 5:
344
+ r = t.getUint32(n, !0);
345
+ break;
346
+ case 6:
347
+ r = t.getInt32(n, !0);
348
+ break;
349
+ case 7:
350
+ r = Number(t.getBigUint64(n, !0));
351
+ break;
352
+ case 8:
353
+ r = Number(t.getBigInt64(n, !0));
354
+ break;
355
+ case 9:
356
+ r = t.getFloat32(n, !0);
357
+ break;
358
+ default: r = t.getFloat64(n, !0);
359
+ }
360
+ W[e.name][a] = r === e.noData ? NaN : r * e.scale + e.addOffset;
361
+ }
362
+ },
363
+ finish: (t) => {
364
+ if (t < p) {
365
+ let e = (e, n = 1) => e.subarray(0, t * n);
366
+ w = e(w, 3), T = e(T), E = e(E), D = e(D), O = e(O), k = e(k), A = e(A), j = e(j), M = e(M), N = e(N), P = e(P), F &&= e(F), I &&= e(I), L &&= e(L, 3), R &&= e(R), z &&= e(z), B &&= e(B), V &&= e(V), H &&= e(H), U &&= e(U, 3);
367
+ for (let t of Object.keys(W)) W[t] = e(W[t]);
368
+ }
369
+ return {
370
+ header: e,
371
+ records: i,
372
+ crs: h,
373
+ extraBytes: m,
374
+ count: t,
375
+ origin: v,
376
+ positions: w,
377
+ intensity: T,
378
+ returnNumber: E,
379
+ numberOfReturns: D,
380
+ classification: O,
381
+ classificationFlags: k,
382
+ scanDirection: A,
383
+ edgeOfFlightLine: j,
384
+ scanAngle: M,
385
+ userData: N,
386
+ pointSourceId: P,
387
+ scannerChannel: F,
388
+ gpsTime: I,
389
+ rgb: L,
390
+ nir: R,
391
+ wavePackets: z && {
392
+ descriptor: z,
393
+ offset: B,
394
+ size: V,
395
+ location: H,
396
+ direction: U
397
+ },
398
+ extra: W
399
+ };
400
+ }
401
+ };
402
+ }
403
+ async function _(t, n = {}) {
404
+ let r = await (n.fetch ?? globalThis.fetch)(t, { signal: n.signal });
405
+ if (!r.ok) throw new e("failed", `GET ${t} answered ${r.status}; check the URL and the server`);
406
+ return m(await r.arrayBuffer(), n);
407
+ }
408
+ function v(e) {
409
+ let i = e.positions.length / 3;
410
+ if (!Number.isInteger(i)) throw RangeError("positions length must be a multiple of 3");
411
+ let a = e.pointFormat ?? (e.rgb ? 7 : 6), o = e.versionMinor ?? 4;
412
+ if (!Number.isInteger(a) || a < 0 || a > 10) throw RangeError("Invalid pointFormat; use 0 to 10");
413
+ if (!Number.isInteger(o) || o < 0 || o > 5) throw RangeError("Invalid versionMinor; use 0 to 5");
414
+ if (a >= 6 && o < 4) throw RangeError("Point formats 6 to 10 need LAS 1.4; set versionMinor to 4");
415
+ if (a < 6 && o >= 5) throw RangeError("LAS 1.5 removed point formats 0 to 5; use format 6 to 10");
416
+ if (e.epsg && !e.wkt && (a >= 6 || o >= 5)) throw RangeError("A GeoTIFF EPSG code needs point format 0 to 5 before LAS 1.5; pass the CRS as wkt");
417
+ let s = Object.keys(e.extra ?? {}), c = t[a], l = c + s.length * 8, u = e.scale ?? [
418
+ .001,
419
+ .001,
420
+ .001
421
+ ], d = [
422
+ Infinity,
423
+ Infinity,
424
+ Infinity
425
+ ], f = [
426
+ -Infinity,
427
+ -Infinity,
428
+ -Infinity
429
+ ];
430
+ for (let t = 0; t < i * 3; t++) {
431
+ let n = e.positions[t];
432
+ if (!Number.isFinite(n)) throw RangeError("positions must be finite");
433
+ n < d[t % 3] && (d[t % 3] = n), n > f[t % 3] && (f[t % 3] = n);
434
+ }
435
+ i || (d.fill(0), f.fill(0));
436
+ let p = d.map((e, t) => Math.floor((e + f[t]) / 2)), m = [];
437
+ if (s.length) {
438
+ let e = new Uint8Array(192 * s.length), t = new DataView(e.buffer);
439
+ s.forEach((n, r) => {
440
+ t.setUint8(r * 192 + 2, 10), e.set(new TextEncoder().encode(n.slice(0, 32)), r * 192 + 4);
441
+ }), m.push({
442
+ user: "LASF_Spec",
443
+ id: 4,
444
+ data: e
445
+ });
446
+ }
447
+ if (e.wkt && m.push({
448
+ user: "LASF_Projection",
449
+ id: 2112,
450
+ data: new TextEncoder().encode(`${e.wkt}\0`)
451
+ }), e.epsg) {
452
+ let t = new Uint16Array([
453
+ 1,
454
+ 1,
455
+ 0,
456
+ 1,
457
+ 3072,
458
+ 0,
459
+ 1,
460
+ e.epsg
461
+ ]);
462
+ m.push({
463
+ user: "LASF_Projection",
464
+ id: 34735,
465
+ data: new Uint8Array(t.buffer)
466
+ });
467
+ }
468
+ let h = o >= 5 ? 393 : o >= 4 ? 375 : o === 3 ? 235 : 227, g = h + m.reduce((e, t) => e + 54 + t.data.byteLength, 0), _ = new Uint8Array(g + i * l), v = new DataView(_.buffer), y = (e, t, n = 0) => e ? e[t] : n;
469
+ _.set([
470
+ 76,
471
+ 65,
472
+ 83,
473
+ 70
474
+ ]), v.setUint16(6, o >= 4 && e.wkt ? 16 : 0, !0), v.setUint8(24, 1), v.setUint8(25, o), _.set(new TextEncoder().encode("Margo Engine"), 58), v.setUint16(94, h, !0), v.setUint32(96, g, !0), v.setUint32(100, m.length, !0), v.setUint8(104, a), v.setUint16(105, l, !0), v.setUint32(107, a < 6 && i < 2 ** 32 ? i : 0, !0);
475
+ for (let e = 0; e < 3; e++) v.setFloat64(131 + e * 8, u[e], !0), v.setFloat64(155 + e * 8, p[e], !0), v.setFloat64(179 + e * 16, f[e], !0), v.setFloat64(187 + e * 16, d[e], !0);
476
+ let b = /* @__PURE__ */ new Float64Array(15), x = Infinity, S = -Infinity;
477
+ for (let t = 0; t < i; t++) {
478
+ let r = y(e.returnNumber, t, 1) & (a >= 6 ? 15 : 7);
479
+ r >= 1 && r <= 15 && b[r - 1]++, e.gpsTime && n[a] >= 0 && (x = Math.min(x, e.gpsTime[t]), S = Math.max(S, e.gpsTime[t]));
480
+ }
481
+ if (a < 6 && i < 2 ** 32) for (let e = 0; e < 5; e++) v.setUint32(111 + e * 4, b[e], !0);
482
+ if (o >= 4) {
483
+ v.setBigUint64(247, BigInt(i), !0);
484
+ for (let e = 0; e < 15; e++) v.setBigUint64(255 + e * 8, BigInt(b[e]), !0);
485
+ }
486
+ o >= 5 && x <= S && (v.setFloat64(375, S, !0), v.setFloat64(383, x, !0));
487
+ let C = h;
488
+ for (let e of m) _.set(new TextEncoder().encode(e.user), C + 2), v.setUint16(C + 18, e.id, !0), v.setUint16(C + 20, e.data.byteLength, !0), _.set(e.data, C + 54), C += 54 + e.data.byteLength;
489
+ for (let t = 0; t < i; t++) {
490
+ let i = g + t * l;
491
+ for (let n = 0; n < 3; n++) v.setInt32(i + n * 4, Math.round((e.positions[t * 3 + n] - p[n]) / u[n]), !0);
492
+ v.setUint16(i + 12, y(e.intensity, t), !0);
493
+ let o = y(e.returnNumber, t, 1), d = y(e.numberOfReturns, t, 1);
494
+ if (a >= 6 ? (v.setUint8(i + 14, o & 15 | (d & 15) << 4), v.setUint8(i + 16, y(e.classification, t)), v.setUint16(i + 20, y(e.pointSourceId, t), !0)) : (v.setUint8(i + 14, o & 7 | (d & 7) << 3), v.setUint8(i + 15, y(e.classification, t) & 31), v.setUint16(i + 18, y(e.pointSourceId, t), !0)), n[a] >= 0 && v.setFloat64(i + n[a], y(e.gpsTime, t), !0), r[a] >= 0) for (let n = 0; n < 3; n++) v.setUint16(i + r[a] + n * 2, y(e.rgb, t * 3 + n), !0);
495
+ (a === 8 || a === 10) && v.setUint16(i + 36, y(e.nir, t), !0), s.forEach((n, r) => v.setFloat64(i + c + r * 8, e.extra[n][t], !0));
496
+ }
497
+ return _;
498
+ }
499
+ //#endregion
500
+ export { t as LAS_RECORD_SIZES, h as decodePoints, d as lasCrs, u as lasExtraBytes, f as lasWaveDescriptors, p as lasWaveform, _ as loadLAS, m as parseLAS, l as readLASHeader, v as writeLAS };
package/dist/laz.d.ts ADDED
@@ -0,0 +1,50 @@
1
+ import type { LASHeader, LASRecord, LazDecoder } from './las.js';
2
+ /** One item of a LASzip record: a part of each point record and how it is compressed. */
3
+ export interface LazItem {
4
+ /** LASzip item type id: 0 BYTE, 6 POINT10, 7 GPSTIME11, 8 RGB12, 9 WAVEPACKET13, 10 POINT14, 11 RGB14, 12 RGBNIR14, 13 WAVEPACKET14, 14 BYTE14. */
5
+ readonly type: number;
6
+ /** The item's name, for messages (`POINT10`, `RGB14`, ...). */
7
+ readonly name: string;
8
+ /** Bytes of the point record the item covers. */
9
+ readonly size: number;
10
+ /** Compression version of the item. */
11
+ readonly version: number;
12
+ }
13
+ /** The LASzip record (user id `laszip encoded`, record id 22204) of a LAZ file. */
14
+ export interface LazInfo {
15
+ /** 0 none (plain records), 1 pointwise, 2 pointwise chunked (formats 0 to 5), 3 layered chunked (formats 6 to 10). */
16
+ readonly compressor: number;
17
+ /** 0: arithmetic coding (the only coder defined). */
18
+ readonly coder: number;
19
+ /** Version of the software that wrote the file, as `major.minor.revision`. */
20
+ readonly version: string;
21
+ readonly options: number;
22
+ /** Points per chunk, or `'variable'` when the chunk table stores each chunk's count. */
23
+ readonly chunkSize: number | 'variable';
24
+ readonly items: readonly LazItem[];
25
+ }
26
+ /** Options of `lazChunks`. */
27
+ export interface LazChunkOptions {
28
+ /** Stops decoding between chunks. */
29
+ readonly signal?: AbortSignal;
30
+ }
31
+ /** Reads the LASzip record. Throws a TypeError when the file has none or it is malformed. */
32
+ export declare function lazInfo(records: readonly LASRecord[]): LazInfo;
33
+ /**
34
+ * Decodes a LAZ file one chunk at a time: yields the uncompressed point records of each chunk, in file order. Stops
35
+ * with `signal` between chunks (and gives the event loop a turn about every 30 ms). Throws a MargoError with code
36
+ * `unsupported` for items this decoder does not read, a RangeError or TypeError for corrupt or truncated data.
37
+ */
38
+ export declare function lazChunks(file: Uint8Array, header: LASHeader, records: readonly LASRecord[], options?: LazChunkOptions): AsyncGenerator<Uint8Array, void, undefined>;
39
+ /**
40
+ * Decodes one chunk held by itself (a COPC node's bytes): `count` uncompressed point records, for a file with `header`
41
+ * and `records`. Throws as `lazChunks`.
42
+ */
43
+ export declare function decodeLazChunk(chunk: Uint8Array, count: number, header: LASHeader, records: readonly LASRecord[]): Uint8Array;
44
+ /**
45
+ * A LAZ decoder for `parseLAS` / `loadLAS`, which load this one by themselves when `options.laz` is not given. Point
46
+ * formats 0 to 5 (POINT10, GPSTIME11, RGB12 and extra bytes, version 2, WAVEPACKET13, version 1) and 6 to 10 (POINT14,
47
+ * RGB14, RGBNIR14, WAVEPACKET14 and extra bytes, layered version 3), pointwise, or in fixed or variable chunks. Decodes
48
+ * one chunk at a time into the point arrays.
49
+ */
50
+ export declare function createLazDecoder(): LazDecoder;