@math.gl/geometry 5.0.0-beta.11 → 5.0.0-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/arrow/index.cjs +926 -0
  2. package/dist/arrow/index.cjs.map +6 -0
  3. package/dist/arrow/index.d.ts +3 -0
  4. package/dist/arrow/index.d.ts.map +1 -0
  5. package/dist/arrow/index.js +6 -0
  6. package/dist/arrow/index.js.map +1 -0
  7. package/dist/arrow/stream-tessellate.d.ts +34 -0
  8. package/dist/arrow/stream-tessellate.d.ts.map +1 -0
  9. package/dist/arrow/stream-tessellate.js +171 -0
  10. package/dist/arrow/stream-tessellate.js.map +1 -0
  11. package/dist/arrow/tessellate.d.ts +31 -0
  12. package/dist/arrow/tessellate.d.ts.map +1 -0
  13. package/dist/arrow/tessellate.js +102 -0
  14. package/dist/arrow/tessellate.js.map +1 -0
  15. package/dist/color/index.cjs +3 -108
  16. package/dist/color/index.cjs.map +3 -3
  17. package/dist/color/index.d.ts +2 -3
  18. package/dist/color/index.d.ts.map +1 -1
  19. package/dist/color/index.js +1 -1
  20. package/dist/color/index.js.map +1 -1
  21. package/dist/culling/index.cjs +3 -1
  22. package/dist/culling/index.cjs.map +1 -1
  23. package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.d.ts +4 -1
  24. package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.d.ts.map +1 -1
  25. package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js +9 -2
  26. package/dist/culling/lib/algorithms/oriented-bounding-box-quaternion.js.map +1 -1
  27. package/dist/index.cjs +625 -523
  28. package/dist/index.cjs.map +2 -2
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js.map +1 -1
  32. package/dist/polygon/earcut.d.ts +12 -1
  33. package/dist/polygon/earcut.d.ts.map +1 -1
  34. package/dist/polygon/earcut.js +855 -630
  35. package/dist/polygon/earcut.js.map +1 -1
  36. package/dist/polygon/index.d.ts +1 -0
  37. package/dist/polygon/index.d.ts.map +1 -1
  38. package/dist/polygon/index.js.map +1 -1
  39. package/package.json +16 -3
  40. package/{dist/color/color-lut-types.js → src/arrow/index.ts} +3 -2
  41. package/src/arrow/stream-tessellate.ts +209 -0
  42. package/src/arrow/tessellate.ts +133 -0
  43. package/src/color/index.ts +3 -3
  44. package/src/culling/lib/algorithms/oriented-bounding-box-quaternion.ts +8 -2
  45. package/src/index.ts +14 -13
  46. package/src/polygon/earcut.ts +946 -668
  47. package/src/polygon/index.ts +1 -0
  48. package/dist/color/color-lut-types.d.ts +0 -16
  49. package/dist/color/color-lut-types.d.ts.map +0 -1
  50. package/dist/color/color-lut-types.js.map +0 -1
  51. package/dist/color/sample-lut.d.ts +0 -13
  52. package/dist/color/sample-lut.d.ts.map +0 -1
  53. package/dist/color/sample-lut.js +0 -132
  54. package/dist/color/sample-lut.js.map +0 -1
  55. package/src/color/color-lut-types.ts +0 -19
  56. package/src/color/sample-lut.ts +0 -175
@@ -13,6 +13,7 @@ export {
13
13
  export type {PolygonWinding, WindingDirection} from './polygon-utils';
14
14
 
15
15
  export {earcut} from './earcut';
16
+ export type {EarcutOptions} from './earcut';
16
17
 
17
18
  export {clipPolygon, clipPolyline} from './lineclip';
18
19
 
@@ -1,16 +0,0 @@
1
- /** Numerical RGB lookup table, independent of its file encoding or renderer. */
2
- export type ColorLUT = {
3
- /** Independent 1D curves or one 3D RGB mapping. */
4
- dimension: 1 | 3;
5
- /** Number of samples along each axis. */
6
- size: number;
7
- /** Interleaved RGB values, red coordinate varying fastest for 3D tables. */
8
- data: Float32Array;
9
- /** Minimum input coordinate for each channel. */
10
- domainMinimum: number[];
11
- /** Maximum input coordinate for each channel. */
12
- domainMaximum: number[];
13
- /** Optional strictly increasing normalized knots from 0 through 1. */
14
- inputGrid?: Float64Array;
15
- };
16
- //# sourceMappingURL=color-lut-types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"color-lut-types.d.ts","sourceRoot":"","sources":["../../src/color/color-lut-types.ts"],"names":[],"mappings":"AAIA,gFAAgF;AAChF,MAAM,MAAM,QAAQ,GAAG;IACrB,mDAAmD;IACnD,SAAS,EAAE,CAAC,GAAG,CAAC,CAAC;IACjB,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,4EAA4E;IAC5E,IAAI,EAAE,YAAY,CAAC;IACnB,iDAAiD;IACjD,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,iDAAiD;IACjD,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,sEAAsE;IACtE,SAAS,CAAC,EAAE,YAAY,CAAC;CAC1B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"color-lut-types.js","sourceRoot":"","sources":["../../src/color/color-lut-types.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D"}
@@ -1,13 +0,0 @@
1
- import type { ColorLUT } from "./color-lut-types.js";
2
- /** Reusable RGB sampler; inputs use the authored domain and outputs retain signed/HDR values. */
3
- export type ColorLUTSampler = (red: number, green: number, blue: number) => [number, number, number];
4
- /** Options for interleaved floating-point RGB or RGBA buffers. */
5
- export type ApplyColorLUTOptions = {
6
- /** Number of interleaved components; default 3. Alpha is copied at float32 precision. */
7
- components?: 3 | 4;
8
- };
9
- /** Creates a snapshot sampler with per-channel 1D linear or red-fastest 3D trilinear interpolation. */
10
- export declare function createColorLUTSampler(lut: ColorLUT): ColorLUTSampler;
11
- /** Applies a LUT to floating-point pixels without changing the source or applying transfer functions. */
12
- export declare function applyColorLUT(lut: ColorLUT, colors: Float32Array | Float64Array, options?: ApplyColorLUTOptions): Float32Array;
13
- //# sourceMappingURL=sample-lut.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sample-lut.d.ts","sourceRoot":"","sources":["../../src/color/sample-lut.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,QAAQ,EAAC,6BAA0B;AAEhD,iGAAiG;AACjG,MAAM,MAAM,eAAe,GAAG,CAC5B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,KACT,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAE9B,kEAAkE;AAClE,MAAM,MAAM,oBAAoB,GAAG;IACjC,yFAAyF;IACzF,UAAU,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;CACpB,CAAC;AAEF,uGAAuG;AACvG,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,QAAQ,GAAG,eAAe,CAOpE;AAmGD,yGAAyG;AACzG,wBAAgB,aAAa,CAC3B,GAAG,EAAE,QAAQ,EACb,MAAM,EAAE,YAAY,GAAG,YAAY,EACnC,OAAO,GAAE,oBAAyB,GACjC,YAAY,CAgBd"}
@@ -1,132 +0,0 @@
1
- /** Creates a snapshot sampler with per-channel 1D linear or red-fastest 3D trilinear interpolation. */
2
- export function createColorLUTSampler(lut) {
3
- const writeSample = createColorLUTWriter(lut);
4
- return (red, green, blue) => {
5
- const result = [0, 0, 0];
6
- writeSample(red, green, blue, result, 0);
7
- return result;
8
- };
9
- }
10
- /** Creates a validated snapshot writer with reusable per-sampler scratch storage. */
11
- function createColorLUTWriter(lut) {
12
- const { dimension, size } = lut;
13
- if (![1, 3].includes(dimension) ||
14
- !Number.isSafeInteger(size) ||
15
- size < 2 ||
16
- !Number.isSafeInteger(size ** dimension * 3) ||
17
- lut.data.length !== size ** dimension * 3 ||
18
- lut.domainMinimum.length !== 3 ||
19
- lut.domainMaximum.length !== 3) {
20
- throw new Error('LUT: invalid calculation table');
21
- }
22
- const minimum = Array.from(lut.domainMinimum);
23
- const maximum = Array.from(lut.domainMaximum);
24
- for (let channel = 0; channel < 3; channel++) {
25
- if (!Number.isFinite(minimum[channel]) ||
26
- !Number.isFinite(maximum[channel]) ||
27
- !Number.isFinite(maximum[channel] - minimum[channel]) ||
28
- maximum[channel] <= minimum[channel])
29
- throw new Error('LUT: invalid calculation domain');
30
- }
31
- if (!lut.data.every(Number.isFinite))
32
- throw new Error('LUT: invalid calculation samples');
33
- const data = lut.data.slice();
34
- const grid = lut.inputGrid?.slice();
35
- if (grid &&
36
- (grid.length !== size ||
37
- grid[0] !== 0 ||
38
- grid[size - 1] !== 1 ||
39
- grid.some((value, index) => !Number.isFinite(value) || (index > 0 && value <= grid[index - 1])))) {
40
- throw new Error('LUT: invalid nonuniform input grid');
41
- }
42
- const coordinates = [0, 0, 0];
43
- const indices = [0, 0, 0];
44
- const weights = [0, 0, 0];
45
- const accumulated = [0, 0, 0];
46
- return (red, green, blue, result, resultOffset) => {
47
- coordinates[0] = red;
48
- coordinates[1] = green;
49
- coordinates[2] = blue;
50
- for (let channel = 0; channel < 3; channel++) {
51
- const value = coordinates[channel];
52
- if (!Number.isFinite(value))
53
- throw new Error('LUT: input colors must be finite');
54
- const normalized = value <= minimum[channel]
55
- ? 0
56
- : value >= maximum[channel]
57
- ? 1
58
- : (value - minimum[channel]) / (maximum[channel] - minimum[channel]);
59
- writeLUTInterval(normalized, size, grid, indices, weights, channel);
60
- }
61
- accumulated[0] = 0;
62
- accumulated[1] = 0;
63
- accumulated[2] = 0;
64
- if (dimension === 1) {
65
- for (let channel = 0; channel < 3; channel++) {
66
- const offset = indices[channel] * 3 + channel;
67
- accumulated[channel] =
68
- data[offset] * (1 - weights[channel]) + data[offset + 3] * weights[channel];
69
- }
70
- }
71
- else {
72
- for (let blueCorner = 0; blueCorner < 2; blueCorner++) {
73
- for (let greenCorner = 0; greenCorner < 2; greenCorner++) {
74
- for (let redCorner = 0; redCorner < 2; redCorner++) {
75
- const weight = (redCorner ? weights[0] : 1 - weights[0]) *
76
- (greenCorner ? weights[1] : 1 - weights[1]) *
77
- (blueCorner ? weights[2] : 1 - weights[2]);
78
- const offset = (((indices[2] + blueCorner) * size + indices[1] + greenCorner) * size +
79
- indices[0] +
80
- redCorner) *
81
- 3;
82
- for (let channel = 0; channel < 3; channel++)
83
- accumulated[channel] += data[offset + channel] * weight;
84
- }
85
- }
86
- }
87
- }
88
- for (let channel = 0; channel < 3; channel++)
89
- result[resultOffset + channel] = accumulated[channel];
90
- };
91
- }
92
- /** Applies a LUT to floating-point pixels without changing the source or applying transfer functions. */
93
- export function applyColorLUT(lut, colors, options = {}) {
94
- const { components = 3 } = options;
95
- if (![3, 4].includes(components) || colors.length % components !== 0)
96
- throw new Error('LUT: invalid pixel component count');
97
- const writeSample = createColorLUTWriter(lut);
98
- const result = new Float32Array(colors.length);
99
- for (let offset = 0; offset < colors.length; offset += components) {
100
- writeSample(colors[offset], colors[offset + 1], colors[offset + 2], result, offset);
101
- if (components === 4) {
102
- const alpha = colors[offset + 3];
103
- result[offset + 3] = alpha;
104
- if (!Number.isFinite(alpha) || !Number.isFinite(result[offset + 3]))
105
- throw new Error('LUT: alpha cannot be represented as float32');
106
- }
107
- }
108
- return result;
109
- }
110
- /** Finds normalized uniform/nonuniform knots, retaining the final endpoint in the last interval. */
111
- function writeLUTInterval(value, size, grid, indices, weights, channel) {
112
- if (!grid) {
113
- const coordinate = value * (size - 1);
114
- const lower = Math.min(Math.floor(coordinate), size - 2);
115
- indices[channel] = lower;
116
- weights[channel] = coordinate - lower;
117
- return;
118
- }
119
- let lower = 0;
120
- let upper = size - 1;
121
- while (upper - lower > 1) {
122
- const midpoint = Math.floor((lower + upper) / 2);
123
- if (value < grid[midpoint])
124
- upper = midpoint;
125
- else
126
- lower = midpoint;
127
- }
128
- lower = Math.min(lower, size - 2);
129
- indices[channel] = lower;
130
- weights[channel] = (value - grid[lower]) / (grid[lower + 1] - grid[lower]);
131
- }
132
- //# sourceMappingURL=sample-lut.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sample-lut.js","sourceRoot":"","sources":["../../src/color/sample-lut.ts"],"names":[],"mappings":"AAkBA,uGAAuG;AACvG,MAAM,UAAU,qBAAqB,CAAC,GAAa;IACjD,MAAM,WAAW,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAC;I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,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7E,CAAC"}
@@ -1,19 +0,0 @@
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
- };
@@ -1,175 +0,0 @@
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
- }