@vcollab/shader-library 0.0.0-stage → 1.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.
@@ -0,0 +1,451 @@
1
+ 'use strict';
2
+
3
+ // src/derived/errors.ts
4
+ var DerivedError = class extends Error {
5
+ name = "DerivedError";
6
+ };
7
+
8
+ // src/derived/dispatch.ts
9
+ var FAMILY_COMPONENTS = {
10
+ scalar: 1,
11
+ vector: 3,
12
+ dof6: 6,
13
+ symtensor: 6
14
+ };
15
+ var SCALAR_DISPATCH = {
16
+ identity: 0,
17
+ absolute: 1,
18
+ affine: 2,
19
+ celsius_to_kelvin: 3,
20
+ kelvin_to_celsius: 4,
21
+ fahrenheit_to_kelvin: 5,
22
+ kelvin_to_fahrenheit: 6,
23
+ fahrenheit_to_celsius: 7,
24
+ celsius_to_fahrenheit: 8
25
+ };
26
+ var VECTOR_DISPATCH = {
27
+ x: 0,
28
+ y: 1,
29
+ z: 2,
30
+ magnitude: 3
31
+ };
32
+ var DOF6_DISPATCH = {
33
+ tx: 0,
34
+ ty: 1,
35
+ tz: 2,
36
+ rx: 3,
37
+ ry: 4,
38
+ rz: 5,
39
+ translation_magnitude: 6,
40
+ rotation_magnitude: 7
41
+ };
42
+ var SYMTENSOR_DISPATCH = {
43
+ xx: 0,
44
+ yy: 1,
45
+ zz: 2,
46
+ xy: 3,
47
+ yz: 4,
48
+ xz: 5,
49
+ mean: 6,
50
+ von_mises: 7,
51
+ equivalent_strain: 8,
52
+ equivalent_strain_engineering: 9,
53
+ octahedral: 10,
54
+ max_shear: 11,
55
+ equal_direct: 12,
56
+ intensity: 13,
57
+ abs_max_principal: 14,
58
+ abs_max_principal_engineering: 15,
59
+ determinant: 16,
60
+ min_principal: 17,
61
+ min_principal_engineering: 18,
62
+ deviatoric_min_principal: 19,
63
+ mid_principal: 20,
64
+ mid_principal_engineering: 21,
65
+ deviatoric_mid_principal: 22,
66
+ max_principal: 23,
67
+ max_principal_engineering: 24,
68
+ deviatoric_max_principal: 25
69
+ };
70
+ var DISPATCH = {
71
+ scalar: SCALAR_DISPATCH,
72
+ vector: VECTOR_DISPATCH,
73
+ dof6: DOF6_DISPATCH,
74
+ symtensor: SYMTENSOR_DISPATCH
75
+ };
76
+ function dispatchTable(family) {
77
+ if (!Object.hasOwn(DISPATCH, family)) {
78
+ throw new DerivedError(
79
+ `there is no derived family ${JSON.stringify(family)}; there are ${Object.keys(DISPATCH).join(", ")}.`
80
+ );
81
+ }
82
+ return DISPATCH[family];
83
+ }
84
+ function derivedTypeNames(family) {
85
+ const table = dispatchTable(family);
86
+ return Object.keys(table).sort((a, b) => table[a] - table[b]);
87
+ }
88
+ function dispatchId(family, name) {
89
+ const table = dispatchTable(family);
90
+ return Object.hasOwn(table, name) ? table[name] : void 0;
91
+ }
92
+ function dispatchName(family, id) {
93
+ return Object.entries(dispatchTable(family)).find(([, value]) => value === id)?.[0];
94
+ }
95
+
96
+ // src/derived/kernels.ts
97
+ var SYMTENSOR_COMPONENTS = ["xx", "yy", "zz", "xy", "yz", "xz"];
98
+ var DOF6_COMPONENTS = ["tx", "ty", "tz", "rx", "ry", "rz"];
99
+ var VECTOR_COMPONENTS = ["x", "y", "z"];
100
+ var OCTAHEDRAL_SCALE = Math.SQRT2 / 3;
101
+ var F_SCALE = 5 / 9;
102
+ var KELVIN_OFFSET = 273.15;
103
+ var RANKINE_OFFSET = 459.67;
104
+ var TEMPERATURE_CONVERSIONS = {
105
+ celsius_to_kelvin: [1, KELVIN_OFFSET],
106
+ kelvin_to_celsius: [1, -KELVIN_OFFSET],
107
+ fahrenheit_to_kelvin: [F_SCALE, RANKINE_OFFSET * F_SCALE],
108
+ kelvin_to_fahrenheit: [1 / F_SCALE, -RANKINE_OFFSET],
109
+ fahrenheit_to_celsius: [F_SCALE, -32 * F_SCALE],
110
+ celsius_to_fahrenheit: [1 / F_SCALE, 32]
111
+ };
112
+ var at = (row, slot, order) => row[order == null ? slot : order[slot]];
113
+ function components6(row, order) {
114
+ return [
115
+ at(row, 0, order),
116
+ at(row, 1, order),
117
+ at(row, 2, order),
118
+ at(row, 3, order),
119
+ at(row, 4, order),
120
+ at(row, 5, order)
121
+ ];
122
+ }
123
+ var affine = (a, scale = 1, offset = 0) => a * scale + offset;
124
+ function vectorMagnitude(row, order) {
125
+ const x = at(row, 0, order);
126
+ const y = at(row, 1, order);
127
+ const z = at(row, 2, order);
128
+ return Math.sqrt(x * x + y * y + z * z);
129
+ }
130
+ function translationMagnitude(row, order) {
131
+ const x = at(row, 0, order);
132
+ const y = at(row, 1, order);
133
+ const z = at(row, 2, order);
134
+ return Math.sqrt(x * x + y * y + z * z);
135
+ }
136
+ function rotationMagnitude(row, order) {
137
+ const x = at(row, 3, order);
138
+ const y = at(row, 4, order);
139
+ const z = at(row, 5, order);
140
+ return Math.sqrt(x * x + y * y + z * z);
141
+ }
142
+ function mean(row, order) {
143
+ return (at(row, 0, order) + at(row, 1, order) + at(row, 2, order)) / 3;
144
+ }
145
+ function vonMises(row, scale = 1, shearFactor = 1, order) {
146
+ const [xx, yy, zz, xy, yz, xz] = components6(row, order);
147
+ const f2 = shearFactor * shearFactor;
148
+ const squared = 0.5 * ((xx - yy) ** 2 + (yy - zz) ** 2 + (zz - xx) ** 2) + 3 * f2 * (xy * xy + yz * yz + xz * xz);
149
+ return scale * Math.sqrt(squared);
150
+ }
151
+ function equivalentStrain(row, nu = 0.5, shearFactor = 1, order) {
152
+ return vonMises(row, 1 / (1 + nu), shearFactor, order);
153
+ }
154
+ function octahedral(row, shearFactor = 1, order) {
155
+ return vonMises(row, OCTAHEDRAL_SCALE, shearFactor, order);
156
+ }
157
+ function determinant(row, shearFactor = 1, order) {
158
+ const [xx, yy, zz] = components6(row, order);
159
+ const xy = shearFactor * at(row, 3, order);
160
+ const yz = shearFactor * at(row, 4, order);
161
+ const xz = shearFactor * at(row, 5, order);
162
+ return xx * yy * zz + 2 * xy * yz * xz - xy * xy * zz - yz * yz * xx - xz * xz * yy;
163
+ }
164
+ function principals(row, shearFactor = 1, order) {
165
+ const [xx, yy, zz, xy0, yz0, xz0] = components6(row, order);
166
+ const entries = [xx, yy, zz, xy0, yz0, xz0];
167
+ if (!Number.isFinite(xx + yy + zz + xy0 + yz0 + xz0) && !entries.every(Number.isFinite)) {
168
+ if (entries.some(Number.isNaN)) return [Number.NaN, Number.NaN, Number.NaN];
169
+ throw new DerivedError(
170
+ `a tensor with an infinite component (${entries.join(", ")}) has no principal values.`
171
+ );
172
+ }
173
+ let a00 = xx;
174
+ let a11 = yy;
175
+ let a22 = zz;
176
+ let a01 = shearFactor * xy0;
177
+ let a12 = shearFactor * yz0;
178
+ let a02 = shearFactor * xz0;
179
+ for (let sweep = 0; sweep < 24; sweep++) {
180
+ const off = Math.abs(a01) + Math.abs(a12) + Math.abs(a02);
181
+ if (off === 0) break;
182
+ const rotate = (app, aqq, apq) => {
183
+ const theta = (aqq - app) / (2 * apq);
184
+ const t = Math.sign(theta || 1) / (Math.abs(theta) + Math.sqrt(theta * theta + 1));
185
+ return [t, 1 / Math.sqrt(t * t + 1)];
186
+ };
187
+ if (a01 !== 0) {
188
+ const [t, c] = rotate(a00, a11, a01);
189
+ const s = t * c;
190
+ const n00 = a00 - t * a01;
191
+ const n11 = a11 + t * a01;
192
+ const n02 = c * a02 - s * a12;
193
+ const n12 = s * a02 + c * a12;
194
+ a00 = n00;
195
+ a11 = n11;
196
+ a01 = 0;
197
+ a02 = n02;
198
+ a12 = n12;
199
+ }
200
+ if (a02 !== 0) {
201
+ const [t, c] = rotate(a00, a22, a02);
202
+ const s = t * c;
203
+ const n00 = a00 - t * a02;
204
+ const n22 = a22 + t * a02;
205
+ const n01 = c * a01 - s * a12;
206
+ const n12 = s * a01 + c * a12;
207
+ a00 = n00;
208
+ a22 = n22;
209
+ a02 = 0;
210
+ a01 = n01;
211
+ a12 = n12;
212
+ }
213
+ if (a12 !== 0) {
214
+ const [t, c] = rotate(a11, a22, a12);
215
+ const s = t * c;
216
+ const n11 = a11 - t * a12;
217
+ const n22 = a22 + t * a12;
218
+ const n01 = c * a01 - s * a02;
219
+ const n02 = s * a01 + c * a02;
220
+ a11 = n11;
221
+ a22 = n22;
222
+ a12 = 0;
223
+ a01 = n01;
224
+ a02 = n02;
225
+ }
226
+ }
227
+ const roots = [a00, a11, a22];
228
+ roots.sort((x, y) => x - y);
229
+ return roots;
230
+ }
231
+ function maxShear(row, shearFactor = 1, order) {
232
+ const p = principals(row, shearFactor, order);
233
+ return 0.5 * (p[2] - p[0]);
234
+ }
235
+ function equalDirect(row, shearFactor = 1, order) {
236
+ const p = principals(row, shearFactor, order);
237
+ return 0.5 * (p[2] + p[0]);
238
+ }
239
+ function intensity(row, shearFactor = 1, order) {
240
+ const p = principals(row, shearFactor, order);
241
+ return p[2] - p[0];
242
+ }
243
+ function absMaxPrincipal(row, shearFactor = 1, order) {
244
+ const p = principals(row, shearFactor, order);
245
+ let best = p[0];
246
+ for (const value of p) {
247
+ const byMagnitude = Math.abs(value) - Math.abs(best);
248
+ if (byMagnitude > 0 || byMagnitude === 0 && value > best) best = value;
249
+ }
250
+ return best;
251
+ }
252
+ function deviatoricPrincipal(row, index, shearFactor = 1, order) {
253
+ return principals(row, shearFactor, order)[index] - mean(row, order);
254
+ }
255
+
256
+ // src/derived/index.ts
257
+ var ENGINEERING_SHEAR = 0.5;
258
+ function component(slot) {
259
+ return (row, { order }) => order == null ? row[slot] : row[order[slot]];
260
+ }
261
+ var SCALAR_KERNELS = {
262
+ identity: (row) => row[0],
263
+ absolute: (row) => Math.abs(row[0]),
264
+ affine: (row, { scale = 1, offset = 0 }) => affine(row[0], scale, offset),
265
+ ...Object.fromEntries(
266
+ Object.entries(TEMPERATURE_CONVERSIONS).map(([name, [scale, offset]]) => [
267
+ name,
268
+ ((row) => affine(row[0], scale, offset))
269
+ ])
270
+ )
271
+ };
272
+ var VECTOR_KERNELS = {
273
+ x: component(0),
274
+ y: component(1),
275
+ z: component(2),
276
+ magnitude: (row, { order }) => vectorMagnitude(row, order)
277
+ };
278
+ var DOF6_KERNELS = {
279
+ tx: component(0),
280
+ ty: component(1),
281
+ tz: component(2),
282
+ rx: component(3),
283
+ ry: component(4),
284
+ rz: component(5),
285
+ translation_magnitude: (row, { order }) => translationMagnitude(row, order),
286
+ rotation_magnitude: (row, { order }) => rotationMagnitude(row, order)
287
+ };
288
+ var PRINCIPAL_SLOT = { min: 0, mid: 1, max: 2 };
289
+ var SYMTENSOR_KERNELS = {
290
+ xx: component(0),
291
+ yy: component(1),
292
+ zz: component(2),
293
+ xy: component(3),
294
+ yz: component(4),
295
+ xz: component(5),
296
+ mean: (row, { order }) => mean(row, order),
297
+ von_mises: (row, { order }) => vonMises(row, 1, 1, order),
298
+ equivalent_strain: (row, { nu = 0.5, order }) => equivalentStrain(row, nu, 1, order),
299
+ equivalent_strain_engineering: (row, { nu = 0.5, order }) => equivalentStrain(row, nu, ENGINEERING_SHEAR, order),
300
+ octahedral: (row, { order }) => octahedral(row, 1, order),
301
+ max_shear: (row, { order }) => maxShear(row, 1, order),
302
+ equal_direct: (row, { order }) => equalDirect(row, 1, order),
303
+ intensity: (row, { order }) => intensity(row, 1, order),
304
+ abs_max_principal: (row, { order }) => absMaxPrincipal(row, 1, order),
305
+ abs_max_principal_engineering: (row, { order }) => absMaxPrincipal(row, ENGINEERING_SHEAR, order),
306
+ determinant: (row, { order }) => determinant(row, 1, order),
307
+ ...Object.fromEntries(
308
+ Object.entries(PRINCIPAL_SLOT).flatMap(([which, slot]) => [
309
+ [
310
+ `${which}_principal`,
311
+ ((row, { order }) => principals(row, 1, order)[slot])
312
+ ],
313
+ [
314
+ `${which}_principal_engineering`,
315
+ ((row, { order }) => principals(row, ENGINEERING_SHEAR, order)[slot])
316
+ ],
317
+ [
318
+ `deviatoric_${which}_principal`,
319
+ ((row, { order }) => deviatoricPrincipal(row, slot, 1, order))
320
+ ]
321
+ ])
322
+ )
323
+ };
324
+ var KERNELS = {
325
+ scalar: SCALAR_KERNELS,
326
+ vector: VECTOR_KERNELS,
327
+ dof6: DOF6_KERNELS,
328
+ symtensor: SYMTENSOR_KERNELS
329
+ };
330
+ function kernelFor(family, type) {
331
+ const dispatch = dispatchTable(family);
332
+ const table = KERNELS[family];
333
+ const name = typeof type === "number" ? Object.entries(dispatch).find(([, id]) => id === type)?.[0] : type;
334
+ const kernel = name !== void 0 && Object.hasOwn(table, name) ? table[name] : void 0;
335
+ if (kernel === void 0) {
336
+ throw new DerivedError(
337
+ `the ${family} family has no derived type ${JSON.stringify(type)}; it offers ${Object.keys(table).sort().join(", ")}.`
338
+ );
339
+ }
340
+ return kernel;
341
+ }
342
+ function checkOrder(family, width, order) {
343
+ if (order == null) return;
344
+ const seen = /* @__PURE__ */ new Set();
345
+ for (let slot = 0; slot < order.length; slot++) {
346
+ const index = order[slot];
347
+ if (!Number.isInteger(index) || index < 0 || index >= width || seen.has(index)) {
348
+ throw new DerivedError(
349
+ `order[${slot}] is ${String(index)}, but a ${family} order is a permutation of 0..${width - 1}: each index once.`
350
+ );
351
+ }
352
+ seen.add(index);
353
+ }
354
+ if (order.length !== width) {
355
+ throw new DerivedError(`a ${family} order names ${width} slot(s); got ${order.length}.`);
356
+ }
357
+ }
358
+ function hasNoValue(row, width) {
359
+ for (let slot = 0; slot < width; slot++) if (Number.isNaN(row[slot])) return true;
360
+ return false;
361
+ }
362
+ function widthOf(family) {
363
+ dispatchTable(family);
364
+ return FAMILY_COMPONENTS[family];
365
+ }
366
+ function computeDerived(family, type, datum, options = {}) {
367
+ const width = widthOf(family);
368
+ if (datum.length < width) {
369
+ throw new DerivedError(`a ${family} datum has ${width} component(s); got ${datum.length}.`);
370
+ }
371
+ checkOrder(family, width, options.order);
372
+ const kernel = kernelFor(family, type);
373
+ return hasNoValue(datum, width) ? Number.NaN : kernel(datum, options);
374
+ }
375
+ function computeDerivedField(family, type, field, options = {}, out) {
376
+ const width = widthOf(family);
377
+ if (field.length % width !== 0) {
378
+ throw new DerivedError(
379
+ `a ${family} field holds ${width} component(s) per datum, and ${field.length} values is not a whole number of them.`
380
+ );
381
+ }
382
+ const count = field.length / width;
383
+ const result = out ?? new Float32Array(count);
384
+ if (result.length < count) {
385
+ throw new DerivedError(`the output holds ${result.length} value(s); the field has ${count}.`);
386
+ }
387
+ checkOrder(family, width, options.order);
388
+ const kernel = kernelFor(family, type);
389
+ const datum = ArrayBuffer.isView(field) && field instanceof Float32Array ? field.subarray(0, width) : void 0;
390
+ for (let index = 0; index < count; index++) {
391
+ const at2 = index * width;
392
+ if (datum !== void 0) {
393
+ const row = field.subarray(at2, at2 + width);
394
+ result[index] = hasNoValue(row, width) ? Number.NaN : kernel(row, options);
395
+ } else {
396
+ const row = [];
397
+ for (let slot = 0; slot < width; slot++) row.push(field[at2 + slot]);
398
+ result[index] = hasNoValue(row, width) ? Number.NaN : kernel(row, options);
399
+ }
400
+ }
401
+ return result;
402
+ }
403
+ function fieldRange(values) {
404
+ let min = Number.POSITIVE_INFINITY;
405
+ let max = Number.NEGATIVE_INFINITY;
406
+ let seen = false;
407
+ for (let index = 0; index < values.length; index++) {
408
+ const value = values[index];
409
+ if (!Number.isFinite(value)) continue;
410
+ seen = true;
411
+ if (value < min) min = value;
412
+ if (value > max) max = value;
413
+ }
414
+ return seen ? { min, max } : null;
415
+ }
416
+
417
+ exports.DISPATCH = DISPATCH;
418
+ exports.DOF6_COMPONENTS = DOF6_COMPONENTS;
419
+ exports.DOF6_DISPATCH = DOF6_DISPATCH;
420
+ exports.DerivedError = DerivedError;
421
+ exports.FAMILY_COMPONENTS = FAMILY_COMPONENTS;
422
+ exports.SCALAR_DISPATCH = SCALAR_DISPATCH;
423
+ exports.SYMTENSOR_COMPONENTS = SYMTENSOR_COMPONENTS;
424
+ exports.SYMTENSOR_DISPATCH = SYMTENSOR_DISPATCH;
425
+ exports.TEMPERATURE_CONVERSIONS = TEMPERATURE_CONVERSIONS;
426
+ exports.VECTOR_COMPONENTS = VECTOR_COMPONENTS;
427
+ exports.VECTOR_DISPATCH = VECTOR_DISPATCH;
428
+ exports.absMaxPrincipal = absMaxPrincipal;
429
+ exports.affine = affine;
430
+ exports.computeDerived = computeDerived;
431
+ exports.computeDerivedField = computeDerivedField;
432
+ exports.derivedTypeNames = derivedTypeNames;
433
+ exports.determinant = determinant;
434
+ exports.deviatoricPrincipal = deviatoricPrincipal;
435
+ exports.dispatchId = dispatchId;
436
+ exports.dispatchName = dispatchName;
437
+ exports.dispatchTable = dispatchTable;
438
+ exports.equalDirect = equalDirect;
439
+ exports.equivalentStrain = equivalentStrain;
440
+ exports.fieldRange = fieldRange;
441
+ exports.intensity = intensity;
442
+ exports.maxShear = maxShear;
443
+ exports.mean = mean;
444
+ exports.octahedral = octahedral;
445
+ exports.principals = principals;
446
+ exports.rotationMagnitude = rotationMagnitude;
447
+ exports.translationMagnitude = translationMagnitude;
448
+ exports.vectorMagnitude = vectorMagnitude;
449
+ exports.vonMises = vonMises;
450
+ //# sourceMappingURL=index.cjs.map
451
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/derived/errors.ts","../../src/derived/dispatch.ts","../../src/derived/kernels.ts","../../src/derived/index.ts"],"names":["at"],"mappings":";;;AAIO,IAAM,YAAA,GAAN,cAA2B,KAAA,CAAM;AAAA,EACpB,IAAA,GAAO,cAAA;AAC3B;;;ACoBO,IAAM,iBAAA,GAA6D;AAAA,EACxE,MAAA,EAAQ,CAAA;AAAA,EACR,MAAA,EAAQ,CAAA;AAAA,EACR,IAAA,EAAM,CAAA;AAAA,EACN,SAAA,EAAW;AACb;AAGO,IAAM,eAAA,GAAkB;AAAA,EAC7B,QAAA,EAAU,CAAA;AAAA,EACV,QAAA,EAAU,CAAA;AAAA,EACV,MAAA,EAAQ,CAAA;AAAA,EACR,iBAAA,EAAmB,CAAA;AAAA,EACnB,iBAAA,EAAmB,CAAA;AAAA,EACnB,oBAAA,EAAsB,CAAA;AAAA,EACtB,oBAAA,EAAsB,CAAA;AAAA,EACtB,qBAAA,EA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I,IAAA;AAC/B","file":"index.cjs","sourcesContent":["// Copyright Visual Collaboration Technologies Inc. All Rights Reserved.\n// See LICENSE for details.\n\n/** Raised for a derived type that cannot be computed as asked. */\nexport class DerivedError extends Error {\n override readonly name = \"DerivedError\";\n}\n","// Copyright Visual Collaboration Technologies Inc. All Rights Reserved.\n// See LICENSE for details.\n\n/**\n * The dispatch integers, per family.\n *\n * These are the numbers written to `u_derivedType`. They are declared as data\n * rather than derived from an order of registration, and they are\n * **append-only**: a shipped number is never reused or reassigned, and a\n * retired one stays reserved. Numbering restarts per family, over\n * scalar-output entries only, so adding a vector-valued quantity can never\n * shift the scalar sequence — `symtensor.von_mises` stays 7.\n *\n * The table is duplicated from `vcti.derived` on purpose: a consumer must be\n * able to name a derived type before it has loaded an artifact set. That it\n * still agrees with the contracts the set ships is a test, not an assumption —\n * every entry here is checked against the `namedValues` of the shipped\n * `u_derivedType` uniform.\n */\n\nimport { DerivedError } from \"./errors.js\";\n\n/** A family of result data, by the shape of one datum. */\nexport type DerivedFamily = \"scalar\" | \"vector\" | \"dof6\" | \"symtensor\";\n\n/** How many components one datum of each family carries. */\nexport const FAMILY_COMPONENTS: Readonly<Record<DerivedFamily, number>> = {\n scalar: 1,\n vector: 3,\n dof6: 6,\n symtensor: 6,\n};\n\n/** Scalar-family dispatch integers. */\nexport const SCALAR_DISPATCH = {\n identity: 0,\n absolute: 1,\n affine: 2,\n celsius_to_kelvin: 3,\n kelvin_to_celsius: 4,\n fahrenheit_to_kelvin: 5,\n kelvin_to_fahrenheit: 6,\n fahrenheit_to_celsius: 7,\n celsius_to_fahrenheit: 8,\n} as const;\n\n/** Vector-family dispatch integers. */\nexport const VECTOR_DISPATCH = {\n x: 0,\n y: 1,\n z: 2,\n magnitude: 3,\n} as const;\n\n/** 6-DOF-family dispatch integers. */\nexport const DOF6_DISPATCH = {\n tx: 0,\n ty: 1,\n tz: 2,\n rx: 3,\n ry: 4,\n rz: 5,\n translation_magnitude: 6,\n rotation_magnitude: 7,\n} as const;\n\n/** Symmetric-tensor-family dispatch integers. */\nexport const SYMTENSOR_DISPATCH = {\n xx: 0,\n yy: 1,\n zz: 2,\n xy: 3,\n yz: 4,\n xz: 5,\n mean: 6,\n von_mises: 7,\n equivalent_strain: 8,\n equivalent_strain_engineering: 9,\n octahedral: 10,\n max_shear: 11,\n equal_direct: 12,\n intensity: 13,\n abs_max_principal: 14,\n abs_max_principal_engineering: 15,\n determinant: 16,\n min_principal: 17,\n min_principal_engineering: 18,\n deviatoric_min_principal: 19,\n mid_principal: 20,\n mid_principal_engineering: 21,\n deviatoric_mid_principal: 22,\n max_principal: 23,\n max_principal_engineering: 24,\n deviatoric_max_principal: 25,\n} as const;\n\n/** Every family's table, by family. */\nexport const DISPATCH: Readonly<Record<DerivedFamily, Readonly<Record<string, number>>>> = {\n scalar: SCALAR_DISPATCH,\n vector: VECTOR_DISPATCH,\n dof6: DOF6_DISPATCH,\n symtensor: SYMTENSOR_DISPATCH,\n};\n\n/**\n * The dispatch table of one family.\n *\n * Looked up as an own property, so a name such as `constructor` or\n * `toString` is not mistaken for a family.\n *\n * @throws {DerivedError} if `family` is not one of the four.\n */\nexport function dispatchTable(family: DerivedFamily): Readonly<Record<string, number>> {\n if (!Object.hasOwn(DISPATCH, family)) {\n throw new DerivedError(\n `there is no derived family ${JSON.stringify(family)}; there are ` +\n `${Object.keys(DISPATCH).join(\", \")}.`,\n );\n }\n return DISPATCH[family];\n}\n\n/** The derived type names a family offers, in dispatch order. */\nexport function derivedTypeNames(family: DerivedFamily): string[] {\n const table = dispatchTable(family);\n return Object.keys(table).sort((a, b) => (table[a] as number) - (table[b] as number));\n}\n\n/** The dispatch integer for a name, or `undefined` if the family has no such type. */\nexport function dispatchId(family: DerivedFamily, name: string): number | undefined {\n const table = dispatchTable(family);\n return Object.hasOwn(table, name) ? table[name] : undefined;\n}\n\n/** The name a dispatch integer stands for, or `undefined`. */\nexport function dispatchName(family: DerivedFamily, id: number): string | undefined {\n return Object.entries(dispatchTable(family)).find(([, value]) => value === id)?.[0];\n}\n","// Copyright Visual Collaboration Technologies Inc. All Rights Reserved.\n// See LICENSE for details.\n\n/**\n * The derived-quantity math, on the CPU.\n *\n * The same quantities the `derive` shader feature computes on the GPU, for the\n * work a consumer has to do before it draws — above all a value range, which\n * decides the fringe bands and cannot be read back out of a shader.\n *\n * **This is a second implementation of math that already exists twice**, in\n * Slang and in `vcti.derived`, and the system's answer to that is machinery\n * rather than care: `vcti.derived` is the oracle, the shader feature's\n * execution tests pin the GPU code to it, and this package's tests pin these\n * functions to vectors exported from it. Formulas here follow that package\n * function for function, including its tie-breaks.\n *\n * Components are read through an `order` indirection rather than reordered, so\n * a caller whose data is stored in a different component order passes the\n * permutation instead of copying the buffer — the same indirection the shader\n * takes as `u_componentOrder`. These functions trust `order`;\n * `computeDerived` and `computeDerivedField` check it is a permutation first.\n */\n\nimport { DerivedError } from \"./errors.js\";\n\n/** Canonical symmetric-tensor component order: xx, yy, zz, xy, yz, xz. */\nexport const SYMTENSOR_COMPONENTS = [\"xx\", \"yy\", \"zz\", \"xy\", \"yz\", \"xz\"] as const;\n\n/** Canonical 6-DOF component order: translations then rotations. */\nexport const DOF6_COMPONENTS = [\"tx\", \"ty\", \"tz\", \"rx\", \"ry\", \"rz\"] as const;\n\n/** Canonical vector component order. */\nexport const VECTOR_COMPONENTS = [\"x\", \"y\", \"z\"] as const;\n\nconst OCTAHEDRAL_SCALE = Math.SQRT2 / 3.0;\nconst F_SCALE = 5.0 / 9.0;\nconst KELVIN_OFFSET = 273.15;\nconst RANKINE_OFFSET = 459.67;\n\n/** Named affine temperature conversions: `y = scale·x + offset`. */\nexport const TEMPERATURE_CONVERSIONS: Readonly<Record<string, readonly [number, number]>> = {\n celsius_to_kelvin: [1.0, KELVIN_OFFSET],\n kelvin_to_celsius: [1.0, -KELVIN_OFFSET],\n fahrenheit_to_kelvin: [F_SCALE, RANKINE_OFFSET * F_SCALE],\n kelvin_to_fahrenheit: [1.0 / F_SCALE, -RANKINE_OFFSET],\n fahrenheit_to_celsius: [F_SCALE, -32.0 * F_SCALE],\n celsius_to_fahrenheit: [1.0 / F_SCALE, 32.0],\n};\n\n/**\n * A component permutation: `order[slot]` is the index the canonical slot is\n * stored at. `null` means the data is already canonical.\n */\nexport type ComponentOrder = ArrayLike<number> | null | undefined;\n\nconst at = (row: ArrayLike<number>, slot: number, order: ComponentOrder): number =>\n row[order == null ? slot : (order[slot] as number)] as number;\n\n/** One symmetric tensor's six components, in canonical order. */\nfunction components6(\n row: ArrayLike<number>,\n order: ComponentOrder,\n): [number, number, number, number, number, number] {\n return [\n at(row, 0, order),\n at(row, 1, order),\n at(row, 2, order),\n at(row, 3, order),\n at(row, 4, order),\n at(row, 5, order),\n ];\n}\n\n/* ------------------------------------------------------------------ scalar */\n\n/** `a · scale + offset`. */\nexport const affine = (a: number, scale = 1.0, offset = 0.0): number => a * scale + offset;\n\n/* ------------------------------------------------------------------ vector */\n\n/** Euclidean magnitude of a 3-vector. */\nexport function vectorMagnitude(row: ArrayLike<number>, order?: ComponentOrder): number {\n const x = at(row, 0, order);\n const y = at(row, 1, order);\n const z = at(row, 2, order);\n return Math.sqrt(x * x + y * y + z * z);\n}\n\n/* -------------------------------------------------------------------- dof6 */\n\n/** Magnitude of the three translation slots. */\nexport function translationMagnitude(row: ArrayLike<number>, order?: ComponentOrder): number {\n const x = at(row, 0, order);\n const y = at(row, 1, order);\n const z = at(row, 2, order);\n return Math.sqrt(x * x + y * y + z * z);\n}\n\n/** Magnitude of the three rotation slots. */\nexport function rotationMagnitude(row: ArrayLike<number>, order?: ComponentOrder): number {\n const x = at(row, 3, order);\n const y = at(row, 4, order);\n const z = at(row, 5, order);\n return Math.sqrt(x * x + y * y + z * z);\n}\n\n/* --------------------------------------------------------------- symtensor */\n\n/** Mean (hydrostatic) value: `(xx + yy + zz) / 3`. */\nexport function mean(row: ArrayLike<number>, order?: ComponentOrder): number {\n return (at(row, 0, order) + at(row, 1, order) + at(row, 2, order)) / 3.0;\n}\n\n/**\n * The von Mises kernel.\n *\n * `shearFactor` multiplies the shear components before use — the fused form of\n * \"halve the shears, then …\". Stress binds `(1, 1)`; equivalent strain\n * `(1/(1+ν), 1)`; engineering-shear equivalent strain `(1/(1+ν), 1/2)`;\n * octahedral shear stress `(√2/3, 1)`.\n */\nexport function vonMises(\n row: ArrayLike<number>,\n scale = 1.0,\n shearFactor = 1.0,\n order?: ComponentOrder,\n): number {\n const [xx, yy, zz, xy, yz, xz] = components6(row, order);\n const f2 = shearFactor * shearFactor;\n const squared =\n 0.5 * ((xx - yy) ** 2 + (yy - zz) ** 2 + (zz - xx) ** 2) +\n 3.0 * f2 * (xy * xy + yz * yz + xz * xz);\n return scale * Math.sqrt(squared);\n}\n\n/** Von Mises (equivalent) strain: `1/(1+ν)` of the von Mises value. */\nexport function equivalentStrain(\n row: ArrayLike<number>,\n nu = 0.5,\n shearFactor = 1.0,\n order?: ComponentOrder,\n): number {\n return vonMises(row, 1.0 / (1.0 + nu), shearFactor, order);\n}\n\n/** Octahedral shear stress: `τ_oct = (√2⁄3)·σ_vm`. */\nexport function octahedral(\n row: ArrayLike<number>,\n shearFactor = 1.0,\n order?: ComponentOrder,\n): number {\n return vonMises(row, OCTAHEDRAL_SCALE, shearFactor, order);\n}\n\n/** The tensor determinant (third invariant). */\nexport function determinant(\n row: ArrayLike<number>,\n shearFactor = 1.0,\n order?: ComponentOrder,\n): number {\n const [xx, yy, zz] = components6(row, order);\n const xy = shearFactor * at(row, 3, order);\n const yz = shearFactor * at(row, 4, order);\n const xz = shearFactor * at(row, 5, order);\n return xx * yy * zz + 2.0 * xy * yz * xz - xy * xy * zz - yz * yz * xx - xz * xz * yy;\n}\n\n/**\n * Principal values, ascending.\n *\n * A cyclic Jacobi rotation rather than the closed-form trigonometric roots:\n * the closed form loses precision exactly where CAE data spends much of its\n * time — near-hydrostatic states and repeated roots — and Jacobi converges to\n * machine precision on a 3×3 symmetric matrix in a handful of sweeps. The\n * oracle uses `numpy.linalg.eigvalsh`, which is a different algorithm again;\n * agreeing with it to floating-point tolerance is what the parity tests check.\n *\n * A tensor with a NaN component has no value, and every root is NaN — the\n * oracle's row-level rule for data with no value. One with an infinite\n * component has no eigenvalues at all, and is refused.\n *\n * Only the eigen*values* are returned. For repeated roots the eigenvectors are\n * an arbitrary basis of the degenerate eigenspace, so a shared \"principal\n * direction\" would not be well defined and is deliberately absent here.\n */\nexport function principals(\n row: ArrayLike<number>,\n shearFactor = 1.0,\n order?: ComponentOrder,\n): [number, number, number] {\n const [xx, yy, zz, xy0, yz0, xz0] = components6(row, order);\n // A rotation drives off-diagonal entries to zero by comparing them with\n // zero, which a NaN never is; left alone, a NaN in one entry is rotated away\n // and the other roots come out finite and plausible. So a tensor that is not\n // wholly finite is decided here, before any rotation.\n // The sum is a cheap screen; it can also overflow on finite entries, so the\n // entries themselves decide.\n const entries = [xx, yy, zz, xy0, yz0, xz0];\n if (!Number.isFinite(xx + yy + zz + xy0 + yz0 + xz0) && !entries.every(Number.isFinite)) {\n // NaN is how a datum with no value is carried, and the oracle gives a row\n // with no value no principals.\n if (entries.some(Number.isNaN)) return [Number.NaN, Number.NaN, Number.NaN];\n // An infinite component has no eigenvalues; the oracle's eigvalsh raises\n // rather than answer, and so does this.\n throw new DerivedError(\n `a tensor with an infinite component (${entries.join(\", \")}) has no principal values.`,\n );\n }\n // The working matrix, as its six distinct entries.\n let a00 = xx;\n let a11 = yy;\n let a22 = zz;\n let a01 = shearFactor * xy0;\n let a12 = shearFactor * yz0;\n let a02 = shearFactor * xz0;\n\n for (let sweep = 0; sweep < 24; sweep++) {\n const off = Math.abs(a01) + Math.abs(a12) + Math.abs(a02);\n if (off === 0) break;\n // A rotation that annihilates one off-diagonal entry, applied to the\n // three pairs in turn. `t` is the tangent of the rotation angle, taken\n // as the root of smaller magnitude for numerical stability.\n const rotate = (app: number, aqq: number, apq: number): [number, number] => {\n const theta = (aqq - app) / (2 * apq);\n const t = Math.sign(theta || 1) / (Math.abs(theta) + Math.sqrt(theta * theta + 1));\n return [t, 1 / Math.sqrt(t * t + 1)];\n };\n if (a01 !== 0) {\n const [t, c] = rotate(a00, a11, a01);\n const s = t * c;\n const n00 = a00 - t * a01;\n const n11 = a11 + t * a01;\n const n02 = c * a02 - s * a12;\n const n12 = s * a02 + c * a12;\n a00 = n00;\n a11 = n11;\n a01 = 0;\n a02 = n02;\n a12 = n12;\n }\n if (a02 !== 0) {\n const [t, c] = rotate(a00, a22, a02);\n const s = t * c;\n const n00 = a00 - t * a02;\n const n22 = a22 + t * a02;\n const n01 = c * a01 - s * a12;\n const n12 = s * a01 + c * a12;\n a00 = n00;\n a22 = n22;\n a02 = 0;\n a01 = n01;\n a12 = n12;\n }\n if (a12 !== 0) {\n const [t, c] = rotate(a11, a22, a12);\n const s = t * c;\n const n11 = a11 - t * a12;\n const n22 = a22 + t * a12;\n const n01 = c * a01 - s * a02;\n const n02 = s * a01 + c * a02;\n a11 = n11;\n a22 = n22;\n a12 = 0;\n a01 = n01;\n a02 = n02;\n }\n }\n const roots: [number, number, number] = [a00, a11, a22];\n roots.sort((x, y) => x - y);\n return roots;\n}\n\n/** Maximum shear: `(tmax − tmin) / 2`. */\nexport function maxShear(\n row: ArrayLike<number>,\n shearFactor = 1.0,\n order?: ComponentOrder,\n): number {\n const p = principals(row, shearFactor, order);\n return 0.5 * (p[2] - p[0]);\n}\n\n/** Equal direct value in the max-shear directions: `(tmax + tmin) / 2`. */\nexport function equalDirect(\n row: ArrayLike<number>,\n shearFactor = 1.0,\n order?: ComponentOrder,\n): number {\n const p = principals(row, shearFactor, order);\n return 0.5 * (p[2] + p[0]);\n}\n\n/** Intensity: `tmax − tmin`, always twice the maximum shear. */\nexport function intensity(\n row: ArrayLike<number>,\n shearFactor = 1.0,\n order?: ComponentOrder,\n): number {\n const p = principals(row, shearFactor, order);\n return p[2] - p[0];\n}\n\n/**\n * The principal value of largest magnitude, keeping its sign.\n *\n * **On an exact tie the maximum wins** — pure shear `(-t, 0, t)` and any\n * zero-mean deviator return `+t`. The oracle's `lexsort` tie-break, restated:\n * order by absolute value, then by signed value, and take the last.\n */\nexport function absMaxPrincipal(\n row: ArrayLike<number>,\n shearFactor = 1.0,\n order?: ComponentOrder,\n): number {\n const p = principals(row, shearFactor, order);\n let best = p[0];\n for (const value of p) {\n const byMagnitude = Math.abs(value) - Math.abs(best);\n if (byMagnitude > 0 || (byMagnitude === 0 && value > best)) best = value;\n }\n return best;\n}\n\n/** One principal value of the deviator: the principal shifted by the mean. */\nexport function deviatoricPrincipal(\n row: ArrayLike<number>,\n index: 0 | 1 | 2,\n shearFactor = 1.0,\n order?: ComponentOrder,\n): number {\n return (principals(row, shearFactor, order)[index] as number) - mean(row, order);\n}\n","// Copyright Visual Collaboration Technologies Inc. All Rights Reserved.\n// See LICENSE for details.\n\n/**\n * Derived quantities on the CPU: `@vcollab/shader-library/derived`.\n *\n * The shader computes these per fragment; a consumer computes them here for\n * the decisions it has to make before it draws. The one that always matters is\n * the value range: the fringe bands are uniforms, so something has to know the\n * extent of the field, and a shader cannot tell anyone.\n *\n * The dispatch integers, the formulas and the tie-breaks are those of\n * `vcti.derived`, which is the oracle for all three implementations of this\n * math (see the package design notes).\n */\n\nimport type { DerivedFamily } from \"./dispatch.js\";\nimport { dispatchTable, FAMILY_COMPONENTS } from \"./dispatch.js\";\nimport { DerivedError } from \"./errors.js\";\nimport type { ComponentOrder } from \"./kernels.js\";\nimport {\n absMaxPrincipal,\n affine,\n determinant,\n deviatoricPrincipal,\n equalDirect,\n equivalentStrain,\n intensity,\n maxShear,\n mean,\n octahedral,\n principals,\n rotationMagnitude,\n TEMPERATURE_CONVERSIONS,\n translationMagnitude,\n vectorMagnitude,\n vonMises,\n} from \"./kernels.js\";\n\nexport * from \"./dispatch.js\";\nexport * from \"./errors.js\";\nexport * from \"./kernels.js\";\n\n/** What the parameterized derived types read. */\nexport interface DerivedOptions {\n /** Effective Poisson's ratio, for the equivalent-strain types. */\n readonly nu?: number;\n /** Multiplier for `scalar.affine`. */\n readonly scale?: number;\n /** Addend for `scalar.affine`. */\n readonly offset?: number;\n /** Component permutation: `order[slot]` is where the canonical slot is stored. */\n readonly order?: ComponentOrder;\n}\n\nconst ENGINEERING_SHEAR = 0.5;\n\ntype Kernel = (row: ArrayLike<number>, options: DerivedOptions) => number;\n\nfunction component(slot: number): Kernel {\n return (row, { order }) => (order == null ? row[slot] : row[order[slot] as number]) as number;\n}\n\nconst SCALAR_KERNELS: Readonly<Record<string, Kernel>> = {\n identity: (row) => row[0] as number,\n absolute: (row) => Math.abs(row[0] as number),\n affine: (row, { scale = 1.0, offset = 0.0 }) => affine(row[0] as number, scale, offset),\n ...Object.fromEntries(\n Object.entries(TEMPERATURE_CONVERSIONS).map(([name, [scale, offset]]) => [\n name,\n ((row) => affine(row[0] as number, scale, offset)) satisfies Kernel,\n ]),\n ),\n};\n\nconst VECTOR_KERNELS: Readonly<Record<string, Kernel>> = {\n x: component(0),\n y: component(1),\n z: component(2),\n magnitude: (row, { order }) => vectorMagnitude(row, order),\n};\n\nconst DOF6_KERNELS: Readonly<Record<string, Kernel>> = {\n tx: component(0),\n ty: component(1),\n tz: component(2),\n rx: component(3),\n ry: component(4),\n rz: component(5),\n translation_magnitude: (row, { order }) => translationMagnitude(row, order),\n rotation_magnitude: (row, { order }) => rotationMagnitude(row, order),\n};\n\n/** `min`, `mid`, `max` are principal slots 0, 1, 2 of the ascending roots. */\nconst PRINCIPAL_SLOT = { min: 0, mid: 1, max: 2 } as const;\n\nconst SYMTENSOR_KERNELS: Readonly<Record<string, Kernel>> = {\n xx: component(0),\n yy: component(1),\n zz: component(2),\n xy: component(3),\n yz: component(4),\n xz: component(5),\n mean: (row, { order }) => mean(row, order),\n von_mises: (row, { order }) => vonMises(row, 1.0, 1.0, order),\n equivalent_strain: (row, { nu = 0.5, order }) => equivalentStrain(row, nu, 1.0, order),\n equivalent_strain_engineering: (row, { nu = 0.5, order }) =>\n equivalentStrain(row, nu, ENGINEERING_SHEAR, order),\n octahedral: (row, { order }) => octahedral(row, 1.0, order),\n max_shear: (row, { order }) => maxShear(row, 1.0, order),\n equal_direct: (row, { order }) => equalDirect(row, 1.0, order),\n intensity: (row, { order }) => intensity(row, 1.0, order),\n abs_max_principal: (row, { order }) => absMaxPrincipal(row, 1.0, order),\n abs_max_principal_engineering: (row, { order }) =>\n absMaxPrincipal(row, ENGINEERING_SHEAR, order),\n determinant: (row, { order }) => determinant(row, 1.0, order),\n ...Object.fromEntries(\n Object.entries(PRINCIPAL_SLOT).flatMap(([which, slot]) => [\n [\n `${which}_principal`,\n ((row, { order }) => principals(row, 1.0, order)[slot]) satisfies Kernel,\n ],\n [\n `${which}_principal_engineering`,\n ((row, { order }) => principals(row, ENGINEERING_SHEAR, order)[slot]) satisfies Kernel,\n ],\n [\n `deviatoric_${which}_principal`,\n ((row, { order }) => deviatoricPrincipal(row, slot, 1.0, order)) satisfies Kernel,\n ],\n ]),\n ),\n};\n\nconst KERNELS: Readonly<Record<DerivedFamily, Readonly<Record<string, Kernel>>>> = {\n scalar: SCALAR_KERNELS,\n vector: VECTOR_KERNELS,\n dof6: DOF6_KERNELS,\n symtensor: SYMTENSOR_KERNELS,\n};\n\nfunction kernelFor(family: DerivedFamily, type: string | number): Kernel {\n const dispatch = dispatchTable(family);\n const table = KERNELS[family];\n const name =\n typeof type === \"number\" ? Object.entries(dispatch).find(([, id]) => id === type)?.[0] : type;\n // An own-property lookup: `table[name]` alone reaches the prototype, and\n // `constructor` would come back as a kernel.\n const kernel = name !== undefined && Object.hasOwn(table, name) ? table[name] : undefined;\n if (kernel === undefined) {\n throw new DerivedError(\n `the ${family} family has no derived type ${JSON.stringify(type)}; it offers ` +\n `${Object.keys(table).sort().join(\", \")}.`,\n );\n }\n return kernel;\n}\n\n/**\n * Check `order` is a permutation of a datum's `width` slots.\n *\n * Anything else reads a component that is not there, or reads one twice, and\n * the answer is NaN or a plausible wrong number rather than an error.\n */\nfunction checkOrder(family: DerivedFamily, width: number, order: DerivedOptions[\"order\"]): void {\n if (order == null) return;\n const seen = new Set<number>();\n for (let slot = 0; slot < order.length; slot++) {\n const index = order[slot] as number;\n if (!Number.isInteger(index) || index < 0 || index >= width || seen.has(index)) {\n throw new DerivedError(\n `order[${slot}] is ${String(index)}, but a ${family} order is a permutation of ` +\n `0..${width - 1}: each index once.`,\n );\n }\n seen.add(index);\n }\n if (order.length !== width) {\n throw new DerivedError(`a ${family} order names ${width} slot(s); got ${order.length}.`);\n }\n}\n\n/**\n * Whether a datum has no value: any of its components is NaN.\n *\n * The oracle's rule is per row — a datum missing one component has no value\n * at all, and every quantity derived from it, even another component, has\n * none either.\n */\nfunction hasNoValue(row: ArrayLike<number>, width: number): boolean {\n for (let slot = 0; slot < width; slot++) if (Number.isNaN(row[slot])) return true;\n return false;\n}\n\n/** Look up a family's width, refusing a family that does not exist. */\nfunction widthOf(family: DerivedFamily): number {\n dispatchTable(family);\n return FAMILY_COMPONENTS[family];\n}\n\n/**\n * Compute one derived value from one datum.\n *\n * A datum with a NaN component has no value, and its result is NaN.\n *\n * @throws {DerivedError} for an unknown family or type, a datum too short for\n * its family, or an `order` that is not a permutation of the family's slots.\n */\nexport function computeDerived(\n family: DerivedFamily,\n type: string | number,\n datum: ArrayLike<number>,\n options: DerivedOptions = {},\n): number {\n const width = widthOf(family);\n if (datum.length < width) {\n throw new DerivedError(`a ${family} datum has ${width} component(s); got ${datum.length}.`);\n }\n checkOrder(family, width, options.order);\n const kernel = kernelFor(family, type);\n return hasNoValue(datum, width) ? Number.NaN : kernel(datum, options);\n}\n\n/**\n * Compute a derived value for every datum in a packed field.\n *\n * `field` is `count × components` values, one datum after another. Returns a\n * `Float32Array` of `count` values — the precision the attribute reaches the\n * shader at, so a range taken from it is the range the shader will see. A\n * datum with a NaN component has no value and gives NaN, which\n * {@link fieldRange} leaves out.\n *\n * @throws {DerivedError} as {@link computeDerived} does, and for a field that\n * is not a whole number of data or an `out` too small for it.\n */\nexport function computeDerivedField(\n family: DerivedFamily,\n type: string | number,\n field: ArrayLike<number>,\n options: DerivedOptions = {},\n out?: Float32Array,\n): Float32Array {\n const width = widthOf(family);\n if (field.length % width !== 0) {\n throw new DerivedError(\n `a ${family} field holds ${width} component(s) per datum, and ${field.length} values is ` +\n \"not a whole number of them.\",\n );\n }\n const count = field.length / width;\n const result = out ?? new Float32Array(count);\n if (result.length < count) {\n throw new DerivedError(`the output holds ${result.length} value(s); the field has ${count}.`);\n }\n checkOrder(family, width, options.order);\n const kernel = kernelFor(family, type);\n // One view, moved along the field, rather than a copy per datum: this runs\n // over every vertex of a mesh.\n const datum =\n ArrayBuffer.isView(field) && field instanceof Float32Array\n ? field.subarray(0, width)\n : undefined;\n for (let index = 0; index < count; index++) {\n const at = index * width;\n if (datum !== undefined) {\n const row = (field as Float32Array).subarray(at, at + width);\n result[index] = hasNoValue(row, width) ? Number.NaN : kernel(row, options);\n } else {\n const row: number[] = [];\n for (let slot = 0; slot < width; slot++) row.push(field[at + slot] as number);\n result[index] = hasNoValue(row, width) ? Number.NaN : kernel(row, options);\n }\n }\n return result;\n}\n\n/**\n * The extent of a computed field, ignoring values that are not finite.\n *\n * A no-value datum reaches the shader as NaN and is colored by\n * `u_nanColor`, so it must not drag the band bounds with it. A field with no\n * finite value at all has no range, and `null` says so rather than returning\n * an inverted interval a caller might use.\n */\nexport function fieldRange(values: ArrayLike<number>): { min: number; max: number } | null {\n let min = Number.POSITIVE_INFINITY;\n let max = Number.NEGATIVE_INFINITY;\n let seen = false;\n for (let index = 0; index < values.length; index++) {\n const value = values[index] as number;\n if (!Number.isFinite(value)) continue;\n seen = true;\n if (value < min) min = value;\n if (value > max) max = value;\n }\n return seen ? { min, max } : null;\n}\n"]}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Derived quantities on the CPU: `@vcollab/shader-library/derived`.
3
+ *
4
+ * The shader computes these per fragment; a consumer computes them here for
5
+ * the decisions it has to make before it draws. The one that always matters is
6
+ * the value range: the fringe bands are uniforms, so something has to know the
7
+ * extent of the field, and a shader cannot tell anyone.
8
+ *
9
+ * The dispatch integers, the formulas and the tie-breaks are those of
10
+ * `vcti.derived`, which is the oracle for all three implementations of this
11
+ * math (see the package design notes).
12
+ */
13
+ import type { DerivedFamily } from "./dispatch.js";
14
+ import type { ComponentOrder } from "./kernels.js";
15
+ export * from "./dispatch.js";
16
+ export * from "./errors.js";
17
+ export * from "./kernels.js";
18
+ /** What the parameterized derived types read. */
19
+ export interface DerivedOptions {
20
+ /** Effective Poisson's ratio, for the equivalent-strain types. */
21
+ readonly nu?: number;
22
+ /** Multiplier for `scalar.affine`. */
23
+ readonly scale?: number;
24
+ /** Addend for `scalar.affine`. */
25
+ readonly offset?: number;
26
+ /** Component permutation: `order[slot]` is where the canonical slot is stored. */
27
+ readonly order?: ComponentOrder;
28
+ }
29
+ /**
30
+ * Compute one derived value from one datum.
31
+ *
32
+ * A datum with a NaN component has no value, and its result is NaN.
33
+ *
34
+ * @throws {DerivedError} for an unknown family or type, a datum too short for
35
+ * its family, or an `order` that is not a permutation of the family's slots.
36
+ */
37
+ export declare function computeDerived(family: DerivedFamily, type: string | number, datum: ArrayLike<number>, options?: DerivedOptions): number;
38
+ /**
39
+ * Compute a derived value for every datum in a packed field.
40
+ *
41
+ * `field` is `count × components` values, one datum after another. Returns a
42
+ * `Float32Array` of `count` values — the precision the attribute reaches the
43
+ * shader at, so a range taken from it is the range the shader will see. A
44
+ * datum with a NaN component has no value and gives NaN, which
45
+ * {@link fieldRange} leaves out.
46
+ *
47
+ * @throws {DerivedError} as {@link computeDerived} does, and for a field that
48
+ * is not a whole number of data or an `out` too small for it.
49
+ */
50
+ export declare function computeDerivedField(family: DerivedFamily, type: string | number, field: ArrayLike<number>, options?: DerivedOptions, out?: Float32Array): Float32Array;
51
+ /**
52
+ * The extent of a computed field, ignoring values that are not finite.
53
+ *
54
+ * A no-value datum reaches the shader as NaN and is colored by
55
+ * `u_nanColor`, so it must not drag the band bounds with it. A field with no
56
+ * finite value at all has no range, and `null` says so rather than returning
57
+ * an inverted interval a caller might use.
58
+ */
59
+ export declare function fieldRange(values: ArrayLike<number>): {
60
+ min: number;
61
+ max: number;
62
+ } | null;