@math.gl/geospatial 5.0.0-beta.8 → 5.0.0-beta.9

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 (102) hide show
  1. package/dist/index.cjs +1354 -383
  2. package/dist/index.cjs.map +3 -3
  3. package/dist/index.d.ts +10 -0
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +9 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/tasks/index.cjs +1135 -142
  8. package/dist/tasks/index.cjs.map +3 -3
  9. package/dist/tasks/index.d.ts +12 -0
  10. package/dist/tasks/index.d.ts.map +1 -1
  11. package/dist/tasks/index.js +26 -0
  12. package/dist/tasks/index.js.map +1 -1
  13. package/dist/tasks/terrain-coverage-worker.d.ts +2 -0
  14. package/dist/tasks/terrain-coverage-worker.d.ts.map +1 -0
  15. package/dist/tasks/terrain-coverage-worker.js +7 -0
  16. package/dist/tasks/terrain-coverage-worker.js.map +1 -0
  17. package/dist/tasks/terrain-coverage.d.ts +25 -0
  18. package/dist/tasks/terrain-coverage.d.ts.map +1 -0
  19. package/dist/tasks/terrain-coverage.js +15 -0
  20. package/dist/tasks/terrain-coverage.js.map +1 -0
  21. package/dist/tasks/terrain-residency-worker.d.ts +2 -0
  22. package/dist/tasks/terrain-residency-worker.d.ts.map +1 -0
  23. package/dist/tasks/terrain-residency-worker.js +7 -0
  24. package/dist/tasks/terrain-residency-worker.js.map +1 -0
  25. package/dist/tasks/terrain-residency.d.ts +64 -0
  26. package/dist/tasks/terrain-residency.d.ts.map +1 -0
  27. package/dist/tasks/terrain-residency.js +124 -0
  28. package/dist/tasks/terrain-residency.js.map +1 -0
  29. package/dist/terrain/breakline-mesh.d.ts +18 -0
  30. package/dist/terrain/breakline-mesh.d.ts.map +1 -0
  31. package/dist/terrain/breakline-mesh.js +126 -0
  32. package/dist/terrain/breakline-mesh.js.map +1 -0
  33. package/dist/terrain/breakline-preprocess.d.ts +11 -0
  34. package/dist/terrain/breakline-preprocess.d.ts.map +1 -0
  35. package/dist/terrain/breakline-preprocess.js +94 -0
  36. package/dist/terrain/breakline-preprocess.js.map +1 -0
  37. package/dist/terrain/continuous-mesh-error.d.ts +34 -0
  38. package/dist/terrain/continuous-mesh-error.d.ts.map +1 -0
  39. package/dist/terrain/continuous-mesh-error.js +221 -0
  40. package/dist/terrain/continuous-mesh-error.js.map +1 -0
  41. package/dist/terrain/geographic-seam.d.ts +21 -0
  42. package/dist/terrain/geographic-seam.d.ts.map +1 -0
  43. package/dist/terrain/geographic-seam.js +52 -0
  44. package/dist/terrain/geographic-seam.js.map +1 -0
  45. package/dist/terrain/index.cjs +1104 -133
  46. package/dist/terrain/index.cjs.map +3 -3
  47. package/dist/terrain/index.d.ts +10 -0
  48. package/dist/terrain/index.d.ts.map +1 -1
  49. package/dist/terrain/index.js +9 -0
  50. package/dist/terrain/index.js.map +1 -1
  51. package/dist/terrain/lod-select.d.ts +32 -0
  52. package/dist/terrain/lod-select.d.ts.map +1 -0
  53. package/dist/terrain/lod-select.js +60 -0
  54. package/dist/terrain/lod-select.js.map +1 -0
  55. package/dist/terrain/lod-stitch.d.ts +13 -0
  56. package/dist/terrain/lod-stitch.d.ts.map +1 -0
  57. package/dist/terrain/lod-stitch.js +49 -0
  58. package/dist/terrain/lod-stitch.js.map +1 -0
  59. package/dist/terrain/mesh-coverage.d.ts +35 -0
  60. package/dist/terrain/mesh-coverage.d.ts.map +1 -0
  61. package/dist/terrain/mesh-coverage.js +186 -0
  62. package/dist/terrain/mesh-coverage.js.map +1 -0
  63. package/dist/terrain/mesh-regions-data.d.ts +2 -2
  64. package/dist/terrain/mesh-regions-data.d.ts.map +1 -1
  65. package/dist/terrain/mesh-regions-data.js +20 -10
  66. package/dist/terrain/mesh-regions-data.js.map +1 -1
  67. package/dist/terrain/mixed-halo-update.d.ts.map +1 -1
  68. package/dist/terrain/mixed-halo-update.js +93 -16
  69. package/dist/terrain/mixed-halo-update.js.map +1 -1
  70. package/dist/terrain/mixed-vertex-halos.d.ts +11 -1
  71. package/dist/terrain/mixed-vertex-halos.d.ts.map +1 -1
  72. package/dist/terrain/mixed-vertex-halos.js +43 -5
  73. package/dist/terrain/mixed-vertex-halos.js.map +1 -1
  74. package/dist/terrain/valid-domain-mesh.d.ts +29 -0
  75. package/dist/terrain/valid-domain-mesh.d.ts.map +1 -0
  76. package/dist/terrain/valid-domain-mesh.js +183 -0
  77. package/dist/terrain/valid-domain-mesh.js.map +1 -0
  78. package/dist/terrain/valid-domain-regions.d.ts +16 -0
  79. package/dist/terrain/valid-domain-regions.d.ts.map +1 -0
  80. package/dist/terrain/valid-domain-regions.js +19 -0
  81. package/dist/terrain/valid-domain-regions.js.map +1 -0
  82. package/package.json +9 -8
  83. package/src/index.ts +43 -0
  84. package/src/tasks/index.ts +34 -0
  85. package/src/tasks/terrain-coverage-worker.ts +6 -0
  86. package/src/tasks/terrain-coverage.ts +25 -0
  87. package/src/tasks/terrain-residency-worker.ts +6 -0
  88. package/src/tasks/terrain-residency.ts +154 -0
  89. package/src/terrain/breakline-mesh.ts +164 -0
  90. package/src/terrain/breakline-preprocess.ts +106 -0
  91. package/src/terrain/cdt2d.d.ts +10 -0
  92. package/src/terrain/continuous-mesh-error.ts +321 -0
  93. package/src/terrain/geographic-seam.ts +73 -0
  94. package/src/terrain/index.ts +39 -0
  95. package/src/terrain/lod-select.ts +95 -0
  96. package/src/terrain/lod-stitch.ts +70 -0
  97. package/src/terrain/mesh-coverage.ts +215 -0
  98. package/src/terrain/mesh-regions-data.ts +21 -13
  99. package/src/terrain/mixed-halo-update.ts +105 -17
  100. package/src/terrain/mixed-vertex-halos.ts +58 -4
  101. package/src/terrain/valid-domain-mesh.ts +221 -0
  102. package/src/terrain/valid-domain-regions.ts +41 -0
package/dist/index.cjs CHANGED
@@ -83,9 +83,12 @@ __export(index_exports, {
83
83
  WebMercatorViewport: () => web_mercator_exports.WebMercatorViewport,
84
84
  addMetersToLngLat: () => web_mercator_exports.addMetersToLngLat,
85
85
  altitudeToFovy: () => web_mercator_exports.altitudeToFovy,
86
+ boundTerrainMeshError: () => boundTerrainMeshError,
87
+ certifyTerrainMeshCoverage: () => certifyTerrainMeshCoverage,
86
88
  clipGeographicPolygon: () => clipGeographicPolygon,
87
89
  clipGeographicPolyline: () => clipGeographicPolyline,
88
90
  coordinateTerrainLodMorphs: () => coordinateTerrainLodMorphs,
91
+ createBreaklineTerrainMesh: () => createBreaklineTerrainMesh,
89
92
  createCRSDescriptor: () => createCRSDescriptor,
90
93
  createCRSDictionaryProvider: () => createCRSDictionaryProvider,
91
94
  createCRSExecutionIdentity: () => createCRSExecutionIdentity,
@@ -110,6 +113,7 @@ __export(index_exports, {
110
113
  createTerrainSlopeAspectGrid: () => createTerrainSlopeAspectGrid,
111
114
  createTerrainSurface: () => createTerrainSurface,
112
115
  createTerrainVertexTileHalos: () => createTerrainVertexTileHalos,
116
+ createValidDomainTerrainMesh: () => createValidDomainTerrainMesh,
113
117
  diagnoseTerrainContourBoundaries: () => diagnoseTerrainContourBoundaries,
114
118
  eastNorthUpToFixedFrame: () => eastNorthUpToFixedFrame,
115
119
  encodePROJString: () => encodePROJString,
@@ -154,6 +158,7 @@ __export(index_exports, {
154
158
  lngLatToWorld: () => web_mercator_exports.lngLatToWorld,
155
159
  localFrameToFixedFrame: () => localFrameToFixedFrame2,
156
160
  makeOBBFromRegion: () => makeOBBFromRegion,
161
+ measureGeographicTerrainSeam: () => measureGeographicTerrainSeam,
157
162
  measureTerrainMeshError: () => measureTerrainMeshError,
158
163
  measureTerrainProfile: () => measureTerrainProfile,
159
164
  normalizeCRSIdentifier: () => normalizeCRSIdentifier,
@@ -171,15 +176,18 @@ __export(index_exports, {
171
176
  resolveTileIndex: () => resolveTileIndex,
172
177
  sampleTerrainProfile: () => sampleTerrainProfile,
173
178
  scaleToZoom: () => web_mercator_exports.scaleToZoom,
179
+ selectTerrainLod: () => selectTerrainLod,
174
180
  selectTileMatrix: () => selectTileMatrix,
175
181
  simplifyTerrainContourPaths: () => simplifyTerrainContourPaths,
176
182
  simplifyTerrainContourPathsTopology: () => simplifyTerrainContourPathsTopology,
177
183
  splitGeographicPolygon: () => splitGeographicPolygon,
178
184
  splitGeographicPolyline: () => splitGeographicPolyline,
179
185
  splitGlobeBounds: () => splitGlobeBounds,
186
+ splitTerrainBreaklines: () => splitTerrainBreaklines,
180
187
  standardGridZone: () => standardGridZone,
181
188
  stitchTerrainContourTiles: () => stitchTerrainContourTiles,
182
189
  stitchTerrainContours: () => stitchTerrainContours,
190
+ stitchTerrainLodCut: () => stitchTerrainLodCut,
183
191
  stitchTerrainMeshEdges: () => stitchTerrainMeshEdges,
184
192
  subdivideGeodesicPolyline: () => subdivideGeodesicPolyline,
185
193
  subdivideGeographicCutRing: () => subdivideGeographicCutRing,
@@ -201,6 +209,7 @@ __export(index_exports, {
201
209
  updateTerrainMixedVertexTileHalos: () => updateTerrainMixedVertexTileHalos,
202
210
  updateTerrainPersistentBounds: () => updateTerrainPersistentBounds,
203
211
  updateTerrainPersistentGradients: () => updateTerrainPersistentGradients,
212
+ updateTerrainValidDomainMeshRegions: () => updateTerrainValidDomainMeshRegions,
204
213
  updateTerrainVertexTileHalos: () => updateTerrainVertexTileHalos,
205
214
  validateTileMatrix: () => validateTileMatrix,
206
215
  validateTileMatrixLimits: () => validateTileMatrixLimits,
@@ -210,6 +219,7 @@ __export(index_exports, {
210
219
  weldTerrainMixedContourTiles: () => weldTerrainMixedContourTiles,
211
220
  worldToLngLat: () => web_mercator_exports.worldToLngLat,
212
221
  worldToPixels: () => web_mercator_exports.worldToPixels,
222
+ wrapTerrainLongitude: () => wrapTerrainLongitude,
213
223
  zoomToScale: () => web_mercator_exports.zoomToScale
214
224
  });
215
225
  module.exports = __toCommonJS(index_exports);
@@ -770,10 +780,10 @@ function binaryScale(value3) {
770
780
  return 2 ** Math.min(1023, Math.floor(Math.log2(value3)));
771
781
  }
772
782
  function compensatedDot3(x, y, z, a, b, c) {
773
- const magnitude = Math.max(Math.abs(x), Math.abs(y), Math.abs(z));
774
- if (magnitude === 0)
783
+ const magnitude2 = Math.max(Math.abs(x), Math.abs(y), Math.abs(z));
784
+ if (magnitude2 === 0)
775
785
  return 0;
776
- const scale3 = binaryScale(magnitude);
786
+ const scale3 = binaryScale(magnitude2);
777
787
  const sx = x / scale3, sy = y / scale3, sz = z / scale3;
778
788
  const p = sx * a, q = sy * b, r = sz * c;
779
789
  const s = p + q, t = s + r;
@@ -934,8 +944,8 @@ var EllipsoidTangentPlane = class {
934
944
  const error = 1e-6 * (Math.abs(squaredB) + Math.abs(ac));
935
945
  const discriminant = squaredB - ac;
936
946
  if (!(a > 0) || !Number.isFinite(discriminant) || Math.abs(discriminant) <= error) {
937
- const exact2 = exactNormalIntersection(this.radii, this.anchor, this.east, this.north, n, point2, this.radius);
938
- return exact2 && writeSurfacePoint(exact2[0], exact2[1], exact2[2], result);
947
+ const exact3 = exactNormalIntersection(this.radii, this.anchor, this.east, this.north, n, point2, this.radius);
948
+ return exact3 && writeSurfacePoint(exact3[0], exact3[1], exact3[2], result);
939
949
  }
940
950
  if (discriminant < 0)
941
951
  return void 0;
@@ -2856,14 +2866,14 @@ var SurfacePolygon = class {
2856
2866
  throw new Error("Polygon point requires finite longitude and latitude in [-90, 90]");
2857
2867
  }
2858
2868
  if (this.count) {
2859
- const edge = this.geodesic.inverse(this.lastLat, this.lastLon, latitude, longitude, {
2869
+ const edge2 = this.geodesic.inverse(this.lastLat, this.lastLon, latitude, longitude, {
2860
2870
  area: !this.polyline,
2861
2871
  longitudeTurns: options.longitudeTurns,
2862
2872
  unrollLongitude: Boolean(options.longitudeTurns)
2863
2873
  });
2864
- this.accumulate(edge.s12, this.polyline ? 0 : edge.S12);
2874
+ this.accumulate(edge2.s12, this.polyline ? 0 : edge2.S12);
2865
2875
  if (!this.polyline) {
2866
- this.crossings = (this.crossings + (options.longitudeTurns ? transitDirect(this.lastLon, edge.lon2) : transit(this.lastLon, longitude))) % 2;
2876
+ this.crossings = (this.crossings + (options.longitudeTurns ? transitDirect(this.lastLon, edge2.lon2) : transit(this.lastLon, longitude))) % 2;
2867
2877
  }
2868
2878
  } else {
2869
2879
  this.firstLat = latitude;
@@ -2877,18 +2887,18 @@ var SurfacePolygon = class {
2877
2887
  addEdge(azimuth, distance) {
2878
2888
  if (!this.count)
2879
2889
  throw new Error("Add a starting point before adding an edge");
2880
- const edge = this.geodesic.direct(this.lastLat, this.lastLon, azimuth, distance, {
2890
+ const edge2 = this.geodesic.direct(this.lastLat, this.lastLon, azimuth, distance, {
2881
2891
  area: !this.polyline,
2882
2892
  unrollLongitude: true
2883
2893
  });
2884
- if (!(Number.isFinite(edge.lat2) && Number.isFinite(edge.lon2)))
2894
+ if (!(Number.isFinite(edge2.lat2) && Number.isFinite(edge2.lon2)))
2885
2895
  throw new Error("Unrepresentable geodesic edge");
2886
- this.accumulate(distance, this.polyline ? 0 : edge.S12);
2896
+ this.accumulate(distance, this.polyline ? 0 : edge2.S12);
2887
2897
  if (!this.polyline) {
2888
- this.crossings = (this.crossings + transitDirect(this.lastLon, edge.lon2)) % 2;
2898
+ this.crossings = (this.crossings + transitDirect(this.lastLon, edge2.lon2)) % 2;
2889
2899
  }
2890
- this.lastLat = edge.lat2;
2891
- this.lastLon = edge.lon2;
2900
+ this.lastLat = edge2.lat2;
2901
+ this.lastLon = edge2.lon2;
2892
2902
  ++this.count;
2893
2903
  return this;
2894
2904
  }
@@ -2897,11 +2907,11 @@ var SurfacePolygon = class {
2897
2907
  return this.polyline ? { number: this.count, perimeter: 0 } : { number: this.count, perimeter: 0, area: 0 };
2898
2908
  if (this.polyline)
2899
2909
  return { number: this.count, perimeter: this.perimeter.Sum() };
2900
- const edge = this.geodesic.inverse(this.lastLat, this.lastLon, this.firstLat, this.firstLon, {
2910
+ const edge2 = this.geodesic.inverse(this.lastLat, this.lastLon, this.firstLat, this.firstLon, {
2901
2911
  area: true
2902
2912
  });
2903
2913
  const total = new Accumulator(this.area);
2904
- total.Add(edge.S12);
2914
+ total.Add(edge2.S12);
2905
2915
  const area0 = this.area0;
2906
2916
  total.Remainder(area0);
2907
2917
  if ((this.crossings + transit(this.lastLon, this.firstLon)) % 2 !== 0) {
@@ -2920,7 +2930,7 @@ var SurfacePolygon = class {
2920
2930
  else if (total.Sum() <= -area0 / 2)
2921
2931
  total.Add(area0);
2922
2932
  }
2923
- return { number: this.count, perimeter: this.perimeter.Sum(edge.s12), area: 0 + total.Sum() };
2933
+ return { number: this.count, perimeter: this.perimeter.Sum(edge2.s12), area: 0 + total.Sum() };
2924
2934
  }
2925
2935
  /** Nonmutating preview, with the same compensated arithmetic as insertion. */
2926
2936
  testPoint(latitude, longitude, options = {}) {
@@ -3082,7 +3092,7 @@ var EllipsoidRhumb = class {
3082
3092
  const [sa, ca] = sincosDegrees(azimuth);
3083
3093
  const area = Boolean(options.area), unroll = Boolean(options.unrollLongitude);
3084
3094
  const azi = normalize(azimuth);
3085
- const evaluate = (distance, _index, _array, output2) => {
3095
+ const evaluate2 = (distance, _index, _array, output2) => {
3086
3096
  if (!Number.isFinite(distance))
3087
3097
  throw new RangeError("Rhumb distance must be finite");
3088
3098
  const delta = distance / this.a;
@@ -3122,7 +3132,7 @@ var EllipsoidRhumb = class {
3122
3132
  result.S12 = this.area(latitude, lat2, dlon * DEG2, polar == null ? void 0 : polar.psi);
3123
3133
  return result;
3124
3134
  };
3125
- return { position: evaluate };
3135
+ return { position: evaluate2 };
3126
3136
  }
3127
3137
  means(lat1, lat2) {
3128
3138
  const d = (lat2 - lat1) * DEG2;
@@ -4470,9 +4480,9 @@ function getGlobeHorizonBounds(camera, radius) {
4470
4480
  const extent = Math.asin(Math.min(1, Math.sin(angle3) / Math.cos(latitude))) * degrees2 + padding;
4471
4481
  return [wrap(longitude * degrees2 - extent), south, wrap(longitude * degrees2 + extent), north];
4472
4482
  }
4473
- function splitGlobeBounds(bounds) {
4474
- const [west, south, east, north] = bounds;
4475
- if (bounds.length !== 4 || !bounds.every(Number.isFinite) || west < -180 || west > 180 || east < -180 || east > 180 || south < -90 || north > 90 || south > north)
4483
+ function splitGlobeBounds(bounds2) {
4484
+ const [west, south, east, north] = bounds2;
4485
+ if (bounds2.length !== 4 || !bounds2.every(Number.isFinite) || west < -180 || west > 180 || east < -180 || east > 180 || south < -90 || north > 90 || south > north)
4476
4486
  throw new RangeError("Invalid degree bounds");
4477
4487
  return west <= east ? [[west, south, east, north]] : [
4478
4488
  [west, south, 180, north],
@@ -4735,28 +4745,28 @@ function chartPoint(point2, world, context) {
4735
4745
  function straight(a, b) {
4736
4746
  return { a, b, source: null, sample: (t) => a.map((x, i) => x * (1 - t) + b[i] * t) };
4737
4747
  }
4738
- function slice(edge, lo, hi) {
4739
- const a = lo === 0 ? edge.a : lo === 1 ? edge.b : edge.sample(lo);
4740
- const b = hi === 0 ? edge.a : hi === 1 ? edge.b : edge.sample(hi);
4741
- const source = edge.source && {
4742
- ...edge.source,
4743
- startFraction: edge.source.startFraction + (edge.source.endFraction - edge.source.startFraction) * lo,
4744
- endFraction: edge.source.startFraction + (edge.source.endFraction - edge.source.startFraction) * hi
4748
+ function slice(edge2, lo, hi) {
4749
+ const a = lo === 0 ? edge2.a : lo === 1 ? edge2.b : edge2.sample(lo);
4750
+ const b = hi === 0 ? edge2.a : hi === 1 ? edge2.b : edge2.sample(hi);
4751
+ const source = edge2.source && {
4752
+ ...edge2.source,
4753
+ startFraction: edge2.source.startFraction + (edge2.source.endFraction - edge2.source.startFraction) * lo,
4754
+ endFraction: edge2.source.startFraction + (edge2.source.endFraction - edge2.source.startFraction) * hi
4745
4755
  };
4746
4756
  return {
4747
4757
  a,
4748
4758
  b,
4749
4759
  source,
4750
- sample: (t) => t === 0 ? a.slice() : t === 1 ? b.slice() : edge.sample(lo + (hi - lo) * t)
4760
+ sample: (t) => t === 0 ? a.slice() : t === 1 ? b.slice() : edge2.sample(lo + (hi - lo) * t)
4751
4761
  };
4752
4762
  }
4753
- function shift(edge, delta) {
4763
+ function shift(edge2, delta) {
4754
4764
  const move = (p) => [p[0] + delta, ...p.slice(1)];
4755
4765
  return {
4756
- a: move(edge.a),
4757
- b: move(edge.b),
4758
- source: edge.source && { ...edge.source, longitudeShift: edge.source.longitudeShift + delta },
4759
- sample: (t) => move(edge.sample(t))
4766
+ a: move(edge2.a),
4767
+ b: move(edge2.b),
4768
+ source: edge2.source && { ...edge2.source, longitudeShift: edge2.source.longitudeShift + delta },
4769
+ sample: (t) => move(edge2.sample(t))
4760
4770
  };
4761
4771
  }
4762
4772
  function createEdges(start, end, originalStart, edgeIndex, ringIndex, turns, context, splitLatitude = true) {
@@ -4858,9 +4868,9 @@ function createEdges(start, end, originalStart, edgeIndex, ringIndex, turns, con
4858
4868
  throw new GeographicSeamError("precision", "Nonfinite edge sample");
4859
4869
  return p;
4860
4870
  };
4861
- const edge = { a: first, b: last, source, sample };
4871
+ const edge2 = { a: first, b: last, source, sample };
4862
4872
  if (pole) {
4863
- const incoming = slice(edge, 0, pole.fraction), outgoing = slice(edge, pole.fraction, 1);
4873
+ const incoming = slice(edge2, 0, pole.fraction), outgoing = slice(edge2, pole.fraction, 1);
4864
4874
  incoming.b = [first[0], pole.latitude, ...sample(pole.fraction).slice(2)];
4865
4875
  outgoing.a = [last[0], pole.latitude, ...incoming.b.slice(2)];
4866
4876
  const incomingSample = incoming.sample, outgoingSample = outgoing.sample;
@@ -4868,26 +4878,26 @@ function createEdges(start, end, originalStart, edgeIndex, ringIndex, turns, con
4868
4878
  outgoing.sample = (t) => t === 0 ? outgoing.a.slice() : outgoingSample(t);
4869
4879
  return [incoming, straight(incoming.b, outgoing.a), outgoing];
4870
4880
  }
4871
- return critical !== void 0 && critical > 0 && critical < 1 ? [slice(edge, 0, critical), slice(edge, critical, 1)] : [edge];
4881
+ return critical !== void 0 && critical > 0 && critical < 1 ? [slice(edge2, 0, critical), slice(edge2, critical, 1)] : [edge2];
4872
4882
  }
4873
- function root(edge, axis, value3, context) {
4874
- if (edge.a[axis] === value3)
4883
+ function root(edge2, axis, value3, context) {
4884
+ if (edge2.a[axis] === value3)
4875
4885
  return 0;
4876
- if (edge.b[axis] === value3)
4886
+ if (edge2.b[axis] === value3)
4877
4887
  return 1;
4878
- if (!(value3 > Math.min(edge.a[axis], edge.b[axis]) && value3 < Math.max(edge.a[axis], edge.b[axis])))
4888
+ if (!(value3 > Math.min(edge2.a[axis], edge2.b[axis]) && value3 < Math.max(edge2.a[axis], edge2.b[axis])))
4879
4889
  throw new GeographicSeamError("precision", "Unbracketed seam root");
4880
- let lo = 0, hi = 1, a = edge.a, b = edge.b;
4890
+ let lo = 0, hi = 1, a = edge2.a, b = edge2.b;
4881
4891
  for (let i = 0; i < context.iterations; i++) {
4882
4892
  context.tick();
4883
- const t = (lo + hi) / 2, p = edge.sample(t);
4893
+ const t = (lo + hi) / 2, p = edge2.sample(t);
4884
4894
  if (p[axis] === value3)
4885
4895
  return t;
4886
4896
  if (hi - lo <= 4 * Number.EPSILON && Math.abs(a[0] - b[0]) * Math.max(Math.abs(Math.cos(a[1] * Math.PI / 180)), Math.abs(Math.cos(b[1] * Math.PI / 180))) <= ANGULAR_TOLERANCE && Math.abs(a[1] - b[1]) <= ANGULAR_TOLERANCE)
4887
4897
  return t;
4888
4898
  if (t === lo || t === hi)
4889
4899
  break;
4890
- if (p[axis] < value3 === edge.a[axis] < edge.b[axis]) {
4900
+ if (p[axis] < value3 === edge2.a[axis] < edge2.b[axis]) {
4891
4901
  lo = t;
4892
4902
  a = p;
4893
4903
  } else {
@@ -4897,12 +4907,12 @@ function root(edge, axis, value3, context) {
4897
4907
  }
4898
4908
  throw new GeographicSeamError("precision", "Seam root exhausted its precision/iteration budget");
4899
4909
  }
4900
- function cut(edge, context) {
4901
- const low = Math.min(edge.a[0], edge.b[0]), high = Math.max(edge.a[0], edge.b[0]);
4910
+ function cut(edge2, context) {
4911
+ const low = Math.min(edge2.a[0], edge2.b[0]), high = Math.max(edge2.a[0], edge2.b[0]);
4902
4912
  const fractions = [0, 1];
4903
4913
  for (let k = worldAt(low, context); context.right + 360 * k < high; k++) {
4904
4914
  context.tick();
4905
- fractions.push(root(edge, 0, context.right + 360 * k, context));
4915
+ fractions.push(root(edge2, 0, context.right + 360 * k, context));
4906
4916
  if (fractions.length > context.maxVertices)
4907
4917
  throw new GeographicSeamError("limit", "Too many seam crossings");
4908
4918
  }
@@ -4911,7 +4921,7 @@ function cut(edge, context) {
4911
4921
  for (let i = 1; i < fractions.length; i++) {
4912
4922
  context.tick();
4913
4923
  context.addVertices(2);
4914
- const piece = slice(edge, fractions[i - 1], fractions[i]);
4924
+ const piece = slice(edge2, fractions[i - 1], fractions[i]);
4915
4925
  for (const p of [piece.a, piece.b]) {
4916
4926
  const k = Math.round((p[0] - context.right) / 360), boundary = context.right + 360 * k;
4917
4927
  if (fractions[i - 1] !== 0 && p === piece.a || fractions[i] !== 1 && p === piece.b)
@@ -4936,11 +4946,11 @@ function readLatitudeRange(value3) {
4936
4946
  throw new GeographicSeamError("input", "Expected -90 <= south < north <= 90");
4937
4947
  return [value3[0], value3[1]];
4938
4948
  }
4939
- function clipLatitudeEdge(edge, range, context) {
4949
+ function clipLatitudeEdge(edge2, range, context) {
4940
4950
  const fractions = [0, 1], events = /* @__PURE__ */ new Map();
4941
4951
  for (const latitude of range)
4942
- if (latitude > Math.min(edge.a[1], edge.b[1]) && latitude < Math.max(edge.a[1], edge.b[1])) {
4943
- const t = root(edge, 1, latitude, context);
4952
+ if (latitude > Math.min(edge2.a[1], edge2.b[1]) && latitude < Math.max(edge2.a[1], edge2.b[1])) {
4953
+ const t = root(edge2, 1, latitude, context);
4944
4954
  if (events.has(t) && events.get(t) !== latitude)
4945
4955
  throw new GeographicSeamError("precision", "Unresolvable latitude events");
4946
4956
  fractions.push(t);
@@ -4950,7 +4960,7 @@ function clipLatitudeEdge(edge, range, context) {
4950
4960
  const result = [];
4951
4961
  for (let i = 1; i < fractions.length; i++) {
4952
4962
  context.tick();
4953
- const part = slice(edge, fractions[i - 1], fractions[i]);
4963
+ const part = slice(edge2, fractions[i - 1], fractions[i]);
4954
4964
  const middle = (part.a[1] + part.b[1]) / 2;
4955
4965
  if (middle < range[0] || middle > range[1])
4956
4966
  continue;
@@ -4969,17 +4979,17 @@ function clipLatitudeEdge(edge, range, context) {
4969
4979
  // dist/geographic-seams/polygon.js
4970
4980
  function winding(edges, point2, context, side, generatedBoundary = true, longitudeShift = 0, verticalSide) {
4971
4981
  let value3 = 0, boundary = false;
4972
- for (const edge of edges) {
4982
+ for (const edge2 of edges) {
4973
4983
  context.tick();
4974
- const a = edge.a, b = edge.b;
4984
+ const a = edge2.a, b = edge2.b;
4975
4985
  if (a[1] === b[1]) {
4976
- if ((generatedBoundary || edge.source) && point2[1] === a[1] && point2[0] >= Math.min(context.projectLongitude(a[0], longitudeShift), context.projectLongitude(b[0], longitudeShift)) && point2[0] <= Math.max(context.projectLongitude(a[0], longitudeShift), context.projectLongitude(b[0], longitudeShift)))
4986
+ if ((generatedBoundary || edge2.source) && point2[1] === a[1] && point2[0] >= Math.min(context.projectLongitude(a[0], longitudeShift), context.projectLongitude(b[0], longitudeShift)) && point2[0] <= Math.max(context.projectLongitude(a[0], longitudeShift), context.projectLongitude(b[0], longitudeShift)))
4977
4987
  boundary = true;
4978
4988
  continue;
4979
4989
  }
4980
4990
  if (point2[1] >= Math.min(a[1], b[1]) && point2[1] <= Math.max(a[1], b[1])) {
4981
- const t = root(edge, 1, point2[1], context), x = context.projectLongitude(edge.sample(t)[0], longitudeShift);
4982
- if ((generatedBoundary || edge.source) && Math.abs(x - point2[0]) <= ANGULAR_TOLERANCE)
4991
+ const t = root(edge2, 1, point2[1], context), x = context.projectLongitude(edge2.sample(t)[0], longitudeShift);
4992
+ if ((generatedBoundary || edge2.source) && Math.abs(x - point2[0]) <= ANGULAR_TOLERANCE)
4983
4993
  boundary = true;
4984
4994
  if ((verticalSide === "south" ? a[1] >= point2[1] : a[1] > point2[1]) !== (verticalSide === "south" ? b[1] >= point2[1] : b[1] > point2[1]) && (side === "left" ? x >= point2[0] : x > point2[0]))
4985
4995
  value3 += b[1] > a[1] ? 1 : -1;
@@ -5021,12 +5031,12 @@ function prepare(input, index, context) {
5021
5031
  throw new GeographicSeamError("precision", "Discontinuous ring edge");
5022
5032
  edges.push(straight(cursor, pieces[0].a));
5023
5033
  }
5024
- for (const edge of pieces) {
5025
- if (edge.a[0] === edge.b[0] && edge.a[1] === edge.b[1]) {
5026
- if (!same(edge.a, edge.b))
5034
+ for (const edge2 of pieces) {
5035
+ if (edge2.a[0] === edge2.b[0] && edge2.a[1] === edge2.b[1]) {
5036
+ if (!same(edge2.a, edge2.b))
5027
5037
  throw new GeographicSeamError("topology", "Zero-length polygon edge changes attributes");
5028
5038
  } else
5029
- edges.push(edge);
5039
+ edges.push(edge2);
5030
5040
  }
5031
5041
  cursor = pieces[pieces.length - 1].b;
5032
5042
  }
@@ -5065,24 +5075,24 @@ function prepare(input, index, context) {
5065
5075
  }
5066
5076
  return { edges, membership, min, max, pole: input.pole, poleAttributes };
5067
5077
  }
5068
- function reverse(edge) {
5078
+ function reverse(edge2) {
5069
5079
  return {
5070
- a: edge.b,
5071
- b: edge.a,
5072
- sample: (t) => edge.sample(1 - t),
5073
- source: edge.source && {
5074
- ...edge.source,
5075
- startFraction: edge.source.endFraction,
5076
- endFraction: edge.source.startFraction
5080
+ a: edge2.b,
5081
+ b: edge2.a,
5082
+ sample: (t) => edge2.sample(1 - t),
5083
+ source: edge2.source && {
5084
+ ...edge2.source,
5085
+ startFraction: edge2.source.endFraction,
5086
+ endFraction: edge2.source.startFraction
5077
5087
  }
5078
5088
  };
5079
5089
  }
5080
- function canonicalAlias(edge, context) {
5090
+ function canonicalAlias(edge2, context) {
5081
5091
  const move = (p) => {
5082
5092
  const longitude = context.canonicalLongitude(p[0]);
5083
5093
  return longitude === p[0] ? p : [longitude, ...p.slice(1)];
5084
5094
  };
5085
- return { ...edge, a: move(edge.a), b: move(edge.b), sample: (t) => move(edge.sample(t)) };
5095
+ return { ...edge2, a: move(edge2.a), b: move(edge2.b), sample: (t) => move(edge2.sample(t)) };
5086
5096
  }
5087
5097
  function interior(edges, context) {
5088
5098
  const ys = Array.from(new Set(edges.flatMap((e) => [e.a[1], e.b[1]]))).sort((a, b) => a - b);
@@ -5093,10 +5103,10 @@ function interior(edges, context) {
5093
5103
  if (ys.length < 2 || ys[index] - ys[index - 1] < 8 * ANGULAR_TOLERANCE)
5094
5104
  throw new GeographicSeamError("precision", "Polygon height below the topology budget");
5095
5105
  const y = (ys[index] + ys[index - 1]) / 2, xs = [];
5096
- for (const edge of edges) {
5106
+ for (const edge2 of edges) {
5097
5107
  context.tick();
5098
- if (edge.a[1] > y !== edge.b[1] > y)
5099
- xs.push(edge.sample(root(edge, 1, y, context))[0]);
5108
+ if (edge2.a[1] > y !== edge2.b[1] > y)
5109
+ xs.push(edge2.sample(root(edge2, 1, y, context))[0]);
5100
5110
  }
5101
5111
  xs.sort((a, b) => a - b);
5102
5112
  for (let i = 1; i < xs.length; i++) {
@@ -5135,13 +5145,13 @@ function processPolygon(inputs, options, latitudeRange) {
5135
5145
  const rings = inputs.map((ring, i) => prepare(ring, i, context));
5136
5146
  const graph = [], nodes = /* @__PURE__ */ new Map();
5137
5147
  const key3 = (p) => `${p[0]},${p[1]}`;
5138
- const add3 = (edge) => {
5148
+ const add4 = (edge2) => {
5139
5149
  context.tick();
5140
- if (edge.a[0] === edge.b[0] && edge.a[1] === edge.b[1])
5150
+ if (edge2.a[0] === edge2.b[0] && edge2.a[1] === edge2.b[1])
5141
5151
  return;
5142
5152
  const id = graph.length;
5143
- graph.push(edge);
5144
- for (const p of [edge.a, edge.b]) {
5153
+ graph.push(edge2);
5154
+ for (const p of [edge2.a, edge2.b]) {
5145
5155
  const k = key3(p), node = nodes.get(k);
5146
5156
  if (node) {
5147
5157
  if (!same(node.p, p))
@@ -5169,27 +5179,27 @@ function processPolygon(inputs, options, latitudeRange) {
5169
5179
  for (const ring of rings) {
5170
5180
  for (const original of ring.edges)
5171
5181
  for (const { edge: part } of cut(original, context)) {
5172
- const edge = canonicalAlias(part, context);
5173
- pieces.push(edge);
5174
- if (edge.a[0] === edge.b[0]) {
5175
- const events = meridians.get(edge.a[0]) || /* @__PURE__ */ new Set();
5176
- events.add(edge.a[1]);
5177
- events.add(edge.b[1]);
5178
- meridians.set(edge.a[0], events);
5182
+ const edge2 = canonicalAlias(part, context);
5183
+ pieces.push(edge2);
5184
+ if (edge2.a[0] === edge2.b[0]) {
5185
+ const events = meridians.get(edge2.a[0]) || /* @__PURE__ */ new Set();
5186
+ events.add(edge2.a[1]);
5187
+ events.add(edge2.b[1]);
5188
+ meridians.set(edge2.a[0], events);
5179
5189
  }
5180
5190
  }
5181
5191
  }
5182
- for (const edge of pieces) {
5183
- if (edge.a[0] !== edge.b[0]) {
5184
- add3(edge);
5192
+ for (const edge2 of pieces) {
5193
+ if (edge2.a[0] !== edge2.b[0]) {
5194
+ add4(edge2);
5185
5195
  continue;
5186
5196
  }
5187
5197
  const fractions = [0, 1];
5188
5198
  const latitudes = /* @__PURE__ */ new Map();
5189
- for (const y of meridians.get(edge.a[0])) {
5199
+ for (const y of meridians.get(edge2.a[0])) {
5190
5200
  context.tick();
5191
- if (y > Math.min(edge.a[1], edge.b[1]) && y < Math.max(edge.a[1], edge.b[1])) {
5192
- const fraction = root(edge, 1, y, context);
5201
+ if (y > Math.min(edge2.a[1], edge2.b[1]) && y < Math.max(edge2.a[1], edge2.b[1])) {
5202
+ const fraction = root(edge2, 1, y, context);
5193
5203
  if (latitudes.has(fraction) && latitudes.get(fraction) !== y)
5194
5204
  throw new GeographicSeamError("precision", "Unresolvable meridian event separation");
5195
5205
  fractions.push(fraction);
@@ -5199,7 +5209,7 @@ function processPolygon(inputs, options, latitudeRange) {
5199
5209
  fractions.sort((a, b) => a - b);
5200
5210
  for (let i = 1; i < fractions.length; i++) {
5201
5211
  context.tick();
5202
- const piece = slice(edge, fractions[i - 1], fractions[i]);
5212
+ const piece = slice(edge2, fractions[i - 1], fractions[i]);
5203
5213
  if (latitudes.has(fractions[i - 1]))
5204
5214
  piece.a[1] = latitudes.get(fractions[i - 1]);
5205
5215
  if (latitudes.has(fractions[i]))
@@ -5225,15 +5235,15 @@ function processPolygon(inputs, options, latitudeRange) {
5225
5235
  p[0] = context.right;
5226
5236
  return p;
5227
5237
  };
5228
- add3(assigned);
5238
+ add4(assigned);
5229
5239
  } else
5230
- add3(piece);
5240
+ add4(piece);
5231
5241
  }
5232
5242
  }
5233
5243
  const pole = rings[0].pole;
5234
5244
  if (pole && !rings.slice(1).some((r) => r.pole === pole)) {
5235
5245
  const latitude = pole === "north" ? 90 : -90;
5236
- add3(straight([context.left, latitude, ...rings[0].poleAttributes], [context.right, latitude, ...rings[0].poleAttributes]));
5246
+ add4(straight([context.left, latitude, ...rings[0].poleAttributes], [context.right, latitude, ...rings[0].poleAttributes]));
5237
5247
  }
5238
5248
  for (const boundary of [context.left, context.right]) {
5239
5249
  const boundaryNodes = Array.from(nodes.values()).filter((n) => n.p[0] === boundary).sort((a, b) => a.p[1] - b.p[1]);
@@ -5247,19 +5257,19 @@ function processPolygon(inputs, options, latitudeRange) {
5247
5257
  context.tick();
5248
5258
  return latitude > Math.min(e.a[1], e.b[1]) && latitude < Math.max(e.a[1], e.b[1]);
5249
5259
  }))
5250
- add3(straight(a, b));
5260
+ add4(straight(a, b));
5251
5261
  }
5252
5262
  }
5253
5263
  if (latitudeRange) {
5254
5264
  const sourceGraph = graph.slice();
5255
5265
  graph.length = 0;
5256
5266
  nodes.clear();
5257
- for (const edge of sourceGraph)
5258
- for (const part of clipLatitudeEdge(edge, latitudeRange, context)) {
5267
+ for (const edge2 of sourceGraph)
5268
+ for (const part of clipLatitudeEdge(edge2, latitudeRange, context)) {
5259
5269
  const boundary = part.a[1] === part.b[1] && latitudeRange.includes(part.a[1]);
5260
5270
  if (boundary && !filled(rings, [(part.a[0] + part.b[0]) / 2, part.a[1]], context, void 0, part.a[1] === latitudeRange[0] ? "north" : "south"))
5261
5271
  continue;
5262
- add3(part);
5272
+ add4(part);
5263
5273
  }
5264
5274
  for (const boundary of latitudeRange) {
5265
5275
  const events = Array.from(nodes.values()).filter((n) => n.p[1] === boundary).sort((a, b) => a.p[0] - b.p[0]);
@@ -5273,7 +5283,7 @@ function processPolygon(inputs, options, latitudeRange) {
5273
5283
  context.tick();
5274
5284
  return longitude > Math.min(e.a[0], e.b[0]) && longitude < Math.max(e.a[0], e.b[0]);
5275
5285
  }))
5276
- add3(straight(a, b));
5286
+ add4(straight(a, b));
5277
5287
  }
5278
5288
  }
5279
5289
  }
@@ -5291,9 +5301,9 @@ function processPolygon(inputs, options, latitudeRange) {
5291
5301
  if (used.has(id))
5292
5302
  throw new GeographicSeamError("topology", "Non-simple boundary graph");
5293
5303
  used.add(id);
5294
- const edge = key3(graph[id].a) === current ? graph[id] : reverse(graph[id]);
5295
- cycle.push(edge);
5296
- current = key3(edge.b);
5304
+ const edge2 = key3(graph[id].a) === current ? graph[id] : reverse(graph[id]);
5305
+ cycle.push(edge2);
5306
+ current = key3(edge2.b);
5297
5307
  const adjacent = nodes.get(current).edges;
5298
5308
  id = adjacent[0] === id ? adjacent[1] : adjacent[0];
5299
5309
  } while (current !== start);
@@ -5321,9 +5331,9 @@ function processPolygon(inputs, options, latitudeRange) {
5321
5331
  if (parents[i] === void 0) {
5322
5332
  if (cycles[i].every((e) => e.source && e.source.ringIndex !== 0))
5323
5333
  throw new GeographicSeamError("topology", "Hole is outside the outer ring");
5324
- const polygon = { rings: [output(cycles[i], sign2, context)] };
5325
- result.push(polygon);
5326
- groups.set(i, polygon);
5334
+ const polygon2 = { rings: [output(cycles[i], sign2, context)] };
5335
+ result.push(polygon2);
5336
+ groups.set(i, polygon2);
5327
5337
  }
5328
5338
  for (let i = 0; i < cycles.length; i++)
5329
5339
  if (parents[i] !== void 0) {
@@ -5355,13 +5365,13 @@ function splitGeographicPolyline(input, options) {
5355
5365
  for (const original of edges) {
5356
5366
  if (!original.source)
5357
5367
  continue;
5358
- for (const { edge, world } of cut(original, context)) {
5368
+ for (const { edge: edge2, world } of cut(original, context)) {
5359
5369
  const previous = parts[parts.length - 1];
5360
- if (previous && previous.world === world && same(previous.points[previous.points.length - 1], edge.a)) {
5361
- previous.points.push(edge.b);
5362
- previous.edges.push(edge.source);
5370
+ if (previous && previous.world === world && same(previous.points[previous.points.length - 1], edge2.a)) {
5371
+ previous.points.push(edge2.b);
5372
+ previous.edges.push(edge2.source);
5363
5373
  } else
5364
- parts.push({ points: [edge.a, edge.b], edges: [edge.source], world });
5374
+ parts.push({ points: [edge2.a, edge2.b], edges: [edge2.source], world });
5365
5375
  }
5366
5376
  }
5367
5377
  cursor = edges[edges.length - 1].b;
@@ -5395,9 +5405,9 @@ function getGeographicTile(longitude, latitude, level) {
5395
5405
  level
5396
5406
  };
5397
5407
  }
5398
- function getGeographicTileRanges(bounds, level) {
5408
+ function getGeographicTileRanges(bounds2, level) {
5399
5409
  const size = gridSize(level);
5400
- const split = splitGlobeBounds(bounds);
5410
+ const split = splitGlobeBounds(bounds2);
5401
5411
  const positiveWidth = split.filter(([west, , east]) => east > west);
5402
5412
  const rectangles = positiveWidth.length ? positiveWidth : split;
5403
5413
  const intervals = rectangles.map(([west, south, east, north]) => {
@@ -5547,8 +5557,8 @@ function findTileAxisBoundary(origin, direction, tileSpan, matrixSize, coordinat
5547
5557
  let upper = matrixSize / columnStep;
5548
5558
  while (lower < upper) {
5549
5559
  const middle = lower + Math.floor((upper - lower) / 2);
5550
- const edge = origin + direction * (middle * columnStep * tileSpan);
5551
- const precedesCoordinate = direction === 1 ? includeEqualEdge ? edge < coordinate : edge <= coordinate : includeEqualEdge ? edge > coordinate : edge >= coordinate;
5560
+ const edge2 = origin + direction * (middle * columnStep * tileSpan);
5561
+ const precedesCoordinate = direction === 1 ? includeEqualEdge ? edge2 < coordinate : edge2 <= coordinate : includeEqualEdge ? edge2 > coordinate : edge2 >= coordinate;
5552
5562
  if (precedesCoordinate)
5553
5563
  lower = middle + 1;
5554
5564
  else
@@ -5564,11 +5574,11 @@ function validateTileMatrixCoverage(matrix, limits) {
5564
5574
  throw new RangeError("Invalid tile matrix limits");
5565
5575
  }
5566
5576
  }
5567
- function getRegularTileRange(matrix, bounds, limits) {
5568
- validateTileQueryBounds(bounds);
5569
- const columns = getTileAxisRange(matrix.origin[0], 1, matrix.resolution * matrix.tileSize[0], matrix.matrixSize[0], bounds[0], bounds[2]);
5577
+ function getRegularTileRange(matrix, bounds2, limits) {
5578
+ validateTileQueryBounds(bounds2);
5579
+ const columns = getTileAxisRange(matrix.origin[0], 1, matrix.resolution * matrix.tileSize[0], matrix.matrixSize[0], bounds2[0], bounds2[2]);
5570
5580
  const topLeft = matrix.cornerOfOrigin === "topLeft";
5571
- const rows = getTileAxisRange(matrix.origin[1], topLeft ? -1 : 1, (matrix.resolutionY ?? matrix.resolution) * matrix.tileSize[1], matrix.matrixSize[1], topLeft ? bounds[3] : bounds[1], topLeft ? bounds[1] : bounds[3]);
5581
+ const rows = getTileAxisRange(matrix.origin[1], topLeft ? -1 : 1, (matrix.resolutionY ?? matrix.resolution) * matrix.tileSize[1], matrix.matrixSize[1], topLeft ? bounds2[3] : bounds2[1], topLeft ? bounds2[1] : bounds2[3]);
5572
5582
  if (!columns || !rows)
5573
5583
  return null;
5574
5584
  const range = {
@@ -5579,12 +5589,12 @@ function getRegularTileRange(matrix, bounds, limits) {
5579
5589
  };
5580
5590
  return range.minTileColumn > range.maxTileColumn || range.minTileRow > range.maxTileRow ? null : range;
5581
5591
  }
5582
- function validateTileQueryBounds(bounds) {
5583
- if (bounds.length !== 4 || !bounds.every(Number.isFinite) || bounds[0] > bounds[2] || bounds[1] > bounds[3]) {
5592
+ function validateTileQueryBounds(bounds2) {
5593
+ if (bounds2.length !== 4 || !bounds2.every(Number.isFinite) || bounds2[0] > bounds2[2] || bounds2[1] > bounds2[3]) {
5584
5594
  throw new RangeError("Tile query bounds must be finite and ordered");
5585
5595
  }
5586
5596
  }
5587
- function getTileRange(matrix, bounds, limits) {
5597
+ function getTileRange(matrix, bounds2, limits) {
5588
5598
  var _a;
5589
5599
  validateTileMatrix(matrix);
5590
5600
  if ((_a = matrix.variableMatrixWidths) == null ? void 0 : _a.length) {
@@ -5592,17 +5602,17 @@ function getTileRange(matrix, bounds, limits) {
5592
5602
  }
5593
5603
  if (limits)
5594
5604
  validateTileMatrixCoverage(matrix, limits);
5595
- return getRegularTileRange(matrix, bounds, limits);
5605
+ return getRegularTileRange(matrix, bounds2, limits);
5596
5606
  }
5597
5607
  function getRowCoalesce(matrix, row) {
5598
5608
  var _a, _b;
5599
5609
  return ((_b = (_a = matrix.variableMatrixWidths) == null ? void 0 : _a.find((band) => row >= band.minTileRow && row <= band.maxTileRow)) == null ? void 0 : _b.coalesce) ?? 1;
5600
5610
  }
5601
- function getTileRanges(matrix, bounds, limits) {
5611
+ function getTileRanges(matrix, bounds2, limits) {
5602
5612
  const declaredBands = validateTileMatrixGeometry(matrix);
5603
5613
  if (limits)
5604
5614
  validateTileMatrixCoverage(matrix, limits);
5605
- validateTileQueryBounds(bounds);
5615
+ validateTileQueryBounds(bounds2);
5606
5616
  const bands = [];
5607
5617
  let nextRow = 0;
5608
5618
  for (const band of declaredBands) {
@@ -5616,7 +5626,7 @@ function getTileRanges(matrix, bounds, limits) {
5616
5626
  bands.push({ coalesce: 1, minTileRow: nextRow, maxTileRow: matrix.matrixSize[1] - 1 });
5617
5627
  }
5618
5628
  const topLeft = matrix.cornerOfOrigin === "topLeft";
5619
- const rows = getTileAxisRange(matrix.origin[1], topLeft ? -1 : 1, (matrix.resolutionY ?? matrix.resolution) * matrix.tileSize[1], matrix.matrixSize[1], topLeft ? bounds[3] : bounds[1], topLeft ? bounds[1] : bounds[3]);
5629
+ const rows = getTileAxisRange(matrix.origin[1], topLeft ? -1 : 1, (matrix.resolutionY ?? matrix.resolution) * matrix.tileSize[1], matrix.matrixSize[1], topLeft ? bounds2[3] : bounds2[1], topLeft ? bounds2[1] : bounds2[3]);
5620
5630
  if (!rows)
5621
5631
  return [];
5622
5632
  const ranges = [];
@@ -5625,7 +5635,7 @@ function getTileRanges(matrix, bounds, limits) {
5625
5635
  const maximumRow = Math.min(band.maxTileRow, rows[1], (limits == null ? void 0 : limits.maxTileRow) ?? matrix.matrixSize[1] - 1);
5626
5636
  if (minimumRow > maximumRow)
5627
5637
  continue;
5628
- const columns = getTileAxisRange(matrix.origin[0], 1, matrix.resolution * matrix.tileSize[0], matrix.matrixSize[0], bounds[0], bounds[2], band.coalesce);
5638
+ const columns = getTileAxisRange(matrix.origin[0], 1, matrix.resolution * matrix.tileSize[0], matrix.matrixSize[0], bounds2[0], bounds2[2], band.coalesce);
5629
5639
  if (!columns)
5630
5640
  continue;
5631
5641
  const minimumColumn = Math.max(columns[0], Math.floor(((limits == null ? void 0 : limits.minTileColumn) ?? 0) / band.coalesce) * band.coalesce);
@@ -6252,7 +6262,7 @@ function validateNodeValues(node) {
6252
6262
  const keyword = node.keyword.toUpperCase();
6253
6263
  const values = node.values;
6254
6264
  const typeAt = (index, ...types) => Boolean(values[index] && types.includes(values[index].type));
6255
- const exact2 = (length, ...types) => values.length === length && types.every((type, index) => typeAt(index, type));
6265
+ const exact3 = (length, ...types) => values.length === length && types.every((type, index) => typeAt(index, type));
6256
6266
  if ([
6257
6267
  "ANGLEUNIT",
6258
6268
  "LENGTHUNIT",
@@ -6264,10 +6274,10 @@ function validateNodeValues(node) {
6264
6274
  ].includes(keyword) && !(values.length >= 2 && typeAt(0, "string") && typeAt(1, "number"))) {
6265
6275
  return `${node.keyword} must start with a quoted name and numeric conversion factor`;
6266
6276
  }
6267
- if (keyword === "CS" && !exact2(2, "enumeration", "number")) {
6277
+ if (keyword === "CS" && !exact3(2, "enumeration", "number")) {
6268
6278
  return `${node.keyword} must contain a coordinate-system type and dimension`;
6269
6279
  }
6270
- if (keyword === "BBOX" && !exact2(4, "number", "number", "number", "number")) {
6280
+ if (keyword === "BBOX" && !exact3(4, "number", "number", "number", "number")) {
6271
6281
  return `${node.keyword} must contain four numeric bounds`;
6272
6282
  }
6273
6283
  if ([
@@ -6277,10 +6287,10 @@ function validateNodeValues(node) {
6277
6287
  "FRAMEEPOCH",
6278
6288
  "OPERATIONACCURACY",
6279
6289
  "ORDER"
6280
- ].includes(keyword) && !exact2(1, "number")) {
6290
+ ].includes(keyword) && !exact3(1, "number")) {
6281
6291
  return `${node.keyword} must contain one number`;
6282
6292
  }
6283
- if (["ANCHOR", "AREA", "CALENDAR", "CITATION", "REMARK", "SCOPE", "URI", "VERSION"].includes(keyword) && !exact2(1, "string")) {
6293
+ if (["ANCHOR", "AREA", "CALENDAR", "CITATION", "REMARK", "SCOPE", "URI", "VERSION"].includes(keyword) && !exact3(1, "string")) {
6284
6294
  return `${node.keyword} must contain one quoted string`;
6285
6295
  }
6286
6296
  if (["ELLIPSOID", "SPHEROID", "TRIAXIAL"].includes(keyword) && !(values.length >= 3 && typeAt(0, "string") && typeAt(1, "number") && typeAt(2, "number"))) {
@@ -6289,7 +6299,7 @@ function validateNodeValues(node) {
6289
6299
  if (["PARAMETER"].includes(keyword) && !(values.length >= 2 && typeAt(0, "string") && typeAt(1, "number"))) {
6290
6300
  return `${node.keyword} must start with a quoted name and numeric value`;
6291
6301
  }
6292
- if (keyword === "PARAMETERFILE" && !exact2(2, "string", "string")) {
6302
+ if (keyword === "PARAMETERFILE" && !exact3(2, "string", "string")) {
6293
6303
  return `${node.keyword} must contain a quoted name and file name`;
6294
6304
  }
6295
6305
  if (["AUTHORITY", "ID"].includes(keyword) && !(values.length >= 2 && typeAt(0, "string") && typeAt(1, "string", "number"))) {
@@ -6733,13 +6743,13 @@ function snapshot(value3) {
6733
6743
  function createCRSProjectionDomain(domain) {
6734
6744
  if (!domain || !Array.isArray(domain.polygons))
6735
6745
  throw new RangeError("Invalid projection domain");
6736
- const polygons2 = Object.freeze(Array.from(domain.polygons, (polygon) => {
6737
- if (!polygon || polygon.holes !== void 0 && !Array.isArray(polygon.holes)) {
6746
+ const polygons2 = Object.freeze(Array.from(domain.polygons, (polygon2) => {
6747
+ if (!polygon2 || polygon2.holes !== void 0 && !Array.isArray(polygon2.holes)) {
6738
6748
  throw new RangeError("Invalid domain polygon");
6739
6749
  }
6740
6750
  return Object.freeze({
6741
- outer: copyRing(polygon.outer),
6742
- ...polygon.holes === void 0 ? {} : { holes: Object.freeze(Array.from(polygon.holes, copyRing)) }
6751
+ outer: copyRing(polygon2.outer),
6752
+ ...polygon2.holes === void 0 ? {} : { holes: Object.freeze(Array.from(polygon2.holes, copyRing)) }
6743
6753
  });
6744
6754
  }));
6745
6755
  const period = domain.periodic;
@@ -6866,11 +6876,11 @@ function createCRSDescriptor(options) {
6866
6876
  };
6867
6877
  const signature = options.signature ?? getCRSSignature(metadata);
6868
6878
  requireValue(typeof signature === "string" && Boolean(signature.trim()), "signature");
6869
- const bounds = options.renderingBounds;
6870
- requireValue(Array.isArray(bounds) && bounds.length === 2 && [...bounds].every((row) => Array.isArray(row) && row.length === 3 && [...row].every(Number.isFinite)) && bounds[0].every((minimum, i) => minimum <= bounds[1][i]), "renderingBounds");
6879
+ const bounds2 = options.renderingBounds;
6880
+ requireValue(Array.isArray(bounds2) && bounds2.length === 2 && [...bounds2].every((row) => Array.isArray(row) && row.length === 3 && [...row].every(Number.isFinite)) && bounds2[0].every((minimum, i) => minimum <= bounds2[1][i]), "renderingBounds");
6871
6881
  const renderingBounds = Object.freeze([
6872
- Object.freeze([...bounds[0]]),
6873
- Object.freeze([...bounds[1]])
6882
+ Object.freeze([...bounds2[0]]),
6883
+ Object.freeze([...bounds2[1]])
6874
6884
  ]);
6875
6885
  const suppliedScale = options.renderingScale;
6876
6886
  const renderingScale = typeof suppliedScale === "function" ? (coordinate) => {
@@ -7085,14 +7095,14 @@ function chartNormal(f, x, y) {
7085
7095
  }
7086
7096
 
7087
7097
  // dist/geographic-atlas/curves.js
7088
- function sourceCurve(edge, context, a, b, original) {
7098
+ function sourceCurve(edge2, context, a, b, original) {
7089
7099
  const model = context.options.edgeModel, r = b / a, qmax = Math.max(1, 1 / (r * r)), wmin = Math.min(1, 1 / r), K = qmax / wmin;
7090
7100
  let initialAzimuth = 0;
7091
- let length = 0, azimuth = (t) => ({ azi: 0, longitude: edge.a[0] });
7101
+ let length = 0, azimuth = (t) => ({ azi: 0, longitude: edge2.a[0] });
7092
7102
  if (model === "geodesic") {
7093
7103
  const g = context.options.geodesic;
7094
7104
  context.tick(2);
7095
- const first = (original == null ? void 0 : original[0]) ?? edge.a, last = (original == null ? void 0 : original[1]) ?? edge.b;
7105
+ const first = (original == null ? void 0 : original[0]) ?? edge2.a, last = (original == null ? void 0 : original[1]) ?? edge2.b;
7096
7106
  const inv = g.inverse(first[1], first[0], last[1], last[0]);
7097
7107
  initialAzimuth = inv.azi1;
7098
7108
  length = inv.s12 / a;
@@ -7105,22 +7115,22 @@ function sourceCurve(edge, context, a, b, original) {
7105
7115
  } else if (model === "rhumb") {
7106
7116
  const rh = context.options.rhumb;
7107
7117
  context.tick(2);
7108
- const first = rh.inverse(edge.a[1], edge.a[0], edge.b[1], edge.b[0], { unrollLongitude: true });
7109
- const turns = Math.round((edge.b[0] - first.lon2) / 360);
7110
- const inv = turns ? rh.inverse(edge.a[1], edge.a[0], edge.b[1], edge.b[0], { longitudeTurns: turns }) : first;
7118
+ const first = rh.inverse(edge2.a[1], edge2.a[0], edge2.b[1], edge2.b[0], { unrollLongitude: true });
7119
+ const turns = Math.round((edge2.b[0] - first.lon2) / 360);
7120
+ const inv = turns ? rh.inverse(edge2.a[1], edge2.a[0], edge2.b[1], edge2.b[0], { longitudeTurns: turns }) : first;
7111
7121
  length = inv.s12 / a;
7112
- azimuth = () => ({ azi: inv.azi12, longitude: edge.a[0] });
7122
+ azimuth = () => ({ azi: inv.azi12, longitude: edge2.a[0] });
7113
7123
  }
7114
- const dp = (edge.b[1] - edge.a[1]) * Math.PI / 180, dl = (edge.b[0] - edge.a[0]) * Math.PI / 180;
7124
+ const dp = (edge2.b[1] - edge2.a[1]) * Math.PI / 180, dl = (edge2.b[0] - edge2.a[0]) * Math.PI / 180;
7115
7125
  const speed = model === "linear" ? Math.abs(dp) + Math.abs(dl) : length * K;
7116
- const minCos = Math.min(...[edge.a[1], edge.b[1]].map((x) => Math.abs(sincos3(x)[1])));
7126
+ const minCos = Math.min(...[edge2.a[1], edge2.b[1]].map((x) => Math.abs(sincos3(x)[1])));
7117
7127
  const second = model === "linear" ? speed * speed : model === "geodesic" ? 4 * speed * speed : 100 * K * K * speed * speed / (minCos * minCos);
7118
7128
  const curve = {
7119
- sample: edge.sample,
7129
+ sample: edge2.sample,
7120
7130
  speed,
7121
7131
  second,
7122
7132
  derivative: (t) => {
7123
- const p = edge.sample(t), heading = model === "linear" ? void 0 : azimuth(t), longitude = model === "geodesic" && Math.abs(p[1]) === 90 ? heading.longitude : p[0], [sp, cp] = sincos3(p[1]), [sl, cl] = sincos3(longitude);
7133
+ const p = edge2.sample(t), heading = model === "linear" ? void 0 : azimuth(t), longitude = model === "geodesic" && Math.abs(p[1]) === 90 ? heading.longitude : p[0], [sp, cp] = sincos3(p[1]), [sl, cl] = sincos3(longitude);
7124
7134
  const north = [-sp * cl, -sp * sl, cp], east = [-sl, cl, 0];
7125
7135
  if (model === "linear")
7126
7136
  return add(scale(north, dp), scale(east, cp * dl));
@@ -7130,35 +7140,35 @@ function sourceCurve(edge, context, a, b, original) {
7130
7140
  };
7131
7141
  const axis = (coordinate, theta) => {
7132
7142
  const target = theta * 180 / Math.PI;
7133
- if (Math.abs(target - edge.a[coordinate]) < 1e-13)
7143
+ if (Math.abs(target - edge2.a[coordinate]) < 1e-13)
7134
7144
  return 0;
7135
- if (Math.abs(target - edge.b[coordinate]) < 1e-13)
7145
+ if (Math.abs(target - edge2.b[coordinate]) < 1e-13)
7136
7146
  return 1;
7137
- return root(edge, coordinate, target, context);
7147
+ return root(edge2, coordinate, target, context);
7138
7148
  };
7139
- if (edge.a[1] === edge.b[1] && (model !== "geodesic" || edge.a[1] === 0 && Math.abs(initialAzimuth) === 90)) {
7149
+ if (edge2.a[1] === edge2.b[1] && (model !== "geodesic" || edge2.a[1] === 0 && Math.abs(initialAzimuth) === 90)) {
7140
7150
  curve.circular = {
7141
7151
  normal: [0, 0, 1],
7142
- offset: sincos3(edge.a[1])[0],
7152
+ offset: sincos3(edge2.a[1])[0],
7143
7153
  u: [1, 0, 0],
7144
7154
  v: [0, 1, 0],
7145
- start: edge.a[0] * Math.PI / 180,
7146
- end: edge.b[0] * Math.PI / 180,
7155
+ start: edge2.a[0] * Math.PI / 180,
7156
+ end: edge2.b[0] * Math.PI / 180,
7147
7157
  fraction: (t) => axis(0, t)
7148
7158
  };
7149
- } else if (edge.a[0] === edge.b[0]) {
7150
- const [s, c] = sincos3(edge.a[0]);
7159
+ } else if (edge2.a[0] === edge2.b[0]) {
7160
+ const [s, c] = sincos3(edge2.a[0]);
7151
7161
  curve.circular = {
7152
7162
  normal: [s, -c, 0],
7153
7163
  offset: 0,
7154
7164
  u: [c, s, 0],
7155
7165
  v: [0, 0, 1],
7156
- start: edge.a[1] * Math.PI / 180,
7157
- end: edge.b[1] * Math.PI / 180,
7166
+ start: edge2.a[1] * Math.PI / 180,
7167
+ end: edge2.b[1] * Math.PI / 180,
7158
7168
  fraction: (t) => axis(1, t)
7159
7169
  };
7160
7170
  } else if (model === "geodesic" && a === b && length > 0) {
7161
- const u = normal(edge.a), v = unit(curve.derivative(0));
7171
+ const u = normal(edge2.a), v = unit(curve.derivative(0));
7162
7172
  curve.circular = {
7163
7173
  normal: unit(cross3(u, v)),
7164
7174
  offset: 0,
@@ -7238,8 +7248,8 @@ function roots(c, b, context) {
7238
7248
  if (R === 0)
7239
7249
  return { fractions: [], coincident: false };
7240
7250
  const phase = Math.atan2(B2, A3), low = Math.min(z.start, z.end), high = Math.max(z.start, z.end);
7241
- const evaluate = (theta) => A3 * Math.cos(theta) + B2 * Math.sin(theta) - C2;
7242
- let minimum = Math.min(evaluate(low), evaluate(high)), maximum = Math.max(evaluate(low), evaluate(high));
7251
+ const evaluate2 = (theta) => A3 * Math.cos(theta) + B2 * Math.sin(theta) - C2;
7252
+ let minimum = Math.min(evaluate2(low), evaluate2(high)), maximum = Math.max(evaluate2(low), evaluate2(high));
7243
7253
  for (let k = Math.ceil((low - phase) / Math.PI); phase + k * Math.PI <= high; k++) {
7244
7254
  context.tick();
7245
7255
  const value3 = (k % 2 === 0 ? R : -R) - C2;
@@ -7335,12 +7345,12 @@ function reverseArc(e) {
7335
7345
  }
7336
7346
  function crossings(edges, y, frame2, context) {
7337
7347
  const direction = frame2.v.map((x, i) => x - y * frame2.center[i]), m = Math.hypot(...direction), query = circle("ray", unit(direction), y / m), result = [];
7338
- for (const edge of edges) {
7339
- const hits = roots(edge.curve, query, context);
7348
+ for (const edge2 of edges) {
7349
+ const hits = roots(edge2.curve, query, context);
7340
7350
  if (hits.coincident)
7341
7351
  throw new GeographicSeamError("precision", "Interior ray coincides with a boundary");
7342
7352
  for (const t of hits.fractions) {
7343
- const n = edge.curve.sample(t), v = dot2(direction, edge.curve.derivative(t));
7353
+ const n = edge2.curve.sample(t), v = dot2(direction, edge2.curve.derivative(t));
7344
7354
  if (v === 0 || t === 0 && v < 0 || t === 1 && v > 0)
7345
7355
  continue;
7346
7356
  result.push({ x: chartPoint2(frame2, normal(n))[0], sign: Math.sign(v) });
@@ -7366,10 +7376,10 @@ function orientation(edges, frame2, context) {
7366
7376
  return Math.sign(w);
7367
7377
  }
7368
7378
  }
7369
- for (const edge of edges)
7379
+ for (const edge2 of edges)
7370
7380
  for (const t of [0.371, 0.613, 0.5]) {
7371
7381
  context.tick();
7372
- const n = normal(edge.curve.sample(t)), left = cross3(n, edge.curve.derivative(t));
7382
+ const n = normal(edge2.curve.sample(t)), left = cross3(n, edge2.curve.derivative(t));
7373
7383
  if (Math.hypot(...left) === 0)
7374
7384
  continue;
7375
7385
  const direction = unit(left);
@@ -7518,9 +7528,9 @@ function subdivideAtlasRing(sources, boundaries, ring, options, context, axes, c
7518
7528
  });
7519
7529
  const edges = [];
7520
7530
  for (let i = 1; i < result.segmentIndices.length; i++) {
7521
- const index = result.segmentIndices[i], edge = descriptors[index], lo = result.segmentIndices[i - 1] === index ? result.segmentFractions[i - 1] : 0, hi = result.segmentFractions[i];
7522
- if (edge.kind === "source") {
7523
- const s = edge.source, d = s.endFraction - s.startFraction;
7531
+ const index = result.segmentIndices[i], edge2 = descriptors[index], lo = result.segmentIndices[i - 1] === index ? result.segmentFractions[i - 1] : 0, hi = result.segmentFractions[i];
7532
+ if (edge2.kind === "source") {
7533
+ const s = edge2.source, d = s.endFraction - s.startFraction;
7524
7534
  edges.push({
7525
7535
  kind: "source",
7526
7536
  source: {
@@ -7530,11 +7540,11 @@ function subdivideAtlasRing(sources, boundaries, ring, options, context, axes, c
7530
7540
  }
7531
7541
  });
7532
7542
  } else {
7533
- const d = edge.endAngle - edge.startAngle;
7543
+ const d = edge2.endAngle - edge2.startAngle;
7534
7544
  edges.push({
7535
- ...edge,
7536
- startAngle: edge.startAngle + d * lo,
7537
- endAngle: edge.startAngle + d * hi
7545
+ ...edge2,
7546
+ startAngle: edge2.startAngle + d * lo,
7547
+ endAngle: edge2.startAngle + d * hi
7538
7548
  });
7539
7549
  }
7540
7550
  }
@@ -7676,11 +7686,11 @@ var GeographicCutAtlas = class {
7676
7686
  const orientation3 = interior(rings[i].membership, context).sign, reversed = orientation3 !== (i ? -1 : 1), points = originals[i];
7677
7687
  if (points.length > 1 && points[0][0] === points[points.length - 1][0] && points[0][1] === points[points.length - 1][1])
7678
7688
  points.pop();
7679
- for (const edge of mergeEdges(rings[i].edges)) {
7680
- const index = edge.source.edgeIndex;
7689
+ for (const edge2 of mergeEdges(rings[i].edges)) {
7690
+ const index = edge2.source.edgeIndex;
7681
7691
  sources.push({
7682
- edge,
7683
- curve: sourceCurve(edge, context, this.config.axes.semiMajorAxis, this.config.axes.semiMinorAxis, [points[index], points[(index + 1) % points.length]]),
7692
+ edge: edge2,
7693
+ curve: sourceCurve(edge2, context, this.config.axes.semiMajorAxis, this.config.axes.semiMinorAxis, [points[index], points[(index + 1) % points.length]]),
7684
7694
  reversed
7685
7695
  });
7686
7696
  }
@@ -7716,10 +7726,10 @@ var GeographicCutAtlas = class {
7716
7726
  let cursor = points[0];
7717
7727
  for (let i = 1; i < points.length; i++) {
7718
7728
  const pieces = createEdges(cursor, points[i], points[i - 1], i - 1, 0, turns[i - 1], context);
7719
- for (const edge of mergeEdges(pieces))
7729
+ for (const edge2 of mergeEdges(pieces))
7720
7730
  sources.push({
7721
- edge,
7722
- curve: sourceCurve(edge, context, this.config.axes.semiMajorAxis, this.config.axes.semiMinorAxis, [points[i - 1], points[i]]),
7731
+ edge: edge2,
7732
+ curve: sourceCurve(edge2, context, this.config.axes.semiMajorAxis, this.config.axes.semiMinorAxis, [points[i - 1], points[i]]),
7723
7733
  reversed: false
7724
7734
  });
7725
7735
  cursor = pieces[pieces.length - 1].b;
@@ -7776,10 +7786,10 @@ var GeographicCutAtlas = class {
7776
7786
  }
7777
7787
  }
7778
7788
  const sourceArcs = [];
7779
- for (const { edge, curve, reversed } of sources) {
7789
+ for (const { edge: edge2, curve, reversed } of sources) {
7780
7790
  const endpoints = [
7781
- node(normal(edge.a), edge.a.slice(2), true),
7782
- node(normal(edge.b), edge.b.slice(2), true)
7791
+ node(normal(edge2.a), edge2.a.slice(2), true),
7792
+ node(normal(edge2.b), edge2.b.slice(2), true)
7783
7793
  ], at = /* @__PURE__ */ new Map([
7784
7794
  [0, endpoints[0]],
7785
7795
  [1, endpoints[1]]
@@ -7829,10 +7839,10 @@ var GeographicCutAtlas = class {
7829
7839
  const descriptor = {
7830
7840
  kind: "source",
7831
7841
  source: {
7832
- ringIndex: edge.source.ringIndex,
7833
- edgeIndex: edge.source.edgeIndex,
7834
- startFraction: edge.source.startFraction + (edge.source.endFraction - edge.source.startFraction) * lo,
7835
- endFraction: edge.source.startFraction + (edge.source.endFraction - edge.source.startFraction) * hi
7842
+ ringIndex: edge2.source.ringIndex,
7843
+ edgeIndex: edge2.source.edgeIndex,
7844
+ startFraction: edge2.source.startFraction + (edge2.source.endFraction - edge2.source.startFraction) * lo,
7845
+ endFraction: edge2.source.startFraction + (edge2.source.endFraction - edge2.source.startFraction) * hi
7836
7846
  }
7837
7847
  };
7838
7848
  let arc = { a, b, curve: sliceCurve(curve, lo, hi), descriptor, coincident };
@@ -7958,10 +7968,10 @@ var GeographicCutAtlas = class {
7958
7968
  let cursor = points[0];
7959
7969
  for (let i = 1; i < points.length; i++) {
7960
7970
  const pieces = createEdges(cursor, points[i], points[i - 1], i - 1, 0, turns[i - 1], context);
7961
- for (const edge of mergeEdges(pieces))
7971
+ for (const edge2 of mergeEdges(pieces))
7962
7972
  sources.push({
7963
- edge,
7964
- curve: sourceCurve(edge, context, this.config.axes.semiMajorAxis, this.config.axes.semiMinorAxis, [points[i - 1], points[i]])
7973
+ edge: edge2,
7974
+ curve: sourceCurve(edge2, context, this.config.axes.semiMajorAxis, this.config.axes.semiMinorAxis, [points[i - 1], points[i]])
7965
7975
  });
7966
7976
  cursor = pieces[pieces.length - 1].b;
7967
7977
  }
@@ -8303,7 +8313,7 @@ var EllipsoidGeodesicExact = class {
8303
8313
  const includeArea = Boolean(options.area);
8304
8314
  const unroll = Boolean(options.unrollLongitude), azi1 = angleMath.AngNormalize(azimuth);
8305
8315
  const distanceLimit = b * I.E(sig1, 4 * Math.PI);
8306
- const evaluate = (delta, distance, arcDegrees) => {
8316
+ const evaluate2 = (delta, distance, arcDegrees) => {
8307
8317
  const phase = arcDegrees === void 0 ? { s: Math.sin(delta), c: Math.cos(delta) } : angleMath.sincosd(arcDegrees);
8308
8318
  const s2 = s1 * phase.c + c1 * phase.s, c2 = c1 * phase.c - s1 * phase.s;
8309
8319
  const dn2 = Math.sqrt(1 + k2 * s2 * s2), J = I.J(sig1, delta);
@@ -8344,7 +8354,7 @@ var EllipsoidGeodesicExact = class {
8344
8354
  finite(arc);
8345
8355
  if (Math.abs(arc) > 720)
8346
8356
  throw new RangeError("Exact line arc exceeds 720 degrees");
8347
- return evaluate(arc * DEG4, void 0, arc);
8357
+ return evaluate2(arc * DEG4, void 0, arc);
8348
8358
  },
8349
8359
  position: (distance) => {
8350
8360
  finite(distance);
@@ -8356,7 +8366,7 @@ var EllipsoidGeodesicExact = class {
8356
8366
  for (let i = 0; i < 80; i++) {
8357
8367
  const residual = I.E(sig1, delta) - target;
8358
8368
  if (Math.abs(residual) <= Number.EPSILON * Math.max(Math.abs(target), 1e-300))
8359
- return evaluate(delta, distance);
8369
+ return evaluate2(delta, distance);
8360
8370
  if (residual > 0)
8361
8371
  upper = delta;
8362
8372
  else
@@ -8364,7 +8374,7 @@ var EllipsoidGeodesicExact = class {
8364
8374
  const next = delta - residual / Math.sqrt(1 + k2 * Math.sin(sig1 + delta) ** 2);
8365
8375
  const value3 = next > lower && next < upper ? next : (lower + upper) / 2;
8366
8376
  if (value3 === delta)
8367
- return evaluate(delta, distance);
8377
+ return evaluate2(delta, distance);
8368
8378
  delta = value3;
8369
8379
  }
8370
8380
  throw new RangeError("Exact distance inversion did not converge");
@@ -8541,12 +8551,12 @@ var TriaxialEllipsoid = class {
8541
8551
  basis(position2) {
8542
8552
  const p = this.surface(position2), normal2 = unit2(p.map((x, i) => x / this.axes[i] ** 2));
8543
8553
  const horizontal = Math.hypot(p[0], p[1]), meridian = horizontal ? [-p[1] / horizontal, p[0] / horizontal, 0] : [0, 1, 0];
8544
- const cross4 = (a, b) => [
8554
+ const cross5 = (a, b) => [
8545
8555
  a[1] * b[2] - a[2] * b[1],
8546
8556
  a[2] * b[0] - a[0] * b[2],
8547
8557
  a[0] * b[1] - a[1] * b[0]
8548
8558
  ];
8549
- const north = unit2(cross4(normal2, meridian)), east = unit2(cross4(north, normal2));
8559
+ const north = unit2(cross5(normal2, meridian)), east = unit2(cross5(north, normal2));
8550
8560
  return { north, east, normal: normal2 };
8551
8561
  }
8552
8562
  /** Cartesian initial-value geodesic. No global triaxial inverse is implied. */
@@ -8747,19 +8757,19 @@ function createGeographicBounds(west, south, east, north) {
8747
8757
  north
8748
8758
  ];
8749
8759
  }
8750
- function getLongitudeSpan(bounds) {
8751
- const span = bounds[2] - bounds[0];
8760
+ function getLongitudeSpan(bounds2) {
8761
+ const span = bounds2[2] - bounds2[0];
8752
8762
  return span < 0 ? span + 360 : span;
8753
8763
  }
8754
- function splitGeographicBounds(bounds) {
8755
- const [west, south, east, north] = bounds;
8756
- return west <= east ? [bounds] : [
8764
+ function splitGeographicBounds(bounds2) {
8765
+ const [west, south, east, north] = bounds2;
8766
+ return west <= east ? [bounds2] : [
8757
8767
  [west, south, 180, north],
8758
8768
  [-180, south, east, north]
8759
8769
  ];
8760
8770
  }
8761
- function containsGeographicPoint(bounds, point2) {
8762
- const [west, south, east, north] = bounds;
8771
+ function containsGeographicPoint(bounds2, point2) {
8772
+ const [west, south, east, north] = bounds2;
8763
8773
  const longitude = normalizeLongitude2(point2[0]);
8764
8774
  return point2[1] >= south && point2[1] <= north && (west <= east ? longitude >= west && longitude <= east || longitude === -180 && east === 180 : longitude >= west || longitude <= east);
8765
8775
  }
@@ -8794,42 +8804,42 @@ function intersectGeographicBounds(a, b) {
8794
8804
  }
8795
8805
  return merged.map(([west, east]) => [west, south, east, north]);
8796
8806
  }
8797
- function clampGeographicPoint(bounds, point2) {
8807
+ function clampGeographicPoint(bounds2, point2) {
8798
8808
  let longitude = normalizeLongitude2(point2[0]);
8799
- const latitude = Math.max(bounds[1], Math.min(bounds[3], point2[1]));
8800
- if (!containsGeographicPoint(bounds, [longitude, latitude])) {
8801
- const westDistance = Math.abs(normalizeLongitude2(longitude - bounds[0]));
8802
- const eastDistance = Math.abs(normalizeLongitude2(longitude - bounds[2]));
8803
- longitude = westDistance <= eastDistance ? bounds[0] : bounds[2];
8809
+ const latitude = Math.max(bounds2[1], Math.min(bounds2[3], point2[1]));
8810
+ if (!containsGeographicPoint(bounds2, [longitude, latitude])) {
8811
+ const westDistance = Math.abs(normalizeLongitude2(longitude - bounds2[0]));
8812
+ const eastDistance = Math.abs(normalizeLongitude2(longitude - bounds2[2]));
8813
+ longitude = westDistance <= eastDistance ? bounds2[0] : bounds2[2];
8804
8814
  }
8805
8815
  return [longitude, latitude];
8806
8816
  }
8807
- function getAngularRanges(bounds, primeMeridian = 0, origin = 0) {
8808
- const width = getLongitudeSpan(bounds);
8809
- const west = bounds[0] * RADIANS - primeMeridian;
8817
+ function getAngularRanges(bounds2, primeMeridian = 0, origin = 0) {
8818
+ const width = getLongitudeSpan(bounds2);
8819
+ const west = bounds2[0] * RADIANS - primeMeridian;
8810
8820
  const middle = west + width * RADIANS / 2;
8811
8821
  const shift2 = Math.round((origin - middle) / (2 * Math.PI)) * 2 * Math.PI;
8812
- return createAngularRanges(width === 360 ? origin - Math.PI : west + shift2, bounds[1] * RADIANS, width === 360 ? origin + Math.PI : west + shift2 + width * RADIANS, bounds[3] * RADIANS);
8822
+ return createAngularRanges(width === 360 ? origin - Math.PI : west + shift2, bounds2[1] * RADIANS, width === 360 ? origin + Math.PI : west + shift2 + width * RADIANS, bounds2[3] * RADIANS);
8813
8823
  }
8814
8824
  function getGeographicBounds(ranges, primeMeridian = 0) {
8815
8825
  return createGeographicBounds((ranges[0][0] + primeMeridian) / RADIANS, ranges[0][1] / RADIANS, (ranges[1][0] + primeMeridian) / RADIANS, ranges[1][1] / RADIANS);
8816
8826
  }
8817
- function unionRenderingBounds(bounds) {
8818
- if (!bounds.length)
8827
+ function unionRenderingBounds(bounds2) {
8828
+ if (!bounds2.length)
8819
8829
  throw new Error("CRS coverage does not intersect the rendering target");
8820
8830
  return [
8821
- [0, 1, 2].map((axis) => Math.min(...bounds.map((pair2) => pair2[0][axis]))),
8822
- [0, 1, 2].map((axis) => Math.max(...bounds.map((pair2) => pair2[1][axis])))
8831
+ [0, 1, 2].map((axis) => Math.min(...bounds2.map((pair2) => pair2[0][axis]))),
8832
+ [0, 1, 2].map((axis) => Math.max(...bounds2.map((pair2) => pair2[1][axis])))
8823
8833
  ];
8824
8834
  }
8825
8835
 
8826
8836
  // dist/projection/experimental/rendering-profile/rendering-profile.js
8827
8837
  function resolveBounds(profile) {
8828
8838
  var _a;
8829
- const bounds = profile.bounds;
8830
- if (bounds.some((corner) => corner.some((value3) => !Number.isFinite(value3))))
8839
+ const bounds2 = profile.bounds;
8840
+ if (bounds2.some((corner) => corner.some((value3) => !Number.isFinite(value3))))
8831
8841
  throw new Error("Projection rendering bounds must be finite");
8832
- return { bounds, normalize: (_a = profile.normalize) == null ? void 0 : _a.bind(profile) };
8842
+ return { bounds: bounds2, normalize: (_a = profile.normalize) == null ? void 0 : _a.bind(profile) };
8833
8843
  }
8834
8844
  function createAngularNormalization(normalize2, primeMeridian = 0) {
8835
8845
  return (point2) => {
@@ -8929,8 +8939,8 @@ function withRectangleRenderingProfile(implementation, parameters, resolveBounds
8929
8939
  };
8930
8940
  try {
8931
8941
  const profile = createRectangleRenderingProfile(resolveBounds2, coverage, origin, primeMeridian, over);
8932
- const bounds = profile.bounds;
8933
- return { bounds, normalize: profile.normalize };
8942
+ const bounds2 = profile.bounds;
8943
+ return { bounds: bounds2, normalize: profile.normalize };
8934
8944
  } catch {
8935
8945
  return createRegionsRenderingProfile(resolveBounds2, intersectGeographicBounds(coverage, defaults), origin, primeMeridian, over);
8936
8946
  }
@@ -10204,16 +10214,16 @@ function shared(value3) {
10204
10214
  return ArrayBuffer.isView(value3) && typeof SharedArrayBuffer !== "undefined" && value3.buffer instanceof SharedArrayBuffer;
10205
10215
  }
10206
10216
  var LineBuffer = class {
10207
- constructor(evaluate, capacity, fields) {
10208
- this.evaluate = evaluate;
10217
+ constructor(evaluate2, capacity2, fields) {
10218
+ this.evaluate = evaluate2;
10209
10219
  this.scratch = {};
10210
10220
  this.control = { busy: false };
10211
- if (!Number.isSafeInteger(capacity) || capacity < 0 || capacity > 1e6)
10221
+ if (!Number.isSafeInteger(capacity2) || capacity2 < 0 || capacity2 > 1e6)
10212
10222
  throw new RangeError("Buffer capacity must be in [0,1000000]");
10213
- this.capacity = capacity;
10223
+ this.capacity = capacity2;
10214
10224
  this.fields = Object.freeze([...fields]);
10215
10225
  this.stride = fields.length;
10216
- this.stage = new Float64Array(capacity * this.stride);
10226
+ this.stage = new Float64Array(capacity2 * this.stride);
10217
10227
  Object.freeze(this);
10218
10228
  }
10219
10229
  /** Atomically write interleaved rows; input/output aliasing is supported. */
@@ -10249,19 +10259,19 @@ var LineBuffer = class {
10249
10259
  }
10250
10260
  };
10251
10261
  var GeodesicLineBuffer = class extends LineBuffer {
10252
- constructor(line, capacity, options = {}) {
10262
+ constructor(line, capacity2, options = {}) {
10253
10263
  if (!line || typeof line.position !== "function")
10254
10264
  throw new RangeError("Expected a geodesic line");
10255
10265
  const position2 = line.position.bind(line);
10256
- super((distance, result) => position2(distance, void 0, void 0, result), capacity, options.area ? [...GEODESIC_BUFFER_FIELDS, "S12"] : GEODESIC_BUFFER_FIELDS);
10266
+ super((distance, result) => position2(distance, void 0, void 0, result), capacity2, options.area ? [...GEODESIC_BUFFER_FIELDS, "S12"] : GEODESIC_BUFFER_FIELDS);
10257
10267
  }
10258
10268
  };
10259
10269
  var RhumbLineBuffer = class extends LineBuffer {
10260
- constructor(line, capacity, options = {}) {
10270
+ constructor(line, capacity2, options = {}) {
10261
10271
  if (!line || typeof line.position !== "function")
10262
10272
  throw new RangeError("Expected a rhumb line");
10263
10273
  const position2 = line.position.bind(line);
10264
- super((distance, result) => position2(distance, void 0, void 0, result), capacity, options.area ? [...RHUMB_BUFFER_FIELDS, "S12"] : RHUMB_BUFFER_FIELDS);
10274
+ super((distance, result) => position2(distance, void 0, void 0, result), capacity2, options.area ? [...RHUMB_BUFFER_FIELDS, "S12"] : RHUMB_BUFFER_FIELDS);
10265
10275
  }
10266
10276
  };
10267
10277
 
@@ -10312,10 +10322,10 @@ function subdivideGeographicCutRing(inputs, ring, options) {
10312
10322
  else if (settings.edgeModel === "rhumb")
10313
10323
  path = new RhumbPath(first, last, { rhumb: getRhumb(), longitudeTurns: edgeTurns });
10314
10324
  else {
10315
- const edge = createEdges(first, last, first, s.edgeIndex, s.ringIndex, edgeTurns, context)[0];
10325
+ const edge2 = createEdges(first, last, first, s.edgeIndex, s.ringIndex, edgeTurns, context)[0];
10316
10326
  path = {
10317
- length: Math.hypot(...edge.b.map((v, i) => v - edge.a[i])),
10318
- sample: edge.sample
10327
+ length: Math.hypot(...edge2.b.map((v, i) => v - edge2.a[i])),
10328
+ sample: edge2.sample
10319
10329
  };
10320
10330
  }
10321
10331
  sources.set(key3, path);
@@ -10367,15 +10377,15 @@ function subdivideGeographicCutRing(inputs, ring, options) {
10367
10377
  });
10368
10378
  const edges = [];
10369
10379
  for (let i = 1; i < result.segmentIndices.length; i++) {
10370
- const index = result.segmentIndices[i], edge = descriptors[index], lo = result.segmentIndices[i - 1] === index ? result.segmentFractions[i - 1] : 0, hi = result.segmentFractions[i];
10371
- edges.push(edge.kind === "source" ? {
10380
+ const index = result.segmentIndices[i], edge2 = descriptors[index], lo = result.segmentIndices[i - 1] === index ? result.segmentFractions[i - 1] : 0, hi = result.segmentFractions[i];
10381
+ edges.push(edge2.kind === "source" ? {
10372
10382
  kind: "source",
10373
10383
  source: {
10374
- ...edge.source,
10375
- startFraction: edge.source.startFraction + (edge.source.endFraction - edge.source.startFraction) * lo,
10376
- endFraction: edge.source.startFraction + (edge.source.endFraction - edge.source.startFraction) * hi
10384
+ ...edge2.source,
10385
+ startFraction: edge2.source.startFraction + (edge2.source.endFraction - edge2.source.startFraction) * lo,
10386
+ endFraction: edge2.source.startFraction + (edge2.source.endFraction - edge2.source.startFraction) * hi
10377
10387
  }
10378
- } : { ...edge });
10388
+ } : { ...edge2 });
10379
10389
  }
10380
10390
  return { ...result, edges };
10381
10391
  }
@@ -10403,13 +10413,13 @@ function clipGeographicPolyline(input, options) {
10403
10413
  if (!original.source)
10404
10414
  continue;
10405
10415
  for (const retained of clipLatitudeEdge(original, range, context))
10406
- for (const { edge, world } of cut(retained, context)) {
10416
+ for (const { edge: edge2, world } of cut(retained, context)) {
10407
10417
  const previous = parts[parts.length - 1];
10408
- if (previous && previous.world === world && same(previous.points[previous.points.length - 1], edge.a)) {
10409
- previous.points.push(edge.b);
10410
- previous.edges.push(edge.source);
10418
+ if (previous && previous.world === world && same(previous.points[previous.points.length - 1], edge2.a)) {
10419
+ previous.points.push(edge2.b);
10420
+ previous.edges.push(edge2.source);
10411
10421
  } else
10412
- parts.push({ points: [edge.a, edge.b], edges: [edge.source], world });
10422
+ parts.push({ points: [edge2.a, edge2.b], edges: [edge2.source], world });
10413
10423
  }
10414
10424
  }
10415
10425
  cursor = originals[originals.length - 1].b;
@@ -10787,14 +10797,14 @@ function createTerrainSkirt(mesh, options) {
10787
10797
  selected = [];
10788
10798
  const used = /* @__PURE__ */ new Set();
10789
10799
  for (let i = 0; i < edges.length; i += 2) {
10790
- const key3 = edgeKey(edges[i], edges[i + 1]), edge = boundary.get(key3);
10791
- if (!edge || edge.count !== 1 || used.has(key3))
10800
+ const key3 = edgeKey(edges[i], edges[i + 1]), edge2 = boundary.get(key3);
10801
+ if (!edge2 || edge2.count !== 1 || used.has(key3))
10792
10802
  throw new Error("Terrain skirt selection must contain unique boundary edges");
10793
10803
  used.add(key3);
10794
- selected.push(edge);
10804
+ selected.push(edge2);
10795
10805
  }
10796
10806
  } else
10797
- selected = [...boundary.values()].filter((edge) => edge.count === 1);
10807
+ selected = [...boundary.values()].filter((edge2) => edge2.count === 1);
10798
10808
  const outputVertices = vertexCount + selected.length * 2, outputTriangles = triangleCount + selected.length * 2;
10799
10809
  if (!Number.isSafeInteger(outputVertices) || outputVertices > maxVertices || outputVertices > 4294967295 || !Number.isSafeInteger(outputTriangles) || outputTriangles > maxTriangles)
10800
10810
  throw new Error("Terrain skirt output capacity exceeded");
@@ -10945,11 +10955,11 @@ var ECCENTRICITY_SQUARED = 0.0066943799901413165;
10945
10955
  var MAX_MERCATOR_LATITUDE = Math.atan(Math.sinh(Math.PI)) / RADIANS2;
10946
10956
  var GeographicHeightField = class {
10947
10957
  constructor(props) {
10948
- const { bounds } = props;
10958
+ const { bounds: bounds2 } = props;
10949
10959
  this.projection = props.projection ?? "geographic";
10950
10960
  this.heightReference = props.heightReference ?? "unknown";
10951
10961
  const limit = this.projection === "web-mercator" ? MAX_MERCATOR_LATITUDE : 90;
10952
- if (bounds.length !== 4 || !bounds.every(Number.isFinite) || bounds[2] <= bounds[0] || bounds[2] - bounds[0] > 360 || bounds[3] <= bounds[1] || bounds[1] < -limit || bounds[3] > limit || this.projection === "geographic" && (bounds[1] === -90 || bounds[3] === 90)) {
10962
+ if (bounds2.length !== 4 || !bounds2.every(Number.isFinite) || bounds2[2] <= bounds2[0] || bounds2[2] - bounds2[0] > 360 || bounds2[3] <= bounds2[1] || bounds2[1] < -limit || bounds2[3] > limit || this.projection === "geographic" && (bounds2[1] === -90 || bounds2[3] === 90)) {
10953
10963
  throw new Error("Terrain bounds must be increasing, span at most 360 degrees and exclude the projection limits");
10954
10964
  }
10955
10965
  if (this.projection !== "geographic" && this.projection !== "web-mercator")
@@ -10957,11 +10967,11 @@ var GeographicHeightField = class {
10957
10967
  const direction = props.rowDirection ?? "north-to-south";
10958
10968
  if (direction !== "north-to-south" && direction !== "south-to-north")
10959
10969
  throw new Error("Unknown terrain row direction");
10960
- this.bounds = Object.freeze([...bounds]);
10961
- const west = this.projectX(bounds[0]);
10962
- const east = this.projectX(bounds[2]);
10963
- const south = this.projectY(bounds[1]);
10964
- const north = this.projectY(bounds[3]);
10970
+ this.bounds = Object.freeze([...bounds2]);
10971
+ const west = this.projectX(bounds2[0]);
10972
+ const east = this.projectX(bounds2[2]);
10973
+ const south = this.projectY(bounds2[1]);
10974
+ const north = this.projectY(bounds2[3]);
10965
10975
  const cell = props.registration === "cell";
10966
10976
  const descending = direction === "north-to-south";
10967
10977
  this.field = new HeightField({
@@ -11511,7 +11521,7 @@ function createTerrainMesh(field, options = {}) {
11511
11521
  coordinates.set([column, row], (row * field.width + column) * 2);
11512
11522
  const output2 = new Uint32Array((field.width - 1) * (field.height - 1) * 6);
11513
11523
  let used = 0;
11514
- const add3 = (a, b, c) => {
11524
+ const add4 = (a, b, c) => {
11515
11525
  for (const i of [a, b, c])
11516
11526
  if (field.getHeight(i % field.width, Math.floor(i / field.width)) === void 0)
11517
11527
  return;
@@ -11523,11 +11533,11 @@ function createTerrainMesh(field, options = {}) {
11523
11533
  for (let column = 0; column < field.width - 1; column++) {
11524
11534
  const a = row * field.width + column, b = a + 1, c = a + field.width, d = c + 1;
11525
11535
  if (field.diagonal === "00-11") {
11526
- add3(a, b, d);
11527
- add3(a, d, c);
11536
+ add4(a, b, d);
11537
+ add4(a, d, c);
11528
11538
  } else {
11529
- add3(a, b, c);
11530
- add3(b, d, c);
11539
+ add4(a, b, c);
11540
+ add4(b, d, c);
11531
11541
  }
11532
11542
  }
11533
11543
  return assembleTerrainMesh(field, coordinates, used === output2.length ? output2 : output2.slice(0, used), options);
@@ -11560,11 +11570,11 @@ var TerrainSurface = class {
11560
11570
  throw new Error("Terrain vertex index out of bounds");
11561
11571
  this.gradients = new Float64Array(this.triangleCount * 2);
11562
11572
  this.normals = new Float64Array(this.triangleCount * 3);
11563
- const bounds = new Float64Array(this.triangleCount * 4);
11573
+ const bounds2 = new Float64Array(this.triangleCount * 4);
11564
11574
  let active = 0;
11565
11575
  for (let i = 0; i < this.triangleCount; i++) {
11566
11576
  const [a, b, c] = this.triangle(i);
11567
- bounds.set([
11577
+ bounds2.set([
11568
11578
  Math.min(a[0], b[0], c[0]),
11569
11579
  Math.min(a[1], b[1], c[1]),
11570
11580
  Math.max(a[0], b[0], c[0]),
@@ -11590,7 +11600,7 @@ var TerrainSurface = class {
11590
11600
  }
11591
11601
  this.activeTriangleCount = active;
11592
11602
  this.topology = buildTopology(this.indices, this.validity);
11593
- this.xyIndex = new import_geometry7.BoxIndex({ bounds, dimension: 2 });
11603
+ this.xyIndex = new import_geometry7.BoxIndex({ bounds: bounds2, dimension: 2 });
11594
11604
  this.bvh = new import_geometry7.TriangleBVH({ positions: this.positions, indices: this.indices });
11595
11605
  }
11596
11606
  /** Detached source data; changing these buffers never changes this surface. */
@@ -12090,13 +12100,13 @@ function measureTerrainMeshError(field, mesh, options = {}) {
12090
12100
  }
12091
12101
 
12092
12102
  // dist/terrain/mesh-edges.js
12093
- function getTerrainMeshEdge(mesh, edge) {
12103
+ function getTerrainMeshEdge(mesh, edge2) {
12094
12104
  validateTerrainGridMesh(mesh);
12095
- if (!["minColumn", "maxColumn", "minRow", "maxRow"].includes(edge))
12105
+ if (!["minColumn", "maxColumn", "minRow", "maxRow"].includes(edge2))
12096
12106
  throw new Error("Unknown terrain mesh edge");
12097
- const column = edge === "minColumn" || edge === "maxColumn";
12107
+ const column = edge2 === "minColumn" || edge2 === "maxColumn";
12098
12108
  const axis = column ? 0 : 1;
12099
- const value3 = edge.startsWith("min") ? 0 : (column ? mesh.width : mesh.height) - 1;
12109
+ const value3 = edge2.startsWith("min") ? 0 : (column ? mesh.width : mesh.height) - 1;
12100
12110
  const vertices = /* @__PURE__ */ new Set();
12101
12111
  for (const index of mesh.indices)
12102
12112
  if (mesh.gridCoordinates[2 * index + axis] === value3)
@@ -12121,15 +12131,15 @@ function createMartiniTerrainMesh(field, options) {
12121
12131
  if (field.validCount !== size * size)
12122
12132
  throw new Error("Adaptive terrain requires complete source data; use a regular mesh for holes");
12123
12133
  const edges = options.fullEdges ?? [];
12124
- for (const edge of edges)
12125
- if (!["minColumn", "maxColumn", "minRow", "maxRow"].includes(edge))
12134
+ for (const edge2 of edges)
12135
+ if (!["minColumn", "maxColumn", "minRow", "maxRow"].includes(edge2))
12126
12136
  throw new Error("Unknown adaptive terrain edge");
12127
12137
  const { heights } = field.copyData();
12128
12138
  const tile = new import_martini.default(size).createTile(heights);
12129
- for (const edge of edges)
12139
+ for (const edge2 of edges)
12130
12140
  for (let i = 0; i < size; i++) {
12131
- const column = edge === "minColumn" ? 0 : edge === "maxColumn" ? cells : i;
12132
- const row = edge === "minRow" ? 0 : edge === "maxRow" ? cells : i;
12141
+ const column = edge2 === "minColumn" ? 0 : edge2 === "maxColumn" ? cells : i;
12142
+ const row = edge2 === "minRow" ? 0 : edge2 === "maxRow" ? cells : i;
12133
12143
  tile.errors[row * size + column] = Infinity;
12134
12144
  }
12135
12145
  if (edges.length)
@@ -12758,8 +12768,8 @@ function createTerrainContours(field, levels, options = {}) {
12758
12768
  const intersection = (a, b) => {
12759
12769
  if (a > b)
12760
12770
  [a, b] = [b, a];
12761
- const exact2 = height(a) === level ? a : height(b) === level ? b : void 0;
12762
- return exact2 === void 0 ? { a, b, key: `e${a}/${b}` } : { a: exact2, b: exact2, key: `v${exact2}` };
12771
+ const exact3 = height(a) === level ? a : height(b) === level ? b : void 0;
12772
+ return exact3 === void 0 ? { a, b, key: `e${a}/${b}` } : { a: exact3, b: exact3, key: `v${exact3}` };
12763
12773
  };
12764
12774
  const vertex = ({ a, b, key: key3 }) => {
12765
12775
  const existing = vertices.get(key3);
@@ -12925,16 +12935,16 @@ function stitchTerrainContours(contours, options = {}) {
12925
12935
  throw new Error("Terrain contour path capacity exceeded");
12926
12936
  levels.push(assignments[start]);
12927
12937
  append(start);
12928
- let vertex = start, edge = firstEdge;
12929
- while (!visited[edge]) {
12930
- visited[edge] = 1;
12931
- const a = contours.segments[2 * edge], b = contours.segments[2 * edge + 1];
12938
+ let vertex = start, edge2 = firstEdge;
12939
+ while (!visited[edge2]) {
12940
+ visited[edge2] = 1;
12941
+ const a = contours.segments[2 * edge2], b = contours.segments[2 * edge2 + 1];
12932
12942
  vertex = vertex === a ? b : a;
12933
12943
  append(vertex);
12934
12944
  if (vertex === start || degrees2[vertex] !== 2)
12935
12945
  break;
12936
12946
  const e0 = adjacency[starts[vertex]], e1 = adjacency[starts[vertex] + 1];
12937
- edge = visited[e0] ? e1 : e0;
12947
+ edge2 = visited[e0] ? e1 : e0;
12938
12948
  }
12939
12949
  closed.push(vertex === start ? 1 : 0);
12940
12950
  offsets.push(indices.length);
@@ -13048,8 +13058,8 @@ function weldTerrainContourTiles(tiles, options) {
13048
13058
  const level = data.levelIndices[i], a = mapVertex(data.segments[2 * i], level), b = mapVertex(data.segments[2 * i + 1], level);
13049
13059
  if (a === b || positions[3 * a] === positions[3 * b] && positions[3 * a + 1] === positions[3 * b + 1])
13050
13060
  throw new Error("Degenerate terrain contour segment after rebasing");
13051
- const edge = a < b ? `${a}/${b}` : `${b}/${a}`;
13052
- const previous = edges.get(edge);
13061
+ const edge2 = a < b ? `${a}/${b}` : `${b}/${a}`;
13062
+ const previous = edges.get(edge2);
13053
13063
  if (previous !== void 0) {
13054
13064
  if (previous === tileIndex)
13055
13065
  throw new Error("Duplicate terrain contour segment");
@@ -13057,7 +13067,7 @@ function weldTerrainContourTiles(tiles, options) {
13057
13067
  }
13058
13068
  if (levelIndices.length >= limits.maxSegments)
13059
13069
  throw new Error("Terrain contour segment capacity exceeded");
13060
- edges.set(edge, tileIndex);
13070
+ edges.set(edge2, tileIndex);
13061
13071
  segments.push(a, b);
13062
13072
  levelIndices.push(level);
13063
13073
  }
@@ -13339,7 +13349,7 @@ function measureTerrainProfile(profile, options = {}) {
13339
13349
  let validSampleCount = 0, minimum = Infinity, maximum = -Infinity, coveredSegmentCount = 0, missingSegmentCount = 0;
13340
13350
  let meanHeight = 0;
13341
13351
  const sums = new Float64Array(6), corrections = new Float64Array(6);
13342
- const add3 = (index, value3) => {
13352
+ const add4 = (index, value3) => {
13343
13353
  const y = value3 - corrections[index], next = sums[index] + y;
13344
13354
  if (!Number.isFinite(value3) || !Number.isFinite(next))
13345
13355
  throw new Error("Terrain profile measurement arithmetic overflow");
@@ -13364,17 +13374,17 @@ function measureTerrainProfile(profile, options = {}) {
13364
13374
  const ds = distance - profile.distances[i - 1];
13365
13375
  if (status !== TerrainSampleStatus.VALID || profile.statuses[i - 1] !== TerrainSampleStatus.VALID) {
13366
13376
  missingSegmentCount++;
13367
- add3(1, ds);
13377
+ add4(1, ds);
13368
13378
  continue;
13369
13379
  }
13370
13380
  coveredSegmentCount++;
13371
13381
  const previousCovered = sums[0];
13372
- add3(0, ds);
13382
+ add4(0, ds);
13373
13383
  const previous = profile.heights[i - 1], dh = height - previous;
13374
- add3(dh >= 0 ? 2 : 3, Math.abs(dh));
13375
- add3(4, Math.hypot(ds, dh));
13384
+ add4(dh >= 0 ? 2 : 3, Math.abs(dh));
13385
+ add4(4, Math.hypot(ds, dh));
13376
13386
  const average = previous + dh / 2;
13377
- add3(5, average * ds);
13387
+ add4(5, average * ds);
13378
13388
  if (previousCovered === 0)
13379
13389
  meanHeight = average;
13380
13390
  else {
@@ -14111,7 +14121,7 @@ function weldTerrainMixedContourTiles(tiles, options = {}) {
14111
14121
  throw new Error("Mixed contour boundary-test budget exceeded");
14112
14122
  };
14113
14123
  const sorted = [...tiles].sort((a, b) => a.column - b.column || a.row - b.row || a.spacing - b.spacing);
14114
- const bounds = sorted.map((t) => {
14124
+ const bounds2 = sorted.map((t) => {
14115
14125
  if (![t.column, t.row, t.width, t.height, t.spacing].every(Number.isSafeInteger) || t.width < 2 || t.height < 2 || t.spacing < 1 || 2 ** Math.round(Math.log2(t.spacing)) !== t.spacing)
14116
14126
  throw new Error("Invalid mixed contour tile lattice");
14117
14127
  const x1 = t.column + (t.width - 1) * t.spacing, y1 = t.row + (t.height - 1) * t.spacing;
@@ -14119,10 +14129,10 @@ function weldTerrainMixedContourTiles(tiles, options = {}) {
14119
14129
  throw new Error("Mixed contour lattice overflow");
14120
14130
  return [t.column, t.row, x1, y1];
14121
14131
  });
14122
- for (let i = 0; i < bounds.length; i++)
14132
+ for (let i = 0; i < bounds2.length; i++)
14123
14133
  for (let j = 0; j < i; j++) {
14124
14134
  charge();
14125
- const a = bounds[i], b = bounds[j];
14135
+ const a = bounds2[i], b = bounds2[j];
14126
14136
  if (Math.max(a[0], b[0]) < Math.min(a[2], b[2]) && Math.max(a[1], b[1]) < Math.min(a[3], b[3]))
14127
14137
  throw new Error("Mixed contour tile interiors overlap");
14128
14138
  }
@@ -14205,18 +14215,18 @@ function weldTerrainMixedContourTiles(tiles, options = {}) {
14205
14215
  if (localEdges.has(key3))
14206
14216
  throw new Error("Duplicate mixed contour segment");
14207
14217
  localEdges.add(key3);
14208
- const box = bounds[ti];
14218
+ const box = bounds2[ti];
14209
14219
  const seam = grid[2 * a] === grid[2 * b] && (grid[2 * a] === box[0] || grid[2 * a] === box[2]) || grid[2 * a + 1] === grid[2 * b + 1] && (grid[2 * a + 1] === box[1] || grid[2 * a + 1] === box[3]);
14210
14220
  edges.push({ a, b, level, tile: ti, seam });
14211
14221
  }
14212
14222
  }
14213
14223
  const segments = [], levels = [], emitted = /* @__PURE__ */ new Map();
14214
- for (const edge of edges) {
14215
- const { a, b, level } = edge;
14224
+ for (const edge2 of edges) {
14225
+ const { a, b, level } = edge2;
14216
14226
  const axis = grid[2 * a] === grid[2 * b] ? 1 : 0;
14217
14227
  const start = grid[2 * a + axis], end = grid[2 * b + axis];
14218
14228
  const cuts = [a, b];
14219
- if (edge.seam)
14229
+ if (edge2.seam)
14220
14230
  for (const v of boundary) {
14221
14231
  charge();
14222
14232
  const value3 = grid[2 * v + axis];
@@ -14234,13 +14244,13 @@ function weldTerrainMixedContourTiles(tiles, options = {}) {
14234
14244
  const u = cuts[i - 1], v = cuts[i], key3 = u < v ? `${u}/${v}` : `${v}/${u}`;
14235
14245
  const prior = emitted.get(key3);
14236
14246
  if (prior !== void 0) {
14237
- if (prior === edge.tile)
14247
+ if (prior === edge2.tile)
14238
14248
  throw new Error("Overlapping mixed contour segments within tile");
14239
14249
  continue;
14240
14250
  }
14241
14251
  if (levels.length >= limits.maxSegments)
14242
14252
  throw new Error("Mixed contour output segment capacity exceeded");
14243
- emitted.set(key3, edge.tile);
14253
+ emitted.set(key3, edge2.tile);
14244
14254
  segments.push(u, v);
14245
14255
  levels.push(level);
14246
14256
  }
@@ -14256,6 +14266,46 @@ function weldTerrainMixedContourTiles(tiles, options = {}) {
14256
14266
  };
14257
14267
  }
14258
14268
 
14269
+ // dist/terrain/box-index.js
14270
+ var overlaps = (a, b) => a.minX <= b.maxX && b.minX <= a.maxX && a.minY <= b.maxY && b.minY <= a.maxY;
14271
+ function createTerrainBoxIndex(boxes) {
14272
+ const build = (ids) => {
14273
+ const box = { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity };
14274
+ for (const id of ids) {
14275
+ const b = boxes[id];
14276
+ box.minX = Math.min(box.minX, b.minX);
14277
+ box.minY = Math.min(box.minY, b.minY);
14278
+ box.maxX = Math.max(box.maxX, b.maxX);
14279
+ box.maxY = Math.max(box.maxY, b.maxY);
14280
+ }
14281
+ if (ids.length <= 8)
14282
+ return { ...box, ids };
14283
+ const axis = box.maxX - box.minX >= box.maxY - box.minY ? "X" : "Y";
14284
+ ids.sort((a, b) => boxes[a][`min${axis}`] / 2 + boxes[a][`max${axis}`] / 2 - (boxes[b][`min${axis}`] / 2 + boxes[b][`max${axis}`] / 2) || a - b);
14285
+ const mid = ids.length >>> 1;
14286
+ return { ...box, left: build(ids.slice(0, mid)), right: build(ids.slice(mid)) };
14287
+ };
14288
+ const root2 = build(boxes.map((_, i) => i));
14289
+ return (query, charge) => {
14290
+ const found = [], stack = [root2];
14291
+ while (stack.length) {
14292
+ charge();
14293
+ const node = stack.pop();
14294
+ if (!overlaps(node, query))
14295
+ continue;
14296
+ if (node.ids) {
14297
+ for (const id of node.ids) {
14298
+ charge();
14299
+ if (overlaps(boxes[id], query))
14300
+ found.push(id);
14301
+ }
14302
+ } else
14303
+ stack.push(node.right, node.left);
14304
+ }
14305
+ return found.sort((a, b) => a - b);
14306
+ };
14307
+ }
14308
+
14259
14309
  // dist/terrain/sample-triangle-height.js
14260
14310
  function sampleTerrainTriangleHeight(field, x, y) {
14261
14311
  if (Number.isInteger(x) && Number.isInteger(y))
@@ -14303,7 +14353,7 @@ function sampleTerrainTriangleHeight(field, x, y) {
14303
14353
  function createTerrainMixedVertexTileHalos(tiles, options = {}) {
14304
14354
  return buildMixedVertexTileHalos(tiles, options);
14305
14355
  }
14306
- function buildMixedVertexTileHalos(tiles, options = {}, targets) {
14356
+ function buildMixedVertexTileHalos(tiles, options = {}, targets, preparation) {
14307
14357
  const maxSamples = options.maxSamples ?? 4e6, maxTests = options.maxTileTests ?? 1e7;
14308
14358
  if (![maxSamples, maxTests].every((v) => Number.isSafeInteger(v) && v >= 0))
14309
14359
  throw new Error("Invalid mixed halo capacity");
@@ -14320,7 +14370,11 @@ function buildMixedVertexTileHalos(tiles, options = {}, targets) {
14320
14370
  count += (tile.field.width + 2) * (tile.field.height + 2);
14321
14371
  if (!Number.isSafeInteger(count) || count > maxSamples)
14322
14372
  throw new Error("Mixed halo sample capacity exceeded");
14323
- const field = new HeightField(tile.field);
14373
+ let field = preparation == null ? void 0 : preparation.fields.get(tile);
14374
+ if (!field) {
14375
+ field = new HeightField(tile.field);
14376
+ preparation == null ? void 0 : preparation.fields.set(tile, field);
14377
+ }
14324
14378
  if (field.registration !== "vertex")
14325
14379
  throw new Error("Mixed halos require vertex registration");
14326
14380
  const column = field.columnStep.map((v) => v / tile.spacing);
@@ -14347,19 +14401,47 @@ function buildMixedVertexTileHalos(tiles, options = {}, targets) {
14347
14401
  if (sources.length && !Number.isSafeInteger(max - min))
14348
14402
  throw new Error("Mixed halo lattice span overflow");
14349
14403
  }
14404
+ if (targets && targets.size === 0)
14405
+ return { tiles: [] };
14406
+ let index;
14407
+ if (sources.length > 8) {
14408
+ const keys = preparation && sources.map((tile) => `${tile.spacing}/${tile.column}/${tile.row}/${tile.source.width}/${tile.source.height}`);
14409
+ const cached = preparation == null ? void 0 : preparation.layout;
14410
+ if (keys && cached && keys.length === cached.keys.length && keys.every((key3, i) => key3 === cached.keys[i])) {
14411
+ index = cached.query;
14412
+ } else {
14413
+ index = createTerrainBoxIndex(sources.map((tile) => ({
14414
+ minX: tile.column,
14415
+ minY: tile.row,
14416
+ maxX: tile.column + (tile.source.width - 1) * tile.spacing,
14417
+ maxY: tile.row + (tile.source.height - 1) * tile.spacing
14418
+ })));
14419
+ if (preparation && keys)
14420
+ preparation.layout = { keys, query: index };
14421
+ }
14422
+ }
14350
14423
  let tests = 0;
14424
+ const charge = () => {
14425
+ if (++tests > maxTests)
14426
+ throw new Error("Mixed halo tile-test budget exceeded");
14427
+ };
14351
14428
  return {
14352
14429
  tiles: sources.filter((tile) => !targets || targets.has(`${tile.spacing}/${tile.column}/${tile.row}`)).map((tile) => {
14353
14430
  const source = tile.source, width = source.width + 2, height = source.height + 2;
14354
14431
  const heights = new Float64Array(width * height), validity = new Uint8Array(heights.length), statuses = new Uint8Array(heights.length);
14432
+ const candidates = (index == null ? void 0 : index({
14433
+ minX: tile.column - tile.spacing,
14434
+ minY: tile.row - tile.spacing,
14435
+ maxX: tile.column + source.width * tile.spacing,
14436
+ maxY: tile.row + source.height * tile.spacing
14437
+ }, charge).map((id) => sources[id])) ?? sources;
14355
14438
  for (let y = 0; y < height; y++)
14356
14439
  for (let x = 0; x < width; x++) {
14357
14440
  const gx = tile.column + (x - 1) * tile.spacing, gy = tile.row + (y - 1) * tile.spacing;
14358
14441
  if (![gx, gy].every(Number.isSafeInteger))
14359
14442
  throw new Error("Mixed halo lattice overflow");
14360
- for (const candidate of sources) {
14361
- if (++tests > maxTests)
14362
- throw new Error("Mixed halo tile-test budget exceeded");
14443
+ for (const candidate of candidates) {
14444
+ charge();
14363
14445
  const cx = (gx - candidate.column) / candidate.spacing, cy = (gy - candidate.row) / candidate.spacing;
14364
14446
  const f = candidate.source;
14365
14447
  if (cx < 0 || cy < 0 || cx > f.width - 1 || cy > f.height - 1)
@@ -14404,36 +14486,108 @@ function buildMixedVertexTileHalos(tiles, options = {}, targets) {
14404
14486
 
14405
14487
  // dist/terrain/mixed-halo-update.js
14406
14488
  var key2 = (t) => `${t.spacing}/${t.column}/${t.row}`;
14489
+ var bounds = (tile, padding = 0) => ({
14490
+ minX: tile.column - padding,
14491
+ minY: tile.row - padding,
14492
+ maxX: tile.column + (tile.field.width - 1) * tile.spacing + padding,
14493
+ maxY: tile.row + (tile.field.height - 1) * tile.spacing + padding
14494
+ });
14495
+ var preparations = /* @__PURE__ */ new WeakMap();
14496
+ var targetIndexes = /* @__PURE__ */ new WeakMap();
14497
+ function editedBounds(old, next) {
14498
+ const a = old.field;
14499
+ const b = next.field;
14500
+ if (a.width !== b.width || a.height !== b.height || (a.diagonal ?? "00-11") !== (b.diagonal ?? "00-11"))
14501
+ return bounds(next);
14502
+ const sample = (field, x, y) => {
14503
+ const i = (field.offset ?? 0) + y * (field.stride ?? field.width) + x;
14504
+ const z = field.heights[i];
14505
+ return Number.isFinite(z) && (field.validity === void 0 || field.validity[i] !== 0) ? z : void 0;
14506
+ };
14507
+ let left = b.width, right = -1, top = b.height, bottom = -1;
14508
+ for (let y = 0; y < b.height; y++) {
14509
+ for (let x = 0; x < b.width; x++) {
14510
+ if (Object.is(sample(a, x, y), sample(b, x, y)))
14511
+ continue;
14512
+ left = Math.min(left, x);
14513
+ right = Math.max(right, x);
14514
+ top = Math.min(top, y);
14515
+ bottom = Math.max(bottom, y);
14516
+ }
14517
+ }
14518
+ if (right < 0)
14519
+ return null;
14520
+ return {
14521
+ minX: next.column + Math.max(0, left - 1) * next.spacing,
14522
+ maxX: next.column + Math.min(b.width - 1, right + 1) * next.spacing,
14523
+ minY: next.row + Math.max(0, top - 1) * next.spacing,
14524
+ maxY: next.row + Math.min(b.height - 1, bottom + 1) * next.spacing
14525
+ };
14526
+ }
14407
14527
  function updateTerrainMixedVertexTileHalos(previous, resident, options = {}) {
14408
14528
  const budget = options.maxDependencyTests ?? 1e7;
14409
14529
  if (!Number.isSafeInteger(budget) || budget < 0)
14410
14530
  throw new Error("Invalid mixed halo dependency budget");
14411
14531
  const old = new Map(previous == null ? void 0 : previous.sources.map((t) => [key2(t), t]));
14412
14532
  const current = new Map(resident.map((t) => [key2(t), t]));
14413
- const changed = [...old.values()].filter((t) => current.get(key2(t)) !== t).concat(resident.filter((t) => old.get(key2(t)) !== t));
14414
14533
  const cached = new Map(previous == null ? void 0 : previous.tiles.map((t) => [key2(t), t]));
14415
14534
  const targets = /* @__PURE__ */ new Set();
14535
+ const unchangedLayout = (previous == null ? void 0 : previous.sources.length) === resident.length && resident.every((tile, i) => {
14536
+ const prior = previous.sources[i];
14537
+ return key2(prior) === key2(tile) && prior.field.width === tile.field.width && prior.field.height === tile.field.height;
14538
+ });
14539
+ let index = unchangedLayout && previous ? targetIndexes.get(previous) : void 0;
14416
14540
  let tests = 0;
14541
+ const charge = () => {
14542
+ if (++tests > budget)
14543
+ throw new Error("Mixed halo dependency budget exceeded");
14544
+ };
14545
+ function invalidate(box) {
14546
+ index ?? (index = createTerrainBoxIndex(resident.map((tile) => bounds(tile, tile.spacing))));
14547
+ for (const id of index(box, charge))
14548
+ targets.add(key2(resident[id]));
14549
+ }
14417
14550
  for (const tile of resident) {
14418
- if (!cached.has(key2(tile)))
14419
- targets.add(key2(tile));
14420
- for (const source of changed) {
14421
- if (++tests > budget)
14422
- throw new Error("Mixed halo dependency budget exceeded");
14423
- if (tile.column - tile.spacing <= source.column + (source.field.width - 1) * source.spacing && tile.column + tile.field.width * tile.spacing >= source.column && tile.row - tile.spacing <= source.row + (source.field.height - 1) * source.spacing && tile.row + tile.field.height * tile.spacing >= source.row)
14424
- targets.add(key2(tile));
14551
+ const address = key2(tile);
14552
+ const prior = old.get(address);
14553
+ if (!cached.has(address) || prior !== tile)
14554
+ targets.add(address);
14555
+ if (prior === tile || !previous)
14556
+ continue;
14557
+ if (!prior) {
14558
+ invalidate(bounds(tile));
14559
+ } else if (prior.field.width !== tile.field.width || prior.field.height !== tile.field.height) {
14560
+ invalidate(bounds(prior));
14561
+ invalidate(bounds(tile));
14562
+ } else {
14563
+ const dirty = editedBounds(prior, tile);
14564
+ if (dirty)
14565
+ invalidate(dirty);
14425
14566
  }
14426
14567
  }
14427
- const built = buildMixedVertexTileHalos(resident, options, targets).tiles;
14568
+ for (const [address, tile] of old) {
14569
+ if (!current.has(address) && resident.length)
14570
+ invalidate(bounds(tile));
14571
+ }
14572
+ const priorPreparation = previous && preparations.get(previous);
14573
+ const preparation = {
14574
+ fields: (priorPreparation == null ? void 0 : priorPreparation.fields) ?? /* @__PURE__ */ new WeakMap(),
14575
+ layout: priorPreparation == null ? void 0 : priorPreparation.layout
14576
+ };
14577
+ const built = buildMixedVertexTileHalos(resident, options, targets, preparation).tiles;
14428
14578
  for (const tile of built)
14429
14579
  cached.set(key2(tile), tile);
14430
14580
  const tiles = resident.map((t) => cached.get(key2(t))).sort((a, b) => a.spacing - b.spacing || a.column - b.column || a.row - b.row);
14431
- return {
14581
+ const snapshot2 = {
14432
14582
  sources: resident.slice(),
14433
14583
  tiles,
14434
14584
  rebuilt: built.map(key2),
14435
14585
  removed: [...old.keys()].filter((k) => !current.has(k)).sort()
14436
14586
  };
14587
+ preparations.set(snapshot2, preparation);
14588
+ if (index)
14589
+ targetIndexes.set(snapshot2, index);
14590
+ return snapshot2;
14437
14591
  }
14438
14592
 
14439
14593
  // dist/terrain/mixed-gradient-update.js
@@ -14455,46 +14609,6 @@ function updateTerrainMixedGradientGrids(previous, halos, options = {}) {
14455
14609
  };
14456
14610
  }
14457
14611
 
14458
- // dist/terrain/box-index.js
14459
- var overlaps = (a, b) => a.minX <= b.maxX && b.minX <= a.maxX && a.minY <= b.maxY && b.minY <= a.maxY;
14460
- function createTerrainBoxIndex(boxes) {
14461
- const build = (ids) => {
14462
- const box = { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity };
14463
- for (const id of ids) {
14464
- const b = boxes[id];
14465
- box.minX = Math.min(box.minX, b.minX);
14466
- box.minY = Math.min(box.minY, b.minY);
14467
- box.maxX = Math.max(box.maxX, b.maxX);
14468
- box.maxY = Math.max(box.maxY, b.maxY);
14469
- }
14470
- if (ids.length <= 8)
14471
- return { ...box, ids };
14472
- const axis = box.maxX - box.minX >= box.maxY - box.minY ? "X" : "Y";
14473
- ids.sort((a, b) => boxes[a][`min${axis}`] / 2 + boxes[a][`max${axis}`] / 2 - (boxes[b][`min${axis}`] / 2 + boxes[b][`max${axis}`] / 2) || a - b);
14474
- const mid = ids.length >>> 1;
14475
- return { ...box, left: build(ids.slice(0, mid)), right: build(ids.slice(mid)) };
14476
- };
14477
- const root2 = build(boxes.map((_, i) => i));
14478
- return (query, charge) => {
14479
- const found = [], stack = [root2];
14480
- while (stack.length) {
14481
- charge();
14482
- const node = stack.pop();
14483
- if (!overlaps(node, query))
14484
- continue;
14485
- if (node.ids) {
14486
- for (const id of node.ids) {
14487
- charge();
14488
- if (overlaps(boxes[id], query))
14489
- found.push(id);
14490
- }
14491
- } else
14492
- stack.push(node.right, node.left);
14493
- }
14494
- return found.sort((a, b) => a - b);
14495
- };
14496
- }
14497
-
14498
14612
  // dist/terrain/contour-topology.js
14499
14613
  var bits = new DataView(new ArrayBuffer(8));
14500
14614
  function integer(x) {
@@ -14577,19 +14691,19 @@ function simplifyTerrainContourPathsTopology(paths, options) {
14577
14691
  const interior2 = new Set(Array.from(paths.indices.subarray(start + 1, end)));
14578
14692
  let unsafe = false;
14579
14693
  for (const edgeId of edgeIndex(box(a, b), charge)) {
14580
- const edge = edges[edgeId];
14581
- if (edge.p === p && edge.i >= start && edge.i < end) {
14694
+ const edge2 = edges[edgeId];
14695
+ if (edge2.p === p && edge2.i >= start && edge2.i < end) {
14582
14696
  if (straight2)
14583
14697
  continue;
14584
14698
  charge();
14585
- const others2 = [edge.a, edge.b].filter((v) => v !== a && v !== b);
14586
- if (others2.some((v) => on(points[a], points[b], points[v])) || others2.length === 2 && intersects(points[a], points[b], points[edge.a], points[edge.b]))
14699
+ const others2 = [edge2.a, edge2.b].filter((v) => v !== a && v !== b);
14700
+ if (others2.some((v) => on(points[a], points[b], points[v])) || others2.length === 2 && intersects(points[a], points[b], points[edge2.a], points[edge2.b]))
14587
14701
  unsafe = true;
14588
14702
  continue;
14589
14703
  }
14590
14704
  charge();
14591
- const others = [edge.a, edge.b].filter((v) => v !== a && v !== b);
14592
- if (others.some((v) => on(points[a], points[b], points[v])) || others.length === 2 && intersects(points[a], points[b], points[edge.a], points[edge.b]))
14705
+ const others = [edge2.a, edge2.b].filter((v) => v !== a && v !== b);
14706
+ if (others.some((v) => on(points[a], points[b], points[v])) || others.length === 2 && intersects(points[a], points[b], points[edge2.a], points[edge2.b]))
14593
14707
  unsafe = true;
14594
14708
  }
14595
14709
  const swept = { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity };
@@ -14891,20 +15005,20 @@ function createTerrainIsobands(fields, levels, options = {}) {
14891
15005
  }
14892
15006
  while (edges.size) {
14893
15007
  const first = edges.values().next().value, ring = [];
14894
- let edge = first;
15008
+ let edge2 = first;
14895
15009
  for (; ; ) {
14896
15010
  charge();
14897
- ring.push(edge.a);
14898
- edges.delete(`${edge.a.key}>${edge.b.key}`);
14899
- outgoing.get(edge.a.key).delete(`${edge.a.key}>${edge.b.key}`);
14900
- if (edge.b.key === first.a.key)
15011
+ ring.push(edge2.a);
15012
+ edges.delete(`${edge2.a.key}>${edge2.b.key}`);
15013
+ outgoing.get(edge2.a.key).delete(`${edge2.a.key}>${edge2.b.key}`);
15014
+ if (edge2.b.key === first.a.key)
14901
15015
  break;
14902
- const choices = [...outgoing.get(edge.b.key) ?? []].map((k) => edges.get(k));
15016
+ const choices = [...outgoing.get(edge2.b.key) ?? []].map((k) => edges.get(k));
14903
15017
  if (!choices.length)
14904
15018
  throw new Error("Open isoband boundary");
14905
- const angle3 = (e) => Math.atan2((edge.b.x - edge.a.x) * (e.b.y - e.a.y) - (edge.b.y - edge.a.y) * (e.b.x - e.a.x), (edge.b.x - edge.a.x) * (e.b.x - e.a.x) + (edge.b.y - edge.a.y) * (e.b.y - e.a.y));
15019
+ const angle3 = (e) => Math.atan2((edge2.b.x - edge2.a.x) * (e.b.y - e.a.y) - (edge2.b.y - edge2.a.y) * (e.b.x - e.a.x), (edge2.b.x - edge2.a.x) * (e.b.x - e.a.x) + (edge2.b.y - edge2.a.y) * (e.b.y - e.a.y));
14906
15020
  choices.sort((a, b) => angle3(b) - angle3(a) || a.b.key.localeCompare(b.b.key));
14907
- edge = choices[0];
15021
+ edge2 = choices[0];
14908
15022
  }
14909
15023
  rings.push(ring);
14910
15024
  bands.push(band);
@@ -15041,6 +15155,24 @@ function updateMeshRegions(previous, field, dirty, options, configuration, creat
15041
15155
  let count = 0, tests = 0;
15042
15156
  const regions = [], rebuilt = [];
15043
15157
  const reusable = previous && sameTerrainFrame(previous.field, field) && previous.cellsPerRegion === cells && previous.configuration === configuration;
15158
+ const affectedRegions = /* @__PURE__ */ new Set();
15159
+ const columns = Math.ceil((field.width - 1) / cells);
15160
+ const rows = Math.ceil((field.height - 1) / cells);
15161
+ if (reusable) {
15162
+ for (const window of dirty) {
15163
+ const firstColumn = Math.max(0, Math.ceil(window.minColumn / cells) - 1);
15164
+ const firstRow = Math.max(0, Math.ceil(window.minRow / cells) - 1);
15165
+ const lastColumn = Math.min(columns - 1, Math.floor(window.maxColumn / cells));
15166
+ const lastRow = Math.min(rows - 1, Math.floor(window.maxRow / cells));
15167
+ for (let y = firstRow; y <= lastRow; y++) {
15168
+ for (let x = firstColumn; x <= lastColumn; x++) {
15169
+ if (++tests > budget)
15170
+ throw new Error("Terrain mesh region work budget exceeded");
15171
+ affectedRegions.add(y * columns + x);
15172
+ }
15173
+ }
15174
+ }
15175
+ }
15044
15176
  const cache = new Map(previous == null ? void 0 : previous.regions.map((r) => [`${r.column},${r.row}`, r]));
15045
15177
  for (let row = 0; row < field.height - 1; row += cells)
15046
15178
  for (let column = 0; column < field.width - 1; column += cells) {
@@ -15048,13 +15180,7 @@ function updateMeshRegions(previous, field, dirty, options, configuration, creat
15048
15180
  count += width * height;
15049
15181
  if (!Number.isSafeInteger(count) || count > limit)
15050
15182
  throw new Error("Terrain mesh region sample capacity exceeded");
15051
- let affected = !reusable;
15052
- for (const w of reusable ? dirty : []) {
15053
- if (++tests > budget)
15054
- throw new Error("Terrain mesh region work budget exceeded");
15055
- if (w.minColumn <= column + width - 1 && w.maxColumn >= column && w.minRow <= row + height - 1 && w.maxRow >= row)
15056
- affected = true;
15057
- }
15183
+ const affected = !reusable || affectedRegions.has(row / cells * columns + column / cells);
15058
15184
  const old = cache.get(`${column},${row}`);
15059
15185
  if (!affected && old) {
15060
15186
  regions.push(old);
@@ -15134,7 +15260,7 @@ function updateTerrainBoundsRegions(previous, field, dirty, options = {}) {
15134
15260
  throw new Error("Invalid bounds region capacity");
15135
15261
  validateTerrainDirtyWindows(dirty, field.width, field.height);
15136
15262
  if (!previous || !sameTerrainFrame(previous.field, field)) {
15137
- const bounds = new HeightFieldMinMax(field), levels2 = Array.from({ length: bounds.levelCount }, (_, i) => bounds.copyLevel(i));
15263
+ const bounds2 = new HeightFieldMinMax(field), levels2 = Array.from({ length: bounds2.levelCount }, (_, i) => bounds2.copyLevel(i));
15138
15264
  return { field, levels: levels2, updatedCounts: Uint32Array.from(levels2, (l) => l.width * l.height) };
15139
15265
  }
15140
15266
  let tests = 0;
@@ -15395,8 +15521,8 @@ function updateTerrainPersistentBounds(previous, field, dirty, options = {}) {
15395
15521
  const { nodesPerBlock, charge } = persistentHierarchyOptions(options, field.width * field.height);
15396
15522
  validateTerrainDirtyWindows(dirty, field.width, field.height);
15397
15523
  if (!previous || !sameTerrainFrame(previous.field, field) || previous.levels[0].nodesPerBlock !== nodesPerBlock) {
15398
- const bounds = new HeightFieldMinMax(field), levels = Array.from({ length: bounds.levelCount }, (_, i) => {
15399
- const l = bounds.copyLevel(i), values = new Float64Array(2 * l.width * l.height), counts = new Uint32Array(values.length);
15524
+ const bounds2 = new HeightFieldMinMax(field), levels = Array.from({ length: bounds2.levelCount }, (_, i) => {
15525
+ const l = bounds2.copyLevel(i), values = new Float64Array(2 * l.width * l.height), counts = new Uint32Array(values.length);
15400
15526
  for (let j = 0; j < l.width * l.height; j++) {
15401
15527
  values[2 * j] = l.minimums[j];
15402
15528
  values[2 * j + 1] = l.maximums[j];
@@ -15744,4 +15870,849 @@ function createTerrainMixedIsobands(tiles, levels, options = {}) {
15744
15870
  sharedSamples: surface2.sharedSamples
15745
15871
  };
15746
15872
  }
15873
+
15874
+ // dist/terrain/valid-domain-mesh.js
15875
+ var import_cdt2d = __toESM(require("cdt2d"), 1);
15876
+ function capacity(value3) {
15877
+ if (!Number.isSafeInteger(value3) || value3 < 1)
15878
+ throw new Error("Invalid mesh work limit");
15879
+ return value3;
15880
+ }
15881
+ function createValidDomainTerrainMesh(field, options) {
15882
+ return meshValidDomain(field, options);
15883
+ }
15884
+ function meshValidDomain(field, options, constraints) {
15885
+ const { maxError } = options;
15886
+ const count = field.width * field.height;
15887
+ if (!Number.isFinite(maxError) || maxError < 0)
15888
+ throw new Error("Invalid maximum error");
15889
+ if (count > capacity(options.maxSamples ?? 11e5))
15890
+ throw new Error("Sample limit exceeded");
15891
+ const maxTriangles = capacity(options.maxTriangles ?? 22e5);
15892
+ const maxTests = capacity(options.maxSampleTests ?? 4e7);
15893
+ const regular = createTerrainMesh(field, options);
15894
+ const { width, height, origin, heightReference } = regular;
15895
+ const active = new Uint8Array(count);
15896
+ const boundary = /* @__PURE__ */ new Map();
15897
+ const edgeKey2 = (a, b) => Math.min(a, b) * count + Math.max(a, b);
15898
+ for (let i = 0; i < regular.indices.length; i += 3) {
15899
+ for (let j = 0; j < 3; j++) {
15900
+ const a = regular.indices[i + j], b = regular.indices[i + (j + 1) % 3];
15901
+ active[a] = 1;
15902
+ const key3 = edgeKey2(a, b);
15903
+ if (!boundary.delete(key3))
15904
+ boundary.set(key3, [a, b]);
15905
+ }
15906
+ }
15907
+ const selected = new Int32Array(count).fill(-1);
15908
+ const points = [];
15909
+ const heights = [];
15910
+ const add4 = (i) => {
15911
+ if (selected[i] < 0) {
15912
+ selected[i] = points.length;
15913
+ points.push([i % width, Math.floor(i / width)]);
15914
+ heights.push(regular.positions[3 * i + 2]);
15915
+ }
15916
+ return selected[i];
15917
+ };
15918
+ const edges = Array.from(boundary.values(), ([a, b]) => [add4(a), add4(b)]);
15919
+ const extra = constraints == null ? void 0 : constraints(points, heights, edges, selected, origin[2]);
15920
+ const inDomain = ([a, b, c]) => {
15921
+ const x = (points[a][0] + points[b][0] + points[c][0]) / 3;
15922
+ const y = (points[a][1] + points[b][1] + points[c][1]) / 3;
15923
+ const i = Math.floor(x), j = Math.floor(y);
15924
+ const u = x - i, v = y - j;
15925
+ const valid = (dx, dy) => field.getHeight(i + dx, j + dy) !== void 0;
15926
+ if (field.diagonal === "00-11") {
15927
+ return valid(0, 0) && valid(1, 1) && (u > v ? valid(1, 0) : valid(0, 1));
15928
+ }
15929
+ return valid(1, 0) && valid(0, 1) && (u + v < 1 ? valid(0, 0) : valid(1, 1));
15930
+ };
15931
+ const covered = new Uint8Array(count);
15932
+ let triangles = [];
15933
+ let maxSampleError = 0;
15934
+ let certifiedSamples = 0;
15935
+ let tests = 0;
15936
+ for (let pass = 0; points.length; pass++) {
15937
+ triangles = (0, import_cdt2d.default)(points, (extra == null ? void 0 : extra.edges) ?? edges, {
15938
+ exterior: Boolean(extra),
15939
+ delaunay: false
15940
+ });
15941
+ if (extra)
15942
+ triangles = triangles.filter(inDomain);
15943
+ if (triangles.length > maxTriangles)
15944
+ throw new Error("Triangle limit exceeded");
15945
+ covered.fill(0);
15946
+ const refine = /* @__PURE__ */ new Set();
15947
+ maxSampleError = 0;
15948
+ certifiedSamples = 0;
15949
+ for (const [a, b, c] of triangles) {
15950
+ const [ax, ay] = points[a], [bx, by] = points[b], [cx, cy] = points[c];
15951
+ const det = (bx - ax) * (cy - ay) - (by - ay) * (cx - ax);
15952
+ if (det === 0)
15953
+ throw new Error("Degenerate triangulation");
15954
+ let worst = maxError;
15955
+ let candidate = -1;
15956
+ const sides = [
15957
+ [ax, ay, bx, by],
15958
+ [bx, by, cx, cy],
15959
+ [cx, cy, ax, ay]
15960
+ ];
15961
+ for (let y = Math.ceil(Math.min(ay, by, cy)); y <= Math.floor(Math.max(ay, by, cy)); y++) {
15962
+ let left = Infinity;
15963
+ let right = -Infinity;
15964
+ for (const [x0, y0, x1, y1] of sides) {
15965
+ if (y < Math.min(y0, y1) || y > Math.max(y0, y1))
15966
+ continue;
15967
+ const x = y0 === y1 ? x0 : x0 + (x1 - x0) * (y - y0) / (y1 - y0);
15968
+ left = Math.min(left, x);
15969
+ right = Math.max(right, y0 === y1 ? Math.max(x0, x1) : x);
15970
+ if (y0 === y1)
15971
+ left = Math.min(left, x1);
15972
+ }
15973
+ for (let x = Math.ceil(left - 1e-10); x <= Math.floor(right + 1e-10); x++) {
15974
+ if (++tests > maxTests)
15975
+ throw new Error("Sample test limit exceeded");
15976
+ const i = y * width + x;
15977
+ if (!active[i] || (extra == null ? void 0 : extra.excluded.has(i)))
15978
+ continue;
15979
+ const u = ((x - ax) * (cy - ay) - (y - ay) * (cx - ax)) / det;
15980
+ const v = ((bx - ax) * (y - ay) - (by - ay) * (x - ax)) / det;
15981
+ const w = 1 - u - v;
15982
+ if (Math.min(u, v, w) < -1e-12)
15983
+ continue;
15984
+ if (!covered[i])
15985
+ certifiedSamples++;
15986
+ covered[i] = 1;
15987
+ const error = !extra && (selected[i] === a || selected[i] === b || selected[i] === c) ? 0 : Math.abs(w * heights[a] + u * heights[b] + v * heights[c] - regular.positions[3 * i + 2]);
15988
+ maxSampleError = Math.max(maxSampleError, error);
15989
+ if (error > worst && !(extra == null ? void 0 : extra.fixedSamples.has(i))) {
15990
+ worst = error;
15991
+ candidate = i;
15992
+ }
15993
+ }
15994
+ }
15995
+ if (candidate >= 0)
15996
+ refine.add(candidate);
15997
+ }
15998
+ if (active.some((value3, i) => value3 && !covered[i] && !(extra == null ? void 0 : extra.excluded.has(i))))
15999
+ throw new Error("Incomplete domain triangulation");
16000
+ if (maxSampleError <= maxError)
16001
+ break;
16002
+ if (!Array.from(refine).some((i) => selected[i] < 0))
16003
+ throw new Error("Cannot certify mesh tolerance");
16004
+ if (pass === 63) {
16005
+ for (let i = 0; i < count; i++)
16006
+ if (active[i] && !(extra == null ? void 0 : extra.fixedSamples.has(i)))
16007
+ add4(i);
16008
+ } else {
16009
+ for (const i of refine)
16010
+ add4(i);
16011
+ }
16012
+ }
16013
+ const reverse2 = field.columnStep[0] * field.rowStep[1] - field.columnStep[1] * field.rowStep[0] < 0;
16014
+ const positions = new Float64Array(points.length * 3);
16015
+ const shift2 = field.registration === "cell" ? 0.5 : 0;
16016
+ for (let i = 0; i < points.length; i++) {
16017
+ const [x, y] = points[i];
16018
+ positions.set([
16019
+ field.origin[0] - origin[0] + (x + shift2) * field.columnStep[0] + (y + shift2) * field.rowStep[0],
16020
+ field.origin[1] - origin[1] + (x + shift2) * field.columnStep[1] + (y + shift2) * field.rowStep[1],
16021
+ heights[i]
16022
+ ], i * 3);
16023
+ }
16024
+ const indices = new Uint32Array(triangles.length * 3);
16025
+ for (let i = 0; i < triangles.length; i++) {
16026
+ const [a, b, c] = triangles[i];
16027
+ const [ax, ay] = points[a], [bx, by] = points[b], [cx, cy] = points[c];
16028
+ const clockwise = (bx - ax) * (cy - ay) - (by - ay) * (cx - ax) < 0;
16029
+ indices.set(reverse2 === clockwise ? [a, b, c] : [a, c, b], 3 * i);
16030
+ }
16031
+ return {
16032
+ positions,
16033
+ indices,
16034
+ gridCoordinates: Float64Array.from(points.flat()),
16035
+ origin,
16036
+ width,
16037
+ height,
16038
+ heightReference,
16039
+ maxSampleError,
16040
+ certifiedSamples
16041
+ };
16042
+ }
16043
+
16044
+ // dist/terrain/breakline-mesh.js
16045
+ var cross4 = (a, b, c) => (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
16046
+ var onSegment = (a, b, p) => Math.abs(cross4(a, b, p)) <= 8 * Number.EPSILON * (Math.abs((b[0] - a[0]) * (p[1] - a[1])) + Math.abs((b[1] - a[1]) * (p[0] - a[0]))) && p[0] >= Math.min(a[0], b[0]) && p[0] <= Math.max(a[0], b[0]) && p[1] >= Math.min(a[1], b[1]) && p[1] <= Math.max(a[1], b[1]);
16047
+ function createBreaklineTerrainMesh(field, options) {
16048
+ const breaklineEdges = [];
16049
+ let overriddenSamples = 0;
16050
+ const mesh = meshValidDomain(field, options, (points, heights, boundary, selected, originZ) => {
16051
+ const ids = new Map(points.map(([x, y], i) => [`${x},${y}`, i]));
16052
+ const fixed = /* @__PURE__ */ new Map();
16053
+ const excluded = /* @__PURE__ */ new Set();
16054
+ const fixedSamples = /* @__PURE__ */ new Set();
16055
+ const add4 = ([x, y, z]) => {
16056
+ if (![x, y, z, z - originZ].every(Number.isFinite) || x < 0 || y < 0 || x > field.width - 1 || y > field.height - 1) {
16057
+ throw new Error("Breakline endpoint is outside the sample rectangle or nonfinite");
16058
+ }
16059
+ const key3 = `${x},${y}`;
16060
+ const id = ids.get(key3) ?? points.length;
16061
+ if (fixed.has(id) && fixed.get(id) !== z)
16062
+ throw new Error("Conflicting breakline heights");
16063
+ if (!ids.has(key3)) {
16064
+ points.push([x, y]);
16065
+ ids.set(key3, id);
16066
+ }
16067
+ fixed.set(id, z);
16068
+ heights[id] = z - originZ;
16069
+ if (Number.isInteger(x) && Number.isInteger(y))
16070
+ selected[y * field.width + x] = id;
16071
+ return id;
16072
+ };
16073
+ if (options.breaklines.length > 2048)
16074
+ throw new Error("Breakline limit exceeded");
16075
+ for (const [a, b] of options.breaklines) {
16076
+ const p = add4(a), q = add4(b);
16077
+ if (p === q)
16078
+ throw new Error("Zero-length breakline");
16079
+ breaklineEdges.push([p, q]);
16080
+ }
16081
+ const edges2 = [];
16082
+ for (const [a, b] of boundary) {
16083
+ const split = [
16084
+ a,
16085
+ ...Array.from(fixed.keys()).filter((id) => id !== a && id !== b && onSegment(points[a], points[b], points[id])),
16086
+ b
16087
+ ];
16088
+ const [x, y] = points[a];
16089
+ split.sort((i, j) => Math.hypot(points[i][0] - x, points[i][1] - y) - Math.hypot(points[j][0] - x, points[j][1] - y));
16090
+ for (let i = 1; i < split.length; i++)
16091
+ edges2.push([split[i - 1], split[i]]);
16092
+ }
16093
+ const seen = /* @__PURE__ */ new Set();
16094
+ for (const [a, b] of breaklineEdges) {
16095
+ const key3 = `${Math.min(a, b)},${Math.max(a, b)}`;
16096
+ if (seen.has(key3))
16097
+ throw new Error("Duplicate breakline");
16098
+ seen.add(key3);
16099
+ const p = points[a], q = points[b];
16100
+ let coincident = false;
16101
+ for (const [c, d] of edges2) {
16102
+ if (a === c && b === d || a === d && b === c) {
16103
+ coincident = true;
16104
+ continue;
16105
+ }
16106
+ const r = points[c], s = points[d];
16107
+ const intersects2 = Math.sign(cross4(p, q, r)) * Math.sign(cross4(p, q, s)) < 0 && Math.sign(cross4(r, s, p)) * Math.sign(cross4(r, s, q)) < 0;
16108
+ if (intersects2 || c !== a && c !== b && onSegment(p, q, r) || d !== a && d !== b && onSegment(p, q, s) || a !== c && a !== d && onSegment(r, s, p) || b !== c && b !== d && onSegment(r, s, q)) {
16109
+ throw new Error("Breaklines and domain edges must meet only at shared endpoints");
16110
+ }
16111
+ }
16112
+ if (!coincident)
16113
+ edges2.push([a, b]);
16114
+ for (let y = Math.ceil(Math.min(p[1], q[1])); y <= Math.floor(Math.max(p[1], q[1])); y++) {
16115
+ for (let x = Math.ceil(Math.min(p[0], q[0])); x <= Math.floor(Math.max(p[0], q[0])); x++) {
16116
+ const source = field.getHeight(x, y);
16117
+ if (source === void 0 || !onSegment(p, q, [x, y]))
16118
+ continue;
16119
+ fixedSamples.add(y * field.width + x);
16120
+ const dx = q[0] - p[0], dy = q[1] - p[1];
16121
+ const f = Math.abs(dx) >= Math.abs(dy) ? (x - p[0]) / dx : (y - p[1]) / dy;
16122
+ const z = (1 - f) * heights[a] + f * heights[b] + originZ;
16123
+ if (Math.abs(source - z) <= options.maxError)
16124
+ continue;
16125
+ if (!options.breaklinesOverrideSamples)
16126
+ throw new Error("Breakline conflicts with source tolerance");
16127
+ excluded.add(y * field.width + x);
16128
+ }
16129
+ }
16130
+ }
16131
+ overriddenSamples = excluded.size;
16132
+ return { edges: edges2, excluded, fixedSamples };
16133
+ });
16134
+ const edges = /* @__PURE__ */ new Set();
16135
+ for (let i = 0; i < mesh.indices.length; i += 3) {
16136
+ for (let j = 0; j < 3; j++) {
16137
+ const a = mesh.indices[i + j], b = mesh.indices[i + (j + 1) % 3];
16138
+ edges.add(`${Math.min(a, b)},${Math.max(a, b)}`);
16139
+ }
16140
+ }
16141
+ if (breaklineEdges.some(([a, b]) => !edges.has(`${Math.min(a, b)},${Math.max(a, b)}`))) {
16142
+ throw new Error("Breakline was not preserved inside the valid terrain domain");
16143
+ }
16144
+ return { ...mesh, breaklineEdges: Uint32Array.from(breaklineEdges.flat()), overriddenSamples };
16145
+ }
16146
+
16147
+ // dist/terrain/continuous-mesh-error.js
16148
+ var exact2 = (x) => [x, x];
16149
+ function outward(lo, hi) {
16150
+ if (!Number.isFinite(lo) || !Number.isFinite(hi))
16151
+ throw new Error("Continuous error arithmetic overflow");
16152
+ const result = [
16153
+ lo - Math.max(Number.MIN_VALUE, Math.abs(lo) * Number.EPSILON),
16154
+ hi + Math.max(Number.MIN_VALUE, Math.abs(hi) * Number.EPSILON)
16155
+ ];
16156
+ if (!result.every(Number.isFinite))
16157
+ throw new Error("Continuous error arithmetic overflow");
16158
+ return result;
16159
+ }
16160
+ var add3 = (a, b) => outward(a[0] + b[0], a[1] + b[1]);
16161
+ var sub = (a, b) => outward(a[0] - b[1], a[1] - b[0]);
16162
+ function mul2(a, b) {
16163
+ const values = [a[0] * b[0], a[0] * b[1], a[1] * b[0], a[1] * b[1]];
16164
+ return outward(Math.min(...values), Math.max(...values));
16165
+ }
16166
+ function div2(a, b) {
16167
+ if (b[0] <= 0 && b[1] >= 0)
16168
+ throw new Error("Degenerate or numerically unresolved mesh triangle");
16169
+ return mul2(a, outward(1 / b[1], 1 / b[0]));
16170
+ }
16171
+ var magnitude = (a) => Math.max(-a[0], a[1]);
16172
+ var minimumMagnitude = (a) => Math.max(0, a[0], -a[1]);
16173
+ var evaluate = (p, x, y) => add3(p[0], add3(mul2(p[1], x), mul2(p[2], y)));
16174
+ function edge(a, b, column, row) {
16175
+ const dx = sub(exact2(b[0]), exact2(a[0]));
16176
+ const dy = sub(exact2(b[1]), exact2(a[1]));
16177
+ return [
16178
+ sub(mul2(dx, sub(exact2(row), exact2(a[1]))), mul2(dy, sub(exact2(column), exact2(a[0])))),
16179
+ [-dy[1], -dy[0]],
16180
+ dx
16181
+ ];
16182
+ }
16183
+ function polygon(triangle, column, row) {
16184
+ const [a, b, c] = triangle;
16185
+ const first = edge(a, b, a[0], a[1]);
16186
+ const orientation3 = evaluate(first, sub(exact2(c[0]), exact2(a[0])), sub(exact2(c[1]), exact2(a[1])));
16187
+ if (orientation3[0] <= 0 && orientation3[1] >= 0)
16188
+ throw new Error("Degenerate or numerically unresolved mesh triangle");
16189
+ const sides = [edge(a, b, column, row), edge(b, c, column, row), edge(c, a, column, row)];
16190
+ return orientation3[0] > 0 ? sides : sides.map((p) => p.map(([lo, hi]) => [-hi, -lo]));
16191
+ }
16192
+ function boundTerrainMeshError(field, mesh, options = {}) {
16193
+ const { reference = "triangle", gap = 0.05, maxBoxes = 2e6, maxDepth = 12 } = options;
16194
+ const { gridCoordinates: xy, positions, indices, origin } = mesh;
16195
+ if (!["triangle", "bilinear"].includes(reference) || !Number.isFinite(gap) || gap < 0 || !Number.isSafeInteger(maxBoxes) || maxBoxes < 1 || !Number.isSafeInteger(maxDepth) || maxDepth < 0 || maxDepth > 24)
16196
+ throw new Error("Invalid continuous error options");
16197
+ if (mesh.heightReference !== field.heightReference || !Number.isFinite(origin[2]) || positions.length % 3 || xy.length !== positions.length / 3 * 2 || indices.length % 3)
16198
+ throw new Error("Invalid continuous error mesh buffers or height reference");
16199
+ let upperBound = null;
16200
+ let lowerBound = 0;
16201
+ let witness = null;
16202
+ let boxes = 0;
16203
+ for (let i = 0; i < indices.length; i += 3) {
16204
+ const ids = [indices[i], indices[i + 1], indices[i + 2]];
16205
+ if (ids.some((id) => !Number.isSafeInteger(id) || id < 0 || id >= xy.length / 2)) {
16206
+ throw new Error("Invalid continuous error index");
16207
+ }
16208
+ const triangle = [
16209
+ [xy[2 * ids[0]], xy[2 * ids[0] + 1]],
16210
+ [xy[2 * ids[1]], xy[2 * ids[1] + 1]],
16211
+ [xy[2 * ids[2]], xy[2 * ids[2] + 1]]
16212
+ ];
16213
+ const [a, b, c] = triangle;
16214
+ const [za, zb, zc] = ids.map((id) => exact2(positions[3 * id + 2]));
16215
+ if (triangle.some(([x, y]) => !Number.isFinite(x) || !Number.isFinite(y)) || [za, zb, zc].some((z) => !Number.isFinite(z[0])))
16216
+ throw new Error("Nonfinite continuous error vertex");
16217
+ if (reference === "triangle" && origin[2] === 0 && matchesReferenceHalf(field, triangle, [za[0], zb[0], zc[0]])) {
16218
+ if (++boxes > maxBoxes)
16219
+ throw new Error("Continuous error box limit exceeded");
16220
+ upperBound ?? (upperBound = 0);
16221
+ witness ?? (witness = a);
16222
+ continue;
16223
+ }
16224
+ const dx = sub(exact2(b[0]), exact2(a[0])), dy = sub(exact2(b[1]), exact2(a[1]));
16225
+ const ex = sub(exact2(c[0]), exact2(a[0])), ey = sub(exact2(c[1]), exact2(a[1]));
16226
+ const det = sub(mul2(dx, ey), mul2(dy, ex));
16227
+ const dz = sub(zb, za), ez = sub(zc, za);
16228
+ const sx = div2(sub(mul2(dz, ey), mul2(ez, dy)), det);
16229
+ const sy = div2(sub(mul2(dx, ez), mul2(ex, dz)), det);
16230
+ for (let row = Math.max(0, Math.ceil(Math.min(a[1], b[1], c[1])) - 1); row <= Math.min(field.height - 2, Math.floor(Math.max(a[1], b[1], c[1]))); row++) {
16231
+ for (let column = Math.max(0, Math.ceil(Math.min(a[0], b[0], c[0])) - 1); column <= Math.min(field.width - 2, Math.floor(Math.max(a[0], b[0], c[0]))); column++) {
16232
+ let visit = function(constraints, p, mixed, x, y, depth) {
16233
+ if (++boxes > maxBoxes)
16234
+ throw new Error("Continuous error box limit exceeded");
16235
+ if (constraints.some((side) => evaluate(side, x, y)[1] < 0))
16236
+ return;
16237
+ const error = (u2, v2) => add3(evaluate(p, u2, v2), mul2(mixed, mul2(u2, v2)));
16238
+ const centerX = (x[0] + x[1]) / 2;
16239
+ const centerY = (y[0] + y[1]) / 2;
16240
+ const u = exact2(centerX), v = exact2(centerY);
16241
+ if (constraints.every((side) => evaluate(side, u, v)[0] >= 0)) {
16242
+ const lower = minimumMagnitude(error(u, v));
16243
+ if (!witness || lower > lowerBound) {
16244
+ lowerBound = lower;
16245
+ witness = [column + centerX, row + centerY];
16246
+ }
16247
+ }
16248
+ const upper = Math.max(...x.flatMap((u2) => y.map((v2) => magnitude(error(exact2(u2), exact2(v2))))));
16249
+ if (upper <= lowerBound + gap || depth === maxDepth) {
16250
+ upperBound = Math.max(upperBound ?? 0, upper);
16251
+ return;
16252
+ }
16253
+ if (x[1] - x[0] >= y[1] - y[0]) {
16254
+ visit(constraints, p, mixed, [x[0], centerX], y, depth + 1);
16255
+ visit(constraints, p, mixed, [centerX, x[1]], y, depth + 1);
16256
+ } else {
16257
+ visit(constraints, p, mixed, x, [y[0], centerY], depth + 1);
16258
+ visit(constraints, p, mixed, x, [centerY, y[1]], depth + 1);
16259
+ }
16260
+ };
16261
+ if (++boxes > maxBoxes)
16262
+ throw new Error("Continuous error box limit exceeded");
16263
+ const vertices = [
16264
+ [0, 0],
16265
+ [1, 0],
16266
+ [0, 1],
16267
+ [1, 1]
16268
+ ];
16269
+ const h = vertices.map(([x, y]) => field.getHeight(column + x, row + y));
16270
+ const sides = polygon(triangle, column, row);
16271
+ const base = add3(za, add3(mul2(sx, sub(exact2(column), exact2(a[0]))), mul2(sy, sub(exact2(row), exact2(a[1])))));
16272
+ const compare = (constant, x, y, mixed, constraints) => visit(constraints, [sub(base, sub(constant, exact2(origin[2]))), sub(sx, x), sub(sy, y)], [-mixed[1], -mixed[0]], [0, 1], [0, 1], 0);
16273
+ if (reference === "bilinear") {
16274
+ const [h00, h10, h01, h11] = h;
16275
+ if (h00 === void 0 || h10 === void 0 || h01 === void 0 || h11 === void 0)
16276
+ continue;
16277
+ const x = sub(exact2(h10), exact2(h00)), y = sub(exact2(h01), exact2(h00));
16278
+ compare(exact2(h00), x, y, sub(sub(exact2(h11), exact2(h01)), x), sides);
16279
+ } else {
16280
+ const halves = field.diagonal === "00-11" ? [
16281
+ [0, 1, 3],
16282
+ [0, 3, 2]
16283
+ ] : [
16284
+ [0, 1, 2],
16285
+ [1, 3, 2]
16286
+ ];
16287
+ for (const [j, k, l] of halves) {
16288
+ const z0 = h[j], z1 = h[k], z2 = h[l];
16289
+ if (z0 === void 0 || z1 === void 0 || z2 === void 0)
16290
+ continue;
16291
+ const p = vertices[j], q = vertices[k], r = vertices[l];
16292
+ const x = sub(mul2(sub(exact2(z1), exact2(z0)), exact2(r[1] - p[1])), mul2(sub(exact2(z2), exact2(z0)), exact2(q[1] - p[1])));
16293
+ const y = sub(mul2(exact2(q[0] - p[0]), sub(exact2(z2), exact2(z0))), mul2(exact2(r[0] - p[0]), sub(exact2(z1), exact2(z0))));
16294
+ compare(sub(exact2(z0), add3(mul2(x, exact2(p[0])), mul2(y, exact2(p[1])))), x, y, exact2(0), [
16295
+ ...sides,
16296
+ ...polygon([p, q, r], 0, 0)
16297
+ ]);
16298
+ }
16299
+ }
16300
+ }
16301
+ }
16302
+ }
16303
+ return {
16304
+ upperBound,
16305
+ lowerBound,
16306
+ witness,
16307
+ boxes,
16308
+ converged: upperBound !== null && upperBound - lowerBound <= gap
16309
+ };
16310
+ }
16311
+ function matchesReferenceHalf(field, triangle, heights) {
16312
+ const column = Math.min(...triangle.map((p) => p[0]));
16313
+ const row = Math.min(...triangle.map((p) => p[1]));
16314
+ if (!Number.isInteger(column) || !Number.isInteger(row) || column < 0 || row < 0 || column >= field.width - 1 || row >= field.height - 1)
16315
+ return false;
16316
+ const corners = /* @__PURE__ */ new Set();
16317
+ for (let i = 0; i < 3; i++) {
16318
+ const [x, y] = triangle[i];
16319
+ const u = x - column, v = y - row;
16320
+ if (u !== 0 && u !== 1 || v !== 0 && v !== 1 || field.getHeight(x, y) !== heights[i])
16321
+ return false;
16322
+ corners.add(u + 2 * v);
16323
+ }
16324
+ return corners.size === 3 && (field.diagonal === "00-11" ? corners.has(0) && corners.has(3) : corners.has(1) && corners.has(2));
16325
+ }
16326
+
16327
+ // dist/terrain/geographic-seam.js
16328
+ function wrapTerrainLongitude(longitude, west, east) {
16329
+ if (![longitude, west, east].every(Number.isFinite) || east <= west || east - west > 360)
16330
+ throw new Error("Invalid terrain longitude interval or query");
16331
+ if (longitude >= west && longitude < east)
16332
+ return longitude;
16333
+ const delta = (longitude % 360 - west % 360) % 360;
16334
+ const offset2 = delta < 0 ? delta + 360 : delta;
16335
+ const mapped = west + offset2;
16336
+ return mapped <= east ? mapped : void 0;
16337
+ }
16338
+ function measureGeographicTerrainSeam(a, b, probes, options = {}) {
16339
+ if (a && b && a.heightReference !== b.heightReference)
16340
+ throw new Error("Terrain seam height references differ");
16341
+ const sample = (field, longitude, latitude) => {
16342
+ if (!field || !Number.isFinite(longitude))
16343
+ return field == null ? void 0 : field.sample(longitude, latitude, options);
16344
+ const mapped = wrapTerrainLongitude(longitude, field.bounds[0], field.bounds[2]);
16345
+ return field.sample(mapped ?? longitude, latitude, options);
16346
+ };
16347
+ return probes.map(([longitude, latitude]) => {
16348
+ const left = sample(a, longitude, latitude);
16349
+ const right = sample(b, longitude, latitude);
16350
+ const valid = (left == null ? void 0 : left.status) === TerrainSampleStatus.VALID && (right == null ? void 0 : right.status) === TerrainSampleStatus.VALID;
16351
+ const derivatives = (left == null ? void 0 : left.gradientStatus) === TerrainSampleStatus.VALID && (right == null ? void 0 : right.gradientStatus) === TerrainSampleStatus.VALID;
16352
+ const normalAngle = derivatives ? Math.atan2(Math.hypot(left.normalY * right.normalZ - left.normalZ * right.normalY, left.normalZ * right.normalX - left.normalX * right.normalZ, left.normalX * right.normalY - left.normalY * right.normalX), left.normalX * right.normalX + left.normalY * right.normalY + left.normalZ * right.normalZ) : null;
16353
+ return {
16354
+ longitude,
16355
+ latitude,
16356
+ statusA: (left == null ? void 0 : left.status) ?? TerrainSampleStatus.NOT_RESIDENT,
16357
+ statusB: (right == null ? void 0 : right.status) ?? TerrainSampleStatus.NOT_RESIDENT,
16358
+ gradientStatusA: (left == null ? void 0 : left.gradientStatus) ?? TerrainSampleStatus.NOT_RESIDENT,
16359
+ gradientStatusB: (right == null ? void 0 : right.gradientStatus) ?? TerrainSampleStatus.NOT_RESIDENT,
16360
+ heightJump: valid ? Math.abs(left.height - right.height) : null,
16361
+ normalAngle
16362
+ };
16363
+ });
16364
+ }
16365
+
16366
+ // dist/terrain/lod-select.js
16367
+ function selectTerrainLod(roots2, view) {
16368
+ var _a;
16369
+ const { position: position2, verticalFov, viewportHeight, targetPixels, hysteresis = 0.2, previouslyRefined, maxVisited = 1e5 } = view;
16370
+ if (!position2.every(Number.isFinite) || !Number.isFinite(verticalFov) || verticalFov <= 0 || verticalFov >= Math.PI || !Number.isFinite(viewportHeight) || viewportHeight <= 0 || !Number.isFinite(targetPixels) || targetPixels <= 0 || !(hysteresis >= 0 && hysteresis < 1) || !Number.isSafeInteger(maxVisited) || maxVisited < 1)
16371
+ throw new Error("Invalid terrain LOD view");
16372
+ const scale3 = viewportHeight / (2 * Math.tan(verticalFov / 2));
16373
+ if (!Number.isFinite(scale3))
16374
+ throw new Error("Terrain LOD projection scale overflow");
16375
+ const selected = [];
16376
+ const refined = /* @__PURE__ */ new Set();
16377
+ const unavailable = [];
16378
+ const seen = /* @__PURE__ */ new Set();
16379
+ const pending = [...roots2].reverse();
16380
+ while (pending.length) {
16381
+ const tile = pending.pop();
16382
+ if (seen.size >= maxVisited)
16383
+ throw new Error("Terrain LOD visit limit exceeded");
16384
+ if (seen.has(tile.id))
16385
+ throw new Error("Duplicate terrain LOD tile or cycle");
16386
+ seen.add(tile.id);
16387
+ if (![...tile.min, ...tile.max, tile.geometricError].every(Number.isFinite) || tile.geometricError < 0 || tile.min.some((n, i) => n > tile.max[i]))
16388
+ throw new Error("Invalid terrain LOD tile bounds or error");
16389
+ if (!tile.resident) {
16390
+ unavailable.push(tile.id);
16391
+ continue;
16392
+ }
16393
+ const distance = Math.hypot(...position2.map((n, i) => Math.max(tile.min[i] - n, n - tile.max[i], 0)));
16394
+ const pixels = tile.geometricError === 0 ? 0 : tile.geometricError / distance * scale3;
16395
+ const threshold = targetPixels * ((previouslyRefined == null ? void 0 : previouslyRefined.has(tile.id)) ? 1 - hysteresis : 1);
16396
+ if (pixels > threshold && ((_a = tile.children) == null ? void 0 : _a.length) && tile.children.every((child) => child.resident)) {
16397
+ if (pending.length + seen.size + tile.children.length > maxVisited)
16398
+ throw new Error("Terrain LOD visit limit exceeded");
16399
+ refined.add(tile.id);
16400
+ for (let i = tile.children.length - 1; i >= 0; i--)
16401
+ pending.push(tile.children[i]);
16402
+ } else {
16403
+ selected.push({ tile, pixels });
16404
+ }
16405
+ }
16406
+ return { selected, refined, unavailable };
16407
+ }
16408
+
16409
+ // dist/terrain/lod-stitch.js
16410
+ function stitchTerrainLodCut(input, seams) {
16411
+ const meshes = input.slice();
16412
+ const paired = [];
16413
+ for (const { a, edgeA, b, edgeB, options } of seams) {
16414
+ if (a === b || !Number.isInteger(a) || !Number.isInteger(b) || !meshes[a] || !meshes[b])
16415
+ throw new Error("Invalid terrain LOD seam tile index");
16416
+ const result = stitchTerrainMeshEdges(meshes[a], edgeA, meshes[b], edgeB, options);
16417
+ meshes[a] = result.a;
16418
+ meshes[b] = result.b;
16419
+ paired.push({ a, b, idsA: result.seamA, idsB: result.seamB });
16420
+ }
16421
+ for (const { a, b, idsA, idsB } of paired) {
16422
+ const ma = meshes[a], mb = meshes[b];
16423
+ const path = (mesh, ids) => {
16424
+ const links = /* @__PURE__ */ new Set();
16425
+ for (let i = 1; i < ids.length; i++) {
16426
+ links.add(`${Math.min(ids[i - 1], ids[i])},${Math.max(ids[i - 1], ids[i])}`);
16427
+ }
16428
+ for (let i = 0; i < mesh.indices.length; i += 3) {
16429
+ for (let j = 0; j < 3; j++) {
16430
+ const p = mesh.indices[i + j], q = mesh.indices[i + (j + 1) % 3];
16431
+ links.delete(`${Math.min(p, q)},${Math.max(p, q)}`);
16432
+ }
16433
+ }
16434
+ return links.size === 0;
16435
+ };
16436
+ if (!path(ma, idsA) || !path(mb, idsB))
16437
+ throw new Error("Overlapping terrain LOD seam ranges require a common subdivision");
16438
+ for (let i = 0; i < idsA.length; i++) {
16439
+ for (let axis = 0; axis < 3; axis++) {
16440
+ const offset2 = mb.origin[axis] - ma.origin[axis];
16441
+ const av = ma.positions[3 * idsA[i] + axis], bv = mb.positions[3 * idsB[i] + axis];
16442
+ const residual = av - bv - offset2;
16443
+ const roundoff = 8 * Number.EPSILON * (Math.abs(av) + Math.abs(bv) + Math.abs(offset2));
16444
+ if (!Number.isFinite(residual) || Math.abs(residual) > roundoff)
16445
+ throw new Error("Incompatible terrain LOD seam heights or shared corners");
16446
+ }
16447
+ }
16448
+ }
16449
+ return meshes;
16450
+ }
16451
+
16452
+ // dist/terrain/breakline-preprocess.js
16453
+ function splitTerrainBreaklines(input, options = {}) {
16454
+ const { heightTolerance = 1e-8, maxPairTests = 21e5, maxSegments = 2048 } = options;
16455
+ if (!Number.isFinite(heightTolerance) || heightTolerance < 0 || ![maxPairTests, maxSegments].every((n) => Number.isSafeInteger(n) && n >= 0 && n <= 4294967295))
16456
+ throw new Error("Invalid breakline split limits");
16457
+ if (input.length > maxSegments || input.length * (input.length - 1) / 2 > maxPairTests)
16458
+ throw new Error("Breakline preprocessing work limit exceeded");
16459
+ const vertices = /* @__PURE__ */ new Map();
16460
+ const canonical = (p) => {
16461
+ if (!p.every(Number.isFinite))
16462
+ throw new Error("Invalid breakline vertex");
16463
+ const key3 = `${p[0]},${p[1]}`;
16464
+ const prior = vertices.get(key3);
16465
+ if (prior) {
16466
+ if (Math.abs(prior[2] - p[2]) > heightTolerance)
16467
+ throw new Error("Conflicting breakline heights");
16468
+ return prior;
16469
+ }
16470
+ const point2 = [...p];
16471
+ vertices.set(key3, point2);
16472
+ return point2;
16473
+ };
16474
+ const lines = input.map(([a, b]) => {
16475
+ const p = canonical(a), q = canonical(b);
16476
+ if (p === q)
16477
+ throw new Error("Zero-length breakline");
16478
+ const knots = [
16479
+ { t: 0, point: p },
16480
+ { t: 1, point: q }
16481
+ ];
16482
+ return { p, q, dx: q[0] - p[0], dy: q[1] - p[1], knots };
16483
+ });
16484
+ let count = input.length;
16485
+ const add4 = (knots, t, point2) => {
16486
+ if (knots.some((k) => k.point === point2))
16487
+ return;
16488
+ if (knots.some((k) => k.t === t))
16489
+ throw new Error("Unresolved coincident breakline intersections");
16490
+ if (++count > maxSegments)
16491
+ throw new Error("Breakline output limit exceeded");
16492
+ knots.push({ t, point: point2 });
16493
+ };
16494
+ const cross5 = (ax, ay, bx, by) => ax * by - ay * bx;
16495
+ for (let i = 0; i < lines.length; i++) {
16496
+ const a = lines[i];
16497
+ for (let j = i + 1; j < lines.length; j++) {
16498
+ const b = lines[j];
16499
+ const x = b.p[0] - a.p[0], y = b.p[1] - a.p[1];
16500
+ const det = cross5(a.dx, a.dy, b.dx, b.dy);
16501
+ const u = cross5(x, y, a.dx, a.dy), t = cross5(x, y, b.dx, b.dy);
16502
+ if (![det, u, t].every(Number.isFinite))
16503
+ throw new Error("Breakline intersection overflow");
16504
+ if (det === 0) {
16505
+ if (u !== 0 || t !== 0)
16506
+ continue;
16507
+ const axis = Math.abs(a.dx) >= Math.abs(a.dy) ? 0 : 1;
16508
+ if (Math.max(Math.min(a.p[axis], a.q[axis]), Math.min(b.p[axis], b.q[axis])) < Math.min(Math.max(a.p[axis], a.q[axis]), Math.max(b.p[axis], b.q[axis])))
16509
+ throw new Error("Overlapping collinear breaklines");
16510
+ continue;
16511
+ }
16512
+ const fa = t / det, fb = u / det;
16513
+ if (fa < 0 || fa > 1 || fb < 0 || fb > 1)
16514
+ continue;
16515
+ const za = (1 - fa) * a.p[2] + fa * a.q[2], zb = (1 - fb) * b.p[2] + fb * b.q[2];
16516
+ if (!Number.isFinite(za) || !Number.isFinite(zb) || Math.abs(za - zb) > heightTolerance)
16517
+ throw new Error("Conflicting breakline heights at intersection");
16518
+ const point2 = canonical(fa === 0 ? a.p : fa === 1 ? a.q : fb === 0 ? b.p : fb === 1 ? b.q : [a.p[0] + fa * a.dx, a.p[1] + fa * a.dy, za]);
16519
+ add4(a.knots, fa, point2);
16520
+ add4(b.knots, fb, point2);
16521
+ }
16522
+ }
16523
+ const segments = [];
16524
+ const sourceSegments = new Uint32Array(count);
16525
+ for (let i = 0; i < lines.length; i++) {
16526
+ const knots = lines[i].knots.sort((a, b) => a.t - b.t);
16527
+ for (let j = 1; j < knots.length; j++) {
16528
+ sourceSegments[segments.length] = i;
16529
+ segments.push([knots[j - 1].point, knots[j].point]);
16530
+ }
16531
+ }
16532
+ return { segments, sourceSegments };
16533
+ }
16534
+
16535
+ // dist/terrain/valid-domain-regions.js
16536
+ function updateTerrainValidDomainMeshRegions(previous, field, dirty, options) {
16537
+ const { maxError, maxTrianglesPerRegion, maxSampleTestsPerRegion } = options;
16538
+ if (!Number.isFinite(maxError) || maxError < 0)
16539
+ throw new Error("Invalid regional mesh error");
16540
+ for (const limit of [maxTrianglesPerRegion, maxSampleTestsPerRegion]) {
16541
+ if (limit !== void 0 && (!Number.isSafeInteger(limit) || limit < 1))
16542
+ throw new Error("Invalid regional mesh work limit");
16543
+ }
16544
+ const configuration = `valid-domain:${maxError}:${maxTrianglesPerRegion ?? ""}:${maxSampleTestsPerRegion ?? ""}`;
16545
+ return updateMeshRegions(previous, field, dirty, options, configuration, (region) => createValidDomainTerrainMesh(region, {
16546
+ maxError,
16547
+ maxTriangles: maxTrianglesPerRegion,
16548
+ maxSampleTests: maxSampleTestsPerRegion
16549
+ }));
16550
+ }
16551
+
16552
+ // dist/terrain/mesh-coverage.js
16553
+ function gcd(a, b) {
16554
+ if (a < 0n)
16555
+ a = -a;
16556
+ if (b < 0n)
16557
+ b = -b;
16558
+ while (b !== 0n)
16559
+ [a, b] = [b, a % b];
16560
+ return a;
16561
+ }
16562
+ function certifyTerrainMeshCoverage(field, mesh, options = {}) {
16563
+ var _a, _b;
16564
+ const { reference = "triangle", maxTriangles = 2e6 } = options;
16565
+ const referenceMesh = typeof reference === "object" ? reference : null;
16566
+ const validShape = (input) => input.indices.length % 3 === 0 && input.gridCoordinates.length % 2 === 0;
16567
+ if (!Number.isSafeInteger(maxTriangles) || maxTriangles < 1 || !referenceMesh && reference !== "triangle" && reference !== "bilinear" || !validShape(mesh) || referenceMesh && !validShape(referenceMesh))
16568
+ throw new Error("Invalid terrain coverage input");
16569
+ const trianglesVisited = mesh.indices.length / 3 + (referenceMesh ? referenceMesh.indices.length / 3 : 2 * (field.width - 1) * (field.height - 1));
16570
+ if (trianglesVisited > maxTriangles) {
16571
+ return {
16572
+ status: "budget-exhausted",
16573
+ unmatchedSegments: 0,
16574
+ witness: null,
16575
+ trianglesVisited: 0,
16576
+ residualEdges: 0
16577
+ };
16578
+ }
16579
+ const bits2 = new DataView(new ArrayBuffer(8));
16580
+ function exact3(value3) {
16581
+ bits2.setFloat64(0, value3);
16582
+ const raw = bits2.getBigUint64(0);
16583
+ const exponent = Number(raw >> 52n & 2047n);
16584
+ const fraction = raw & (1n << 52n) - 1n;
16585
+ const integer2 = exponent === 0 ? fraction : (1n << 52n | fraction) << BigInt(exponent - 1);
16586
+ return value3 < 0 ? -integer2 : integer2;
16587
+ }
16588
+ const vertices = [];
16589
+ const vertexIds = /* @__PURE__ */ new Map();
16590
+ const edges = /* @__PURE__ */ new Map();
16591
+ function vertex(x, y) {
16592
+ if (!Number.isFinite(x) || !Number.isFinite(y))
16593
+ throw new Error("Nonfinite coverage coordinate");
16594
+ const key3 = `${x},${y}`;
16595
+ const previous = vertexIds.get(key3);
16596
+ if (previous !== void 0)
16597
+ return previous;
16598
+ const id = vertices.length;
16599
+ vertices.push([x, y]);
16600
+ vertexIds.set(key3, id);
16601
+ return id;
16602
+ }
16603
+ function edge2(a, b, weight) {
16604
+ var _a2;
16605
+ if (a > b) {
16606
+ [a, b] = [b, a];
16607
+ weight = -weight;
16608
+ }
16609
+ const key3 = b < 2 ** 26 ? a * 2 ** 26 + b : `${a},${b}`;
16610
+ const sum = (((_a2 = edges.get(key3)) == null ? void 0 : _a2.weight) ?? 0) + weight;
16611
+ if (sum === 0)
16612
+ edges.delete(key3);
16613
+ else
16614
+ edges.set(key3, { a, b, weight: sum });
16615
+ }
16616
+ function triangle(a, b, c, weight) {
16617
+ edge2(a, b, weight);
16618
+ edge2(b, c, weight);
16619
+ edge2(c, a, weight);
16620
+ }
16621
+ function addMesh({ indices, gridCoordinates }, weight) {
16622
+ for (let i = 0; i < indices.length; i += 3) {
16623
+ const ids = [indices[i], indices[i + 1], indices[i + 2]].map((id) => {
16624
+ if (!Number.isSafeInteger(id) || id < 0 || id >= gridCoordinates.length / 2)
16625
+ throw new Error("Invalid coverage vertex index");
16626
+ return vertex(gridCoordinates[id * 2], gridCoordinates[id * 2 + 1]);
16627
+ });
16628
+ const [a, b, c] = ids.map((id) => vertices[id]);
16629
+ const left = (b[0] - a[0]) * (c[1] - a[1]);
16630
+ const right = (b[1] - a[1]) * (c[0] - a[0]);
16631
+ const det = left - right;
16632
+ const limit = 8 * Number.EPSILON * (Math.abs(left) + Math.abs(right)) + 8 * Number.MIN_VALUE;
16633
+ let sign2 = Math.sign(det);
16634
+ if (!Number.isFinite(det) || Math.abs(det) <= limit) {
16635
+ const [ax, ay] = a.map(exact3), [bx, by] = b.map(exact3), [cx, cy] = c.map(exact3);
16636
+ const determinant = (bx - ax) * (cy - ay) - (by - ay) * (cx - ax);
16637
+ sign2 = determinant > 0n ? 1 : determinant < 0n ? -1 : 0;
16638
+ }
16639
+ if (!sign2)
16640
+ throw new Error("Degenerate coverage triangle");
16641
+ triangle(ids[0], ids[1], ids[2], weight * sign2);
16642
+ }
16643
+ }
16644
+ addMesh(mesh, 1);
16645
+ if (referenceMesh)
16646
+ addMesh(referenceMesh, -1);
16647
+ else
16648
+ for (let y = 0; y < field.height - 1; y++) {
16649
+ for (let x = 0; x < field.width - 1; x++) {
16650
+ const valid = [
16651
+ field.getHeight(x, y),
16652
+ field.getHeight(x + 1, y),
16653
+ field.getHeight(x, y + 1),
16654
+ field.getHeight(x + 1, y + 1)
16655
+ ].map((z) => z !== void 0);
16656
+ if (reference === "bilinear" && !valid.every(Boolean))
16657
+ continue;
16658
+ const corners = [
16659
+ [x, y],
16660
+ [x + 1, y],
16661
+ [x, y + 1],
16662
+ [x + 1, y + 1]
16663
+ ];
16664
+ const faces = field.diagonal === "00-11" ? [
16665
+ [0, 1, 3],
16666
+ [0, 3, 2]
16667
+ ] : [
16668
+ [0, 1, 2],
16669
+ [1, 3, 2]
16670
+ ];
16671
+ for (const [a, b, c] of faces) {
16672
+ if (!valid[a] || !valid[b] || !valid[c])
16673
+ continue;
16674
+ triangle(vertex(...corners[a]), vertex(...corners[b]), vertex(...corners[c]), -1);
16675
+ }
16676
+ }
16677
+ }
16678
+ const lines = /* @__PURE__ */ new Map();
16679
+ for (const { a, b, weight } of edges.values()) {
16680
+ const p = vertices[a], q = vertices[b];
16681
+ const [x, y] = p.map(exact3), [u, v] = q.map(exact3);
16682
+ const divisor = gcd(u - x, v - y);
16683
+ let dx = (u - x) / divisor, dy = (v - y) / divisor;
16684
+ if (dx < 0n || dx === 0n && dy < 0n)
16685
+ [dx, dy] = [-dx, -dy];
16686
+ const key3 = `${dx},${dy},${dx * y - dy * x}`;
16687
+ let events = lines.get(key3);
16688
+ if (!events) {
16689
+ events = /* @__PURE__ */ new Map();
16690
+ lines.set(key3, events);
16691
+ }
16692
+ const axis = dx === 0n ? 1 : 0;
16693
+ const delta = weight;
16694
+ events.set(p[axis], { point: p, delta: (((_a = events.get(p[axis])) == null ? void 0 : _a.delta) ?? 0) + delta });
16695
+ events.set(q[axis], { point: q, delta: (((_b = events.get(q[axis])) == null ? void 0 : _b.delta) ?? 0) - delta });
16696
+ }
16697
+ let unmatchedSegments = 0;
16698
+ let witness = null;
16699
+ for (const events of lines.values()) {
16700
+ const sorted = [...events].sort(([a], [b]) => a - b);
16701
+ let jump = 0;
16702
+ for (let i = 0; i + 1 < sorted.length; i++) {
16703
+ jump += sorted[i][1].delta;
16704
+ if (!jump)
16705
+ continue;
16706
+ unmatchedSegments++;
16707
+ witness ?? (witness = { start: sorted[i][1].point, end: sorted[i + 1][1].point, multiplicityJump: jump });
16708
+ }
16709
+ }
16710
+ return {
16711
+ status: unmatchedSegments ? "mismatch" : "certified",
16712
+ unmatchedSegments,
16713
+ witness,
16714
+ trianglesVisited,
16715
+ residualEdges: edges.size
16716
+ };
16717
+ }
15747
16718
  //# sourceMappingURL=index.cjs.map