@math.gl/geospatial 5.0.0-beta.3 → 5.0.0-beta.4

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 (35) hide show
  1. package/dist/index.cjs +244 -0
  2. package/dist/index.cjs.map +3 -3
  3. package/dist/index.d.ts +7 -0
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +4 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/terrain/contour-boundary-diagnostics.d.ts +23 -0
  8. package/dist/terrain/contour-boundary-diagnostics.d.ts.map +1 -0
  9. package/dist/terrain/contour-boundary-diagnostics.js +62 -0
  10. package/dist/terrain/contour-boundary-diagnostics.js.map +1 -0
  11. package/dist/terrain/contour-tile-paths.d.ts +7 -0
  12. package/dist/terrain/contour-tile-paths.d.ts.map +1 -0
  13. package/dist/terrain/contour-tile-paths.js +12 -0
  14. package/dist/terrain/contour-tile-paths.js.map +1 -0
  15. package/dist/terrain/contour-tile-weld.d.ts +24 -0
  16. package/dist/terrain/contour-tile-weld.d.ts.map +1 -0
  17. package/dist/terrain/contour-tile-weld.js +147 -0
  18. package/dist/terrain/contour-tile-weld.js.map +1 -0
  19. package/dist/terrain/gradient-pyramid.d.ts +29 -0
  20. package/dist/terrain/gradient-pyramid.d.ts.map +1 -0
  21. package/dist/terrain/gradient-pyramid.js +94 -0
  22. package/dist/terrain/gradient-pyramid.js.map +1 -0
  23. package/dist/terrain/index.cjs +245 -1
  24. package/dist/terrain/index.cjs.map +2 -2
  25. package/dist/terrain/index.d.ts +7 -0
  26. package/dist/terrain/index.d.ts.map +1 -1
  27. package/dist/terrain/index.js +4 -0
  28. package/dist/terrain/index.js.map +1 -1
  29. package/package.json +5 -5
  30. package/src/index.ts +10 -0
  31. package/src/terrain/contour-boundary-diagnostics.ts +90 -0
  32. package/src/terrain/contour-tile-paths.ts +20 -0
  33. package/src/terrain/contour-tile-weld.ts +182 -0
  34. package/src/terrain/gradient-pyramid.ts +129 -0
  35. package/src/terrain/index.ts +10 -0
@@ -34,6 +34,7 @@ __export(index_exports, {
34
34
  HeightFieldGeometry: () => HeightFieldGeometry,
35
35
  HeightFieldMinMax: () => HeightFieldMinMax,
36
36
  TERRAIN_BUFFER_VERSION: () => TERRAIN_BUFFER_VERSION,
37
+ TerrainContourBoundaryAxis: () => TerrainContourBoundaryAxis,
37
38
  TerrainProfileViewStatus: () => TerrainProfileViewStatus,
38
39
  TerrainSampleStatus: () => TerrainSampleStatus,
39
40
  TerrainSurface: () => TerrainSurface,
@@ -44,11 +45,13 @@ __export(index_exports, {
44
45
  createTerrainContours: () => createTerrainContours,
45
46
  createTerrainFilteredPyramid: () => createTerrainFilteredPyramid,
46
47
  createTerrainGradientGrid: () => createTerrainGradientGrid,
48
+ createTerrainGradientPyramid: () => createTerrainGradientPyramid,
47
49
  createTerrainMesh: () => createTerrainMesh,
48
50
  createTerrainSkirt: () => createTerrainSkirt,
49
51
  createTerrainSlopeAspectGrid: () => createTerrainSlopeAspectGrid,
50
52
  createTerrainSurface: () => createTerrainSurface,
51
53
  createTerrainVertexTileHalos: () => createTerrainVertexTileHalos,
54
+ diagnoseTerrainContourBoundaries: () => diagnoseTerrainContourBoundaries,
52
55
  getTerrainMeshEdge: () => getTerrainMeshEdge,
53
56
  getTerrainProfileHorizon: () => getTerrainProfileHorizon,
54
57
  getTerrainProfileViewshed: () => getTerrainProfileViewshed,
@@ -61,10 +64,12 @@ __export(index_exports, {
61
64
  reconcileTerrainVertexTiles: () => reconcileTerrainVertexTiles,
62
65
  sampleTerrainProfile: () => sampleTerrainProfile,
63
66
  simplifyTerrainContourPaths: () => simplifyTerrainContourPaths,
67
+ stitchTerrainContourTiles: () => stitchTerrainContourTiles,
64
68
  stitchTerrainContours: () => stitchTerrainContours,
65
69
  stitchTerrainMeshEdges: () => stitchTerrainMeshEdges,
66
70
  unpackTerrainHeightField: () => unpackTerrainHeightField,
67
- updateTerrainVertexTileHalos: () => updateTerrainVertexTileHalos
71
+ updateTerrainVertexTileHalos: () => updateTerrainVertexTileHalos,
72
+ weldTerrainContourTiles: () => weldTerrainContourTiles
68
73
  });
69
74
  module.exports = __toCommonJS(index_exports);
70
75
 
@@ -2575,6 +2580,245 @@ function stitchTerrainContours(contours, options = {}) {
2575
2580
  };
2576
2581
  }
2577
2582
 
2583
+ // dist/terrain/contour-tile-weld.js
2584
+ function weldTerrainContourTiles(tiles, options) {
2585
+ const { width, height } = options;
2586
+ const limits = contourPathLimits(options);
2587
+ const tolerance = options.maxPositionDifference ?? 0;
2588
+ const maxTiles = options.maxTiles ?? 4096;
2589
+ if (!Number.isSafeInteger(width) || width < 2 || !Number.isSafeInteger(height) || height < 2 || !Number.isFinite(tolerance) || tolerance < 0 || !Number.isSafeInteger(maxTiles) || maxTiles < 1 || tiles.length > maxTiles || !tiles.length)
2590
+ throw new Error("Invalid terrain contour tile dimensions or tolerance");
2591
+ const sorted = [...tiles].sort((a, b) => a.column - b.column || a.row - b.row);
2592
+ const first = sorted[0].contours;
2593
+ const origin = [...first.origin];
2594
+ const levels = first.levels.slice();
2595
+ const positions = [], grid = [], segments = [], levelIndices = [];
2596
+ const vertices = /* @__PURE__ */ new Map();
2597
+ const edges = /* @__PURE__ */ new Map();
2598
+ const addresses = /* @__PURE__ */ new Set();
2599
+ let inputVertices = 0;
2600
+ let inputSegments = 0;
2601
+ for (let tileIndex = 0; tileIndex < sorted.length; tileIndex++) {
2602
+ const tile = sorted[tileIndex], data = tile.contours;
2603
+ const id = `${tile.column},${tile.row}`;
2604
+ if (!Number.isSafeInteger(tile.column) || !Number.isSafeInteger(tile.row) || addresses.has(id))
2605
+ throw new Error("Invalid or duplicate terrain contour tile address");
2606
+ addresses.add(id);
2607
+ const x0 = tile.column * (width - 1), y0 = tile.row * (height - 1);
2608
+ if (![x0, y0, x0 + width - 1, y0 + height - 1].every(Number.isSafeInteger))
2609
+ throw new Error("Terrain contour tile lattice overflow");
2610
+ const count = validateContourData(data, limits);
2611
+ inputVertices += count;
2612
+ if (inputVertices > limits.maxVertices)
2613
+ throw new Error("Terrain contour input vertex capacity exceeded");
2614
+ if (data.heightReference !== first.heightReference || data.levels.length !== levels.length || !data.levels.every((level, i) => level === levels[i]))
2615
+ throw new Error("Terrain contour tile levels or height reference differ");
2616
+ if (!(data.segments instanceof Uint32Array) || data.segments.length % 2 || !(data.levelIndices instanceof Uint32Array) || data.levelIndices.length !== data.segments.length / 2 || data.levelIndices.length > limits.maxSegments)
2617
+ throw new Error("Invalid terrain contour tile segments");
2618
+ inputSegments += data.levelIndices.length;
2619
+ if (inputSegments > limits.maxSegments)
2620
+ throw new Error("Terrain contour input segment capacity exceeded");
2621
+ const assigned = new Uint32Array(count).fill(4294967295);
2622
+ const remap = new Uint32Array(count).fill(4294967295);
2623
+ const localBoundary = /* @__PURE__ */ new Set();
2624
+ const mapVertex = (source, level) => {
2625
+ validateContourVertex(data, source, level, assigned);
2626
+ if (remap[source] !== 4294967295)
2627
+ return remap[source];
2628
+ const x = data.gridCoordinates[2 * source], y = data.gridCoordinates[2 * source + 1];
2629
+ if (x < 0 || x > width - 1 || y < 0 || y > height - 1)
2630
+ throw new Error("Terrain contour vertex outside tile lattice");
2631
+ const gx = x0 + x, gy = y0 + y;
2632
+ if (!Number.isFinite(gx) || !Number.isFinite(gy) || x % 1 !== 0 && Number.isInteger(gx) || y % 1 !== 0 && Number.isInteger(gy))
2633
+ throw new Error("Terrain contour tile lattice loses precision");
2634
+ const px = data.positions[3 * source] + (data.origin[0] - origin[0]);
2635
+ const py = data.positions[3 * source + 1] + (data.origin[1] - origin[1]);
2636
+ if (!Number.isFinite(px) || !Number.isFinite(py))
2637
+ throw new Error("Terrain contour frame overflow");
2638
+ const boundary = x === 0 || y === 0 || x === width - 1 || y === height - 1;
2639
+ const xi = Math.floor(x), yi = Math.floor(y);
2640
+ const vertexKey = `${level}/${x0 + xi}/${x - xi}/${y0 + yi}/${y - yi}`;
2641
+ if (boundary) {
2642
+ if (localBoundary.has(vertexKey))
2643
+ throw new Error("Duplicate terrain contour boundary vertex");
2644
+ localBoundary.add(vertexKey);
2645
+ }
2646
+ const found = boundary ? vertices.get(vertexKey) : void 0;
2647
+ if (found) {
2648
+ if (found.tile === tileIndex)
2649
+ throw new Error("Duplicate terrain contour boundary vertex");
2650
+ const delta = Math.hypot(px - positions[3 * found.id], py - positions[3 * found.id + 1]);
2651
+ if (!Number.isFinite(delta) || delta > tolerance)
2652
+ throw new Error("Terrain contour boundary positions disagree");
2653
+ remap[source] = found.id;
2654
+ return found.id;
2655
+ }
2656
+ if (positions.length / 3 >= limits.maxVertices)
2657
+ throw new Error("Terrain contour vertex capacity exceeded");
2658
+ const output = positions.length / 3;
2659
+ const pz = levels[level] - origin[2];
2660
+ if (!Number.isFinite(pz))
2661
+ throw new Error("Terrain contour frame overflow");
2662
+ positions.push(px, py, pz);
2663
+ grid.push(gx, gy);
2664
+ if (boundary)
2665
+ vertices.set(vertexKey, { id: output, tile: tileIndex });
2666
+ remap[source] = output;
2667
+ return output;
2668
+ };
2669
+ for (let i = 0; i < data.levelIndices.length; i++) {
2670
+ const level = data.levelIndices[i], a = mapVertex(data.segments[2 * i], level), b = mapVertex(data.segments[2 * i + 1], level);
2671
+ if (a === b || positions[3 * a] === positions[3 * b] && positions[3 * a + 1] === positions[3 * b + 1])
2672
+ throw new Error("Degenerate terrain contour segment after rebasing");
2673
+ const edge = a < b ? `${a}/${b}` : `${b}/${a}`;
2674
+ const previous = edges.get(edge);
2675
+ if (previous !== void 0) {
2676
+ if (previous === tileIndex)
2677
+ throw new Error("Duplicate terrain contour segment");
2678
+ continue;
2679
+ }
2680
+ if (levelIndices.length >= limits.maxSegments)
2681
+ throw new Error("Terrain contour segment capacity exceeded");
2682
+ edges.set(edge, tileIndex);
2683
+ segments.push(a, b);
2684
+ levelIndices.push(level);
2685
+ }
2686
+ }
2687
+ return {
2688
+ positions: Float64Array.from(positions),
2689
+ gridCoordinates: Float64Array.from(grid),
2690
+ segments: Uint32Array.from(segments),
2691
+ levelIndices: Uint32Array.from(levelIndices),
2692
+ levels,
2693
+ origin,
2694
+ heightReference: first.heightReference
2695
+ };
2696
+ }
2697
+
2698
+ // dist/terrain/contour-boundary-diagnostics.js
2699
+ var TerrainContourBoundaryAxis = { COLUMN: 1, ROW: 2 };
2700
+ function diagnoseTerrainContourBoundaries(contours, options) {
2701
+ const { width, height } = options;
2702
+ if (!Number.isSafeInteger(width) || width < 2 || !Number.isSafeInteger(height) || height < 2)
2703
+ throw new Error("Invalid terrain contour boundary tile dimensions");
2704
+ const limits = contourPathLimits(options);
2705
+ const count = validateContourData(contours, limits);
2706
+ if (!(contours.segments instanceof Uint32Array) || contours.segments.length % 2 || !(contours.levelIndices instanceof Uint32Array) || contours.levelIndices.length !== contours.segments.length / 2 || contours.levelIndices.length > limits.maxSegments)
2707
+ throw new Error("Invalid terrain contour boundary segments or capacity");
2708
+ const degrees = new Uint32Array(count), assignments = new Uint32Array(count).fill(4294967295);
2709
+ const seen = /* @__PURE__ */ new Set();
2710
+ for (let i = 0; i < contours.levelIndices.length; i++) {
2711
+ const a = contours.segments[2 * i], b = contours.segments[2 * i + 1], level = contours.levelIndices[i];
2712
+ validateContourVertex(contours, a, level, assignments);
2713
+ validateContourVertex(contours, b, level, assignments);
2714
+ if (a === b || contours.positions[3 * a] === contours.positions[3 * b] && contours.positions[3 * a + 1] === contours.positions[3 * b + 1])
2715
+ throw new Error("Degenerate terrain contour segment");
2716
+ const key = a < b ? `${a}/${b}` : `${b}/${a}`;
2717
+ if (seen.has(key))
2718
+ throw new Error("Duplicate terrain contour segment");
2719
+ seen.add(key);
2720
+ degrees[a]++;
2721
+ degrees[b]++;
2722
+ }
2723
+ const vertices = [], resultDegrees = [], levels = [], axes = [];
2724
+ for (let i = 0; i < count; i++) {
2725
+ if (degrees[i] !== 1 && degrees[i] <= 2)
2726
+ continue;
2727
+ const x = contours.gridCoordinates[2 * i], y = contours.gridCoordinates[2 * i + 1];
2728
+ if (Math.abs(x) > Number.MAX_SAFE_INTEGER || Math.abs(y) > Number.MAX_SAFE_INTEGER)
2729
+ throw new Error("Terrain contour boundary lattice exceeds safe integer range");
2730
+ const axis = (Number.isSafeInteger(x) && x % (width - 1) === 0 ? TerrainContourBoundaryAxis.COLUMN : 0) | (Number.isSafeInteger(y) && y % (height - 1) === 0 ? TerrainContourBoundaryAxis.ROW : 0);
2731
+ if (!axis)
2732
+ continue;
2733
+ vertices.push(i);
2734
+ resultDegrees.push(degrees[i]);
2735
+ levels.push(assignments[i]);
2736
+ axes.push(axis);
2737
+ }
2738
+ return {
2739
+ vertexIndices: Uint32Array.from(vertices),
2740
+ degrees: Uint32Array.from(resultDegrees),
2741
+ levelIndices: Uint32Array.from(levels),
2742
+ boundaryAxes: Uint8Array.from(axes)
2743
+ };
2744
+ }
2745
+
2746
+ // dist/terrain/contour-tile-paths.js
2747
+ function stitchTerrainContourTiles(tiles, options) {
2748
+ return stitchTerrainContours(weldTerrainContourTiles(tiles, options), options);
2749
+ }
2750
+
2751
+ // dist/terrain/gradient-pyramid.js
2752
+ function createTerrainGradientPyramid(grid, options = {}) {
2753
+ const { width, height, gradients, statuses } = grid;
2754
+ const count = width * height, limit = options.maxSamples ?? 4e6;
2755
+ if (!Number.isSafeInteger(width) || width < 1 || !Number.isSafeInteger(height) || height < 1 || !Number.isSafeInteger(count) || count > 4294967295 || !Number.isSafeInteger(limit) || limit < count || !(gradients instanceof Float64Array) || gradients.length !== 2 * count || !(statuses instanceof Uint8Array) || statuses.length !== count || grid.method !== "horn" && grid.method !== "zevenbergen-thorne" || grid.registration !== "cell" && grid.registration !== "vertex" || typeof grid.heightReference !== "string" || ![grid.origin, grid.columnStep, grid.rowStep].every((v) => v.length === 2 && v.every(Number.isFinite)))
2756
+ throw new Error("Invalid terrain gradient pyramid input or capacity");
2757
+ const base = {
2758
+ width,
2759
+ height,
2760
+ blockSize: 1,
2761
+ gradients: new Float64Array(2 * count),
2762
+ validCounts: new Uint32Array(count),
2763
+ sampleCounts: new Uint32Array(count).fill(1)
2764
+ };
2765
+ for (let i = 0; i < count; i++) {
2766
+ if (statuses[i] > TerrainSampleStatus.NOT_RESIDENT)
2767
+ throw new Error("Invalid terrain gradient status");
2768
+ if (statuses[i] === TerrainSampleStatus.VALID) {
2769
+ if (!Number.isFinite(gradients[2 * i]) || !Number.isFinite(gradients[2 * i + 1]))
2770
+ throw new Error("Invalid terrain gradient value");
2771
+ base.gradients[2 * i] = gradients[2 * i];
2772
+ base.gradients[2 * i + 1] = gradients[2 * i + 1];
2773
+ base.validCounts[i] = 1;
2774
+ }
2775
+ }
2776
+ const levels = [base];
2777
+ let source = base;
2778
+ while (source.width > 1 || source.height > 1) {
2779
+ const w = Math.ceil(source.width / 2), h = Math.ceil(source.height / 2);
2780
+ const next = {
2781
+ width: w,
2782
+ height: h,
2783
+ blockSize: source.blockSize * 2,
2784
+ gradients: new Float64Array(2 * w * h),
2785
+ validCounts: new Uint32Array(w * h),
2786
+ sampleCounts: new Uint32Array(w * h)
2787
+ };
2788
+ for (let y = 0; y < h; y++)
2789
+ for (let x = 0; x < w; x++) {
2790
+ const out = y * w + x;
2791
+ for (let dy = 0; dy < 2; dy++)
2792
+ for (let dx = 0; dx < 2; dx++) {
2793
+ const sx = 2 * x + dx, sy = 2 * y + dy;
2794
+ if (sx >= source.width || sy >= source.height)
2795
+ continue;
2796
+ const index = sy * source.width + sx, n = source.validCounts[index], old = next.validCounts[out];
2797
+ next.sampleCounts[out] += source.sampleCounts[index];
2798
+ if (n) {
2799
+ const total = old + n;
2800
+ for (let axis = 0; axis < 2; axis++) {
2801
+ const a = next.gradients[2 * out + axis], b = source.gradients[2 * index + axis];
2802
+ next.gradients[2 * out + axis] = old ? a * (old / total) + b * (n / total) : b;
2803
+ }
2804
+ next.validCounts[out] = total;
2805
+ }
2806
+ }
2807
+ }
2808
+ levels.push(next);
2809
+ source = next;
2810
+ }
2811
+ return {
2812
+ levels,
2813
+ method: grid.method,
2814
+ origin: [...grid.origin],
2815
+ columnStep: [...grid.columnStep],
2816
+ rowStep: [...grid.rowStep],
2817
+ registration: grid.registration,
2818
+ heightReference: grid.heightReference
2819
+ };
2820
+ }
2821
+
2578
2822
  // dist/terrain/contour-simplify.js
2579
2823
  function simplifyTerrainContourPaths(paths, options) {
2580
2824
  const limits = contourPathLimits(options), count = validateContourData(paths, limits);