@math.gl/geometry 5.0.0-beta.10 → 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 (100) 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 +735 -684
  28. package/dist/index.cjs.map +3 -3
  29. package/dist/index.d.ts +3 -3
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +1 -1
  32. package/dist/index.js.map +1 -1
  33. package/dist/polygon/cut-by-grid.d.ts.map +1 -1
  34. package/dist/polygon/cut-by-grid.js +18 -0
  35. package/dist/polygon/cut-by-grid.js.map +1 -1
  36. package/dist/polygon/earcut.d.ts +12 -1
  37. package/dist/polygon/earcut.d.ts.map +1 -1
  38. package/dist/polygon/earcut.js +855 -630
  39. package/dist/polygon/earcut.js.map +1 -1
  40. package/dist/polygon/index.d.ts +1 -0
  41. package/dist/polygon/index.d.ts.map +1 -1
  42. package/dist/polygon/index.js.map +1 -1
  43. package/dist/polygon/subdivide-triangle-mesh.d.ts.map +1 -1
  44. package/dist/polygon/subdivide-triangle-mesh.js +55 -17
  45. package/dist/polygon/subdivide-triangle-mesh.js.map +1 -1
  46. package/dist/utils/compute-vertex-normals.d.ts +2 -2
  47. package/dist/utils/compute-vertex-normals.d.ts.map +1 -1
  48. package/dist/utils/compute-vertex-normals.js +3 -4
  49. package/dist/utils/compute-vertex-normals.js.map +1 -1
  50. package/dist/utils/geometry.d.ts +11 -4
  51. package/dist/utils/geometry.d.ts.map +1 -1
  52. package/dist/utils/geometry.js +19 -2
  53. package/dist/utils/geometry.js.map +1 -1
  54. package/dist/utils/index.d.ts +1 -3
  55. package/dist/utils/index.d.ts.map +1 -1
  56. package/dist/utils/index.js +0 -2
  57. package/dist/utils/index.js.map +1 -1
  58. package/dist/utils/mesh-processing.d.ts +16 -6
  59. package/dist/utils/mesh-processing.d.ts.map +1 -1
  60. package/dist/utils/mesh-processing.js +9 -6
  61. package/dist/utils/mesh-processing.js.map +1 -1
  62. package/dist/utils/primitive-iterator.d.ts +16 -8
  63. package/dist/utils/primitive-iterator.d.ts.map +1 -1
  64. package/dist/utils/primitive-iterator.js +32 -35
  65. package/dist/utils/primitive-iterator.js.map +1 -1
  66. package/package.json +16 -3
  67. package/{dist/color/color-lut-types.js → src/arrow/index.ts} +3 -2
  68. package/src/arrow/stream-tessellate.ts +209 -0
  69. package/src/arrow/tessellate.ts +133 -0
  70. package/src/color/index.ts +3 -3
  71. package/src/culling/lib/algorithms/oriented-bounding-box-quaternion.ts +8 -2
  72. package/src/index.ts +34 -22
  73. package/src/polygon/cut-by-grid.ts +18 -0
  74. package/src/polygon/earcut.ts +946 -668
  75. package/src/polygon/index.ts +1 -0
  76. package/src/polygon/subdivide-triangle-mesh.ts +56 -16
  77. package/src/utils/compute-vertex-normals.ts +5 -6
  78. package/src/utils/geometry.ts +32 -6
  79. package/src/utils/index.ts +5 -5
  80. package/src/utils/mesh-processing.ts +30 -14
  81. package/src/utils/primitive-iterator.ts +45 -43
  82. package/dist/color/color-lut-types.d.ts +0 -16
  83. package/dist/color/color-lut-types.d.ts.map +0 -1
  84. package/dist/color/color-lut-types.js.map +0 -1
  85. package/dist/color/sample-lut.d.ts +0 -13
  86. package/dist/color/sample-lut.d.ts.map +0 -1
  87. package/dist/color/sample-lut.js +0 -132
  88. package/dist/color/sample-lut.js.map +0 -1
  89. package/dist/utils/constants.d.ts +0 -52
  90. package/dist/utils/constants.d.ts.map +0 -1
  91. package/dist/utils/constants.js +0 -39
  92. package/dist/utils/constants.js.map +0 -1
  93. package/dist/utils/gl-type.d.ts +0 -17
  94. package/dist/utils/gl-type.d.ts.map +0 -1
  95. package/dist/utils/gl-type.js +0 -69
  96. package/dist/utils/gl-type.js.map +0 -1
  97. package/src/color/color-lut-types.ts +0 -19
  98. package/src/color/sample-lut.ts +0 -175
  99. package/src/utils/constants.ts +0 -42
  100. package/src/utils/gl-type.ts +0 -87
@@ -0,0 +1,926 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // dist/arrow/index.js
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
+ tessellateGeoArrowPolygons: () => tessellateGeoArrowPolygons,
23
+ tessellateGeoArrowStream: () => tessellateGeoArrowStream
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // dist/polygon/polygon-utils.js
28
+ var import_core = require("@math.gl/core");
29
+ var DimIndex = {
30
+ x: 0,
31
+ y: 1,
32
+ z: 2
33
+ };
34
+
35
+ // dist/polygon/earcut.js
36
+ function earcut(positions, holeIndices, dim = 2, areas, plane = "xy", options = {}) {
37
+ if (!triangulators[callDepth])
38
+ triangulators[callDepth] = createTriangulator();
39
+ const triangulate = triangulators[callDepth];
40
+ callDepth++;
41
+ try {
42
+ return triangulate(positions, holeIndices, dim, areas, plane, options);
43
+ } finally {
44
+ callDepth--;
45
+ }
46
+ }
47
+ var triangulators = [];
48
+ var callDepth = 0;
49
+ function createTriangulator() {
50
+ let balanceTriangles = false;
51
+ const steiners = /* @__PURE__ */ new Set();
52
+ const splitStack = [];
53
+ let filteredOut = false;
54
+ function triangulate(data, holeIndices, dim, areas, plane) {
55
+ const hasHoles = holeIndices && holeIndices.length;
56
+ const outerLen = hasHoles ? holeIndices[0] * dim : data.length;
57
+ if (steiners.size)
58
+ steiners.clear();
59
+ let outerNode = linkedList(data, 0, outerLen, dim, true, areas && areas[0], plane);
60
+ const triangles = [];
61
+ if (!outerNode || outerNode.next === outerNode.prev)
62
+ return triangles;
63
+ let minX = 0, minY = 0, invSize = 0;
64
+ if (hasHoles)
65
+ outerNode = eliminateHoles(data, holeIndices, outerNode, dim, areas, plane);
66
+ if (data.length > 80 * dim) {
67
+ const i0 = DimIndex[plane[0]], i1 = DimIndex[plane[1]];
68
+ minX = data[i0];
69
+ minY = data[i1];
70
+ let maxX = minX;
71
+ let maxY = minY;
72
+ for (let i = dim; i < outerLen; i += dim) {
73
+ const x = data[i + i0];
74
+ const y = data[i + i1];
75
+ if (x < minX)
76
+ minX = x;
77
+ if (y < minY)
78
+ minY = y;
79
+ if (x > maxX)
80
+ maxX = x;
81
+ if (y > maxY)
82
+ maxY = y;
83
+ }
84
+ invSize = Math.max(maxX - minX, maxY - minY);
85
+ invSize = invSize !== 0 ? 32767 / invSize : 0;
86
+ }
87
+ earcutLinked(outerNode, triangles, minX, minY, invSize);
88
+ while (splitStack.length)
89
+ earcutLinked(
90
+ /** @type {Node} */
91
+ splitStack.pop(),
92
+ triangles,
93
+ minX,
94
+ minY,
95
+ invSize
96
+ );
97
+ return triangles;
98
+ }
99
+ function linkedList(data, start, end, dim, clockwise, area2, plane) {
100
+ if (start >= end)
101
+ return null;
102
+ let i;
103
+ let last;
104
+ const i0 = DimIndex[plane[0]];
105
+ const i1 = DimIndex[plane[1]];
106
+ if (area2 === void 0) {
107
+ let sum = 0;
108
+ let previousX = data[end - dim + i0];
109
+ let previousY = data[end - dim + i1];
110
+ for (i = start; i < end; i += dim) {
111
+ const x = data[i + i0];
112
+ const y = data[i + i1];
113
+ sum += (x - previousX) * (y + previousY);
114
+ last = insertNode(i / dim, x, y, last);
115
+ previousX = x;
116
+ previousY = y;
117
+ }
118
+ if (last && clockwise !== sum / 2 < 0) {
119
+ let node = last;
120
+ do {
121
+ const next = node.next;
122
+ node.next = node.prev;
123
+ node.prev = next;
124
+ node = next;
125
+ } while (node !== last);
126
+ last = last.prev;
127
+ }
128
+ } else if (clockwise === area2 < 0) {
129
+ for (i = start; i < end; i += dim)
130
+ last = insertNode(i / dim, data[i + i0], data[i + i1], last);
131
+ } else {
132
+ for (i = end - dim; i >= start; i -= dim)
133
+ last = insertNode(i / dim, data[i + i0], data[i + i1], last);
134
+ }
135
+ if (last && equals2(last, last.next)) {
136
+ removeNode(last);
137
+ last = last.next;
138
+ }
139
+ return last;
140
+ }
141
+ function filterPoints(start, end = start) {
142
+ const full = end === start;
143
+ let p = start, again;
144
+ do {
145
+ again = false;
146
+ if (p !== p.next && (steiners.size === 0 || !steiners.has(p)) && (equals2(p, p.next) || area(p.prev, p, p.next) === 0)) {
147
+ if (full || p === end)
148
+ end = p.prev;
149
+ filteredOut = true;
150
+ removeNode(p);
151
+ p = p.prev;
152
+ again = true;
153
+ } else if (full || p !== end) {
154
+ p = p.next;
155
+ again = !full;
156
+ }
157
+ } while (again || p !== end);
158
+ return end;
159
+ }
160
+ function earcutLinked(ear, triangles, minX, minY, invSize) {
161
+ if (invSize)
162
+ indexCurve(ear, minX, minY, invSize);
163
+ let stop = ear, cured = false, convex = invSize ? isConvex(ear) : false;
164
+ while (ear.prev !== ear.next) {
165
+ const prev = ear.prev;
166
+ const next = ear.next;
167
+ if (area(prev, ear, next) < 0 && (convex || (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)))) {
168
+ triangles.push(prev.i, ear.i, next.i);
169
+ removeNode(ear);
170
+ ear = balanceTriangles ? next.next : next;
171
+ stop = ear;
172
+ continue;
173
+ }
174
+ convex = false;
175
+ ear = next;
176
+ if (ear === stop) {
177
+ filteredOut = false;
178
+ ear = filterPoints(ear);
179
+ if (filteredOut) {
180
+ stop = ear;
181
+ continue;
182
+ }
183
+ if (!cured) {
184
+ ear = cureLocalIntersections(ear, triangles);
185
+ stop = ear;
186
+ cured = true;
187
+ continue;
188
+ }
189
+ splitEarcut(ear);
190
+ break;
191
+ }
192
+ }
193
+ }
194
+ function isConvex(start) {
195
+ let p = start;
196
+ do {
197
+ if (area(p.prev, p, p.next) >= 0)
198
+ return false;
199
+ p = p.next;
200
+ } while (p !== start);
201
+ return true;
202
+ }
203
+ function isEar(ear) {
204
+ const a = ear.prev, b = ear, c = ear.next, ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y, x0 = Math.min(ax, bx, cx), y0 = Math.min(ay, by, cy), x1 = Math.max(ax, bx, cx), y1 = Math.max(ay, by, cy);
205
+ let p = c.next;
206
+ while (p !== a) {
207
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && !(ax === p.x && ay === p.y) && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
208
+ return false;
209
+ p = p.next;
210
+ }
211
+ return true;
212
+ }
213
+ function isEarHashed(ear, minX, minY, invSize) {
214
+ const a = ear.prev, b = ear, c = ear.next, ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y, x0 = Math.min(ax, bx, cx), y0 = Math.min(ay, by, cy), x1 = Math.max(ax, bx, cx), y1 = Math.max(ay, by, cy), minZ = zOrder(x0, y0, minX, minY, invSize), maxZ = zOrder(x1, y1, minX, minY, invSize);
215
+ let p = ear.prevZ;
216
+ while (p && p.z >= minZ) {
217
+ if (p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== c && !(ax === p.x && ay === p.y) && pointInTriangle(ax, ay, bx, by, cx, cy, p.x, p.y) && area(p.prev, p, p.next) >= 0)
218
+ return false;
219
+ p = p.prevZ;
220
+ }
221
+ let n = ear.nextZ;
222
+ while (n && n.z <= maxZ) {
223
+ if (n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== c && !(ax === n.x && ay === n.y) && pointInTriangle(ax, ay, bx, by, cx, cy, n.x, n.y) && area(n.prev, n, n.next) >= 0)
224
+ return false;
225
+ n = n.nextZ;
226
+ }
227
+ return true;
228
+ }
229
+ function cureLocalIntersections(start, triangles) {
230
+ let p = start;
231
+ let cured = false;
232
+ do {
233
+ const a = p.prev, b = p.next.next;
234
+ if (intersects(a, p, p.next, b, false) && locallyInside(a, b) && locallyInside(b, a)) {
235
+ triangles.push(a.i, p.i, b.i);
236
+ removeNode(p);
237
+ removeNode(p.next);
238
+ p = start = b;
239
+ cured = true;
240
+ }
241
+ p = p.next;
242
+ } while (p !== start);
243
+ return cured ? filterPoints(p) : p;
244
+ }
245
+ function splitEarcut(start) {
246
+ let a = start;
247
+ do {
248
+ let b = a.next.next;
249
+ while (b !== a.prev) {
250
+ if (a.i !== b.i && isValidDiagonal(a, b)) {
251
+ let c = splitPolygon(a, b);
252
+ a = filterPoints(a, a.next);
253
+ c = filterPoints(c, c.next);
254
+ splitStack.push(c, a);
255
+ return;
256
+ }
257
+ b = b.next;
258
+ }
259
+ a = a.next;
260
+ } while (a !== start);
261
+ }
262
+ let indexActive = false;
263
+ function eliminateHoles(data, holeIndices, outerNode, dim, areas, plane) {
264
+ const queue = holeQueue;
265
+ for (let i = 0, len = holeIndices.length; i < len; i++) {
266
+ const start = holeIndices[i] * dim;
267
+ const end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
268
+ const list = (
269
+ /** @type {Node} */
270
+ linkedList(data, start, end, dim, false, areas && areas[i + 1], plane)
271
+ );
272
+ if (!list)
273
+ continue;
274
+ if (list === list.next)
275
+ steiners.add(list);
276
+ queue.push(getLeftmost(list));
277
+ }
278
+ queue.sort(compareXYSlope);
279
+ buildBlockIndex(data.length / dim, holeIndices.length);
280
+ indexSegment(outerNode, outerNode);
281
+ indexActive = true;
282
+ for (let i = 0; i < queue.length; i++) {
283
+ outerNode = eliminateHole(queue[i], outerNode);
284
+ }
285
+ indexActive = false;
286
+ return filterPoints(outerNode);
287
+ }
288
+ function compareXYSlope(a, b) {
289
+ return a.x - b.x || a.y - b.y || (a.next.y - a.y) / (a.next.x - a.x) - (b.next.y - b.y) / (b.next.x - b.x);
290
+ }
291
+ function eliminateHole(hole, outerNode) {
292
+ const bridge = findHoleBridge(hole, outerNode);
293
+ if (!bridge) {
294
+ return outerNode;
295
+ }
296
+ const bridgeReverse = splitPolygon(bridge, hole);
297
+ const bridge2 = bridgeReverse.next;
298
+ indexSegment(bridge, bridge2.next);
299
+ filterPoints(bridgeReverse.prev, bridgeReverse);
300
+ const a = bridge.prev;
301
+ if (area(a, bridge, hole) === 0 && (a.x - bridge.x) * (hole.x - bridge.x) + (a.y - bridge.y) * (hole.y - bridge.y) < 0)
302
+ return bridge;
303
+ return filterPoints(bridge, bridge.next);
304
+ }
305
+ const K = 16;
306
+ let blockBBox = new Float64Array(0);
307
+ let numBlocks = 0;
308
+ const blockHead = [];
309
+ const blockStop = [];
310
+ function buildBlockIndex(maxNodes, numHoles) {
311
+ const maxBlocks = Math.ceil((maxNodes + 2 * numHoles) / K) + numHoles + 2;
312
+ if (blockBBox.length < maxBlocks * 4)
313
+ blockBBox = new Float64Array(maxBlocks * 4);
314
+ numBlocks = 0;
315
+ }
316
+ function indexSegment(head, stop) {
317
+ let p = head;
318
+ do {
319
+ const b = numBlocks++;
320
+ blockHead[b] = p;
321
+ let minX = p.x, minY = p.y, maxX = p.x, maxY = p.y;
322
+ let k = 0;
323
+ do {
324
+ const c = p.next;
325
+ p.z = b;
326
+ if (c.x < minX)
327
+ minX = c.x;
328
+ if (c.x > maxX)
329
+ maxX = c.x;
330
+ if (c.y < minY)
331
+ minY = c.y;
332
+ if (c.y > maxY)
333
+ maxY = c.y;
334
+ p = c;
335
+ } while (++k < K && p !== stop);
336
+ blockStop[b] = p;
337
+ const g = b * 4;
338
+ blockBBox[g] = minX;
339
+ blockBBox[g + 1] = minY;
340
+ blockBBox[g + 2] = maxX;
341
+ blockBBox[g + 3] = maxY;
342
+ } while (p !== stop);
343
+ }
344
+ function growBlock(head, tail) {
345
+ const g = head.z * 4;
346
+ if (tail.x < blockBBox[g])
347
+ blockBBox[g] = tail.x;
348
+ if (tail.y < blockBBox[g + 1])
349
+ blockBBox[g + 1] = tail.y;
350
+ if (tail.x > blockBBox[g + 2])
351
+ blockBBox[g + 2] = tail.x;
352
+ if (tail.y > blockBBox[g + 3])
353
+ blockBBox[g + 3] = tail.y;
354
+ }
355
+ function liveBlockStop(b) {
356
+ let stop = blockStop[b];
357
+ while (stop.prev.next !== stop)
358
+ stop = stop.next;
359
+ blockStop[b] = stop;
360
+ return stop;
361
+ }
362
+ function liveBlockHead(b) {
363
+ let head = blockHead[b];
364
+ while (head.prev.next !== head)
365
+ head = head.next;
366
+ blockHead[b] = head;
367
+ return head;
368
+ }
369
+ function findHoleBridge(hole, outerNode) {
370
+ let p = outerNode;
371
+ const hx = hole.x;
372
+ const hy = hole.y;
373
+ let qx = -Infinity;
374
+ let m;
375
+ if (equals2(hole, p))
376
+ return p;
377
+ for (let b = 0, g = 0; b < numBlocks; b++, g += 4) {
378
+ if (hy < blockBBox[g + 1] || hy > blockBBox[g + 3] || blockBBox[g] > hx || blockBBox[g + 2] <= qx)
379
+ continue;
380
+ const stop = liveBlockStop(b);
381
+ p = liveBlockHead(b);
382
+ do {
383
+ if (equals2(hole, p.next))
384
+ return p.next;
385
+ else if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
386
+ const x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
387
+ if (x <= hx && x > qx) {
388
+ qx = x;
389
+ m = p.x < p.next.x ? p : p.next;
390
+ if (x === hx)
391
+ return m;
392
+ }
393
+ }
394
+ p = p.next;
395
+ } while (p !== stop);
396
+ }
397
+ if (!m)
398
+ return null;
399
+ const mx = m.x;
400
+ const my = m.y;
401
+ const tminY = Math.min(hy, my);
402
+ const tmaxY = Math.max(hy, my);
403
+ let tanMin = Infinity;
404
+ for (let b = 0, g = 0; b < numBlocks; b++, g += 4) {
405
+ if (blockBBox[g + 2] < mx || blockBBox[g] > hx || blockBBox[g + 3] < tminY || blockBBox[g + 1] > tmaxY)
406
+ continue;
407
+ const stop = liveBlockStop(b);
408
+ p = liveBlockHead(b);
409
+ do {
410
+ if (hx >= p.x && p.x >= mx && hx !== p.x && pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
411
+ const tan = Math.abs(hy - p.y) / (hx - p.x);
412
+ if ((locallyInside(p, hole) || p.y === hy && p.next.y === hy && p.next.x > hx) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
413
+ m = p;
414
+ tanMin = tan;
415
+ }
416
+ }
417
+ p = p.next;
418
+ } while (p !== stop);
419
+ }
420
+ return m;
421
+ }
422
+ function sectorContainsSector(m, p) {
423
+ return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
424
+ }
425
+ const sortArr = [];
426
+ let sortBuf = [];
427
+ let zArr = new Uint32Array(0);
428
+ let zBuf = new Uint32Array(0);
429
+ const counts = new Uint32Array(256);
430
+ function indexCurve(start, minX, minY, invSize) {
431
+ let p = start;
432
+ let n = 0;
433
+ do {
434
+ p.z = zOrder(p.x, p.y, minX, minY, invSize);
435
+ sortArr[n++] = p;
436
+ p = p.next;
437
+ } while (p !== start);
438
+ sortNodes(n);
439
+ let prev = null;
440
+ for (let i = 0; i < n; i++) {
441
+ const node = sortArr[i];
442
+ node.prevZ = prev;
443
+ if (prev)
444
+ prev.nextZ = node;
445
+ prev = node;
446
+ }
447
+ prev.nextZ = null;
448
+ sortArr.fill(
449
+ /** @type {Node} */
450
+ /** @type {unknown} */
451
+ null,
452
+ 0,
453
+ n
454
+ );
455
+ sortBuf.fill(
456
+ /** @type {Node} */
457
+ /** @type {unknown} */
458
+ null,
459
+ 0,
460
+ n
461
+ );
462
+ }
463
+ function sortNodes(n) {
464
+ if (n <= 32) {
465
+ for (let i = 1; i < n; i++) {
466
+ const node = sortArr[i], z = node.z;
467
+ let j = i - 1;
468
+ while (j >= 0 && sortArr[j].z > z) {
469
+ sortArr[j + 1] = sortArr[j];
470
+ j--;
471
+ }
472
+ sortArr[j + 1] = node;
473
+ }
474
+ return;
475
+ }
476
+ if (zArr.length < n) {
477
+ zArr = new Uint32Array(n);
478
+ zBuf = new Uint32Array(n);
479
+ sortBuf = new Array(n);
480
+ }
481
+ for (let i = 0; i < n; i++)
482
+ zArr[i] = sortArr[i].z;
483
+ radixPass(n, sortArr, zArr, sortBuf, zBuf, 0);
484
+ radixPass(n, sortBuf, zBuf, sortArr, zArr, 8);
485
+ radixPass(n, sortArr, zArr, sortBuf, zBuf, 16);
486
+ radixPass(n, sortBuf, zBuf, sortArr, zArr, 24);
487
+ }
488
+ function radixPass(n, src, srcZ, dst, dstZ, shift) {
489
+ counts.fill(0);
490
+ for (let i = 0; i < n; i++)
491
+ counts[srcZ[i] >>> shift & 255]++;
492
+ let sum = 0;
493
+ for (let b = 0; b < 256; b++) {
494
+ const c = counts[b];
495
+ counts[b] = sum;
496
+ sum += c;
497
+ }
498
+ for (let i = 0; i < n; i++) {
499
+ const z = srcZ[i];
500
+ const pos = counts[z >>> shift & 255]++;
501
+ dst[pos] = src[i];
502
+ dstZ[pos] = z;
503
+ }
504
+ }
505
+ function zOrder(x, y, minX, minY, invSize) {
506
+ x = (x - minX) * invSize | 0;
507
+ y = (y - minY) * invSize | 0;
508
+ x = (x | x << 8) & 16711935;
509
+ x = (x | x << 4) & 252645135;
510
+ x = (x | x << 2) & 858993459;
511
+ x = (x | x << 1) & 1431655765;
512
+ y = (y | y << 8) & 16711935;
513
+ y = (y | y << 4) & 252645135;
514
+ y = (y | y << 2) & 858993459;
515
+ y = (y | y << 1) & 1431655765;
516
+ return x | y << 1;
517
+ }
518
+ function getLeftmost(start) {
519
+ let p = start, leftmost = start;
520
+ do {
521
+ if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y)
522
+ leftmost = p;
523
+ p = p.next;
524
+ } while (p !== start);
525
+ return leftmost;
526
+ }
527
+ function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
528
+ return (cx - px) * (ay - py) >= (ax - px) * (cy - py) && (ax - px) * (by - py) >= (bx - px) * (ay - py) && (bx - px) * (cy - py) >= (cx - px) * (by - py);
529
+ }
530
+ function isValidDiagonal(a, b) {
531
+ const zeroLength = equals2(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0;
532
+ return a.next.i !== b.i && (zeroLength || locallyInside(a, b) && locallyInside(b, a) && // // locally visible
533
+ (area(a.prev, a, b.prev) !== 0 || area(a, b.prev, b) !== 0)) && // no opposite-facing sectors
534
+ !intersectsPolygon(a, b) && (zeroLength || middleInside(a, b));
535
+ }
536
+ function area(p, q, r) {
537
+ return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
538
+ }
539
+ function equals2(p1, p2) {
540
+ return p1.x === p2.x && p1.y === p2.y;
541
+ }
542
+ function intersects(p1, q1, p2, q2, includeBoundary = true) {
543
+ const o1 = area(p1, q1, p2);
544
+ const o2 = area(p1, q1, q2);
545
+ const o3 = area(p2, q2, p1);
546
+ const o4 = area(p2, q2, q1);
547
+ if ((o1 > 0 && o2 < 0 || o1 < 0 && o2 > 0) && (o3 > 0 && o4 < 0 || o3 < 0 && o4 > 0))
548
+ return true;
549
+ if (!includeBoundary)
550
+ return false;
551
+ if (o1 === 0 && onSegment(p1, p2, q1))
552
+ return true;
553
+ if (o2 === 0 && onSegment(p1, q2, q1))
554
+ return true;
555
+ if (o3 === 0 && onSegment(p2, p1, q2))
556
+ return true;
557
+ if (o4 === 0 && onSegment(p2, q1, q2))
558
+ return true;
559
+ return false;
560
+ }
561
+ function onSegment(p, q, r) {
562
+ return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
563
+ }
564
+ function intersectsPolygon(a, b) {
565
+ const minX = Math.min(a.x, b.x);
566
+ const maxX = Math.max(a.x, b.x);
567
+ const minY = Math.min(a.y, b.y);
568
+ const maxY = Math.max(a.y, b.y);
569
+ let p = a;
570
+ do {
571
+ const n = p.next;
572
+ if (p.x > maxX && n.x > maxX || p.x < minX && n.x < minX || p.y > maxY && n.y > maxY || p.y < minY && n.y < minY) {
573
+ p = n;
574
+ continue;
575
+ }
576
+ if (p.i !== a.i && n.i !== a.i && p.i !== b.i && n.i !== b.i && intersects(p, n, a, b))
577
+ return true;
578
+ p = n;
579
+ } while (p !== a);
580
+ return false;
581
+ }
582
+ function locallyInside(a, b) {
583
+ return area(a.prev, a, a.next) < 0 ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
584
+ }
585
+ function middleInside(a, b) {
586
+ let p = a;
587
+ let inside = false;
588
+ const px = (a.x + b.x) / 2;
589
+ const py = (a.y + b.y) / 2;
590
+ do {
591
+ const n = p.next;
592
+ if (p.y > py !== n.y > py && px < (n.x - p.x) * (py - p.y) / (n.y - p.y) + p.x)
593
+ inside = !inside;
594
+ p = n;
595
+ } while (p !== a);
596
+ return inside;
597
+ }
598
+ function splitPolygon(a, b) {
599
+ const a2 = createNode(a.i, a.x, a.y), b2 = createNode(b.i, b.x, b.y), an = a.next, bp = b.prev;
600
+ a.next = b;
601
+ b.prev = a;
602
+ a2.next = an;
603
+ an.prev = a2;
604
+ b2.next = a2;
605
+ a2.prev = b2;
606
+ bp.next = b2;
607
+ b2.prev = bp;
608
+ return b2;
609
+ }
610
+ function insertNode(i, x, y, last) {
611
+ const p = createNode(i, x, y);
612
+ if (!last) {
613
+ p.prev = p;
614
+ p.next = p;
615
+ } else {
616
+ p.next = last.next;
617
+ p.prev = last;
618
+ last.next.prev = p;
619
+ last.next = p;
620
+ }
621
+ return p;
622
+ }
623
+ function removeNode(p) {
624
+ p.next.prev = p.prev;
625
+ p.prev.next = p.next;
626
+ if (p.prevZ)
627
+ p.prevZ.nextZ = p.nextZ;
628
+ if (p.nextZ)
629
+ p.nextZ.prevZ = p.prevZ;
630
+ if (indexActive)
631
+ growBlock(p.prev, p.next);
632
+ }
633
+ function createNode(i, x, y) {
634
+ let vertex = vertexPool[vertexPoolIndex];
635
+ if (!vertex)
636
+ vertexPool[vertexPoolIndex] = vertex = new Vertex(i, x, y);
637
+ vertexPoolIndex++;
638
+ vertex.i = i;
639
+ vertex.x = x;
640
+ vertex.y = y;
641
+ vertex.prev = vertex.next = vertex.prevZ = vertex.nextZ = null;
642
+ vertex.z = 0;
643
+ return vertex;
644
+ }
645
+ const vertexPool = [];
646
+ let vertexPoolIndex = 0;
647
+ const holeQueue = [];
648
+ return (positions, holeIndices, dim, areas, plane, options) => {
649
+ try {
650
+ balanceTriangles = options.triangulation === "balanced";
651
+ return triangulate(positions, holeIndices, dim, areas, plane);
652
+ } finally {
653
+ vertexPoolIndex = 0;
654
+ indexActive = false;
655
+ filteredOut = false;
656
+ steiners.clear();
657
+ splitStack.length = holeQueue.length = blockHead.length = blockStop.length = 0;
658
+ numBlocks = 0;
659
+ if (vertexPool.length > 65536 || blockBBox.length > 65536 * 4 || zArr.length > 65536) {
660
+ vertexPool.length = sortArr.length = sortBuf.length = 0;
661
+ blockBBox = new Float64Array(0);
662
+ zArr = new Uint32Array(0);
663
+ zBuf = new Uint32Array(0);
664
+ }
665
+ }
666
+ };
667
+ }
668
+ var Vertex = class {
669
+ /** Initialize a node; links are assigned before the first read. */
670
+ constructor(i, x, y) {
671
+ this.prev = null;
672
+ this.next = null;
673
+ this.z = 0;
674
+ this.prevZ = null;
675
+ this.nextZ = null;
676
+ this.i = i;
677
+ this.x = x;
678
+ this.y = y;
679
+ }
680
+ };
681
+
682
+ // dist/arrow/tessellate.js
683
+ var import_arrow = require("@math.gl/core/arrow");
684
+ var import_arrow2 = require("@math.gl/core/arrow");
685
+ var import_arrow3 = require("@math.gl/core/arrow");
686
+ function tessellateGeoArrowPolygons(column, options = {}) {
687
+ (0, import_arrow3.assertGeoArrowResourceLimits)(column, options.limits);
688
+ const rows = (0, import_arrow2.materializeGeoArrowRows)(column);
689
+ const sourceDimension = (0, import_arrow.getGeoArrowDimensionSize)(column.dimension);
690
+ const positionSize = options.positionSize || sourceDimension;
691
+ const sourceRowOffset = options.sourceRowOffset || 0;
692
+ const positions = [];
693
+ const sourceRowIndices = [];
694
+ const indices = [];
695
+ let polygonCount = 0;
696
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
697
+ const row = rows[rowIndex];
698
+ if (row) {
699
+ visitPolygons(row, (polygon) => {
700
+ const vertexOffset = positions.length / positionSize;
701
+ const flatCoordinates = [];
702
+ const holeIndices = [];
703
+ let localVertexCount = 0;
704
+ for (let ringIndex = 0; ringIndex < polygon.length; ringIndex++) {
705
+ const ring = removeClosingCoordinate(polygon[ringIndex]);
706
+ if (ring.length < 3)
707
+ continue;
708
+ if (localVertexCount > 0)
709
+ holeIndices.push(localVertexCount);
710
+ for (const coordinate of ring) {
711
+ for (let component = 0; component < sourceDimension; component++) {
712
+ flatCoordinates.push(coordinate[component] ?? 0);
713
+ }
714
+ for (let component = 0; component < positionSize; component++) {
715
+ positions.push(coordinate[component] ?? 0);
716
+ }
717
+ sourceRowIndices.push(sourceRowOffset + rowIndex);
718
+ localVertexCount++;
719
+ }
720
+ }
721
+ if (localVertexCount >= 3) {
722
+ const localIndices = earcut(flatCoordinates, holeIndices, sourceDimension);
723
+ for (const index of localIndices)
724
+ indices.push(vertexOffset + index);
725
+ polygonCount++;
726
+ }
727
+ });
728
+ }
729
+ }
730
+ const vertexCount = positions.length / positionSize;
731
+ const IndexArray = vertexCount <= 65535 ? Uint16Array : Uint32Array;
732
+ return {
733
+ positions: Float32Array.from(positions),
734
+ sourceRowIndices: Uint32Array.from(sourceRowIndices),
735
+ indices: IndexArray.from(indices),
736
+ sourceDimension,
737
+ positionSize,
738
+ rowCount: rows.length,
739
+ polygonCount,
740
+ vertexCount,
741
+ triangleCount: indices.length / 3
742
+ };
743
+ }
744
+ function visitPolygons(geometry, visitor) {
745
+ switch (geometry.type) {
746
+ case "Polygon":
747
+ visitor(geometry.coordinates);
748
+ break;
749
+ case "MultiPolygon":
750
+ for (const polygon of geometry.coordinates)
751
+ visitor(polygon);
752
+ break;
753
+ case "GeometryCollection":
754
+ for (const child of geometry.geometries)
755
+ visitPolygons(child, visitor);
756
+ break;
757
+ default:
758
+ break;
759
+ }
760
+ }
761
+ function removeClosingCoordinate(ring) {
762
+ if (ring.length < 2)
763
+ return ring;
764
+ const first = ring[0];
765
+ const last = ring[ring.length - 1];
766
+ if (first.length !== last.length)
767
+ return ring;
768
+ for (let index = 0; index < first.length; index++) {
769
+ if (first[index] !== last[index])
770
+ return ring;
771
+ }
772
+ return ring.slice(0, -1);
773
+ }
774
+
775
+ // dist/arrow/stream-tessellate.js
776
+ var import_arrow4 = require("@math.gl/core/arrow");
777
+ function tessellateGeoArrowStream(column, options = {}) {
778
+ var _a;
779
+ const { maxVertices = 65536, maxTriangles = 131072, maxRingComparisons = 1e6 } = options;
780
+ if (![maxVertices, maxTriangles, maxRingComparisons].every((v) => Number.isSafeInteger(v) && v >= 0 && v <= 4294967295))
781
+ throw new RangeError("Invalid stream limits");
782
+ const positions = [], indices = [], polygonStarts = [0], polygonSourceRows = [], sourceRowIndices = [];
783
+ let row = 0, vertices = 0, comparisons = 0, inPolygon = false;
784
+ let rings = [], ring = null;
785
+ const sink = {
786
+ polygonStart() {
787
+ if (inPolygon)
788
+ throw new Error("Nested stream polygon");
789
+ inPolygon = true;
790
+ rings = [];
791
+ },
792
+ lineStart() {
793
+ if (inPolygon) {
794
+ if (ring)
795
+ throw new Error("Nested stream ring");
796
+ ring = [];
797
+ }
798
+ },
799
+ point(x, y) {
800
+ if (!inPolygon)
801
+ return;
802
+ if (!ring || !Number.isFinite(x) || !Number.isFinite(y))
803
+ throw new Error("Invalid polygon stream point");
804
+ if (++vertices > maxVertices)
805
+ throw new RangeError("Stream exceeded maxVertices");
806
+ ring.push(x, y);
807
+ },
808
+ lineEnd() {
809
+ if (!inPolygon)
810
+ return;
811
+ if (!ring)
812
+ throw new Error("Missing stream ring");
813
+ if (ring.length >= 4 && ring[0] === ring[ring.length - 2] && ring[1] === ring[ring.length - 1])
814
+ ring.splice(-2);
815
+ if (ring.length >= 6)
816
+ rings.push(ring);
817
+ ring = null;
818
+ },
819
+ polygonEnd() {
820
+ if (!inPolygon || ring)
821
+ throw new Error("Incomplete stream polygon");
822
+ const areas = rings.map(signedArea);
823
+ const parents = rings.map((r, i) => {
824
+ let parent = -1;
825
+ for (let j = 0; j < rings.length; j++) {
826
+ if (++comparisons > maxRingComparisons)
827
+ throw new RangeError("Stream exceeded maxRingComparisons");
828
+ if (Math.abs(areas[j]) > Math.abs(areas[i]) && (parent < 0 || Math.abs(areas[j]) < Math.abs(areas[parent])) && containsRing(rings[j], r))
829
+ parent = j;
830
+ }
831
+ return parent;
832
+ });
833
+ const depths = parents.map((parent) => {
834
+ let depth = 0;
835
+ while (parent >= 0) {
836
+ depth++;
837
+ parent = parents[parent];
838
+ }
839
+ return depth;
840
+ });
841
+ for (let i = 0; i < rings.length; i++) {
842
+ if (depths[i] % 2 || areas[i] === 0)
843
+ continue;
844
+ const flat = [...rings[i]], holes = [];
845
+ for (let j = 0; j < rings.length; j++)
846
+ if (parents[j] === i) {
847
+ holes.push(flat.length / 2);
848
+ for (const value of rings[j])
849
+ flat.push(value);
850
+ }
851
+ const triangles = earcut(flat, holes, 2);
852
+ if (indices.length / 3 + triangles.length / 3 > maxTriangles)
853
+ throw new RangeError("Stream exceeded maxTriangles");
854
+ const start = positions.length / 2;
855
+ for (const value of flat)
856
+ positions.push(value);
857
+ for (let j = 0; j < flat.length / 2; j++)
858
+ sourceRowIndices.push(row);
859
+ for (const index of triangles)
860
+ indices.push(start + index);
861
+ polygonSourceRows.push(row);
862
+ polygonStarts.push(positions.length / 2);
863
+ }
864
+ rings = [];
865
+ inPolygon = false;
866
+ }
867
+ };
868
+ const stream = ((_a = options.createStream) == null ? void 0 : _a.call(options, sink)) ?? sink;
869
+ (0, import_arrow4.streamGeoArrow)(column, stream, {
870
+ ...options,
871
+ onRowStart(index) {
872
+ var _a2;
873
+ if (index > 4294967295)
874
+ throw new RangeError("Source row exceeds Uint32");
875
+ row = index;
876
+ (_a2 = options.onRowStart) == null ? void 0 : _a2.call(options, index);
877
+ },
878
+ onRowEnd(index) {
879
+ var _a2;
880
+ if (inPolygon || ring)
881
+ throw new Error("Stream must flush each source row synchronously");
882
+ (_a2 = options.onRowEnd) == null ? void 0 : _a2.call(options, index);
883
+ }
884
+ });
885
+ return {
886
+ positions: new Float64Array(positions),
887
+ indices: new Uint32Array(indices),
888
+ polygonStarts: new Uint32Array(polygonStarts),
889
+ polygonSourceRows: new Uint32Array(polygonSourceRows),
890
+ sourceRowIndices: new Uint32Array(sourceRowIndices)
891
+ };
892
+ }
893
+ function signedArea(ring) {
894
+ let result = 0;
895
+ for (let i = 2; i + 3 < ring.length; i += 2)
896
+ result += (ring[i] - ring[0]) * (ring[i + 3] - ring[1]) - (ring[i + 1] - ring[1]) * (ring[i + 2] - ring[0]);
897
+ if (!Number.isFinite(result))
898
+ throw new RangeError("Unrepresentable stream ring area");
899
+ return result;
900
+ }
901
+ function containsRing(outer, inner) {
902
+ for (let i = 0; i < inner.length; i += 2) {
903
+ const j = (i + 2) % inner.length;
904
+ for (const [x, y] of [
905
+ [inner[i], inner[i + 1]],
906
+ [inner[i] / 2 + inner[j] / 2, inner[i + 1] / 2 + inner[j + 1] / 2]
907
+ ]) {
908
+ const location = locate(outer, x, y);
909
+ if (location !== 0)
910
+ return location > 0;
911
+ }
912
+ }
913
+ return true;
914
+ }
915
+ function locate(ring, x, y) {
916
+ let inside = false;
917
+ for (let i = 0, j = ring.length - 2; i < ring.length; j = i, i += 2) {
918
+ const ax = ring[i], ay = ring[i + 1], bx = ring[j], by = ring[j + 1];
919
+ if ((bx - ax) * (y - ay) === (by - ay) * (x - ax) && x >= Math.min(ax, bx) && x <= Math.max(ax, bx) && y >= Math.min(ay, by) && y <= Math.max(ay, by))
920
+ return 0;
921
+ if (ay > y !== by > y && x < (bx - ax) * (y - ay) / (by - ay) + ax)
922
+ inside = !inside;
923
+ }
924
+ return inside ? 1 : -1;
925
+ }
926
+ //# sourceMappingURL=index.cjs.map