@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
package/src/utils/index.ts
CHANGED
|
@@ -4,10 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
export type {TypedArray, TypedArrayConstructor} from '@math.gl/core';
|
|
6
6
|
|
|
7
|
-
export {
|
|
8
|
-
export {default as GLType} from './gl-type';
|
|
9
|
-
|
|
10
|
-
export type {Geometry, GeometryAttribute} from './geometry';
|
|
7
|
+
export type {GeometryInput, GeometryAttribute} from './geometry';
|
|
11
8
|
export {isGeometry} from './geometry';
|
|
12
9
|
|
|
13
10
|
export type {Primitive} from './primitive-iterator';
|
|
@@ -43,7 +40,10 @@ export {
|
|
|
43
40
|
weldGeometry,
|
|
44
41
|
getDegenerateTriangles
|
|
45
42
|
} from './mesh-processing';
|
|
46
|
-
export type {
|
|
43
|
+
export type {
|
|
44
|
+
WeldGeometryOptions,
|
|
45
|
+
WeldGeometryResult
|
|
46
|
+
} from './mesh-processing';
|
|
47
47
|
|
|
48
48
|
export {interpolatePackedAttributes} from './interpolate-packed-attributes';
|
|
49
49
|
export type {
|
|
@@ -4,21 +4,28 @@
|
|
|
4
4
|
|
|
5
5
|
import {Matrix4} from '@math.gl/core';
|
|
6
6
|
import type {TypedArray, TypedArrayConstructor} from '@math.gl/core';
|
|
7
|
-
import {
|
|
8
|
-
import {getAttributeValues, type Geometry, type GeometryAttribute} from './geometry';
|
|
7
|
+
import {getAttributeValues, type GeometryInput, type GeometryAttribute} from './geometry';
|
|
9
8
|
|
|
9
|
+
/** Geometry emitted by triangle mesh operations. */
|
|
10
|
+
type TriangleGeometry = GeometryInput & {topology: 'triangle-list'};
|
|
11
|
+
|
|
12
|
+
/** Validated, packed mesh buffers used internally by mesh operations. */
|
|
10
13
|
type MeshData = {
|
|
14
|
+
/** Attributes with resolved buffers and element sizes. */
|
|
11
15
|
attributes: Record<string, {value: TypedArray; size: number}>;
|
|
16
|
+
/** Semantic name of the position attribute. */
|
|
12
17
|
position: string;
|
|
18
|
+
/** Number of vertices in each attribute buffer. */
|
|
13
19
|
count: number;
|
|
20
|
+
/** Explicit triangle indices, including those generated for non-indexed input. */
|
|
14
21
|
indices: Uint32Array;
|
|
15
22
|
};
|
|
16
23
|
|
|
17
24
|
/** Fresh, indexed triangle-list geometry. No input buffers are changed. */
|
|
18
25
|
export function transformGeometry(
|
|
19
|
-
geometry:
|
|
26
|
+
geometry: GeometryInput,
|
|
20
27
|
matrix: Readonly<ArrayLike<number>>
|
|
21
|
-
):
|
|
28
|
+
): TriangleGeometry {
|
|
22
29
|
const mesh = readMesh(geometry);
|
|
23
30
|
if (
|
|
24
31
|
matrix.length !== 16 ||
|
|
@@ -99,11 +106,11 @@ export function transformGeometry(
|
|
|
99
106
|
if (determinant < 0)
|
|
100
107
|
for (let i = 0; i < indices.length; i += 3)
|
|
101
108
|
[indices[i + 1], indices[i + 2]] = [indices[i + 2], indices[i + 1]];
|
|
102
|
-
return {
|
|
109
|
+
return {topology: 'triangle-list', attributes, indices};
|
|
103
110
|
}
|
|
104
111
|
|
|
105
112
|
/** Concatenates compatible triangle meshes and offsets vertex indices. */
|
|
106
|
-
export function mergeGeometries(geometries: readonly
|
|
113
|
+
export function mergeGeometries(geometries: readonly GeometryInput[]): TriangleGeometry {
|
|
107
114
|
if (!geometries.length) throw new RangeError('At least one geometry is required');
|
|
108
115
|
const meshes = geometries.map(readMesh),
|
|
109
116
|
first = meshes[0],
|
|
@@ -148,21 +155,26 @@ export function mergeGeometries(geometries: readonly Geometry[]): Geometry {
|
|
|
148
155
|
for (const index of mesh.indices) indices[indexOffset++] = index + vertexOffset;
|
|
149
156
|
vertexOffset += mesh.count;
|
|
150
157
|
}
|
|
151
|
-
return {
|
|
158
|
+
return {topology: 'triangle-list', attributes, indices};
|
|
152
159
|
}
|
|
153
160
|
|
|
161
|
+
/** Controls vertex matching during a weld. */
|
|
154
162
|
export type WeldGeometryOptions = {
|
|
155
163
|
/** Position quantization step; zero means exact matching. */ positionGridSize?: number;
|
|
156
164
|
};
|
|
165
|
+
/** Welded mesh and the mapping from its original vertices. */
|
|
157
166
|
export type WeldGeometryResult = {
|
|
158
|
-
|
|
167
|
+
/** Welded triangle mesh. */
|
|
168
|
+
geometry: TriangleGeometry;
|
|
169
|
+
/** Welded vertex index for each original vertex. */
|
|
159
170
|
vertexMap: Uint32Array;
|
|
171
|
+
/** Number of duplicate vertices removed. */
|
|
160
172
|
removedVertices: number;
|
|
161
173
|
};
|
|
162
174
|
|
|
163
175
|
/** Welds full attribute tuples, preserving UV seams and hard normal edges. */
|
|
164
176
|
export function weldGeometry(
|
|
165
|
-
geometry:
|
|
177
|
+
geometry: GeometryInput,
|
|
166
178
|
options: WeldGeometryOptions = {}
|
|
167
179
|
): WeldGeometryResult {
|
|
168
180
|
const mesh = readMesh(geometry),
|
|
@@ -208,7 +220,7 @@ export function weldGeometry(
|
|
|
208
220
|
}
|
|
209
221
|
return {
|
|
210
222
|
geometry: {
|
|
211
|
-
|
|
223
|
+
topology: 'triangle-list',
|
|
212
224
|
attributes,
|
|
213
225
|
indices: Uint32Array.from(mesh.indices, index => vertexMap[index])
|
|
214
226
|
},
|
|
@@ -218,7 +230,7 @@ export function weldGeometry(
|
|
|
218
230
|
}
|
|
219
231
|
|
|
220
232
|
/** Returns triangle numbers with area <= areaEpsilon, in original draw order. */
|
|
221
|
-
export function getDegenerateTriangles(geometry:
|
|
233
|
+
export function getDegenerateTriangles(geometry: GeometryInput, areaEpsilon = 0): Uint32Array {
|
|
222
234
|
if (!Number.isFinite(areaEpsilon) || areaEpsilon < 0)
|
|
223
235
|
throw new RangeError('Area epsilon must be finite and nonnegative');
|
|
224
236
|
const mesh = readMesh(geometry),
|
|
@@ -256,8 +268,9 @@ export function getDegenerateTriangles(geometry: Geometry, areaEpsilon = 0): Uin
|
|
|
256
268
|
return Uint32Array.from(result);
|
|
257
269
|
}
|
|
258
270
|
|
|
259
|
-
|
|
260
|
-
|
|
271
|
+
/** Validates triangle connectivity and resolves the packed input buffers. */
|
|
272
|
+
function readMesh(geometry: GeometryInput): MeshData {
|
|
273
|
+
if (geometry.topology !== 'triangle-list')
|
|
261
274
|
throw new RangeError('Packed triangle-list geometry is required');
|
|
262
275
|
const position = geometry.attributes['POSITION']
|
|
263
276
|
? 'POSITION'
|
|
@@ -363,7 +376,10 @@ function toDyadic(value: number): Dyadic {
|
|
|
363
376
|
const exponentBits = (high >>> 20) & 0x7ff;
|
|
364
377
|
const fraction = (BigInt(high & 0xfffff) << 32n) | BigInt(low);
|
|
365
378
|
const n = exponentBits ? (1n << 52n) | fraction : fraction;
|
|
366
|
-
return {
|
|
379
|
+
return {
|
|
380
|
+
n: high >>> 31 ? -n : n,
|
|
381
|
+
exponent: exponentBits ? exponentBits - 1075 : -1074
|
|
382
|
+
};
|
|
367
383
|
}
|
|
368
384
|
function subtractDyadic(a: Dyadic, b: Dyadic): Dyadic {
|
|
369
385
|
const exponent = Math.min(a.exponent, b.exponent);
|
|
@@ -2,72 +2,77 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {
|
|
6
|
-
import {GL} from './constants';
|
|
7
|
-
import type {Geometry} from './geometry';
|
|
5
|
+
import type {GeometryInput} from './geometry';
|
|
8
6
|
import {getAttributeValues, getPositionAttribute, isGeometry} from './geometry';
|
|
9
7
|
|
|
10
8
|
/** One dereferenced point, line, or triangle primitive. */
|
|
11
9
|
export type Primitive = {
|
|
10
|
+
/** The input geometry’s attribute map. */
|
|
12
11
|
attributes: object;
|
|
13
|
-
|
|
12
|
+
/** List topology of the emitted primitive. */
|
|
13
|
+
type: 'point-list' | 'line-list' | 'triangle-list';
|
|
14
|
+
/** Index of the first vertex. */
|
|
14
15
|
i1: number;
|
|
16
|
+
/** Index of the second vertex on a line or triangle. */
|
|
15
17
|
i2?: number;
|
|
18
|
+
/** Index of the third vertex on a triangle. */
|
|
16
19
|
i3?: number;
|
|
20
|
+
/** Zero-based index in this iteration. */
|
|
17
21
|
primitiveIndex: number;
|
|
18
22
|
};
|
|
19
23
|
|
|
20
24
|
/**
|
|
21
25
|
* Iterates through a geometry's primitives and dereferences optional indices.
|
|
22
26
|
*
|
|
23
|
-
*
|
|
27
|
+
* @param geometry - Geometry whose optional indices are dereferenced.
|
|
28
|
+
* @param options - Zero-based, end-exclusive range in the index or vertex sequence.
|
|
24
29
|
*/
|
|
25
30
|
export function* makePrimitiveIterator(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
geometry: GeometryInput,
|
|
32
|
+
options: {
|
|
33
|
+
/** Offset of the first index or vertex to consider. */
|
|
34
|
+
start?: number;
|
|
35
|
+
/** Exclusive end of the range. Defaults to the index or vertex count. */
|
|
36
|
+
end?: number;
|
|
37
|
+
} = {}
|
|
31
38
|
): Iterable<Primitive> {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
if (!isGeometry(geometry)) {
|
|
40
|
+
throw new TypeError('Geometry with a supported topology and attributes is required');
|
|
41
|
+
}
|
|
42
|
+
const {start = 0} = options;
|
|
43
|
+
let end = options.end;
|
|
44
|
+
const {attributes, topology} = geometry;
|
|
45
|
+
const indices = geometry.indices ? getAttributeValues(geometry.indices) : undefined;
|
|
46
|
+
if (end === undefined) {
|
|
47
|
+
if (indices) {
|
|
48
|
+
end = indices.length;
|
|
49
|
+
} else {
|
|
39
50
|
const position = getPositionAttribute(geometry);
|
|
40
|
-
end =
|
|
51
|
+
end = getAttributeValues(position).length / (position.size || 3);
|
|
41
52
|
}
|
|
42
|
-
} else if (geometryOrIndices) {
|
|
43
|
-
indices = getAttributeValues(geometryOrIndices);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (mode === undefined) {
|
|
47
|
-
throw new Error('Primitive mode is required');
|
|
48
53
|
}
|
|
49
|
-
end ??= indices?.length ?? start;
|
|
50
54
|
|
|
55
|
+
/** Resolves an index-buffer offset or sequential vertex index. */
|
|
51
56
|
const dereference = (index: number): number => Number(indices ? indices[index] : index);
|
|
52
57
|
let primitiveIndex = 0;
|
|
53
58
|
|
|
54
|
-
switch (
|
|
55
|
-
case
|
|
59
|
+
switch (topology) {
|
|
60
|
+
case 'point-list':
|
|
56
61
|
for (let index = start; index < end; index++) {
|
|
57
62
|
yield {
|
|
58
63
|
attributes,
|
|
59
|
-
type:
|
|
64
|
+
type: 'point-list',
|
|
60
65
|
i1: dereference(index),
|
|
61
66
|
primitiveIndex: primitiveIndex++
|
|
62
67
|
};
|
|
63
68
|
}
|
|
64
69
|
return;
|
|
65
70
|
|
|
66
|
-
case
|
|
71
|
+
case 'line-list':
|
|
67
72
|
for (let index = start; index + 1 < end; index += 2) {
|
|
68
73
|
yield {
|
|
69
74
|
attributes,
|
|
70
|
-
type:
|
|
75
|
+
type: 'line-list',
|
|
71
76
|
i1: dereference(index),
|
|
72
77
|
i2: dereference(index + 1),
|
|
73
78
|
primitiveIndex: primitiveIndex++
|
|
@@ -75,11 +80,11 @@ export function* makePrimitiveIterator(
|
|
|
75
80
|
}
|
|
76
81
|
return;
|
|
77
82
|
|
|
78
|
-
case
|
|
83
|
+
case 'line-strip':
|
|
79
84
|
for (let index = start; index + 1 < end; index++) {
|
|
80
85
|
yield {
|
|
81
86
|
attributes,
|
|
82
|
-
type:
|
|
87
|
+
type: 'line-list',
|
|
83
88
|
i1: dereference(index),
|
|
84
89
|
i2: dereference(index + 1),
|
|
85
90
|
primitiveIndex: primitiveIndex++
|
|
@@ -87,11 +92,11 @@ export function* makePrimitiveIterator(
|
|
|
87
92
|
}
|
|
88
93
|
return;
|
|
89
94
|
|
|
90
|
-
case
|
|
95
|
+
case 'line-loop':
|
|
91
96
|
for (let index = start; index < end; index++) {
|
|
92
97
|
yield {
|
|
93
98
|
attributes,
|
|
94
|
-
type:
|
|
99
|
+
type: 'line-list',
|
|
95
100
|
i1: dereference(index),
|
|
96
101
|
i2: dereference(index + 1 < end ? index + 1 : start),
|
|
97
102
|
primitiveIndex: primitiveIndex++
|
|
@@ -99,11 +104,11 @@ export function* makePrimitiveIterator(
|
|
|
99
104
|
}
|
|
100
105
|
return;
|
|
101
106
|
|
|
102
|
-
case
|
|
107
|
+
case 'triangle-list':
|
|
103
108
|
for (let index = start; index + 2 < end; index += 3) {
|
|
104
109
|
yield {
|
|
105
110
|
attributes,
|
|
106
|
-
type:
|
|
111
|
+
type: 'triangle-list',
|
|
107
112
|
i1: dereference(index),
|
|
108
113
|
i2: dereference(index + 1),
|
|
109
114
|
i3: dereference(index + 2),
|
|
@@ -112,12 +117,12 @@ export function* makePrimitiveIterator(
|
|
|
112
117
|
}
|
|
113
118
|
return;
|
|
114
119
|
|
|
115
|
-
case
|
|
120
|
+
case 'triangle-strip':
|
|
116
121
|
for (let index = start; index + 2 < end; index++) {
|
|
117
122
|
const odd = (index - start) % 2 === 1;
|
|
118
123
|
yield {
|
|
119
124
|
attributes,
|
|
120
|
-
type:
|
|
125
|
+
type: 'triangle-list',
|
|
121
126
|
i1: dereference(odd ? index + 1 : index),
|
|
122
127
|
i2: dereference(odd ? index : index + 1),
|
|
123
128
|
i3: dereference(index + 2),
|
|
@@ -126,11 +131,11 @@ export function* makePrimitiveIterator(
|
|
|
126
131
|
}
|
|
127
132
|
return;
|
|
128
133
|
|
|
129
|
-
case
|
|
134
|
+
case 'triangle-fan':
|
|
130
135
|
for (let index = start + 1; index + 1 < end; index++) {
|
|
131
136
|
yield {
|
|
132
137
|
attributes,
|
|
133
|
-
type:
|
|
138
|
+
type: 'triangle-list',
|
|
134
139
|
i1: dereference(start),
|
|
135
140
|
i2: dereference(index),
|
|
136
141
|
i3: dereference(index + 1),
|
|
@@ -138,8 +143,5 @@ export function* makePrimitiveIterator(
|
|
|
138
143
|
};
|
|
139
144
|
}
|
|
140
145
|
return;
|
|
141
|
-
|
|
142
|
-
default:
|
|
143
|
-
throw new Error(`Unknown primitive mode ${mode}`);
|
|
144
146
|
}
|
|
145
147
|
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/** A finite, continuous source box with ordered minimum and maximum coordinates. */
|
|
6
|
+
export type ProjectionSourceBounds = readonly [ArrayLike<number>, ArrayLike<number>];
|
|
7
|
+
|
|
8
|
+
/** Controls bounded sampling of a prepared synchronous coordinate transform. */
|
|
9
|
+
export type ProjectBoundsOptions = {
|
|
10
|
+
/** Receives a fresh source array. Null/nonfinite output rejects the whole result.
|
|
11
|
+
* Exceptions propagate unchanged; no projection engine is imported by this helper.
|
|
12
|
+
*/
|
|
13
|
+
transform: (position: readonly number[]) => ArrayLike<number> | null;
|
|
14
|
+
/** Output dimension, 2 or 3. Defaults to the source dimension. */
|
|
15
|
+
targetSize?: 2 | 3;
|
|
16
|
+
/** Equal subdivisions on each nonzero source axis. Positive integer; default 8. */
|
|
17
|
+
subdivisions?: number;
|
|
18
|
+
/** Maximum transform calls. Positive safe integer; default 262144. */
|
|
19
|
+
maxSamples?: number;
|
|
20
|
+
/** Optional caller-qualified global Lipschitz constant for EACH output component,
|
|
21
|
+
* measured against Euclidean source distance over the ENTIRE source box.
|
|
22
|
+
* Requires a finite continuous transform throughout the box, not merely at samples.
|
|
23
|
+
* This contract cannot be inferred or verified from point samples.
|
|
24
|
+
*/
|
|
25
|
+
lipschitz?: readonly number[];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** Detached bounds plus an explicit qualification; invalid results never expose partial bounds. */
|
|
29
|
+
export type ProjectedBoundsResult =
|
|
30
|
+
| {
|
|
31
|
+
/** 'sampled' is for approximate fitting only; 'conservative' requires the supplied contract. */
|
|
32
|
+
status: 'sampled' | 'conservative';
|
|
33
|
+
/** Output minimum and maximum vectors; safe for culling only in conservative mode. */
|
|
34
|
+
bounds: [number[], number[]];
|
|
35
|
+
/** Number of transform calls. */
|
|
36
|
+
sampleCount: number;
|
|
37
|
+
}
|
|
38
|
+
| {
|
|
39
|
+
/** A null/nonfinite transform sample or unrepresentable enclosure was encountered. */
|
|
40
|
+
status: 'invalid';
|
|
41
|
+
/** No partial result is safe to use. */
|
|
42
|
+
bounds: null;
|
|
43
|
+
/** Number of transform calls, including an invalid sample if applicable. */
|
|
44
|
+
sampleCount: number;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Projects a lattice covering corners, edges, faces and the interior of a 2D/3D box.
|
|
48
|
+
* Sampling alone cannot establish an enclosure for a nonlinear transform. When qualified
|
|
49
|
+
* global Lipschitz constants are supplied, inflate by the lattice covering radius instead
|
|
50
|
+
* of claiming corner/sample extrema are conservative. Split seams and domains beforehand.
|
|
51
|
+
*/
|
|
52
|
+
export function projectBounds(
|
|
53
|
+
sourceBounds: ProjectionSourceBounds,
|
|
54
|
+
options: ProjectBoundsOptions
|
|
55
|
+
): ProjectedBoundsResult {
|
|
56
|
+
const [minimum, maximum] = sourceBounds;
|
|
57
|
+
const size = minimum.length;
|
|
58
|
+
const {transform, targetSize = size, subdivisions = 8, maxSamples = 262144, lipschitz} = options;
|
|
59
|
+
if (
|
|
60
|
+
(size !== 2 && size !== 3) ||
|
|
61
|
+
maximum.length !== size ||
|
|
62
|
+
(targetSize !== 2 && targetSize !== 3)
|
|
63
|
+
) {
|
|
64
|
+
throw new RangeError('Bounds and target dimension must be 2 or 3');
|
|
65
|
+
}
|
|
66
|
+
if (
|
|
67
|
+
!Number.isSafeInteger(subdivisions) ||
|
|
68
|
+
subdivisions < 1 ||
|
|
69
|
+
!Number.isSafeInteger(maxSamples) ||
|
|
70
|
+
maxSamples < 1
|
|
71
|
+
) {
|
|
72
|
+
throw new RangeError('Subdivision and sample budgets must be positive safe integers');
|
|
73
|
+
}
|
|
74
|
+
if (
|
|
75
|
+
lipschitz &&
|
|
76
|
+
(lipschitz.length !== targetSize ||
|
|
77
|
+
!Array.from(lipschitz).every(value => Number.isFinite(value) && value >= 0))
|
|
78
|
+
) {
|
|
79
|
+
throw new RangeError('Lipschitz constants must be finite, nonnegative and match target size');
|
|
80
|
+
}
|
|
81
|
+
const widths: number[] = [];
|
|
82
|
+
const counts: number[] = [];
|
|
83
|
+
let count = 1;
|
|
84
|
+
for (let axis = 0; axis < size; axis++) {
|
|
85
|
+
const width = maximum[axis] - minimum[axis];
|
|
86
|
+
if (
|
|
87
|
+
!Number.isFinite(minimum[axis]) ||
|
|
88
|
+
!Number.isFinite(maximum[axis]) ||
|
|
89
|
+
!Number.isFinite(width) ||
|
|
90
|
+
width < 0
|
|
91
|
+
) {
|
|
92
|
+
throw new RangeError('Source bounds must have finite ordered coordinates and extents');
|
|
93
|
+
}
|
|
94
|
+
widths.push(width);
|
|
95
|
+
counts.push(width === 0 ? 1 : subdivisions + 1);
|
|
96
|
+
count *= counts[axis];
|
|
97
|
+
if (!Number.isSafeInteger(count) || count > maxSamples) {
|
|
98
|
+
throw new RangeError('Projected bounds exceed the sample budget');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const lower = new Array<number>(targetSize).fill(Infinity);
|
|
102
|
+
const upper = new Array<number>(targetSize).fill(-Infinity);
|
|
103
|
+
for (let index = 0; index < count; index++) {
|
|
104
|
+
let remaining = index;
|
|
105
|
+
const source: number[] = [];
|
|
106
|
+
for (let axis = 0; axis < size; axis++) {
|
|
107
|
+
const step = remaining % counts[axis];
|
|
108
|
+
remaining = Math.floor(remaining / counts[axis]);
|
|
109
|
+
source.push(
|
|
110
|
+
step === 0
|
|
111
|
+
? minimum[axis]
|
|
112
|
+
: step === subdivisions
|
|
113
|
+
? maximum[axis]
|
|
114
|
+
: minimum[axis] + widths[axis] * (step / subdivisions)
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
const projected = transform(source);
|
|
118
|
+
if (!projected || projected.length < targetSize) {
|
|
119
|
+
return {status: 'invalid', bounds: null, sampleCount: index + 1};
|
|
120
|
+
}
|
|
121
|
+
for (let axis = 0; axis < targetSize; axis++) {
|
|
122
|
+
if (!Number.isFinite(projected[axis]))
|
|
123
|
+
return {status: 'invalid', bounds: null, sampleCount: index + 1};
|
|
124
|
+
lower[axis] = Math.min(lower[axis], projected[axis]);
|
|
125
|
+
upper[axis] = Math.max(upper[axis], projected[axis]);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (lipschitz) {
|
|
129
|
+
const radius = Math.hypot(
|
|
130
|
+
...widths.map(
|
|
131
|
+
(width, axis) =>
|
|
132
|
+
width / subdivisions / 2 +
|
|
133
|
+
4 * Number.EPSILON * Math.max(Math.abs(minimum[axis]), Math.abs(maximum[axis]))
|
|
134
|
+
)
|
|
135
|
+
);
|
|
136
|
+
for (let axis = 0; axis < targetSize; axis++) {
|
|
137
|
+
const displacement = lipschitz[axis] * radius;
|
|
138
|
+
const roundoff =
|
|
139
|
+
8 *
|
|
140
|
+
Number.EPSILON *
|
|
141
|
+
Math.max(1, Math.abs(lower[axis]), Math.abs(upper[axis]), displacement);
|
|
142
|
+
lower[axis] -= displacement + roundoff;
|
|
143
|
+
upper[axis] += displacement + roundoff;
|
|
144
|
+
if (!Number.isFinite(lower[axis]) || !Number.isFinite(upper[axis])) {
|
|
145
|
+
return {status: 'invalid', bounds: null, sampleCount: count};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
status: lipschitz ? 'conservative' : 'sampled',
|
|
151
|
+
bounds: [lower, upper],
|
|
152
|
+
sampleCount: count
|
|
153
|
+
};
|
|
154
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/** Projects packed source vertices into an explicitly located image rectangle. */
|
|
6
|
+
export type ProjectTextureCoordinatesOptions = {
|
|
7
|
+
/** Prepared synchronous source-to-image transform. Receives a fresh source array.
|
|
8
|
+
* Null or nonfinite XY rejects the operation; exceptions propagate unchanged.
|
|
9
|
+
*/
|
|
10
|
+
transform: (position: readonly number[]) => ArrayLike<number> | null;
|
|
11
|
+
/** Image rectangle [left, bottom, right, top], in the transform's output coordinates. */
|
|
12
|
+
bounds: readonly [number, number, number, number];
|
|
13
|
+
/** Number of packed source components per vertex. Default 3. */
|
|
14
|
+
size?: 2 | 3;
|
|
15
|
+
/** Texture origin. Default 'top-left'; bottom-left makes V increase with image Y. */
|
|
16
|
+
origin?: 'top-left' | 'bottom-left';
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Generates detached float64 UVs without changing positions, indices or vertex order.
|
|
20
|
+
* Outside-image coordinates remain outside [0, 1]. This performs no subdivision,
|
|
21
|
+
* seam inference, domain clipping, GPU readback, or asynchronous preparation.
|
|
22
|
+
*/
|
|
23
|
+
export function projectTextureCoordinates(
|
|
24
|
+
positions: ArrayLike<number>,
|
|
25
|
+
options: ProjectTextureCoordinatesOptions
|
|
26
|
+
): Float64Array {
|
|
27
|
+
const {transform, bounds, size = 3, origin = 'top-left'} = options;
|
|
28
|
+
if (size !== 2 && size !== 3) throw new RangeError('Source size must be 2 or 3');
|
|
29
|
+
if (!Number.isSafeInteger(positions.length) || positions.length < 0 || positions.length % size) {
|
|
30
|
+
throw new RangeError('Positions must contain complete packed vertices');
|
|
31
|
+
}
|
|
32
|
+
if (origin !== 'top-left' && origin !== 'bottom-left') {
|
|
33
|
+
throw new RangeError('Invalid texture origin');
|
|
34
|
+
}
|
|
35
|
+
if (bounds.length !== 4 || !bounds.every(Number.isFinite)) {
|
|
36
|
+
throw new RangeError('Image bounds must contain four finite values');
|
|
37
|
+
}
|
|
38
|
+
const [left, bottom, right, top] = bounds;
|
|
39
|
+
const width = right - left;
|
|
40
|
+
const height = top - bottom;
|
|
41
|
+
if (!(width > 0) || !(height > 0) || !Number.isFinite(width) || !Number.isFinite(height)) {
|
|
42
|
+
throw new RangeError('Image bounds must have finite positive extents');
|
|
43
|
+
}
|
|
44
|
+
const count = positions.length / size;
|
|
45
|
+
const result = new Float64Array(count * 2);
|
|
46
|
+
for (let index = 0; index < count; index++) {
|
|
47
|
+
const source = Array.from({length: size}, (_, axis) => positions[index * size + axis]);
|
|
48
|
+
if (!source.every(Number.isFinite)) throw new RangeError(`Invalid source vertex ${index}`);
|
|
49
|
+
const projected = transform(source);
|
|
50
|
+
if (
|
|
51
|
+
!projected ||
|
|
52
|
+
projected.length < 2 ||
|
|
53
|
+
!Number.isFinite(projected[0]) ||
|
|
54
|
+
!Number.isFinite(projected[1])
|
|
55
|
+
) {
|
|
56
|
+
throw new RangeError(`Invalid projected vertex ${index}`);
|
|
57
|
+
}
|
|
58
|
+
const u = (projected[0] - left) / width;
|
|
59
|
+
const v =
|
|
60
|
+
origin === 'top-left' ? (top - projected[1]) / height : (projected[1] - bottom) / height;
|
|
61
|
+
if (!Number.isFinite(u) || !Number.isFinite(v))
|
|
62
|
+
throw new RangeError(`Invalid UV at vertex ${index}`);
|
|
63
|
+
result[index * 2] = u;
|
|
64
|
+
result[index * 2 + 1] = v;
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|