@math.gl/geometry 5.0.0-beta.1 → 5.0.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -0
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/dist/color/color-lut-types.d.ts +16 -0
- package/dist/color/color-lut-types.d.ts.map +1 -0
- package/dist/color/color-lut-types.js +5 -0
- package/dist/color/color-lut-types.js.map +1 -0
- package/dist/color/index.cjs +132 -0
- package/dist/color/index.cjs.map +6 -0
- package/dist/color/index.d.ts +4 -0
- package/dist/color/index.d.ts.map +1 -0
- package/dist/color/index.js +5 -0
- package/dist/color/index.js.map +1 -0
- package/dist/color/sample-lut.d.ts +13 -0
- package/dist/color/sample-lut.d.ts.map +1 -0
- package/dist/color/sample-lut.js +132 -0
- package/dist/color/sample-lut.js.map +1 -0
- package/dist/culling/bounds.d.ts +20 -0
- package/dist/culling/bounds.d.ts.map +1 -0
- package/dist/culling/bounds.js +121 -0
- package/dist/culling/bounds.js.map +1 -0
- package/dist/culling/frustum-planes.d.ts +5 -0
- package/dist/culling/frustum-planes.d.ts.map +1 -0
- package/dist/culling/frustum-planes.js +37 -0
- package/dist/culling/frustum-planes.js.map +1 -0
- package/dist/culling/geometric-queries.d.ts +34 -0
- package/dist/culling/geometric-queries.d.ts.map +1 -0
- package/dist/culling/geometric-queries.js +208 -0
- package/dist/culling/geometric-queries.js.map +1 -0
- package/dist/culling/index.cjs +944 -508
- package/dist/culling/index.cjs.map +3 -3
- package/dist/culling/index.d.ts +7 -1
- package/dist/culling/index.d.ts.map +1 -1
- package/dist/culling/index.js +4 -0
- package/dist/culling/index.js.map +1 -1
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts +3 -3
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.d.ts.map +1 -1
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js +25 -8
- package/dist/culling/lib/bounding-volumes/axis-aligned-bounding-box.js.map +1 -1
- package/dist/culling/lib/culling-volume.d.ts +3 -0
- package/dist/culling/lib/culling-volume.d.ts.map +1 -1
- package/dist/culling/lib/culling-volume.js +7 -0
- package/dist/culling/lib/culling-volume.js.map +1 -1
- package/dist/culling/lib/ray.d.ts +5 -0
- package/dist/culling/lib/ray.d.ts.map +1 -1
- package/dist/culling/lib/ray.js +21 -0
- package/dist/culling/lib/ray.js.map +1 -1
- package/dist/culling/screen-ray.d.ts +22 -0
- package/dist/culling/screen-ray.d.ts.map +1 -0
- package/dist/culling/screen-ray.js +55 -0
- package/dist/culling/screen-ray.js.map +1 -0
- package/dist/curves/adaptive-sampling.d.ts +16 -0
- package/dist/curves/adaptive-sampling.d.ts.map +1 -0
- package/dist/curves/adaptive-sampling.js +59 -0
- package/dist/curves/adaptive-sampling.js.map +1 -0
- package/dist/curves/index.d.ts +4 -0
- package/dist/curves/index.d.ts.map +1 -1
- package/dist/curves/index.js +2 -0
- package/dist/curves/index.js.map +1 -1
- package/dist/curves/parallel-transport.d.ts +12 -0
- package/dist/curves/parallel-transport.d.ts.map +1 -0
- package/dist/curves/parallel-transport.js +83 -0
- package/dist/curves/parallel-transport.js.map +1 -0
- package/dist/index.cjs +1988 -934
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +17 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/dist/lighting/index.cjs +175 -0
- package/dist/lighting/index.cjs.map +6 -0
- package/dist/lighting/index.d.ts +4 -0
- package/dist/lighting/index.d.ts.map +1 -0
- package/dist/lighting/index.js +5 -0
- package/dist/lighting/index.js.map +1 -0
- package/dist/lighting/lighting-types.d.ts +16 -0
- package/dist/lighting/lighting-types.d.ts.map +1 -0
- package/dist/lighting/lighting-types.js +5 -0
- package/dist/lighting/lighting-types.js.map +1 -0
- package/dist/lighting/photometry.d.ts +36 -0
- package/dist/lighting/photometry.d.ts.map +1 -0
- package/dist/lighting/photometry.js +181 -0
- package/dist/lighting/photometry.js.map +1 -0
- package/dist/polygon/cut-by-grid.d.ts.map +1 -1
- package/dist/polygon/cut-by-grid.js +18 -0
- package/dist/polygon/cut-by-grid.js.map +1 -1
- package/dist/polygon/earcut.d.ts.map +1 -1
- package/dist/polygon/earcut.js +100 -34
- package/dist/polygon/earcut.js.map +1 -1
- package/dist/polygon/index.d.ts +2 -0
- package/dist/polygon/index.d.ts.map +1 -1
- package/dist/polygon/index.js +1 -0
- package/dist/polygon/index.js.map +1 -1
- package/dist/polygon/pole-of-inaccessibility.d.ts +21 -0
- package/dist/polygon/pole-of-inaccessibility.d.ts.map +1 -0
- package/dist/polygon/pole-of-inaccessibility.js +285 -0
- package/dist/polygon/pole-of-inaccessibility.js.map +1 -0
- package/dist/polygon/subdivide-triangle-mesh.d.ts +10 -0
- package/dist/polygon/subdivide-triangle-mesh.d.ts.map +1 -1
- package/dist/polygon/subdivide-triangle-mesh.js +67 -19
- package/dist/polygon/subdivide-triangle-mesh.js.map +1 -1
- package/dist/utils/compose-attribute-provenance.d.ts +13 -0
- package/dist/utils/compose-attribute-provenance.d.ts.map +1 -0
- package/dist/utils/compose-attribute-provenance.js +63 -0
- package/dist/utils/compose-attribute-provenance.js.map +1 -0
- package/dist/utils/compute-vertex-normals.d.ts +2 -2
- package/dist/utils/compute-vertex-normals.d.ts.map +1 -1
- package/dist/utils/compute-vertex-normals.js +3 -4
- package/dist/utils/compute-vertex-normals.js.map +1 -1
- package/dist/utils/geometry.d.ts +11 -4
- package/dist/utils/geometry.d.ts.map +1 -1
- package/dist/utils/geometry.js +19 -2
- package/dist/utils/geometry.js.map +1 -1
- package/dist/utils/index.d.ts +1 -3
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +0 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/mesh-processing.d.ts +16 -6
- package/dist/utils/mesh-processing.d.ts.map +1 -1
- package/dist/utils/mesh-processing.js +9 -6
- package/dist/utils/mesh-processing.js.map +1 -1
- package/dist/utils/primitive-iterator.d.ts +16 -8
- package/dist/utils/primitive-iterator.d.ts.map +1 -1
- package/dist/utils/primitive-iterator.js +32 -35
- package/dist/utils/primitive-iterator.js.map +1 -1
- package/dist/utils/project-bounds.d.ts +44 -0
- package/dist/utils/project-bounds.d.ts.map +1 -0
- package/dist/utils/project-bounds.js +93 -0
- package/dist/utils/project-bounds.js.map +1 -0
- package/dist/utils/project-texture-coordinates.d.ts +19 -0
- package/dist/utils/project-texture-coordinates.d.ts.map +1 -0
- package/dist/utils/project-texture-coordinates.js +49 -0
- package/dist/utils/project-texture-coordinates.js.map +1 -0
- package/dist/utils/qualify-surface-transition.d.ts +21 -0
- package/dist/utils/qualify-surface-transition.d.ts.map +1 -0
- package/dist/utils/qualify-surface-transition.js +140 -0
- package/dist/utils/qualify-surface-transition.js.map +1 -0
- package/package.json +15 -3
- package/src/color/color-lut-types.ts +19 -0
- package/src/color/index.ts +6 -0
- package/src/color/sample-lut.ts +175 -0
- package/src/culling/bounds.ts +152 -0
- package/src/culling/frustum-planes.ts +41 -0
- package/src/culling/geometric-queries.ts +299 -0
- package/src/culling/index.ts +39 -1
- package/src/culling/lib/bounding-volumes/axis-aligned-bounding-box.ts +26 -8
- package/src/culling/lib/culling-volume.ts +9 -1
- package/src/culling/lib/ray.ts +21 -0
- package/src/culling/screen-ray.ts +75 -0
- package/src/curves/adaptive-sampling.ts +85 -0
- package/src/curves/index.ts +4 -0
- package/src/curves/parallel-transport.ts +104 -0
- package/src/index.ts +71 -9
- package/src/lighting/index.ts +10 -0
- package/src/lighting/lighting-types.ts +20 -0
- package/src/lighting/photometry.ts +264 -0
- package/src/polygon/cut-by-grid.ts +18 -0
- package/src/polygon/earcut.ts +98 -37
- package/src/polygon/index.ts +6 -0
- package/src/polygon/pole-of-inaccessibility.ts +330 -0
- package/src/polygon/subdivide-triangle-mesh.ts +77 -17
- package/src/utils/compose-attribute-provenance.ts +74 -0
- package/src/utils/compute-vertex-normals.ts +5 -6
- package/src/utils/geometry.ts +32 -6
- package/src/utils/index.ts +5 -5
- package/src/utils/mesh-processing.ts +30 -14
- package/src/utils/primitive-iterator.ts +45 -43
- package/src/utils/project-bounds.ts +154 -0
- package/src/utils/project-texture-coordinates.ts +67 -0
- package/src/utils/qualify-surface-transition.ts +169 -0
- package/dist/utils/constants.d.ts +0 -52
- package/dist/utils/constants.d.ts.map +0 -1
- package/dist/utils/constants.js +0 -39
- package/dist/utils/constants.js.map +0 -1
- package/dist/utils/gl-type.d.ts +0 -17
- package/dist/utils/gl-type.d.ts.map +0 -1
- package/dist/utils/gl-type.js +0 -69
- package/dist/utils/gl-type.js.map +0 -1
- package/src/utils/constants.ts +0 -42
- package/src/utils/gl-type.ts +0 -87
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-bounds.d.ts","sourceRoot":"","sources":["../../src/utils/project-bounds.ts"],"names":[],"mappings":"AAIA,oFAAoF;AACpF,MAAM,MAAM,sBAAsB,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;AAErF,gFAAgF;AAChF,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,SAAS,EAAE,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,KAAK,SAAS,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IACrE,kEAAkE;IAClE,UAAU,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IACnB,mFAAmF;IACnF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC/B,CAAC;AAEF,mGAAmG;AACnG,MAAM,MAAM,qBAAqB,GAC7B;IACE,gGAAgG;IAChG,MAAM,EAAE,SAAS,GAAG,cAAc,CAAC;IACnC,sFAAsF;IACtF,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7B,iCAAiC;IACjC,WAAW,EAAE,MAAM,CAAC;CACrB,GACD;IACE,sFAAsF;IACtF,MAAM,EAAE,SAAS,CAAC;IAClB,wCAAwC;IACxC,MAAM,EAAE,IAAI,CAAC;IACb,4EAA4E;IAC5E,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEN;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,YAAY,EAAE,sBAAsB,EACpC,OAAO,EAAE,oBAAoB,GAC5B,qBAAqB,CAmGvB"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
/** Projects a lattice covering corners, edges, faces and the interior of a 2D/3D box.
|
|
5
|
+
* Sampling alone cannot establish an enclosure for a nonlinear transform. When qualified
|
|
6
|
+
* global Lipschitz constants are supplied, inflate by the lattice covering radius instead
|
|
7
|
+
* of claiming corner/sample extrema are conservative. Split seams and domains beforehand.
|
|
8
|
+
*/
|
|
9
|
+
export function projectBounds(sourceBounds, options) {
|
|
10
|
+
const [minimum, maximum] = sourceBounds;
|
|
11
|
+
const size = minimum.length;
|
|
12
|
+
const { transform, targetSize = size, subdivisions = 8, maxSamples = 262144, lipschitz } = options;
|
|
13
|
+
if ((size !== 2 && size !== 3) ||
|
|
14
|
+
maximum.length !== size ||
|
|
15
|
+
(targetSize !== 2 && targetSize !== 3)) {
|
|
16
|
+
throw new RangeError('Bounds and target dimension must be 2 or 3');
|
|
17
|
+
}
|
|
18
|
+
if (!Number.isSafeInteger(subdivisions) ||
|
|
19
|
+
subdivisions < 1 ||
|
|
20
|
+
!Number.isSafeInteger(maxSamples) ||
|
|
21
|
+
maxSamples < 1) {
|
|
22
|
+
throw new RangeError('Subdivision and sample budgets must be positive safe integers');
|
|
23
|
+
}
|
|
24
|
+
if (lipschitz &&
|
|
25
|
+
(lipschitz.length !== targetSize ||
|
|
26
|
+
!Array.from(lipschitz).every(value => Number.isFinite(value) && value >= 0))) {
|
|
27
|
+
throw new RangeError('Lipschitz constants must be finite, nonnegative and match target size');
|
|
28
|
+
}
|
|
29
|
+
const widths = [];
|
|
30
|
+
const counts = [];
|
|
31
|
+
let count = 1;
|
|
32
|
+
for (let axis = 0; axis < size; axis++) {
|
|
33
|
+
const width = maximum[axis] - minimum[axis];
|
|
34
|
+
if (!Number.isFinite(minimum[axis]) ||
|
|
35
|
+
!Number.isFinite(maximum[axis]) ||
|
|
36
|
+
!Number.isFinite(width) ||
|
|
37
|
+
width < 0) {
|
|
38
|
+
throw new RangeError('Source bounds must have finite ordered coordinates and extents');
|
|
39
|
+
}
|
|
40
|
+
widths.push(width);
|
|
41
|
+
counts.push(width === 0 ? 1 : subdivisions + 1);
|
|
42
|
+
count *= counts[axis];
|
|
43
|
+
if (!Number.isSafeInteger(count) || count > maxSamples) {
|
|
44
|
+
throw new RangeError('Projected bounds exceed the sample budget');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const lower = new Array(targetSize).fill(Infinity);
|
|
48
|
+
const upper = new Array(targetSize).fill(-Infinity);
|
|
49
|
+
for (let index = 0; index < count; index++) {
|
|
50
|
+
let remaining = index;
|
|
51
|
+
const source = [];
|
|
52
|
+
for (let axis = 0; axis < size; axis++) {
|
|
53
|
+
const step = remaining % counts[axis];
|
|
54
|
+
remaining = Math.floor(remaining / counts[axis]);
|
|
55
|
+
source.push(step === 0
|
|
56
|
+
? minimum[axis]
|
|
57
|
+
: step === subdivisions
|
|
58
|
+
? maximum[axis]
|
|
59
|
+
: minimum[axis] + widths[axis] * (step / subdivisions));
|
|
60
|
+
}
|
|
61
|
+
const projected = transform(source);
|
|
62
|
+
if (!projected || projected.length < targetSize) {
|
|
63
|
+
return { status: 'invalid', bounds: null, sampleCount: index + 1 };
|
|
64
|
+
}
|
|
65
|
+
for (let axis = 0; axis < targetSize; axis++) {
|
|
66
|
+
if (!Number.isFinite(projected[axis]))
|
|
67
|
+
return { status: 'invalid', bounds: null, sampleCount: index + 1 };
|
|
68
|
+
lower[axis] = Math.min(lower[axis], projected[axis]);
|
|
69
|
+
upper[axis] = Math.max(upper[axis], projected[axis]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (lipschitz) {
|
|
73
|
+
const radius = Math.hypot(...widths.map((width, axis) => width / subdivisions / 2 +
|
|
74
|
+
4 * Number.EPSILON * Math.max(Math.abs(minimum[axis]), Math.abs(maximum[axis]))));
|
|
75
|
+
for (let axis = 0; axis < targetSize; axis++) {
|
|
76
|
+
const displacement = lipschitz[axis] * radius;
|
|
77
|
+
const roundoff = 8 *
|
|
78
|
+
Number.EPSILON *
|
|
79
|
+
Math.max(1, Math.abs(lower[axis]), Math.abs(upper[axis]), displacement);
|
|
80
|
+
lower[axis] -= displacement + roundoff;
|
|
81
|
+
upper[axis] += displacement + roundoff;
|
|
82
|
+
if (!Number.isFinite(lower[axis]) || !Number.isFinite(upper[axis])) {
|
|
83
|
+
return { status: 'invalid', bounds: null, sampleCount: count };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
status: lipschitz ? 'conservative' : 'sampled',
|
|
89
|
+
bounds: [lower, upper],
|
|
90
|
+
sampleCount: count
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=project-bounds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-bounds.js","sourceRoot":"","sources":["../../src/utils/project-bounds.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AA4C5D;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAC3B,YAAoC,EACpC,OAA6B;IAE7B,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,YAAY,CAAC;IACxC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;IAC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
+
/** Projects packed source vertices into an explicitly located image rectangle. */
|
|
2
|
+
export type ProjectTextureCoordinatesOptions = {
|
|
3
|
+
/** Prepared synchronous source-to-image transform. Receives a fresh source array.
|
|
4
|
+
* Null or nonfinite XY rejects the operation; exceptions propagate unchanged.
|
|
5
|
+
*/
|
|
6
|
+
transform: (position: readonly number[]) => ArrayLike<number> | null;
|
|
7
|
+
/** Image rectangle [left, bottom, right, top], in the transform's output coordinates. */
|
|
8
|
+
bounds: readonly [number, number, number, number];
|
|
9
|
+
/** Number of packed source components per vertex. Default 3. */
|
|
10
|
+
size?: 2 | 3;
|
|
11
|
+
/** Texture origin. Default 'top-left'; bottom-left makes V increase with image Y. */
|
|
12
|
+
origin?: 'top-left' | 'bottom-left';
|
|
13
|
+
};
|
|
14
|
+
/** Generates detached float64 UVs without changing positions, indices or vertex order.
|
|
15
|
+
* Outside-image coordinates remain outside [0, 1]. This performs no subdivision,
|
|
16
|
+
* seam inference, domain clipping, GPU readback, or asynchronous preparation.
|
|
17
|
+
*/
|
|
18
|
+
export declare function projectTextureCoordinates(positions: ArrayLike<number>, options: ProjectTextureCoordinatesOptions): Float64Array;
|
|
19
|
+
//# sourceMappingURL=project-texture-coordinates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-texture-coordinates.d.ts","sourceRoot":"","sources":["../../src/utils/project-texture-coordinates.ts"],"names":[],"mappings":"AAIA,kFAAkF;AAClF,MAAM,MAAM,gCAAgC,GAAG;IAC7C;;OAEG;IACH,SAAS,EAAE,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,KAAK,SAAS,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IACrE,yFAAyF;IACzF,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAClD,gEAAgE;IAChE,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IACb,qFAAqF;IACrF,MAAM,CAAC,EAAE,UAAU,GAAG,aAAa,CAAC;CACrC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,EAC5B,OAAO,EAAE,gCAAgC,GACxC,YAAY,CAyCd"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
/** Generates detached float64 UVs without changing positions, indices or vertex order.
|
|
5
|
+
* Outside-image coordinates remain outside [0, 1]. This performs no subdivision,
|
|
6
|
+
* seam inference, domain clipping, GPU readback, or asynchronous preparation.
|
|
7
|
+
*/
|
|
8
|
+
export function projectTextureCoordinates(positions, options) {
|
|
9
|
+
const { transform, bounds, size = 3, origin = 'top-left' } = options;
|
|
10
|
+
if (size !== 2 && size !== 3)
|
|
11
|
+
throw new RangeError('Source size must be 2 or 3');
|
|
12
|
+
if (!Number.isSafeInteger(positions.length) || positions.length < 0 || positions.length % size) {
|
|
13
|
+
throw new RangeError('Positions must contain complete packed vertices');
|
|
14
|
+
}
|
|
15
|
+
if (origin !== 'top-left' && origin !== 'bottom-left') {
|
|
16
|
+
throw new RangeError('Invalid texture origin');
|
|
17
|
+
}
|
|
18
|
+
if (bounds.length !== 4 || !bounds.every(Number.isFinite)) {
|
|
19
|
+
throw new RangeError('Image bounds must contain four finite values');
|
|
20
|
+
}
|
|
21
|
+
const [left, bottom, right, top] = bounds;
|
|
22
|
+
const width = right - left;
|
|
23
|
+
const height = top - bottom;
|
|
24
|
+
if (!(width > 0) || !(height > 0) || !Number.isFinite(width) || !Number.isFinite(height)) {
|
|
25
|
+
throw new RangeError('Image bounds must have finite positive extents');
|
|
26
|
+
}
|
|
27
|
+
const count = positions.length / size;
|
|
28
|
+
const result = new Float64Array(count * 2);
|
|
29
|
+
for (let index = 0; index < count; index++) {
|
|
30
|
+
const source = Array.from({ length: size }, (_, axis) => positions[index * size + axis]);
|
|
31
|
+
if (!source.every(Number.isFinite))
|
|
32
|
+
throw new RangeError(`Invalid source vertex ${index}`);
|
|
33
|
+
const projected = transform(source);
|
|
34
|
+
if (!projected ||
|
|
35
|
+
projected.length < 2 ||
|
|
36
|
+
!Number.isFinite(projected[0]) ||
|
|
37
|
+
!Number.isFinite(projected[1])) {
|
|
38
|
+
throw new RangeError(`Invalid projected vertex ${index}`);
|
|
39
|
+
}
|
|
40
|
+
const u = (projected[0] - left) / width;
|
|
41
|
+
const v = origin === 'top-left' ? (top - projected[1]) / height : (projected[1] - bottom) / height;
|
|
42
|
+
if (!Number.isFinite(u) || !Number.isFinite(v))
|
|
43
|
+
throw new RangeError(`Invalid UV at vertex ${index}`);
|
|
44
|
+
result[index * 2] = u;
|
|
45
|
+
result[index * 2 + 1] = v;
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=project-texture-coordinates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-texture-coordinates.js","sourceRoot":"","sources":["../../src/utils/project-texture-coordinates.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAgB5D;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CACvC,SAA4B,EAC5B,OAAyC;IAEzC,MAAM,EAAC,SAAS,EAAE,MAAM,EAAE,IAAI,GAAG,CAAC,EAAE,MAAM,GAAG,UAAU,EAAC,GAAG,OAAO,CAAC;IACnE,IAAI,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,4BAA4B,CAAC,CAAC;IACjF,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,SAAS,CAAC,MAAM,GAAG,IAAI,EAAE,CAAC;QAC/F,MAAM,IAAI,UAAU,CAAC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,CAAC,MAAM,CAAC,QAAQ,CAAC;YAAE,MAAM,IAAI,UAAU,CAAC,yBAAyB,KAAK,EAAE,CAAC,CAAC;QAC3F,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;QACpC,IACE,CAAC,SAAS;YACV,SAAS,CAAC,MAAM,GAAG,CAAC;YACpB,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YAC9B,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAC9B,CAAC;YACD,MAAM,IAAI,UAAU,CAAC,4BAA4B,KAAK,EAAE,CAAC,CAAC;QAC5D,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,KAAK,CAAC;QACxC,MAAM,CAAC,GACL,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;QAC3F,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC5C,MAAM,IAAI,UAAU,CAAC,wBAAwB,KAAK,EAAE,CAAC,CAAC;QACxD,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QACtB,MAAM,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { TriangleMesh } from "../polygon/subdivide-triangle-mesh.js";
|
|
2
|
+
export type SurfaceTransitionQualification = {
|
|
3
|
+
/** A fixed indexed disk stays a graph over XY throughout linear vertex interpolation. */
|
|
4
|
+
scope: 'convex-xy-disk-linear';
|
|
5
|
+
minimumProjectedDoubleArea: number;
|
|
6
|
+
boundary: Uint32Array;
|
|
7
|
+
};
|
|
8
|
+
/** Qualify a conservative subset of 3D mesh morphs, without time sampling.
|
|
9
|
+
* Input is an oriented, connected triangulated disk. Both endpoints share indices.
|
|
10
|
+
* Every triangle must retain positive XY orientation and the boundary must stay
|
|
11
|
+
* convex throughout linear vertex motion. Quadratic extrema test the full [0,1].
|
|
12
|
+
* This excludes holes, folded surfaces, most global globe meshes and curved vertex
|
|
13
|
+
* trajectories. It qualifies the piecewise-linear mesh, not its underlying smooth
|
|
14
|
+
* projection or a camera's approximation error. Floating-point margins reject
|
|
15
|
+
* near-degeneracy; this is not a formal interval-arithmetic certificate.
|
|
16
|
+
*/
|
|
17
|
+
export declare function qualifySurfaceTransition(mesh: TriangleMesh, targetPositions: ArrayLike<number>, options?: {
|
|
18
|
+
minimumDoubleArea?: number;
|
|
19
|
+
maxChecks?: number;
|
|
20
|
+
}): SurfaceTransitionQualification;
|
|
21
|
+
//# sourceMappingURL=qualify-surface-transition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qualify-surface-transition.d.ts","sourceRoot":"","sources":["../../src/utils/qualify-surface-transition.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,YAAY,EAAC,8CAA2C;AAErE,MAAM,MAAM,8BAA8B,GAAG;IAC3C,yFAAyF;IACzF,KAAK,EAAE,uBAAuB,CAAC;IAC/B,0BAA0B,EAAE,MAAM,CAAC;IACnC,QAAQ,EAAE,WAAW,CAAC;CACvB,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,YAAY,EAClB,eAAe,EAAE,SAAS,CAAC,MAAM,CAAC,EAClC,OAAO,GAAE;IAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAM,GAC7D,8BAA8B,CAiIhC"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/** Qualify a conservative subset of 3D mesh morphs, without time sampling.
|
|
2
|
+
* Input is an oriented, connected triangulated disk. Both endpoints share indices.
|
|
3
|
+
* Every triangle must retain positive XY orientation and the boundary must stay
|
|
4
|
+
* convex throughout linear vertex motion. Quadratic extrema test the full [0,1].
|
|
5
|
+
* This excludes holes, folded surfaces, most global globe meshes and curved vertex
|
|
6
|
+
* trajectories. It qualifies the piecewise-linear mesh, not its underlying smooth
|
|
7
|
+
* projection or a camera's approximation error. Floating-point margins reject
|
|
8
|
+
* near-degeneracy; this is not a formal interval-arithmetic certificate.
|
|
9
|
+
*/
|
|
10
|
+
export function qualifySurfaceTransition(mesh, targetPositions, options = {}) {
|
|
11
|
+
const from = Array.from(mesh.positions), to = Array.from(targetPositions), indices = Array.from(mesh.indices), count = from.length / 3, maxChecks = options.maxChecks ?? 1000000;
|
|
12
|
+
if (!from.length ||
|
|
13
|
+
from.length % 3 ||
|
|
14
|
+
to.length !== from.length ||
|
|
15
|
+
!indices.length ||
|
|
16
|
+
indices.length % 3 ||
|
|
17
|
+
!from.every(Number.isFinite) ||
|
|
18
|
+
!to.every(Number.isFinite) ||
|
|
19
|
+
!indices.every(i => Number.isSafeInteger(i) && i >= 0 && i < count) ||
|
|
20
|
+
!Number.isSafeInteger(maxChecks) ||
|
|
21
|
+
maxChecks < 0)
|
|
22
|
+
throw new RangeError('Invalid surface transition mesh or budget');
|
|
23
|
+
let scale = 0;
|
|
24
|
+
for (const positions of [from, to])
|
|
25
|
+
for (let i = 0; i < indices.length; i += 3)
|
|
26
|
+
for (let j = 0; j < 3; j++) {
|
|
27
|
+
const a = indices[i + j] * 3, b = indices[i + ((j + 1) % 3)] * 3;
|
|
28
|
+
scale = Math.max(scale, Math.hypot(positions[b] - positions[a], positions[b + 1] - positions[a + 1]));
|
|
29
|
+
}
|
|
30
|
+
const margin = options.minimumDoubleArea ?? scale * scale * 1e-12;
|
|
31
|
+
if (!Number.isFinite(margin) || margin <= 0)
|
|
32
|
+
throw new RangeError('Expected positive finite area margin');
|
|
33
|
+
let checks = 0;
|
|
34
|
+
const tick = () => {
|
|
35
|
+
if (++checks > maxChecks)
|
|
36
|
+
throw new RangeError('Surface qualification exceeded maxChecks');
|
|
37
|
+
};
|
|
38
|
+
const edges = new Map(), used = new Set(indices);
|
|
39
|
+
let minimum = Infinity;
|
|
40
|
+
const orientation = (a, b, c, t) => {
|
|
41
|
+
// Interpolate relative edges, avoiding cancellation from translating a patch
|
|
42
|
+
// across large world-coordinate origins before subtracting vertex positions.
|
|
43
|
+
const edge = (v, k) => (from[3 * v + k] - from[3 * a + k]) * (1 - t) + (to[3 * v + k] - to[3 * a + k]) * t;
|
|
44
|
+
return edge(b, 0) * edge(c, 1) - edge(b, 1) * edge(c, 0);
|
|
45
|
+
};
|
|
46
|
+
const minimumOrientation = (a, b, c) => {
|
|
47
|
+
tick();
|
|
48
|
+
return quadraticMinimum(t => orientation(a, b, c, t));
|
|
49
|
+
};
|
|
50
|
+
for (let i = 0; i < indices.length; i += 3) {
|
|
51
|
+
const tri = indices.slice(i, i + 3);
|
|
52
|
+
const area = minimumOrientation(tri[0], tri[1], tri[2]);
|
|
53
|
+
if (area < margin)
|
|
54
|
+
throw new RangeError('Triangle collapses or reverses during transition');
|
|
55
|
+
minimum = Math.min(minimum, area);
|
|
56
|
+
for (let j = 0; j < 3; j++) {
|
|
57
|
+
const a = tri[j], b = tri[(j + 1) % 3], key = a < b ? `${a}:${b}` : `${b}:${a}`, edge = edges.get(key);
|
|
58
|
+
if (edge) {
|
|
59
|
+
if (edge.faces !== 1 || edge.a !== b || edge.b !== a)
|
|
60
|
+
throw new RangeError('Expected oriented manifold edges');
|
|
61
|
+
edge.faces++;
|
|
62
|
+
}
|
|
63
|
+
else
|
|
64
|
+
edges.set(key, { a, b, faces: 1 });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const next = new Map();
|
|
68
|
+
for (const edge of edges.values())
|
|
69
|
+
if (edge.faces === 1) {
|
|
70
|
+
if (next.has(edge.a))
|
|
71
|
+
throw new RangeError('Nonmanifold boundary');
|
|
72
|
+
next.set(edge.a, edge.b);
|
|
73
|
+
}
|
|
74
|
+
if (!next.size || used.size !== count || used.size - edges.size + indices.length / 3 !== 1)
|
|
75
|
+
throw new RangeError('Expected a triangulated disk without unused vertices');
|
|
76
|
+
const start = next.keys().next().value, boundary = [];
|
|
77
|
+
const visitedBoundary = new Set();
|
|
78
|
+
let v = start;
|
|
79
|
+
do {
|
|
80
|
+
if (visitedBoundary.has(v) || !next.has(v))
|
|
81
|
+
throw new RangeError('Expected one boundary cycle');
|
|
82
|
+
visitedBoundary.add(v);
|
|
83
|
+
boundary.push(v);
|
|
84
|
+
v = next.get(v);
|
|
85
|
+
} while (v !== start);
|
|
86
|
+
if (boundary.length !== next.size)
|
|
87
|
+
throw new RangeError('Multiple boundary cycles');
|
|
88
|
+
// Every boundary vertex stays left of each directed support edge. This allows
|
|
89
|
+
// collinear refinement vertices while rejecting a nonconvex or crossing outline.
|
|
90
|
+
for (let i = 0; i < boundary.length; i++) {
|
|
91
|
+
const a = boundary[i], b = boundary[(i + 1) % boundary.length];
|
|
92
|
+
// Distinct boundary vertices rule out multiple winding of a convex outline
|
|
93
|
+
// (a locally positive double-cover fan would otherwise pass support tests).
|
|
94
|
+
for (let j = i + 1; j < boundary.length; j++) {
|
|
95
|
+
tick();
|
|
96
|
+
const c = boundary[j];
|
|
97
|
+
const separation = quadraticMinimum(t => {
|
|
98
|
+
const dx = (from[3 * c] - from[3 * a]) * (1 - t) + (to[3 * c] - to[3 * a]) * t, dy = (from[3 * c + 1] - from[3 * a + 1]) * (1 - t) + (to[3 * c + 1] - to[3 * a + 1]) * t;
|
|
99
|
+
return dx * dx + dy * dy;
|
|
100
|
+
});
|
|
101
|
+
if (separation < margin)
|
|
102
|
+
throw new RangeError('Boundary vertices meet during transition');
|
|
103
|
+
}
|
|
104
|
+
for (const c of boundary)
|
|
105
|
+
if (c !== a && c !== b && minimumOrientation(a, b, c) < -margin * 1e-3)
|
|
106
|
+
throw new RangeError('Boundary is not convex throughout transition');
|
|
107
|
+
}
|
|
108
|
+
// Euler characteristic plus one boundary is insufficient if a closed component
|
|
109
|
+
// is present. Explicitly require connectivity of the vertex graph.
|
|
110
|
+
const neighbors = Array.from({ length: count }, () => []);
|
|
111
|
+
for (const { a, b } of edges.values()) {
|
|
112
|
+
neighbors[a].push(b);
|
|
113
|
+
neighbors[b].push(a);
|
|
114
|
+
}
|
|
115
|
+
const seen = new Set([start]), queue = [start];
|
|
116
|
+
for (let i = 0; i < queue.length; i++)
|
|
117
|
+
for (const n of neighbors[queue[i]])
|
|
118
|
+
if (!seen.has(n)) {
|
|
119
|
+
seen.add(n);
|
|
120
|
+
queue.push(n);
|
|
121
|
+
}
|
|
122
|
+
if (seen.size !== count)
|
|
123
|
+
throw new RangeError('Disconnected surface mesh');
|
|
124
|
+
return {
|
|
125
|
+
scope: 'convex-xy-disk-linear',
|
|
126
|
+
minimumProjectedDoubleArea: minimum,
|
|
127
|
+
boundary: new Uint32Array(boundary)
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function quadraticMinimum(value) {
|
|
131
|
+
const f = value(0), g = value(1), h = value(0.5), a = 2 * (f + g - 2 * h), b = g - f - a;
|
|
132
|
+
if (![f, g, h, a, b].every(Number.isFinite))
|
|
133
|
+
throw new RangeError('Nonfinite surface orientation polynomial');
|
|
134
|
+
const t = a > 0 ? -b / (2 * a) : -1;
|
|
135
|
+
const result = Math.min(f, g, t > 0 && t < 1 ? value(t) : Infinity);
|
|
136
|
+
if (!Number.isFinite(result))
|
|
137
|
+
throw new RangeError('Nonfinite surface orientation');
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=qualify-surface-transition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qualify-surface-transition.js","sourceRoot":"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IAChB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC;QACzC,MAAM,IAAI,UAAU,CAAC,0CAA0C,CAAC,CAAC;IACnE,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IACpE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,+BAA+B,CAAC,CAAC;IACpF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
|
-
"version": "5.0.0-beta.
|
|
9
|
+
"version": "5.0.0-beta.11",
|
|
10
10
|
"keywords": [
|
|
11
11
|
"geometry",
|
|
12
12
|
"gltf",
|
|
@@ -32,17 +32,29 @@
|
|
|
32
32
|
"types": "./dist/culling/index.d.ts",
|
|
33
33
|
"import": "./dist/culling/index.js",
|
|
34
34
|
"require": "./dist/culling/index.cjs"
|
|
35
|
+
},
|
|
36
|
+
"./lighting": {
|
|
37
|
+
"types": "./dist/lighting/index.d.ts",
|
|
38
|
+
"import": "./dist/lighting/index.js",
|
|
39
|
+
"require": "./dist/lighting/index.cjs"
|
|
40
|
+
},
|
|
41
|
+
"./color": {
|
|
42
|
+
"types": "./dist/color/index.d.ts",
|
|
43
|
+
"import": "./dist/color/index.js",
|
|
44
|
+
"require": "./dist/color/index.cjs"
|
|
35
45
|
}
|
|
36
46
|
},
|
|
37
47
|
"files": [
|
|
38
48
|
"dist",
|
|
39
49
|
"src",
|
|
50
|
+
"!src/**/README.md",
|
|
51
|
+
"./README.md",
|
|
40
52
|
"LICENSE",
|
|
41
53
|
"THIRD-PARTY-NOTICES.md"
|
|
42
54
|
],
|
|
43
55
|
"dependencies": {
|
|
44
|
-
"@math.gl/core": "5.0.0-beta.
|
|
56
|
+
"@math.gl/core": "5.0.0-beta.11"
|
|
45
57
|
},
|
|
46
58
|
"sideEffects": false,
|
|
47
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "5f2da3c1b2c7ee38c4175c35698891ccaabaa668"
|
|
48
60
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/** Numerical RGB lookup table, independent of its file encoding or renderer. */
|
|
6
|
+
export type ColorLUT = {
|
|
7
|
+
/** Independent 1D curves or one 3D RGB mapping. */
|
|
8
|
+
dimension: 1 | 3;
|
|
9
|
+
/** Number of samples along each axis. */
|
|
10
|
+
size: number;
|
|
11
|
+
/** Interleaved RGB values, red coordinate varying fastest for 3D tables. */
|
|
12
|
+
data: Float32Array;
|
|
13
|
+
/** Minimum input coordinate for each channel. */
|
|
14
|
+
domainMinimum: number[];
|
|
15
|
+
/** Maximum input coordinate for each channel. */
|
|
16
|
+
domainMaximum: number[];
|
|
17
|
+
/** Optional strictly increasing normalized knots from 0 through 1. */
|
|
18
|
+
inputGrid?: Float64Array;
|
|
19
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
export {createColorLUTSampler, applyColorLUT} from './sample-lut';
|
|
5
|
+
export type {ColorLUTSampler, ApplyColorLUTOptions} from './sample-lut';
|
|
6
|
+
export type {ColorLUT} from './color-lut-types';
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import type {ColorLUT} from './color-lut-types';
|
|
5
|
+
|
|
6
|
+
/** Reusable RGB sampler; inputs use the authored domain and outputs retain signed/HDR values. */
|
|
7
|
+
export type ColorLUTSampler = (
|
|
8
|
+
red: number,
|
|
9
|
+
green: number,
|
|
10
|
+
blue: number
|
|
11
|
+
) => [number, number, number];
|
|
12
|
+
|
|
13
|
+
/** Options for interleaved floating-point RGB or RGBA buffers. */
|
|
14
|
+
export type ApplyColorLUTOptions = {
|
|
15
|
+
/** Number of interleaved components; default 3. Alpha is copied at float32 precision. */
|
|
16
|
+
components?: 3 | 4;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Creates a snapshot sampler with per-channel 1D linear or red-fastest 3D trilinear interpolation. */
|
|
20
|
+
export function createColorLUTSampler(lut: ColorLUT): ColorLUTSampler {
|
|
21
|
+
const writeSample = createColorLUTWriter(lut);
|
|
22
|
+
return (red, green, blue) => {
|
|
23
|
+
const result: [number, number, number] = [0, 0, 0];
|
|
24
|
+
writeSample(red, green, blue, result, 0);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Creates a validated snapshot writer with reusable per-sampler scratch storage. */
|
|
30
|
+
function createColorLUTWriter(lut: ColorLUT) {
|
|
31
|
+
const {dimension, size} = lut;
|
|
32
|
+
if (
|
|
33
|
+
![1, 3].includes(dimension) ||
|
|
34
|
+
!Number.isSafeInteger(size) ||
|
|
35
|
+
size < 2 ||
|
|
36
|
+
!Number.isSafeInteger(size ** dimension * 3) ||
|
|
37
|
+
lut.data.length !== size ** dimension * 3 ||
|
|
38
|
+
lut.domainMinimum.length !== 3 ||
|
|
39
|
+
lut.domainMaximum.length !== 3
|
|
40
|
+
) {
|
|
41
|
+
throw new Error('LUT: invalid calculation table');
|
|
42
|
+
}
|
|
43
|
+
const minimum = Array.from(lut.domainMinimum);
|
|
44
|
+
const maximum = Array.from(lut.domainMaximum);
|
|
45
|
+
for (let channel = 0; channel < 3; channel++) {
|
|
46
|
+
if (
|
|
47
|
+
!Number.isFinite(minimum[channel]) ||
|
|
48
|
+
!Number.isFinite(maximum[channel]) ||
|
|
49
|
+
!Number.isFinite(maximum[channel] - minimum[channel]) ||
|
|
50
|
+
maximum[channel] <= minimum[channel]
|
|
51
|
+
)
|
|
52
|
+
throw new Error('LUT: invalid calculation domain');
|
|
53
|
+
}
|
|
54
|
+
if (!lut.data.every(Number.isFinite)) throw new Error('LUT: invalid calculation samples');
|
|
55
|
+
const data = lut.data.slice();
|
|
56
|
+
const grid = lut.inputGrid?.slice();
|
|
57
|
+
if (
|
|
58
|
+
grid &&
|
|
59
|
+
(grid.length !== size ||
|
|
60
|
+
grid[0] !== 0 ||
|
|
61
|
+
grid[size - 1] !== 1 ||
|
|
62
|
+
grid.some(
|
|
63
|
+
(value, index) => !Number.isFinite(value) || (index > 0 && value <= grid[index - 1])
|
|
64
|
+
))
|
|
65
|
+
) {
|
|
66
|
+
throw new Error('LUT: invalid nonuniform input grid');
|
|
67
|
+
}
|
|
68
|
+
const coordinates = [0, 0, 0];
|
|
69
|
+
const indices = [0, 0, 0];
|
|
70
|
+
const weights = [0, 0, 0];
|
|
71
|
+
const accumulated = [0, 0, 0];
|
|
72
|
+
return (
|
|
73
|
+
red: number,
|
|
74
|
+
green: number,
|
|
75
|
+
blue: number,
|
|
76
|
+
result: [number, number, number] | Float32Array,
|
|
77
|
+
resultOffset: number
|
|
78
|
+
): void => {
|
|
79
|
+
coordinates[0] = red;
|
|
80
|
+
coordinates[1] = green;
|
|
81
|
+
coordinates[2] = blue;
|
|
82
|
+
for (let channel = 0; channel < 3; channel++) {
|
|
83
|
+
const value = coordinates[channel];
|
|
84
|
+
if (!Number.isFinite(value)) throw new Error('LUT: input colors must be finite');
|
|
85
|
+
const normalized =
|
|
86
|
+
value <= minimum[channel]
|
|
87
|
+
? 0
|
|
88
|
+
: value >= maximum[channel]
|
|
89
|
+
? 1
|
|
90
|
+
: (value - minimum[channel]) / (maximum[channel] - minimum[channel]);
|
|
91
|
+
writeLUTInterval(normalized, size, grid, indices, weights, channel);
|
|
92
|
+
}
|
|
93
|
+
accumulated[0] = 0;
|
|
94
|
+
accumulated[1] = 0;
|
|
95
|
+
accumulated[2] = 0;
|
|
96
|
+
if (dimension === 1) {
|
|
97
|
+
for (let channel = 0; channel < 3; channel++) {
|
|
98
|
+
const offset = indices[channel] * 3 + channel;
|
|
99
|
+
accumulated[channel] =
|
|
100
|
+
data[offset] * (1 - weights[channel]) + data[offset + 3] * weights[channel];
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
for (let blueCorner = 0; blueCorner < 2; blueCorner++) {
|
|
104
|
+
for (let greenCorner = 0; greenCorner < 2; greenCorner++) {
|
|
105
|
+
for (let redCorner = 0; redCorner < 2; redCorner++) {
|
|
106
|
+
const weight =
|
|
107
|
+
(redCorner ? weights[0] : 1 - weights[0]) *
|
|
108
|
+
(greenCorner ? weights[1] : 1 - weights[1]) *
|
|
109
|
+
(blueCorner ? weights[2] : 1 - weights[2]);
|
|
110
|
+
const offset =
|
|
111
|
+
(((indices[2] + blueCorner) * size + indices[1] + greenCorner) * size +
|
|
112
|
+
indices[0] +
|
|
113
|
+
redCorner) *
|
|
114
|
+
3;
|
|
115
|
+
for (let channel = 0; channel < 3; channel++)
|
|
116
|
+
accumulated[channel] += data[offset + channel] * weight;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
for (let channel = 0; channel < 3; channel++)
|
|
122
|
+
result[resultOffset + channel] = accumulated[channel];
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Applies a LUT to floating-point pixels without changing the source or applying transfer functions. */
|
|
127
|
+
export function applyColorLUT(
|
|
128
|
+
lut: ColorLUT,
|
|
129
|
+
colors: Float32Array | Float64Array,
|
|
130
|
+
options: ApplyColorLUTOptions = {}
|
|
131
|
+
): Float32Array {
|
|
132
|
+
const {components = 3} = options;
|
|
133
|
+
if (![3, 4].includes(components) || colors.length % components !== 0)
|
|
134
|
+
throw new Error('LUT: invalid pixel component count');
|
|
135
|
+
const writeSample = createColorLUTWriter(lut);
|
|
136
|
+
const result = new Float32Array(colors.length);
|
|
137
|
+
for (let offset = 0; offset < colors.length; offset += components) {
|
|
138
|
+
writeSample(colors[offset], colors[offset + 1], colors[offset + 2], result, offset);
|
|
139
|
+
if (components === 4) {
|
|
140
|
+
const alpha = colors[offset + 3];
|
|
141
|
+
result[offset + 3] = alpha;
|
|
142
|
+
if (!Number.isFinite(alpha) || !Number.isFinite(result[offset + 3]))
|
|
143
|
+
throw new Error('LUT: alpha cannot be represented as float32');
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Finds normalized uniform/nonuniform knots, retaining the final endpoint in the last interval. */
|
|
150
|
+
function writeLUTInterval(
|
|
151
|
+
value: number,
|
|
152
|
+
size: number,
|
|
153
|
+
grid: Float64Array | undefined,
|
|
154
|
+
indices: number[],
|
|
155
|
+
weights: number[],
|
|
156
|
+
channel: number
|
|
157
|
+
): void {
|
|
158
|
+
if (!grid) {
|
|
159
|
+
const coordinate = value * (size - 1);
|
|
160
|
+
const lower = Math.min(Math.floor(coordinate), size - 2);
|
|
161
|
+
indices[channel] = lower;
|
|
162
|
+
weights[channel] = coordinate - lower;
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
let lower = 0;
|
|
166
|
+
let upper = size - 1;
|
|
167
|
+
while (upper - lower > 1) {
|
|
168
|
+
const midpoint = Math.floor((lower + upper) / 2);
|
|
169
|
+
if (value < grid[midpoint]) upper = midpoint;
|
|
170
|
+
else lower = midpoint;
|
|
171
|
+
}
|
|
172
|
+
lower = Math.min(lower, size - 2);
|
|
173
|
+
indices[channel] = lower;
|
|
174
|
+
weights[channel] = (value - grid[lower]) / (grid[lower + 1] - grid[lower]);
|
|
175
|
+
}
|