@loaders.gl/tiles 5.0.0-alpha.13 → 5.0.0-alpha.14

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 (38) hide show
  1. package/dist/dist.dev.js +665 -472
  2. package/dist/dist.min.js +3 -3
  3. package/dist/index.cjs +9 -6
  4. package/dist/index.cjs.map +2 -2
  5. package/dist/mlt/index.cjs +9 -11
  6. package/dist/mlt/index.cjs.map +1 -1
  7. package/dist/mlt/mlt-loader.js +1 -1
  8. package/dist/mlt/mlt-writer.js +1 -1
  9. package/dist/mvt/arrow-table-tile-source-loader-types.js +1 -1
  10. package/dist/mvt/arrow-table-tile-source-loader.cjs +8 -10
  11. package/dist/mvt/arrow-table-tile-source-loader.cjs.map +1 -1
  12. package/dist/mvt/dist.dev.js +15 -20
  13. package/dist/mvt/dist.min.js +19 -19
  14. package/dist/mvt/index.cjs +14 -24
  15. package/dist/mvt/index.cjs.map +3 -3
  16. package/dist/mvt/lib/mvt-worker-transport.d.ts.map +1 -1
  17. package/dist/mvt/lib/mvt-worker-transport.js +1 -1
  18. package/dist/mvt/lib/mvt-worker-transport.js.map +1 -1
  19. package/dist/mvt/map-style-loader.js +1 -1
  20. package/dist/mvt/mvt-geojson-loader-types.js +1 -1
  21. package/dist/mvt/mvt-geojson-loader.cjs +1 -1
  22. package/dist/mvt/mvt-loader.js +1 -1
  23. package/dist/mvt/mvt-writer.js +1 -1
  24. package/dist/mvt/tilejson-loader.js +1 -1
  25. package/dist/mvt-worker-node.js +69 -27
  26. package/dist/mvt-worker-node.js.map +4 -4
  27. package/dist/mvt-worker.js +68 -27
  28. package/dist/pmtiles/dist.dev.js +18 -23
  29. package/dist/pmtiles/dist.min.js +15 -15
  30. package/dist/pmtiles/geoarrow.cjs +7 -9
  31. package/dist/pmtiles/geoarrow.cjs.map +1 -1
  32. package/dist/pmtiles/index.cjs +13 -23
  33. package/dist/pmtiles/index.cjs.map +3 -3
  34. package/dist/pmtiles/lib/version.js +1 -1
  35. package/dist/pmtiles/pmtiles-writer.js +1 -1
  36. package/dist/pmtiles/raster.cjs.map +1 -1
  37. package/package.json +9 -9
  38. package/src/mvt/lib/mvt-worker-transport.ts +5 -2
package/dist/dist.dev.js CHANGED
@@ -741,10 +741,10 @@ var __exports__ = (() => {
741
741
  }
742
742
  }
743
743
  }
744
- function getSourceLocation(source, offset) {
744
+ function getSourceLocation(source, offset2) {
745
745
  let line = 1;
746
746
  let column = 1;
747
- for (let index = 0; index < offset && index < source.length; index++) {
747
+ for (let index = 0; index < offset2 && index < source.length; index++) {
748
748
  if (source[index] === "\n") {
749
749
  line++;
750
750
  column = 1;
@@ -759,11 +759,11 @@ var __exports__ = (() => {
759
759
  "../../node_modules/@math.gl/geospatial/dist/crs/wkt-crs.js"() {
760
760
  WKTCRSSyntaxError = class extends SyntaxError {
761
761
  /** Create a WKT syntax error at a source location. */
762
- constructor(message, source, offset) {
763
- const location = getSourceLocation(source, offset);
762
+ constructor(message, source, offset2) {
763
+ const location = getSourceLocation(source, offset2);
764
764
  super(`${message} at ${location.line}:${location.column}`);
765
765
  this.name = "WKTCRSSyntaxError";
766
- this.offset = offset;
766
+ this.offset = offset2;
767
767
  this.line = location.line;
768
768
  this.column = location.column;
769
769
  }
@@ -1080,85 +1080,85 @@ var __exports__ = (() => {
1080
1080
  const parameters = tokens.map((token) => parseParameter(token.raw, token.offset, text));
1081
1081
  return { type: "proj-string", parameters };
1082
1082
  }
1083
- function parseParameter(rawToken, offset, source) {
1083
+ function parseParameter(rawToken, offset2, source) {
1084
1084
  const token = rawToken.startsWith("+") ? rawToken.slice(1) : rawToken;
1085
1085
  if (!token) {
1086
- throw new PROJStringSyntaxError("Expected a parameter after '+'", source, offset);
1086
+ throw new PROJStringSyntaxError("Expected a parameter after '+'", source, offset2);
1087
1087
  }
1088
1088
  const equalsIndex = token.indexOf("=");
1089
1089
  const name = equalsIndex < 0 ? token : token.slice(0, equalsIndex);
1090
1090
  if (!name || /[\s+=]/.test(name)) {
1091
- throw new PROJStringSyntaxError(`Invalid PROJ parameter name '${name}'`, source, offset);
1091
+ throw new PROJStringSyntaxError(`Invalid PROJ parameter name '${name}'`, source, offset2);
1092
1092
  }
1093
1093
  if (equalsIndex < 0) {
1094
1094
  return { type: "parameter", name };
1095
1095
  }
1096
1096
  const rawValue = token.slice(equalsIndex + 1);
1097
- const value = decodeParameterValue(rawValue, source, offset + equalsIndex + 1);
1097
+ const value = decodeParameterValue(rawValue, source, offset2 + equalsIndex + 1);
1098
1098
  return { type: "parameter", name, value, rawValue };
1099
1099
  }
1100
1100
  function tokenizePROJString(source) {
1101
1101
  const tokens = [];
1102
- let offset = 0;
1103
- while (offset < source.length) {
1104
- while (offset < source.length && /\s/.test(source[offset])) {
1105
- offset++;
1102
+ let offset2 = 0;
1103
+ while (offset2 < source.length) {
1104
+ while (offset2 < source.length && /\s/.test(source[offset2])) {
1105
+ offset2++;
1106
1106
  }
1107
- if (offset >= source.length) {
1107
+ if (offset2 >= source.length) {
1108
1108
  break;
1109
1109
  }
1110
- const start = offset;
1110
+ const start = offset2;
1111
1111
  let quote = null;
1112
1112
  let escaped = false;
1113
- while (offset < source.length) {
1114
- const character = source[offset];
1113
+ while (offset2 < source.length) {
1114
+ const character = source[offset2];
1115
1115
  if (escaped) {
1116
1116
  escaped = false;
1117
- offset++;
1117
+ offset2++;
1118
1118
  continue;
1119
1119
  }
1120
1120
  if (character === "\\" && quote) {
1121
1121
  escaped = true;
1122
- offset++;
1122
+ offset2++;
1123
1123
  continue;
1124
1124
  }
1125
1125
  if (quote) {
1126
1126
  if (character === quote) {
1127
1127
  quote = null;
1128
1128
  }
1129
- offset++;
1129
+ offset2++;
1130
1130
  continue;
1131
1131
  }
1132
- if ((character === '"' || character === "'") && source[offset - 1] === "=") {
1132
+ if ((character === '"' || character === "'") && source[offset2 - 1] === "=") {
1133
1133
  quote = character;
1134
- offset++;
1134
+ offset2++;
1135
1135
  continue;
1136
1136
  }
1137
1137
  if (/\s/.test(character)) {
1138
1138
  break;
1139
1139
  }
1140
- offset++;
1140
+ offset2++;
1141
1141
  }
1142
1142
  if (quote) {
1143
1143
  throw new PROJStringSyntaxError("Unterminated quoted PROJ value", source, start);
1144
1144
  }
1145
- tokens.push({ raw: source.slice(start, offset), offset: start });
1145
+ tokens.push({ raw: source.slice(start, offset2), offset: start });
1146
1146
  }
1147
1147
  return tokens;
1148
1148
  }
1149
- function decodeParameterValue(rawValue, source, offset) {
1149
+ function decodeParameterValue(rawValue, source, offset2) {
1150
1150
  if (!rawValue) {
1151
1151
  return "";
1152
1152
  }
1153
1153
  const first = rawValue[0];
1154
1154
  if (first !== '"' && first !== "'") {
1155
1155
  if ((rawValue.includes('"') || rawValue.includes("'")) && !DMS_VALUE.test(rawValue)) {
1156
- throw new PROJStringSyntaxError("Quote must begin a PROJ parameter value", source, offset);
1156
+ throw new PROJStringSyntaxError("Quote must begin a PROJ parameter value", source, offset2);
1157
1157
  }
1158
1158
  return rawValue;
1159
1159
  }
1160
1160
  if (rawValue[rawValue.length - 1] !== first) {
1161
- throw new PROJStringSyntaxError("Unterminated quoted PROJ value", source, offset);
1161
+ throw new PROJStringSyntaxError("Unterminated quoted PROJ value", source, offset2);
1162
1162
  }
1163
1163
  let value = "";
1164
1164
  for (let index = 1; index < rawValue.length - 1; index++) {
@@ -1171,10 +1171,10 @@ var __exports__ = (() => {
1171
1171
  }
1172
1172
  return value;
1173
1173
  }
1174
- function getSourceLocation2(source, offset) {
1174
+ function getSourceLocation2(source, offset2) {
1175
1175
  let line = 1;
1176
1176
  let column = 1;
1177
- for (let index = 0; index < offset && index < source.length; index++) {
1177
+ for (let index = 0; index < offset2 && index < source.length; index++) {
1178
1178
  if (source[index] === "\n") {
1179
1179
  line++;
1180
1180
  column = 1;
@@ -1189,11 +1189,11 @@ var __exports__ = (() => {
1189
1189
  "../../node_modules/@math.gl/geospatial/dist/crs/proj-string.js"() {
1190
1190
  PROJStringSyntaxError = class extends SyntaxError {
1191
1191
  /** Create a PROJ string syntax error at a source location. */
1192
- constructor(message, source, offset) {
1193
- const location = getSourceLocation2(source, offset);
1192
+ constructor(message, source, offset2) {
1193
+ const location = getSourceLocation2(source, offset2);
1194
1194
  super(`${message} at ${location.line}:${location.column}`);
1195
1195
  this.name = "PROJStringSyntaxError";
1196
- this.offset = offset;
1196
+ this.offset = offset2;
1197
1197
  this.line = location.line;
1198
1198
  this.column = location.column;
1199
1199
  }
@@ -1379,15 +1379,15 @@ var __exports__ = (() => {
1379
1379
  clone() {
1380
1380
  return new this.constructor().copy(this);
1381
1381
  }
1382
- fromArray(array, offset = 0) {
1382
+ fromArray(array, offset2 = 0) {
1383
1383
  for (let i = 0; i < this.ELEMENTS; ++i) {
1384
- this[i] = array[i + offset];
1384
+ this[i] = array[i + offset2];
1385
1385
  }
1386
1386
  return this.check();
1387
1387
  }
1388
- toArray(targetArray = [], offset = 0) {
1388
+ toArray(targetArray = [], offset2 = 0) {
1389
1389
  for (let i = 0; i < this.ELEMENTS; ++i) {
1390
- targetArray[offset + i] = this[i];
1390
+ targetArray[offset2 + i] = this[i];
1391
1391
  }
1392
1392
  return targetArray;
1393
1393
  }
@@ -3815,19 +3815,19 @@ var __exports__ = (() => {
3815
3815
  slerp(arg0, arg1, arg2) {
3816
3816
  let start;
3817
3817
  let target;
3818
- let ratio;
3818
+ let ratio2;
3819
3819
  switch (arguments.length) {
3820
3820
  case 2:
3821
3821
  start = this;
3822
3822
  target = arg0;
3823
- ratio = arg1;
3823
+ ratio2 = arg1;
3824
3824
  break;
3825
3825
  default:
3826
3826
  start = arg0;
3827
3827
  target = arg1;
3828
- ratio = arg2;
3828
+ ratio2 = arg2;
3829
3829
  }
3830
- slerp(this, start, target, ratio);
3830
+ slerp(this, start, target, ratio2);
3831
3831
  return this.check();
3832
3832
  }
3833
3833
  // THREE.js Math API compatibility
@@ -3863,29 +3863,30 @@ var __exports__ = (() => {
3863
3863
  function spheroidToCartesian(point, geometry, result = point) {
3864
3864
  const longitude = point.x, latitude = point.y, height = point.z;
3865
3865
  const { semiMajorAxis: a, semiMinorAxis: b, eccentricitySquared: es } = geometry;
3866
- const sin = Math.sin(latitude), cos = Math.cos(latitude);
3867
- const ratio = b / a;
3868
- const radius = es < 0.9 ? a / Math.sqrt(1 - es * sin * sin) : a / Math.hypot(cos, ratio * sin);
3866
+ const sin = Math.sin(latitude), cos = Math.abs(latitude) === Math.PI / 2 ? 0 : Math.cos(latitude);
3867
+ const ratio2 = b / a;
3868
+ const radius = es < 0.9 ? a / Math.sqrt(1 - es * sin * sin) : a / Math.hypot(cos, ratio2 * sin);
3869
3869
  const x = (radius + height) * cos * Math.cos(longitude);
3870
3870
  const y = (radius + height) * cos * Math.sin(longitude);
3871
- const z = (radius * (es < 0.9 ? 1 - es : ratio * ratio) + height) * sin;
3871
+ const z = (radius * (es < 0.9 ? 1 - es : ratio2 * ratio2) + height) * sin;
3872
3872
  return commit(result, x, y, z);
3873
3873
  }
3874
3874
  function cartesianToSpheroid(point, geometry, result = point) {
3875
3875
  const x = point.x, y = point.y, z = point.z;
3876
3876
  const { semiMajorAxis: a, semiMinorAxis: b, eccentricitySquared: es } = geometry;
3877
+ const longitude = Math.atan2(y, x);
3877
3878
  const p = Math.hypot(x, y), rr = Math.hypot(x, y, z);
3878
3879
  if (!(rr > 0) || !Number.isFinite(rr))
3879
3880
  return false;
3880
3881
  if (es === 0)
3881
- return commit(result, p === 0 ? 0 : Math.atan2(y, x), Math.atan2(z, p), rr - a);
3882
+ return commit(result, p === 0 ? 0 : longitude, Math.atan2(z, p), rr - a);
3882
3883
  if (p === 0)
3883
3884
  return commit(result, 0, Math.sign(z) * Math.PI / 2, Math.abs(z) - b);
3884
3885
  const horizontal = p / a, vertical = z / b;
3885
- if (horizontal * horizontal + vertical * vertical < 1 - 16 * Number.EPSILON)
3886
+ if (horizontal * horizontal + vertical * vertical < 1 - 16 * EPSILON21)
3886
3887
  return interiorInverse(x, y, z, p, a, b, result);
3887
3888
  if (es >= 0.9)
3888
- return exteriorInverse(x, y, z, p, a, b, result);
3889
+ return interiorInverse(x, y, z, p, a, b, result);
3889
3890
  const ct = z / rr, st = p / rr;
3890
3891
  let rx = 1 / Math.sqrt(1 - es * (2 - es) * st * st);
3891
3892
  let cos = st * (1 - es) * rx, sin = ct * rx;
@@ -3896,64 +3897,65 @@ var __exports__ = (() => {
3896
3897
  rx = 1 / Math.sqrt(1 - rk * (2 - rk) * st * st);
3897
3898
  const nextCos = st * (1 - rk) * rx, nextSin = ct * rx;
3898
3899
  if (Math.abs(nextSin * cos - nextCos * sin) <= 1e-12) {
3899
- if (!Number.isFinite(height) || !Number.isFinite(nextSin) || !Number.isFinite(nextCos))
3900
+ if (!Number.isFinite(height))
3900
3901
  break;
3901
- return commit(result, Math.atan2(y, x), Math.atan2(nextSin, Math.abs(nextCos)), height);
3902
+ return commit(result, longitude, Math.atan2(nextSin, Math.abs(nextCos)), height);
3902
3903
  }
3903
3904
  cos = nextCos;
3904
3905
  sin = nextSin;
3905
3906
  }
3906
- return exteriorInverse(x, y, z, p, a, b, result);
3907
+ return interiorInverse(x, y, z, p, a, b, result);
3907
3908
  }
3908
3909
  function interiorInverse(x, y, z, p, a, b, result) {
3909
- const ratio = b / a, ratio2 = ratio * ratio;
3910
- const horizontal = p / a, vertical = z / a, delta = 1 - ratio2;
3911
- if (!(ratio2 > 0) || ratio > 1)
3910
+ const longitude = Math.atan2(y, x);
3911
+ const ratio2 = b / a, ratio22 = ratio2 * ratio2;
3912
+ const horizontal = p / a, vertical = z / a, delta = 1 - ratio22;
3913
+ if (!(ratio22 > 0) || ratio2 > 1)
3912
3914
  return false;
3913
- if (z === 0) {
3914
- if (horizontal < delta)
3915
- return false;
3916
- return commit(result, Math.atan2(y, x), 0, p - a);
3917
- }
3918
3915
  const aa = a * a, bb = b * b;
3919
- const ratioError = Number.isFinite(aa) && aa > 0 ? (bb - ratio2 * aa + productError(b, b, bb) - ratio2 * productError(a, a, aa) - productError(ratio2, aa, ratio2 * aa)) / aa : 0;
3916
+ const ratioError = Number.isFinite(aa) && aa > 0 ? (bb - ratio22 * aa + productError(b, b, bb) - ratio22 * productError(a, a, aa) - productError(ratio22, aa, ratio22 * aa)) / aa : 0;
3920
3917
  const pp = p * p, xx = x * x, yy = y * y, sum = xx + yy;
3921
3918
  const radiusError = Number.isFinite(pp) && pp > 0 ? (sum - pp + sumError(xx, yy, sum) + productError(x, x, xx) + productError(y, y, yy) - productError(p, p, pp)) / (2 * p) : 0;
3922
- const shift = a * ratio2, base = p - a + shift;
3923
- const correction = radiusError + sumError(p - a, shift, base) + productError(a, ratio2, shift) + a * ratioError;
3924
- const weighted = Math.abs(vertical) * ratio;
3925
- if (!(weighted > 0))
3919
+ const shift = a * ratio22, distance = p - a, base = distance + shift;
3920
+ const correction = radiusError + sumError(p, -a, distance) + sumError(distance, shift, base) + productError(a, ratio22, shift) + a * ratioError;
3921
+ if (z === 0) {
3922
+ if (base + correction < 0)
3923
+ return false;
3924
+ return commit(result, longitude, 0, distance);
3925
+ }
3926
+ const weighted = Math.abs(vertical) * ratio2;
3927
+ let lower = 0, upper = ratio22 + Math.hypot(horizontal, vertical * ratio2);
3928
+ if (!Number.isFinite(upper))
3926
3929
  return false;
3927
- let lower = 0, upper = ratio2;
3928
3930
  let t = Math.max(weighted, horizontal - delta);
3929
3931
  if (!(t > lower && t < upper))
3930
3932
  t = upper / 2;
3931
- for (let i = 0; i < 128; i++) {
3933
+ const gap = -(base + correction) / a;
3934
+ const limiting = Math.sqrt(gap * (horizontal + delta)) / delta;
3935
+ let latitude = gap > 0 && Math.abs(z) / limiting / a * ratio2 <= EPSILON21 * gap ? Math.atan2(Math.sign(z) * limiting / ratio2, horizontal / delta) : void 0;
3936
+ for (let i = 0; i < 1024 && latitude === void 0; i++) {
3932
3937
  const equatorial = delta + t;
3933
- const u = horizontal / equatorial, v = weighted / t;
3938
+ const u = horizontal / equatorial, verticalAt = z / t / a, v = verticalAt * ratio2;
3934
3939
  const at = a * t, difference = base - at;
3935
- const offset = (difference + (sumError(base, -at, difference) + correction - productError(a, t, at))) / (a * equatorial);
3936
- const term = offset * (u + 1);
3940
+ const offset2 = (difference + (sumError(base, -at, difference) + correction - productError(a, t, at))) / (a * equatorial);
3941
+ const term = offset2 * (u + 1);
3937
3942
  const residual = term + v * v;
3938
- if (Math.abs(residual) <= 4 * Number.EPSILON * (Math.abs(term) + v * v) || upper - lower <= 4 * Number.EPSILON * t) {
3939
- const latitude = Math.atan2(vertical / t, horizontal / equatorial);
3940
- const sin = Math.sin(latitude), cos = Math.cos(latitude);
3941
- return commit(result, Math.atan2(y, x), latitude, p * cos + z * sin - a * Math.hypot(cos, ratio * sin));
3942
- }
3943
+ if (!Number.isFinite(residual))
3944
+ return false;
3943
3945
  if (residual > 0)
3944
3946
  lower = t;
3945
3947
  else
3946
3948
  upper = t;
3947
3949
  const derivative = -2 * (u * u / equatorial + v * v / t);
3948
3950
  const next = t - residual / derivative;
3949
- const candidate = Number.isFinite(next) && next > lower && next < upper ? next : lower + (upper - lower) / 2;
3950
- if (candidate === t) {
3951
- const latitude = Math.atan2(vertical / t, horizontal / equatorial);
3952
- return commit(result, Math.atan2(y, x), latitude, p * Math.cos(latitude) + z * Math.sin(latitude) - a * Math.hypot(Math.cos(latitude), ratio * Math.sin(latitude)));
3951
+ const candidate = next > lower && next < upper ? next : lower + (upper - lower) / 2;
3952
+ if (Math.abs(residual) <= 4 * EPSILON21 * (Math.abs(term) + v * v) || upper - lower <= 4 * EPSILON21 * t) {
3953
+ latitude = Math.atan2(verticalAt, u);
3954
+ break;
3953
3955
  }
3954
3956
  t = candidate;
3955
3957
  }
3956
- return false;
3958
+ return latitude !== void 0 && commitNormal(result, longitude, latitude, p, z, a, ratio2);
3957
3959
  }
3958
3960
  function sumError(x, y, sum) {
3959
3961
  const part = sum - x;
@@ -3966,35 +3968,9 @@ var __exports__ = (() => {
3966
3968
  const hx = sx - (sx - x), hy = sy - (sy - y), lx = x - hx, ly = y - hy;
3967
3969
  return hx * hy - product + hx * ly + lx * hy + lx * ly;
3968
3970
  }
3969
- function exteriorInverse(x, y, z, p, a, b, result) {
3970
- const ratio = b / a, ratio2 = ratio * ratio, horizontal = p / a, vertical = z / a;
3971
- const norm = Math.hypot(horizontal, z / b);
3972
- if (!Number.isFinite(norm) || norm < 1 - 8 * Number.EPSILON || !(ratio2 > 0))
3973
- return false;
3974
- let lower = 0, upper = Math.hypot(horizontal, vertical * ratio);
3975
- if (!Number.isFinite(upper))
3976
- return false;
3977
- let multiplier = norm <= 1 + 8 * Number.EPSILON ? 0 : upper / 2;
3978
- for (let i = 0; i < 96; i++) {
3979
- const equatorial = 1 + multiplier, polar = ratio2 + multiplier;
3980
- const u = horizontal / equatorial, v = vertical * ratio / polar;
3981
- const length4 = Math.hypot(u, v);
3982
- const residual = length4 - 1;
3983
- if (Math.abs(residual) <= 4 * Number.EPSILON) {
3984
- const latitude = Math.atan2(vertical / polar, horizontal / equatorial);
3985
- const sin = Math.sin(latitude), cos = Math.cos(latitude);
3986
- const height = p * cos + z * sin - a * Math.hypot(cos, ratio * sin);
3987
- return commit(result, Math.atan2(y, x), latitude, height);
3988
- }
3989
- if (residual > 0)
3990
- lower = multiplier;
3991
- else
3992
- upper = multiplier;
3993
- const derivative = -(u * u / equatorial + v * v / polar) / length4;
3994
- const next = multiplier - residual / derivative;
3995
- multiplier = Number.isFinite(next) && next > lower && next < upper ? next : (lower + upper) / 2;
3996
- }
3997
- return false;
3971
+ function commitNormal(result, longitude, latitude, p, z, a, ratio2) {
3972
+ const sin = Math.sin(latitude), cos = Math.cos(latitude);
3973
+ return commit(result, longitude, latitude, p * cos + z * sin - a * Math.hypot(cos, ratio2 * sin));
3998
3974
  }
3999
3975
  function commit(result, x, y, z) {
4000
3976
  if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z))
@@ -4004,15 +3980,10 @@ var __exports__ = (() => {
4004
3980
  result.z = z;
4005
3981
  return true;
4006
3982
  }
3983
+ var EPSILON21;
4007
3984
  var init_spheroid = __esm({
4008
3985
  "../../node_modules/@math.gl/core/dist/spheroid.js"() {
4009
- }
4010
- });
4011
-
4012
- // ../../node_modules/@math.gl/core/dist/vec3.js
4013
- var init_vec32 = __esm({
4014
- "../../node_modules/@math.gl/core/dist/vec3.js"() {
4015
- init_vec3();
3986
+ EPSILON21 = Number.EPSILON;
4016
3987
  }
4017
3988
  });
4018
3989
 
@@ -4092,298 +4063,222 @@ var __exports__ = (() => {
4092
4063
  }
4093
4064
  });
4094
4065
 
4095
- // ../../node_modules/@math.gl/core/dist/local-frame.js
4096
- function createLocalFrameBasis() {
4097
- return { eastX: 0, eastY: 1, northZ: 1, upX: 1, upY: 0, upZ: 0 };
4098
- }
4099
- function eastNorthUpBasisFromDirections(east, up, result) {
4100
- const ex = east.x, ey = east.y, ez = east.z;
4101
- const ux = up.x, uy = up.y, uz = up.z;
4102
- if (ez !== 0)
4103
- return false;
4104
- return commitBasis(result, ex, ey, ux * ey - uy * ex, ux, uy, uz);
4105
- }
4106
- function localFrameToMatrix(basis, origin, firstAxis, secondAxis, thirdAxis, result) {
4107
- const first = axisCode(firstAxis), second = axisCode(secondAxis), third = axisCode(thirdAxis);
4108
- const a = Math.abs(first), b = Math.abs(second), c = Math.abs(third);
4109
- if (!a || !b || !c || a === b || a === c || b === c)
4110
- return false;
4111
- const parity = a % 3 + 1 === b ? 1 : -1;
4112
- if (parity * Math.sign(first * second * third) !== 1 || !Array.isArray(result) && result.length < 16)
4113
- return false;
4114
- const ex = basis.eastX, ey = basis.eastY, nz = basis.northZ;
4115
- const ux = basis.upX, uy = basis.upY, uz = basis.upZ;
4116
- const nx = -uz * ey, ny = uz * ex;
4117
- const x = origin.x, y = origin.y, z = origin.z;
4118
- const ax = (a === 1 ? ex : a === 2 ? nx : ux) * Math.sign(first);
4119
- const ay = (a === 1 ? ey : a === 2 ? ny : uy) * Math.sign(first);
4120
- const az = (a === 1 ? 0 : a === 2 ? nz : uz) * Math.sign(first);
4121
- const bx = (b === 1 ? ex : b === 2 ? nx : ux) * Math.sign(second);
4122
- const by = (b === 1 ? ey : b === 2 ? ny : uy) * Math.sign(second);
4123
- const bz = (b === 1 ? 0 : b === 2 ? nz : uz) * Math.sign(second);
4124
- const cx = (c === 1 ? ex : c === 2 ? nx : ux) * Math.sign(third);
4125
- const cy = (c === 1 ? ey : c === 2 ? ny : uy) * Math.sign(third);
4126
- const cz = (c === 1 ? 0 : c === 2 ? nz : uz) * Math.sign(third);
4127
- if (!Number.isFinite(ax) || !Number.isFinite(ay) || !Number.isFinite(az) || !Number.isFinite(bx) || !Number.isFinite(by) || !Number.isFinite(bz) || !Number.isFinite(cx) || !Number.isFinite(cy) || !Number.isFinite(cz) || !Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z))
4128
- return false;
4129
- if (result instanceof Float32Array && (!Number.isFinite(Math.fround(ax)) || !Number.isFinite(Math.fround(ay)) || !Number.isFinite(Math.fround(az)) || !Number.isFinite(Math.fround(bx)) || !Number.isFinite(Math.fround(by)) || !Number.isFinite(Math.fround(bz)) || !Number.isFinite(Math.fround(cx)) || !Number.isFinite(Math.fround(cy)) || !Number.isFinite(Math.fround(cz)) || !Number.isFinite(Math.fround(x)) || !Number.isFinite(Math.fround(y)) || !Number.isFinite(Math.fround(z))))
4066
+ // ../../node_modules/@math.gl/geospatial/dist/ellipsoid-helpers/exact-nearest-surface.js
4067
+ function exactNearestSurface(x, y, z, a, b, c, result) {
4068
+ const values = [a, b, c, Math.abs(x), Math.abs(y), Math.abs(z)];
4069
+ const parts = values.map((value) => {
4070
+ const bits = value.toString(2);
4071
+ const dot4 = bits.indexOf(".");
4072
+ return {
4073
+ integer: BigInt("0b" + bits.replace(".", "")),
4074
+ exponent: dot4 < 0 ? 0 : dot4 + 1 - bits.length
4075
+ };
4076
+ });
4077
+ const exponent = Math.min(...parts.filter((p) => p.integer !== 0n).map((p) => p.exponent));
4078
+ const integers = parts.map((p) => p.integer << BigInt(p.exponent - exponent));
4079
+ const squares = integers.slice(0, 3).map((v) => v * v);
4080
+ const minimum = squares.reduce((p, v) => p < v ? p : v);
4081
+ const offsets = squares.map((v) => v - minimum);
4082
+ const products = squares.map((_, i) => integers[i] * integers[i + 3]);
4083
+ let precision = 64;
4084
+ if (!products.some((u3, i) => offsets[i] === 0n && u3 !== 0n)) {
4085
+ let numerator = -1n, denominator = 1n;
4086
+ for (let i = 0; i < 3; i++) {
4087
+ if (offsets[i] === 0n)
4088
+ continue;
4089
+ const d2 = offsets[i] * offsets[i];
4090
+ numerator = numerator * d2 + products[i] * products[i] * denominator;
4091
+ denominator *= d2;
4092
+ }
4093
+ if (numerator < 0n)
4094
+ return false;
4095
+ if (numerator === 0n) {
4096
+ return commit2(0n, 1n);
4097
+ }
4098
+ const positive = offsets.filter((d2) => d2 > 0n);
4099
+ const least = positive.reduce((p, v) => p < v ? p : v);
4100
+ precision = Math.max(64, (2n * (denominator + numerator)).toString(2).length - (numerator * least).toString(2).length + 128);
4101
+ }
4102
+ const unit = 1n << BigInt(precision);
4103
+ const d = offsets.map((v) => v * unit);
4104
+ const u = products.map((v) => v * unit);
4105
+ const u2 = u.map((v) => v * v);
4106
+ let lower = 0n, upper = u.reduce((sum, v) => sum + v, 0n);
4107
+ if (upper === 0n)
4130
4108
  return false;
4131
- result[0] = ax;
4132
- result[1] = ay;
4133
- result[2] = az;
4134
- result[3] = 0;
4135
- result[4] = bx;
4136
- result[5] = by;
4137
- result[6] = bz;
4138
- result[7] = 0;
4139
- result[8] = cx;
4140
- result[9] = cy;
4141
- result[10] = cz;
4142
- result[11] = 0;
4143
- result[12] = x;
4144
- result[13] = y;
4145
- result[14] = z;
4146
- result[15] = 1;
4147
- return true;
4148
- }
4149
- function axisCode(axis) {
4150
- switch (axis) {
4151
- case "east":
4152
- return 1;
4153
- case "west":
4154
- return -1;
4155
- case "north":
4156
- return 2;
4157
- case "south":
4158
- return -2;
4159
- case "up":
4160
- return 3;
4161
- case "down":
4162
- return -3;
4163
- default:
4164
- return 0;
4109
+ for (let iteration = 0; iteration < 4096; iteration++) {
4110
+ const t = lower + upper >> 1n;
4111
+ if (t === lower)
4112
+ return false;
4113
+ const dx = d[0] + t, dy = d[1] + t, dz = d[2] + t;
4114
+ const xx = dx * dx, yy = dy * dy, zz = dz * dz;
4115
+ const sign = u2[0] * yy * zz + u2[1] * xx * zz + u2[2] * xx * yy - xx * yy * zz;
4116
+ if (sign === 0n)
4117
+ return commit2(t, unit);
4118
+ if (sign > 0n)
4119
+ lower = t;
4120
+ else
4121
+ upper = t;
4122
+ if (lower > 0n && upper - lower <= lower >> 60n)
4123
+ return commit2(lower + upper >> 1n, unit);
4124
+ }
4125
+ return false;
4126
+ function commit2(t, unit2) {
4127
+ const output = squares.map((r2, i) => {
4128
+ const denominator = offsets[i] * unit2 + t;
4129
+ return denominator === 0n ? 0 : ratio(r2 * integers[i + 3] * unit2, denominator, exponent);
4130
+ });
4131
+ if (!output.every(Number.isFinite))
4132
+ return false;
4133
+ const qx = Math.sign(x) * output[0], qy = Math.sign(y) * output[1], qz = Math.sign(z) * output[2];
4134
+ result.x = qx;
4135
+ result.y = qy;
4136
+ result.z = qz;
4137
+ return true;
4165
4138
  }
4166
4139
  }
4167
- function commitBasis(result, ex, ey, nz, ux, uy, uz) {
4168
- if (!Number.isFinite(ex) || !Number.isFinite(ey) || !Number.isFinite(nz) || !Number.isFinite(ux) || !Number.isFinite(uy) || !Number.isFinite(uz))
4169
- return false;
4170
- result.eastX = ex;
4171
- result.eastY = ey;
4172
- result.northZ = nz;
4173
- result.upX = ux;
4174
- result.upY = uy;
4175
- result.upZ = uz;
4176
- return true;
4177
- }
4178
- var init_local_frame = __esm({
4179
- "../../node_modules/@math.gl/core/dist/local-frame.js"() {
4140
+ function ratio(n, d, exponent) {
4141
+ if (n === 0n)
4142
+ return 0;
4143
+ const shift = 52 - (n.toString(2).length - d.toString(2).length);
4144
+ const numerator = shift >= 0 ? n << BigInt(shift) : n;
4145
+ const denominator = shift >= 0 ? d : d << BigInt(-shift);
4146
+ let quotient = numerator / denominator;
4147
+ const remainder = numerator % denominator;
4148
+ if (2n * remainder > denominator || 2n * remainder === denominator && quotient & 1n)
4149
+ quotient++;
4150
+ const power = exponent - shift;
4151
+ const first = Math.max(-1022, Math.min(1023, power));
4152
+ return Number(quotient) * 2 ** first * 2 ** (power - first);
4153
+ }
4154
+ var init_exact_nearest_surface = __esm({
4155
+ "../../node_modules/@math.gl/geospatial/dist/ellipsoid-helpers/exact-nearest-surface.js"() {
4180
4156
  }
4181
4157
  });
4182
4158
 
4183
- // ../../node_modules/@math.gl/geospatial/dist/ellipsoid-helpers/ellipsoid-transform.js
4184
- function localFrameToFixedFrame(ellipsoid, firstAxis, secondAxis, thirdAxis, cartesianOrigin, result) {
4185
- const thirdAxisInferred = VECTOR_PRODUCT_LOCAL_FRAME[firstAxis] && VECTOR_PRODUCT_LOCAL_FRAME[firstAxis][secondAxis];
4186
- assert2(thirdAxisInferred && (!thirdAxis || thirdAxis === thirdAxisInferred));
4187
- let firstAxisVector;
4188
- let secondAxisVector;
4189
- let thirdAxisVector;
4190
- const origin = scratchOrigin.copy(cartesianOrigin);
4191
- const atPole = equals(origin.x, 0, EPSILON142) && equals(origin.y, 0, EPSILON142);
4192
- const radii = ellipsoid.radii;
4193
- if (radii.x === radii.y && radii.x > 0 && radii.z > 0 && radii.z <= radii.x && (!atPole || origin.z !== 0)) {
4194
- const { east, up } = scratchAxisVectors;
4195
- if (atPole) {
4196
- east.set(0, 1, 0);
4197
- up.set(0, 0, Math.sign(origin.z));
4159
+ // ../../node_modules/@math.gl/geospatial/dist/ellipsoid-helpers/nearest-surface.js
4160
+ function nearestSurface(x, y, z, a, b, c, result) {
4161
+ const minimum = Math.min(a, b, c);
4162
+ const minimumSquared = minimum * minimum;
4163
+ const aa = a * a, bb = b * b, cc = c * c;
4164
+ if (!(minimum > 0) || !(minimumSquared > 0) || !Number.isFinite(Math.max(aa, bb, cc)))
4165
+ return false;
4166
+ const minimumError = productError2(minimum, minimum, minimumSquared);
4167
+ const dx = aa - minimumSquared, dy = bb - minimumSquared, dz = cc - minimumSquared;
4168
+ const ex = sumError2(aa, -minimumSquared, dx) + productError2(a, a, aa) - minimumError;
4169
+ const ey = sumError2(bb, -minimumSquared, dy) + productError2(b, b, bb) - minimumError;
4170
+ const ez = sumError2(cc, -minimumSquared, dz) + productError2(c, c, cc) - minimumError;
4171
+ const ux = a * Math.abs(x), uy = b * Math.abs(y), uz = c * Math.abs(z);
4172
+ if (minimumSquared < 2 ** -1022 || x !== 0 && ux < 2 ** -1022 || y !== 0 && uy < 2 ** -1022 || z !== 0 && uz < 2 ** -1022)
4173
+ return exactNearestSurface(x, y, z, a, b, c, result);
4174
+ const fx = productError2(a, Math.abs(x), ux);
4175
+ const fy = productError2(b, Math.abs(y), uy);
4176
+ const fz = productError2(c, Math.abs(z), uz);
4177
+ const limit = Math.hypot(dx === 0 ? ux === 0 ? 0 : Infinity : ux / (dx + ex), dy === 0 ? uy === 0 ? 0 : Infinity : uy / (dy + ey), dz === 0 ? uz === 0 ? 0 : Infinity : uz / (dz + ez));
4178
+ if (limit <= 1 + 64 * Number.EPSILON)
4179
+ return exactNearestSurface(x, y, z, a, b, c, result);
4180
+ if ((x !== 0 ? 1 : 0) + (y !== 0 ? 1 : 0) + (z !== 0 ? 1 : 0) === 1) {
4181
+ result.x = x === 0 ? x : Math.sign(x) * a;
4182
+ result.y = y === 0 ? y : Math.sign(y) * b;
4183
+ result.z = z === 0 ? z : Math.sign(z) * c;
4184
+ return true;
4185
+ }
4186
+ let lower = Math.hypot(dx === 0 ? ux : 0, dy === 0 ? uy : 0, dz === 0 ? uz : 0);
4187
+ let upper = Math.hypot(ux, uy, uz);
4188
+ if (!(upper > 0) || !Number.isFinite(upper))
4189
+ return exactNearestSurface(x, y, z, a, b, c, result);
4190
+ let t = lower > 0 ? lower : upper;
4191
+ for (let iteration = 0; iteration < 512; iteration++) {
4192
+ const hx = dx + t, hy = dy + t, hz = dz + t;
4193
+ const lx = sumError2(dx, t, hx) + ex;
4194
+ const ly = sumError2(dy, t, hy) + ey;
4195
+ const lz = sumError2(dz, t, hz) + ez;
4196
+ const vx = ux / hx, vy = uy / hy, vz = uz / hz;
4197
+ let term, rest;
4198
+ if (vx >= vy && vx >= vz) {
4199
+ term = offset(ux, fx, dx, ex, t, hx) * (vx + 1);
4200
+ rest = (vy * (1 - ly / hy)) ** 2 + (vz * (1 - lz / hz)) ** 2;
4201
+ } else if (vy >= vz) {
4202
+ term = offset(uy, fy, dy, ey, t, hy) * (vy + 1);
4203
+ rest = (vx * (1 - lx / hx)) ** 2 + (vz * (1 - lz / hz)) ** 2;
4198
4204
  } else {
4199
- east.set(-origin.y, origin.x, 0).normalize();
4200
- ellipsoid.geodeticSurfaceNormal(origin, up);
4201
- }
4202
- if (!eastNorthUpBasisFromDirections(east, up, scratchBasis) || !localFrameToMatrix(scratchBasis, origin, firstAxis, secondAxis, thirdAxis, result))
4203
- throw new Error("Unsupported local frame");
4204
- return result;
4205
- }
4206
- if (atPole) {
4207
- const sign = Math.sign(origin.z);
4208
- firstAxisVector = scratchVector1.fromArray(degeneratePositionLocalFrame[firstAxis]);
4209
- if (firstAxis !== "east" && firstAxis !== "west") {
4210
- firstAxisVector.scale(sign);
4211
- }
4212
- secondAxisVector = scratchVector2.fromArray(degeneratePositionLocalFrame[secondAxis]);
4213
- if (secondAxis !== "east" && secondAxis !== "west") {
4214
- secondAxisVector.scale(sign);
4215
- }
4216
- thirdAxisVector = scratchVector3.fromArray(degeneratePositionLocalFrame[thirdAxis]);
4217
- if (thirdAxis !== "east" && thirdAxis !== "west") {
4218
- thirdAxisVector.scale(sign);
4205
+ term = offset(uz, fz, dz, ez, t, hz) * (vz + 1);
4206
+ rest = (vx * (1 - lx / hx)) ** 2 + (vy * (1 - ly / hy)) ** 2;
4207
+ }
4208
+ const derivative = -2 * (vx * vx / hx + vy * vy / hy + vz * vz / hz);
4209
+ const roundoff = 4 * Number.EPSILON * (Math.abs(term) + rest);
4210
+ const residual = term + rest;
4211
+ if (!Number.isFinite(residual))
4212
+ return exactNearestSurface(x, y, z, a, b, c, result);
4213
+ if (Math.abs(residual) <= 4 * Number.EPSILON * (Math.abs(term) + rest) || upper - lower <= 4 * Number.EPSILON * t) {
4214
+ const uncertainty = roundoff / Math.abs(derivative);
4215
+ if (!Number.isFinite(derivative) || !(Math.abs(derivative) > 0) || uncertainty > 2e-13 * t)
4216
+ return exactNearestSurface(x, y, z, a, b, c, result);
4217
+ const qx = Math.sign(x) * a * (vx * (1 - lx / hx));
4218
+ const qy = Math.sign(y) * b * (vy * (1 - ly / hy));
4219
+ const qz = Math.sign(z) * c * (vz * (1 - lz / hz));
4220
+ const displacement = 2 * uncertainty * Math.max(Math.abs(qx / hx), Math.abs(qy / hy), Math.abs(qz / hz));
4221
+ if (!Number.isFinite(displacement) || displacement > 2e-13 * Math.max(a, b, c))
4222
+ return exactNearestSurface(x, y, z, a, b, c, result);
4223
+ if (!Number.isFinite(qx) || !Number.isFinite(qy) || !Number.isFinite(qz))
4224
+ return exactNearestSurface(x, y, z, a, b, c, result);
4225
+ result.x = qx;
4226
+ result.y = qy;
4227
+ result.z = qz;
4228
+ return true;
4219
4229
  }
4220
- } else {
4221
- const { up, east, north } = scratchAxisVectors;
4222
- east.set(-origin.y, origin.x, 0).normalize();
4223
- ellipsoid.geodeticSurfaceNormal(origin, up);
4224
- north.copy(up).cross(east);
4225
- const { down, west, south } = scratchAxisVectors;
4226
- down.copy(up).scale(-1);
4227
- west.copy(east).scale(-1);
4228
- south.copy(north).scale(-1);
4229
- firstAxisVector = scratchAxisVectors[firstAxis];
4230
- secondAxisVector = scratchAxisVectors[secondAxis];
4231
- thirdAxisVector = scratchAxisVectors[thirdAxis];
4232
- }
4233
- const ax = firstAxisVector.x, ay = firstAxisVector.y, az = firstAxisVector.z;
4234
- const bx = secondAxisVector.x, by = secondAxisVector.y, bz = secondAxisVector.z;
4235
- const cx = thirdAxisVector.x, cy = thirdAxisVector.y, cz = thirdAxisVector.z;
4236
- const x = origin.x, y = origin.y, z = origin.z;
4237
- result[0] = ax;
4238
- result[1] = ay;
4239
- result[2] = az;
4240
- result[3] = 0;
4241
- result[4] = bx;
4242
- result[5] = by;
4243
- result[6] = bz;
4244
- result[7] = 0;
4245
- result[8] = cx;
4246
- result[9] = cy;
4247
- result[10] = cz;
4248
- result[11] = 0;
4249
- result[12] = x;
4250
- result[13] = y;
4251
- result[14] = z;
4252
- result[15] = 1;
4253
- return result;
4230
+ if (residual > 0)
4231
+ lower = t;
4232
+ else
4233
+ upper = t;
4234
+ const candidate = t - residual / derivative;
4235
+ const next = candidate > lower && candidate < upper ? candidate : lower + (upper - lower) / 2;
4236
+ if (next === t)
4237
+ return exactNearestSurface(x, y, z, a, b, c, result);
4238
+ t = next;
4239
+ }
4240
+ return exactNearestSurface(x, y, z, a, b, c, result);
4241
+ }
4242
+ function offset(u, error, d, dError, t, denominator) {
4243
+ const difference = u - d;
4244
+ const correction = sumError2(u, -d, difference) + error - dError;
4245
+ const base = difference + correction;
4246
+ const low = sumError2(difference, correction, base);
4247
+ const shifted = base - t;
4248
+ return (shifted + (sumError2(base, -t, shifted) + low)) / denominator;
4249
+ }
4250
+ function sumError2(x, y, sum) {
4251
+ const part = sum - x;
4252
+ return x - (sum - part) + (y - part);
4254
4253
  }
4255
- var EPSILON142, scratchOrigin, scratchBasis, VECTOR_PRODUCT_LOCAL_FRAME, degeneratePositionLocalFrame, scratchAxisVectors, scratchVector1, scratchVector2, scratchVector3;
4256
- var init_ellipsoid_transform = __esm({
4257
- "../../node_modules/@math.gl/geospatial/dist/ellipsoid-helpers/ellipsoid-transform.js"() {
4258
- init_dist();
4259
- init_local_frame();
4260
- EPSILON142 = 1e-14;
4261
- scratchOrigin = new Vector3();
4262
- scratchBasis = createLocalFrameBasis();
4263
- VECTOR_PRODUCT_LOCAL_FRAME = {
4264
- up: {
4265
- south: "east",
4266
- north: "west",
4267
- west: "south",
4268
- east: "north"
4269
- },
4270
- down: {
4271
- south: "west",
4272
- north: "east",
4273
- west: "north",
4274
- east: "south"
4275
- },
4276
- south: {
4277
- up: "west",
4278
- down: "east",
4279
- west: "down",
4280
- east: "up"
4281
- },
4282
- north: {
4283
- up: "east",
4284
- down: "west",
4285
- west: "up",
4286
- east: "down"
4287
- },
4288
- west: {
4289
- up: "north",
4290
- down: "south",
4291
- north: "down",
4292
- south: "up"
4293
- },
4294
- east: {
4295
- up: "south",
4296
- down: "north",
4297
- north: "up",
4298
- south: "down"
4299
- }
4300
- };
4301
- degeneratePositionLocalFrame = {
4302
- north: [-1, 0, 0],
4303
- east: [0, 1, 0],
4304
- up: [0, 0, 1],
4305
- south: [1, 0, 0],
4306
- west: [0, -1, 0],
4307
- down: [0, 0, -1]
4308
- };
4309
- scratchAxisVectors = {
4310
- east: new Vector3(),
4311
- north: new Vector3(),
4312
- up: new Vector3(),
4313
- west: new Vector3(),
4314
- south: new Vector3(),
4315
- down: new Vector3()
4316
- };
4317
- scratchVector1 = new Vector3();
4318
- scratchVector2 = new Vector3();
4319
- scratchVector3 = new Vector3();
4254
+ function productError2(x, y, product) {
4255
+ const sx = 134217729 * x, sy = 134217729 * y;
4256
+ if (!Number.isFinite(sx) || !Number.isFinite(sy))
4257
+ return 0;
4258
+ const hx = sx - (sx - x), hy = sy - (sy - y);
4259
+ const lx = x - hx, ly = y - hy;
4260
+ return hx * hy - product + hx * ly + lx * hy + lx * ly;
4261
+ }
4262
+ var init_nearest_surface = __esm({
4263
+ "../../node_modules/@math.gl/geospatial/dist/ellipsoid-helpers/nearest-surface.js"() {
4264
+ init_exact_nearest_surface();
4320
4265
  }
4321
4266
  });
4322
4267
 
4323
4268
  // ../../node_modules/@math.gl/geospatial/dist/ellipsoid-helpers/scale-to-geodetic-surface.js
4324
4269
  function scaleToGeodeticSurface(cartesian, ellipsoid, result = []) {
4325
- const { oneOverRadii, oneOverRadiiSquared, centerToleranceSquared } = ellipsoid;
4326
4270
  const object = cartesian;
4327
- const positionX = "x" in cartesian ? object.x : cartesian[0];
4328
- const positionY = "x" in cartesian ? object.y : cartesian[1];
4329
- const positionZ = "x" in cartesian ? object.z : cartesian[2];
4330
- if (!Number.isFinite(positionX) || !Number.isFinite(positionY) || !Number.isFinite(positionZ)) {
4271
+ const x = "x" in cartesian ? object.x : cartesian[0];
4272
+ const y = "x" in cartesian ? object.y : cartesian[1];
4273
+ const z = "x" in cartesian ? object.z : cartesian[2];
4274
+ if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z))
4331
4275
  return void 0;
4332
- }
4333
- scratchVector4.set(positionX, positionY, positionZ);
4334
- const oneOverRadiiX = oneOverRadii.x;
4335
- const oneOverRadiiY = oneOverRadii.y;
4336
- const oneOverRadiiZ = oneOverRadii.z;
4337
- const x2 = positionX * positionX * oneOverRadiiX * oneOverRadiiX;
4338
- const y2 = positionY * positionY * oneOverRadiiY * oneOverRadiiY;
4339
- const z2 = positionZ * positionZ * oneOverRadiiZ * oneOverRadiiZ;
4340
- const squaredNorm = x2 + y2 + z2;
4341
- const ratio = Math.sqrt(1 / squaredNorm);
4342
- if (!Number.isFinite(ratio) || !Number.isFinite(squaredNorm)) {
4276
+ if (!Number.isFinite(x * x + y * y + z * z))
4343
4277
  return void 0;
4344
- }
4345
- const intersection = scaleToGeodeticSurfaceIntersection;
4346
- intersection.set(positionX, positionY, positionZ).scale(ratio);
4347
- if (squaredNorm < centerToleranceSquared) {
4348
- return writeResult(result, intersection.x, intersection.y, intersection.z);
4349
- }
4350
- const oneOverRadiiSquaredX = oneOverRadiiSquared.x;
4351
- const oneOverRadiiSquaredY = oneOverRadiiSquared.y;
4352
- const oneOverRadiiSquaredZ = oneOverRadiiSquared.z;
4353
- const gradient = scaleToGeodeticSurfaceGradient;
4354
- gradient.set(intersection.x * oneOverRadiiSquaredX * 2, intersection.y * oneOverRadiiSquaredY * 2, intersection.z * oneOverRadiiSquaredZ * 2);
4355
- let lambda = (1 - ratio) * scratchVector4.len() / (0.5 * gradient.len());
4356
- let correction = 0;
4357
- let xMultiplier;
4358
- let yMultiplier;
4359
- let zMultiplier;
4360
- let func;
4361
- for (let iteration = 0; iteration < 64; iteration++) {
4362
- lambda -= correction;
4363
- xMultiplier = 1 / (1 + lambda * oneOverRadiiSquaredX);
4364
- yMultiplier = 1 / (1 + lambda * oneOverRadiiSquaredY);
4365
- zMultiplier = 1 / (1 + lambda * oneOverRadiiSquaredZ);
4366
- const xMultiplier2 = xMultiplier * xMultiplier;
4367
- const yMultiplier2 = yMultiplier * yMultiplier;
4368
- const zMultiplier2 = zMultiplier * zMultiplier;
4369
- const xMultiplier3 = xMultiplier2 * xMultiplier;
4370
- const yMultiplier3 = yMultiplier2 * yMultiplier;
4371
- const zMultiplier3 = zMultiplier2 * zMultiplier;
4372
- func = x2 * xMultiplier2 + y2 * yMultiplier2 + z2 * zMultiplier2 - 1;
4373
- if (!Number.isFinite(func))
4374
- return void 0;
4375
- if (Math.abs(func) <= math_utils_exports.EPSILON12) {
4376
- return writeResult(result, positionX * xMultiplier, positionY * yMultiplier, positionZ * zMultiplier);
4377
- }
4378
- const denominator = x2 * xMultiplier3 * oneOverRadiiSquaredX + y2 * yMultiplier3 * oneOverRadiiSquaredY + z2 * zMultiplier3 * oneOverRadiiSquaredZ;
4379
- const derivative = -2 * denominator;
4380
- if (!Number.isFinite(derivative) || derivative === 0)
4381
- return void 0;
4382
- correction = func / derivative;
4383
- if (!Number.isFinite(correction))
4384
- return void 0;
4385
- }
4386
- return void 0;
4278
+ const { radii } = ellipsoid;
4279
+ if (!nearestSurface(x, y, z, radii.x, radii.y, radii.z, surface))
4280
+ return void 0;
4281
+ return writeResult(result, surface.x, surface.y, surface.z);
4387
4282
  }
4388
4283
  function writeResult(result, x, y, z) {
4389
4284
  if (isArray(result)) {
@@ -4398,13 +4293,12 @@ var __exports__ = (() => {
4398
4293
  }
4399
4294
  return result;
4400
4295
  }
4401
- var scratchVector4, scaleToGeodeticSurfaceIntersection, scaleToGeodeticSurfaceGradient;
4296
+ var surface;
4402
4297
  var init_scale_to_geodetic_surface = __esm({
4403
4298
  "../../node_modules/@math.gl/geospatial/dist/ellipsoid-helpers/scale-to-geodetic-surface.js"() {
4404
4299
  init_dist();
4405
- scratchVector4 = new Vector3();
4406
- scaleToGeodeticSurfaceIntersection = new Vector3();
4407
- scaleToGeodeticSurfaceGradient = new Vector3();
4300
+ init_nearest_surface();
4301
+ surface = { x: 0, y: 0, z: 0 };
4408
4302
  }
4409
4303
  });
4410
4304
 
@@ -4413,22 +4307,26 @@ var __exports__ = (() => {
4413
4307
  if (!Number.isFinite(a) || !Number.isFinite(b) || a <= 0 || b <= 0 || b > a)
4414
4308
  throw new Error("Spheroid requires finite positive axes with semiMinorAxis <= semiMajorAxis");
4415
4309
  }
4416
- var spheroidScratch, scratchVector5, scratchNormal, scratchK, scratchPosition, scratchHeight, scratchCartesian, Ellipsoid;
4310
+ function normalResult(x, y, z, result) {
4311
+ const scale4 = Math.max(Math.abs(x), Math.abs(y), Math.abs(z));
4312
+ if (!(scale4 > 0) || !Number.isFinite(scale4))
4313
+ return void 0;
4314
+ const nx = x / scale4, ny = y / scale4, nz = z / scale4;
4315
+ const length4 = Math.hypot(nx, ny, nz);
4316
+ return writeResult(result, nx / length4, ny / length4, nz / length4);
4317
+ }
4318
+ var spheroidScratch, scratchVector2, scratchNormal, scratchPosition, scratchCartesian, Ellipsoid;
4417
4319
  var init_ellipsoid = __esm({
4418
4320
  "../../node_modules/@math.gl/geospatial/dist/ellipsoid.js"() {
4419
4321
  init_dist();
4420
4322
  init_spheroid();
4421
- init_vec32();
4422
4323
  init_constants();
4423
4324
  init_type_utils();
4424
- init_ellipsoid_transform();
4425
4325
  init_scale_to_geodetic_surface();
4426
4326
  spheroidScratch = { x: 0, y: 0, z: 0 };
4427
- scratchVector5 = new Vector3();
4327
+ scratchVector2 = new Vector3();
4428
4328
  scratchNormal = new Vector3();
4429
- scratchK = new Vector3();
4430
4329
  scratchPosition = new Vector3();
4431
- scratchHeight = new Vector3();
4432
4330
  scratchCartesian = new Vector3();
4433
4331
  Ellipsoid = class _Ellipsoid {
4434
4332
  /** Construct from two-axis geometry, including normalized projection ellipsoids.
@@ -4441,9 +4339,9 @@ var __exports__ = (() => {
4441
4339
  }
4442
4340
  constructor(x = 0, y = 0, z = 0) {
4443
4341
  this.centerToleranceSquared = math_utils_exports.EPSILON1;
4444
- assert2(x >= 0);
4445
- assert2(y >= 0);
4446
- assert2(z >= 0);
4342
+ assert2(Number.isFinite(x) && x >= 0);
4343
+ assert2(Number.isFinite(y) && y >= 0);
4344
+ assert2(Number.isFinite(z) && z >= 0);
4447
4345
  this.radii = new Vector3(x, y, z);
4448
4346
  this.radiiSquared = new Vector3(x * x, y * y, z * z);
4449
4347
  this.radiiToTheFourth = new Vector3(x * x * x * x, y * y * y * y, z * z * z * z);
@@ -4451,15 +4349,20 @@ var __exports__ = (() => {
4451
4349
  this.oneOverRadiiSquared = new Vector3(x === 0 ? 0 : 1 / (x * x), y === 0 ? 0 : 1 / (y * y), z === 0 ? 0 : 1 / (z * z));
4452
4350
  this.minimumRadius = Math.min(x, y, z);
4453
4351
  this.maximumRadius = Math.max(x, y, z);
4454
- if (this.radiiSquared.z !== 0) {
4455
- this.squaredXOverSquaredZ = this.radiiSquared.x / this.radiiSquared.z;
4352
+ if (z !== 0) {
4353
+ this.squaredXOverSquaredZ = (x / z) ** 2;
4456
4354
  }
4457
4355
  if (x === y && z > 0 && z <= x && Number.isFinite(this.radiiSquared.x) && this.radiiSquared.z > 0)
4458
4356
  this.spheroidGeometry = Object.freeze({
4459
4357
  semiMajorAxis: x,
4460
4358
  semiMinorAxis: z,
4461
- eccentricitySquared: 1 - this.radiiSquared.z / this.radiiSquared.x
4359
+ eccentricitySquared: 1 - (z / x) ** 2
4462
4360
  });
4361
+ Object.freeze(this.radii);
4362
+ Object.freeze(this.radiiSquared);
4363
+ Object.freeze(this.radiiToTheFourth);
4364
+ Object.freeze(this.oneOverRadii);
4365
+ Object.freeze(this.oneOverRadiiSquared);
4463
4366
  Object.freeze(this);
4464
4367
  }
4465
4368
  /** Return an owned geometry snapshot for a sphere or oblate spheroid.
@@ -4477,30 +4380,34 @@ var __exports__ = (() => {
4477
4380
  equals(right) {
4478
4381
  return this === right || Boolean(right && this.radii.equals(right.radii));
4479
4382
  }
4480
- /** Creates a string representing this Ellipsoid in the format '(radii.x, radii.y, radii.z)'. */
4383
+ /** Creates a string representing this Ellipsoid in the format '[radii.x, radii.y, radii.z]'. */
4481
4384
  toString() {
4482
4385
  return this.radii.toString();
4483
4386
  }
4484
4387
  cartographicToCartesian(cartographic, result = [0, 0, 0]) {
4485
- if (this.spheroidGeometry) {
4486
- const llh = fromCartographicToRadians(cartographic, scratchCartesian);
4487
- spheroidScratch.x = llh[0];
4488
- spheroidScratch.y = llh[1];
4489
- spheroidScratch.z = llh[2];
4388
+ const llh = fromCartographicToRadians(cartographic, scratchCartesian);
4389
+ const longitude = llh[0], latitude = llh[1], height = llh[2];
4390
+ if (!Number.isFinite(longitude) || !Number.isFinite(latitude) || !Number.isFinite(height) || !(this.minimumRadius > 0) || !Number.isFinite(this.maximumRadius * this.maximumRadius))
4391
+ return void 0;
4392
+ if (this.spheroidGeometry && (config._cartographicRadians || Math.abs(latitude) <= Math.PI / 4)) {
4393
+ spheroidScratch.x = longitude;
4394
+ spheroidScratch.y = latitude;
4395
+ spheroidScratch.z = height;
4490
4396
  if (!spheroidToCartesian(spheroidScratch, this.spheroidGeometry))
4491
4397
  return void 0;
4492
4398
  return writeResult(result, spheroidScratch.x, spheroidScratch.y, spheroidScratch.z);
4493
4399
  }
4494
4400
  const normal = scratchNormal;
4495
- const k = scratchK;
4496
- const [, , height] = cartographic;
4497
4401
  this.geodeticSurfaceNormalCartographic(cartographic, normal);
4498
- k.copy(this.radiiSquared).scale(normal);
4499
- const gamma = Math.sqrt(normal.dot(k));
4500
- k.scale(1 / gamma);
4501
- normal.scale(height);
4502
- k.add(normal);
4503
- return k.to(result);
4402
+ const nx = normal.x, ny = normal.y, nz = normal.z;
4403
+ const rx = this.radii.x, ry = this.radii.y, rz = this.radii.z;
4404
+ const gamma = Math.hypot(rx * nx, ry * ny, rz * nz);
4405
+ const x = rx * (rx * nx / gamma) + height * nx;
4406
+ const y = ry * (ry * ny / gamma) + height * ny;
4407
+ const z = rz * (rz * nz / gamma) + height * nz;
4408
+ if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z))
4409
+ return void 0;
4410
+ return writeResult(result, x, y, z);
4504
4411
  }
4505
4412
  cartesianToCartographic(cartesian, result = [0, 0, 0]) {
4506
4413
  const object = cartesian;
@@ -4513,45 +4420,68 @@ var __exports__ = (() => {
4513
4420
  spheroidScratch.x = x;
4514
4421
  spheroidScratch.y = y;
4515
4422
  spheroidScratch.z = z;
4516
- if (!cartesianToSpheroid(spheroidScratch, this.spheroidGeometry))
4517
- return void 0;
4518
- const longitude2 = x === 0 && y === 0 ? Math.atan2(y, x) : spheroidScratch.x;
4519
- return toCartographicFromRadiansComponents(longitude2, spheroidScratch.y, spheroidScratch.z, result);
4423
+ const shape = this.spheroidGeometry;
4424
+ const nearBoundary = z === 0 && shape.semiMinorAxis < shape.semiMajorAxis && Math.abs(Math.hypot(x, y) - shape.semiMajorAxis * shape.eccentricitySquared) <= 64 * Number.EPSILON * shape.semiMajorAxis;
4425
+ if (!nearBoundary && cartesianToSpheroid(spheroidScratch, shape)) {
4426
+ const longitude2 = x === 0 && y === 0 ? Math.atan2(y, x) : spheroidScratch.x;
4427
+ return toCartographicFromRadiansComponents(longitude2, spheroidScratch.y, spheroidScratch.z, result);
4428
+ }
4520
4429
  }
4430
+ if (!(this.minimumRadius > 0) || !Number.isFinite(this.maximumRadius * this.maximumRadius) || !Number.isFinite(1 / (this.minimumRadius * this.minimumRadius)))
4431
+ return void 0;
4521
4432
  scratchCartesian.set(x, y, z);
4522
4433
  const point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition);
4523
4434
  if (!point) {
4524
4435
  return void 0;
4525
4436
  }
4526
- const normal = this.geodeticSurfaceNormal(point, scratchNormal);
4527
- const h = scratchHeight;
4528
- h.copy(scratchCartesian).subtract(point);
4529
- const longitude = Math.atan2(normal.y, normal.x);
4530
- const latitude = Math.atan2(normal.z, Math.hypot(normal.x, normal.y));
4531
- const height = Math.sign(dot(h, scratchCartesian)) * length(h);
4437
+ const gx = point[0] * this.oneOverRadiiSquared.x;
4438
+ const gy = point[1] * this.oneOverRadiiSquared.y;
4439
+ const gz = point[2] * this.oneOverRadiiSquared.z;
4440
+ const length4 = Math.hypot(gx, gy, gz);
4441
+ if (!(length4 > 0) || !Number.isFinite(length4))
4442
+ return void 0;
4443
+ const nx = gx / length4, ny = gy / length4, nz = gz / length4;
4444
+ const longitude = Math.atan2(ny, nx);
4445
+ const latitude = Math.atan2(nz, Math.hypot(nx, ny));
4446
+ const height = (x - point[0]) * nx + (y - point[1]) * ny + (z - point[2]) * nz;
4532
4447
  return toCartographicFromRadiansComponents(longitude, latitude, height, result);
4533
4448
  }
4534
- eastNorthUpToFixedFrame(origin, result = new Matrix4()) {
4535
- return localFrameToFixedFrame(this, "east", "north", "up", origin, result);
4536
- }
4537
- // Computes a 4x4 transformation matrix from a reference frame centered at
4538
- // the provided origin to the ellipsoid's fixed reference frame.
4539
- localFrameToFixedFrame(firstAxis, secondAxis, thirdAxis, origin, result = new Matrix4()) {
4540
- return localFrameToFixedFrame(this, firstAxis, secondAxis, thirdAxis, origin, result);
4541
- }
4542
4449
  geocentricSurfaceNormal(cartesian, result = [0, 0, 0]) {
4543
- return scratchVector5.from(cartesian).normalize().to(result);
4450
+ fromCartographic(cartesian, scratchVector2);
4451
+ const point = scratchVector2;
4452
+ return normalResult(point.x, point.y, point.z, result);
4544
4453
  }
4545
4454
  geodeticSurfaceNormalCartographic(cartographic, result = [0, 0, 0]) {
4546
- const cartographicVectorRadians = fromCartographicToRadians(cartographic);
4547
- const longitude = cartographicVectorRadians[0];
4548
- const latitude = cartographicVectorRadians[1];
4549
- const cosLatitude = Math.cos(latitude);
4550
- scratchVector5.set(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), Math.sin(latitude)).normalize();
4551
- return scratchVector5.to(result);
4455
+ const point = fromCartographic(cartographic, scratchCartesian);
4456
+ const longitude = config._cartographicRadians ? point[0] : point[0] * Math.PI / 180;
4457
+ const latitude = config._cartographicRadians ? point[1] : point[1] * Math.PI / 180;
4458
+ const polarDegrees = !config._cartographicRadians && Math.abs(point[1]) > 45;
4459
+ const complement = (90 - Math.abs(point[1])) * Math.PI / 180;
4460
+ const cosLatitude = polarDegrees ? Math.sin(complement) : Math.abs(latitude) === Math.PI / 2 ? 0 : Math.cos(latitude);
4461
+ const sinLatitude = polarDegrees ? Math.sign(point[1]) * Math.cos(complement) : Math.sin(latitude);
4462
+ return normalResult(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), sinLatitude, result);
4552
4463
  }
4553
4464
  geodeticSurfaceNormal(cartesian, result = [0, 0, 0]) {
4554
- return scratchVector5.from(cartesian).scale(this.oneOverRadiiSquared).normalize().to(result);
4465
+ if (!(this.minimumRadius > 0))
4466
+ return void 0;
4467
+ fromCartographic(cartesian, scratchVector2);
4468
+ const point = scratchVector2;
4469
+ const scale4 = Math.max(Math.abs(point.x), Math.abs(point.y), Math.abs(point.z));
4470
+ if (!(scale4 > 0) || !Number.isFinite(scale4))
4471
+ return void 0;
4472
+ const nx = point.x / scale4 * (this.minimumRadius / this.radii.x) ** 2;
4473
+ const ny = point.y / scale4 * (this.minimumRadius / this.radii.y) ** 2;
4474
+ const nz = point.z / scale4 * (this.minimumRadius / this.radii.z) ** 2;
4475
+ if ((point.x === 0 || Math.abs(nx) >= 2 ** -1022) && (point.y === 0 || Math.abs(ny) >= 2 ** -1022) && (point.z === 0 || Math.abs(nz) >= 2 ** -1022))
4476
+ return normalResult(nx, ny, nz, result);
4477
+ const ex = point.x === 0 ? 0 : Math.min(1023, Math.floor(Math.log2(Math.abs(point.x))));
4478
+ const ey = point.y === 0 ? 0 : Math.min(1023, Math.floor(Math.log2(Math.abs(point.y))));
4479
+ const ez = point.z === 0 ? 0 : Math.min(1023, Math.floor(Math.log2(Math.abs(point.z))));
4480
+ const ax = Math.min(1023, Math.floor(Math.log2(this.radii.x)));
4481
+ const ay = Math.min(1023, Math.floor(Math.log2(this.radii.y)));
4482
+ const az = Math.min(1023, Math.floor(Math.log2(this.radii.z)));
4483
+ const common = Math.max(point.x === 0 ? -Infinity : ex - 2 * ax, point.y === 0 ? -Infinity : ey - 2 * ay, point.z === 0 ? -Infinity : ez - 2 * az);
4484
+ return normalResult(point.x === 0 ? point.x : point.x / 2 ** ex / (this.radii.x / 2 ** ax) ** 2 * 2 ** (ex - 2 * ax - common), point.y === 0 ? point.y : point.y / 2 ** ey / (this.radii.y / 2 ** ay) ** 2 * 2 ** (ey - 2 * ay - common), point.z === 0 ? point.z : point.z / 2 ** ez / (this.radii.z / 2 ** az) ** 2 * 2 ** (ez - 2 * az - common), result);
4555
4485
  }
4556
4486
  /** Scales the provided Cartesian position along the geodetic surface normal
4557
4487
  * so that it is on the surface of this ellipsoid. If the position is
@@ -4562,34 +4492,49 @@ var __exports__ = (() => {
4562
4492
  /** Scales the provided Cartesian position along the geocentric surface normal
4563
4493
  * so that it is on the surface of this ellipsoid. */
4564
4494
  scaleToGeocentricSurface(cartesian, result = [0, 0, 0]) {
4565
- scratchPosition.from(cartesian);
4566
- const positionX = scratchPosition.x;
4567
- const positionY = scratchPosition.y;
4568
- const positionZ = scratchPosition.z;
4569
- const oneOverRadiiSquared = this.oneOverRadiiSquared;
4570
- const beta = 1 / Math.sqrt(positionX * positionX * oneOverRadiiSquared.x + positionY * positionY * oneOverRadiiSquared.y + positionZ * positionZ * oneOverRadiiSquared.z);
4571
- return scratchPosition.multiplyByScalar(beta).to(result);
4495
+ fromCartographic(cartesian, scratchPosition);
4496
+ const point = scratchPosition;
4497
+ const scale4 = Math.max(Math.abs(point.x), Math.abs(point.y), Math.abs(point.z));
4498
+ if (!(this.minimumRadius > 0) || !(scale4 > 0) || !Number.isFinite(scale4))
4499
+ return void 0;
4500
+ const squared = point.x * point.x * this.oneOverRadiiSquared.x + point.y * point.y * this.oneOverRadiiSquared.y + point.z * point.z * this.oneOverRadiiSquared.z;
4501
+ if (squared >= 2 ** -1022 && Number.isFinite(squared) && scale4 * scale4 >= 2 ** -1022 && Number.isFinite(scale4 * scale4)) {
4502
+ const beta = 1 / Math.sqrt(squared);
4503
+ return writeResult(result, point.x * beta, point.y * beta, point.z * beta);
4504
+ }
4505
+ const x = point.x / scale4, y = point.y / scale4, z = point.z / scale4;
4506
+ const norm = Math.hypot(x / this.radii.x, y / this.radii.y, z / this.radii.z);
4507
+ if (!(norm > 0) || !Number.isFinite(norm))
4508
+ return void 0;
4509
+ return writeResult(result, x / norm, y / norm, z / norm);
4572
4510
  }
4573
4511
  /** Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying
4574
4512
  * its components by the result of `Ellipsoid#oneOverRadii` */
4575
4513
  transformPositionToScaledSpace(position, result = [0, 0, 0]) {
4576
- return scratchPosition.from(position).scale(this.oneOverRadii).to(result);
4514
+ fromCartographic(position, scratchPosition);
4515
+ const point = scratchPosition.scale(this.oneOverRadii);
4516
+ return writeResult(result, point.x, point.y, point.z);
4577
4517
  }
4578
4518
  /** Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying
4579
4519
  * its components by the result of `Ellipsoid#radii`. */
4580
4520
  transformPositionFromScaledSpace(position, result = [0, 0, 0]) {
4581
- return scratchPosition.from(position).scale(this.radii).to(result);
4521
+ fromCartographic(position, scratchPosition);
4522
+ const point = scratchPosition.scale(this.radii);
4523
+ return writeResult(result, point.x, point.y, point.z);
4582
4524
  }
4583
4525
  /** Computes a point which is the intersection of the surface normal with the z-axis. */
4584
4526
  getSurfaceNormalIntersectionWithZAxis(position, buffer = 0, result = [0, 0, 0]) {
4585
- assert2(equals(this.radii.x, this.radii.y, math_utils_exports.EPSILON15));
4586
- assert2(this.radii.z > 0);
4587
- scratchPosition.from(position);
4527
+ assert2(this.radii.x === this.radii.y && this.minimumRadius > 0);
4528
+ fromCartographic(position, scratchPosition);
4529
+ if (!Number.isFinite(scratchPosition.x) || !Number.isFinite(scratchPosition.y) || !Number.isFinite(scratchPosition.z) || !Number.isFinite(buffer))
4530
+ return void 0;
4588
4531
  const z = scratchPosition.z * (1 - this.squaredXOverSquaredZ);
4532
+ if (!Number.isFinite(z))
4533
+ return void 0;
4589
4534
  if (Math.abs(z) >= this.radii.z - buffer) {
4590
4535
  return void 0;
4591
4536
  }
4592
- return scratchPosition.set(0, 0, z).to(result);
4537
+ return writeResult(result, 0, 0, z);
4593
4538
  }
4594
4539
  };
4595
4540
  Ellipsoid.WGS84 = new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z);
@@ -4604,12 +4549,12 @@ var __exports__ = (() => {
4604
4549
  });
4605
4550
 
4606
4551
  // ../../node_modules/@math.gl/geometry/dist/culling/lib/bounding-volumes/bounding-sphere.js
4607
- var scratchVector6, scratchVector22, BoundingSphere;
4552
+ var scratchVector3, scratchVector22, BoundingSphere;
4608
4553
  var init_bounding_sphere = __esm({
4609
4554
  "../../node_modules/@math.gl/geometry/dist/culling/lib/bounding-volumes/bounding-sphere.js"() {
4610
4555
  init_dist();
4611
4556
  init_mat42();
4612
- scratchVector6 = new Vector3();
4557
+ scratchVector3 = new Vector3();
4613
4558
  scratchVector22 = new Vector3();
4614
4559
  BoundingSphere = class _BoundingSphere {
4615
4560
  /** Creates a bounding sphere */
@@ -4629,7 +4574,7 @@ var __exports__ = (() => {
4629
4574
  * tightly and fully encompasses the box.
4630
4575
  */
4631
4576
  fromCornerPoints(corner, oppositeCorner) {
4632
- oppositeCorner = scratchVector6.from(oppositeCorner);
4577
+ oppositeCorner = scratchVector3.from(oppositeCorner);
4633
4578
  this.center = new Vector3().from(corner).add(oppositeCorner).scale(0.5);
4634
4579
  this.radius = this.center.distance(oppositeCorner);
4635
4580
  return this;
@@ -4648,7 +4593,7 @@ var __exports__ = (() => {
4648
4593
  const leftRadius = this.radius;
4649
4594
  const rightCenter = boundingSphere.center;
4650
4595
  const rightRadius = boundingSphere.radius;
4651
- const toRightCenter = scratchVector6.copy(rightCenter).subtract(leftCenter);
4596
+ const toRightCenter = scratchVector3.copy(rightCenter).subtract(leftCenter);
4652
4597
  const centerSeparation = toRightCenter.magnitude();
4653
4598
  if (leftRadius >= centerSeparation + rightRadius) {
4654
4599
  return this.clone();
@@ -4664,7 +4609,7 @@ var __exports__ = (() => {
4664
4609
  }
4665
4610
  /** Computes a bounding sphere by enlarging the provided sphere to contain the provided point. */
4666
4611
  expand(point) {
4667
- const scratchPoint = scratchVector6.from(point);
4612
+ const scratchPoint = scratchVector3.from(point);
4668
4613
  const radius = scratchPoint.subtract(this.center).magnitude();
4669
4614
  if (radius > this.radius) {
4670
4615
  this.radius = radius;
@@ -4680,7 +4625,7 @@ var __exports__ = (() => {
4680
4625
  */
4681
4626
  transform(transform) {
4682
4627
  this.center.transform(transform);
4683
- const scale4 = getScaling(scratchVector6, transform);
4628
+ const scale4 = getScaling(scratchVector3, transform);
4684
4629
  this.radius = Math.max(scale4[0], Math.max(scale4[1], scale4[2])) * this.radius;
4685
4630
  return this;
4686
4631
  }
@@ -4691,7 +4636,7 @@ var __exports__ = (() => {
4691
4636
  }
4692
4637
  /** Computes the estimated distance from the closest point on a bounding sphere to a point. */
4693
4638
  distanceTo(point) {
4694
- const scratchPoint = scratchVector6.from(point);
4639
+ const scratchPoint = scratchVector3.from(point);
4695
4640
  const delta = scratchPoint.subtract(this.center);
4696
4641
  return Math.max(0, delta.len() - this.radius);
4697
4642
  }
@@ -4905,10 +4850,255 @@ var __exports__ = (() => {
4905
4850
  }
4906
4851
  });
4907
4852
 
4853
+ // ../../node_modules/@math.gl/core/dist/local-frame.js
4854
+ function createLocalFrameBasis() {
4855
+ return { eastX: 0, eastY: 1, northZ: 1, upX: 1, upY: 0, upZ: 0 };
4856
+ }
4857
+ function eastNorthUpBasisFromDirections(east, up, result) {
4858
+ const ex = east.x, ey = east.y, ez = east.z;
4859
+ const ux = up.x, uy = up.y, uz = up.z;
4860
+ if (ez !== 0)
4861
+ return false;
4862
+ return commitBasis(result, ex, ey, ux * ey - uy * ex, ux, uy, uz);
4863
+ }
4864
+ function localFrameToMatrix(basis, origin, firstAxis, secondAxis, thirdAxis, result) {
4865
+ const first = axisCode(firstAxis), second = axisCode(secondAxis), third = axisCode(thirdAxis);
4866
+ const a = Math.abs(first), b = Math.abs(second), c = Math.abs(third);
4867
+ if (!a || !b || !c || a === b || a === c || b === c)
4868
+ return false;
4869
+ const parity = a % 3 + 1 === b ? 1 : -1;
4870
+ if (parity * Math.sign(first * second * third) !== 1 || !Array.isArray(result) && result.length < 16)
4871
+ return false;
4872
+ const ex = basis.eastX, ey = basis.eastY, nz = basis.northZ;
4873
+ const ux = basis.upX, uy = basis.upY, uz = basis.upZ;
4874
+ const nx = -uz * ey, ny = uz * ex;
4875
+ const x = origin.x, y = origin.y, z = origin.z;
4876
+ const ax = (a === 1 ? ex : a === 2 ? nx : ux) * Math.sign(first);
4877
+ const ay = (a === 1 ? ey : a === 2 ? ny : uy) * Math.sign(first);
4878
+ const az = (a === 1 ? 0 : a === 2 ? nz : uz) * Math.sign(first);
4879
+ const bx = (b === 1 ? ex : b === 2 ? nx : ux) * Math.sign(second);
4880
+ const by = (b === 1 ? ey : b === 2 ? ny : uy) * Math.sign(second);
4881
+ const bz = (b === 1 ? 0 : b === 2 ? nz : uz) * Math.sign(second);
4882
+ const cx = (c === 1 ? ex : c === 2 ? nx : ux) * Math.sign(third);
4883
+ const cy = (c === 1 ? ey : c === 2 ? ny : uy) * Math.sign(third);
4884
+ const cz = (c === 1 ? 0 : c === 2 ? nz : uz) * Math.sign(third);
4885
+ if (!Number.isFinite(ax) || !Number.isFinite(ay) || !Number.isFinite(az) || !Number.isFinite(bx) || !Number.isFinite(by) || !Number.isFinite(bz) || !Number.isFinite(cx) || !Number.isFinite(cy) || !Number.isFinite(cz) || !Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z))
4886
+ return false;
4887
+ if (result instanceof Float32Array && (!Number.isFinite(Math.fround(ax)) || !Number.isFinite(Math.fround(ay)) || !Number.isFinite(Math.fround(az)) || !Number.isFinite(Math.fround(bx)) || !Number.isFinite(Math.fround(by)) || !Number.isFinite(Math.fround(bz)) || !Number.isFinite(Math.fround(cx)) || !Number.isFinite(Math.fround(cy)) || !Number.isFinite(Math.fround(cz)) || !Number.isFinite(Math.fround(x)) || !Number.isFinite(Math.fround(y)) || !Number.isFinite(Math.fround(z))))
4888
+ return false;
4889
+ result[0] = ax;
4890
+ result[1] = ay;
4891
+ result[2] = az;
4892
+ result[3] = 0;
4893
+ result[4] = bx;
4894
+ result[5] = by;
4895
+ result[6] = bz;
4896
+ result[7] = 0;
4897
+ result[8] = cx;
4898
+ result[9] = cy;
4899
+ result[10] = cz;
4900
+ result[11] = 0;
4901
+ result[12] = x;
4902
+ result[13] = y;
4903
+ result[14] = z;
4904
+ result[15] = 1;
4905
+ return true;
4906
+ }
4907
+ function axisCode(axis) {
4908
+ switch (axis) {
4909
+ case "east":
4910
+ return 1;
4911
+ case "west":
4912
+ return -1;
4913
+ case "north":
4914
+ return 2;
4915
+ case "south":
4916
+ return -2;
4917
+ case "up":
4918
+ return 3;
4919
+ case "down":
4920
+ return -3;
4921
+ default:
4922
+ return 0;
4923
+ }
4924
+ }
4925
+ function commitBasis(result, ex, ey, nz, ux, uy, uz) {
4926
+ if (!Number.isFinite(ex) || !Number.isFinite(ey) || !Number.isFinite(nz) || !Number.isFinite(ux) || !Number.isFinite(uy) || !Number.isFinite(uz))
4927
+ return false;
4928
+ result.eastX = ex;
4929
+ result.eastY = ey;
4930
+ result.northZ = nz;
4931
+ result.upX = ux;
4932
+ result.upY = uy;
4933
+ result.upZ = uz;
4934
+ return true;
4935
+ }
4936
+ var init_local_frame = __esm({
4937
+ "../../node_modules/@math.gl/core/dist/local-frame.js"() {
4938
+ }
4939
+ });
4940
+
4941
+ // ../../node_modules/@math.gl/geospatial/dist/ellipsoid-helpers/ellipsoid-transform.js
4942
+ function localFrameToFixedFrame(ellipsoid, firstAxis, secondAxis, thirdAxis, cartesianOrigin, result) {
4943
+ const thirdAxisInferred = VECTOR_PRODUCT_LOCAL_FRAME[firstAxis] && VECTOR_PRODUCT_LOCAL_FRAME[firstAxis][secondAxis];
4944
+ assert2(thirdAxisInferred && (!thirdAxis || thirdAxis === thirdAxisInferred));
4945
+ let firstAxisVector;
4946
+ let secondAxisVector;
4947
+ let thirdAxisVector;
4948
+ const origin = scratchOrigin.copy(cartesianOrigin);
4949
+ if (!Number.isFinite(origin.x) || !Number.isFinite(origin.y) || !Number.isFinite(origin.z) || !Array.isArray(result) && result.length < 16)
4950
+ throw new Error("Unsupported local frame");
4951
+ const poleTolerance = EPSILON142 * Math.min(1, ellipsoid.maximumRadius);
4952
+ const atPole = Math.abs(origin.x) <= poleTolerance && Math.abs(origin.y) <= poleTolerance;
4953
+ const radii = ellipsoid.radii;
4954
+ if (radii.x === radii.y && radii.x > 0 && radii.z > 0 && radii.z <= radii.x && (!atPole || origin.z !== 0)) {
4955
+ const { east, up } = scratchAxisVectors;
4956
+ if (atPole) {
4957
+ east.set(0, 1, 0);
4958
+ up.set(0, 0, Math.sign(origin.z));
4959
+ } else {
4960
+ const scale4 = Math.max(Math.abs(origin.x), Math.abs(origin.y));
4961
+ east.set(-origin.y / scale4, origin.x / scale4, 0).normalize();
4962
+ ellipsoid.geodeticSurfaceNormal(origin, up);
4963
+ }
4964
+ if (!eastNorthUpBasisFromDirections(east, up, scratchBasis) || !localFrameToMatrix(scratchBasis, origin, firstAxis, secondAxis, thirdAxis, result))
4965
+ throw new Error("Unsupported local frame");
4966
+ return result;
4967
+ }
4968
+ if (atPole) {
4969
+ const sign = Math.sign(origin.z);
4970
+ firstAxisVector = scratchVector1.fromArray(degeneratePositionLocalFrame[firstAxis]);
4971
+ if (firstAxis !== "east" && firstAxis !== "west") {
4972
+ firstAxisVector.scale(sign);
4973
+ }
4974
+ secondAxisVector = scratchVector23.fromArray(degeneratePositionLocalFrame[secondAxis]);
4975
+ if (secondAxis !== "east" && secondAxis !== "west") {
4976
+ secondAxisVector.scale(sign);
4977
+ }
4978
+ thirdAxisVector = scratchVector32.fromArray(degeneratePositionLocalFrame[thirdAxis]);
4979
+ if (thirdAxis !== "east" && thirdAxis !== "west") {
4980
+ thirdAxisVector.scale(sign);
4981
+ }
4982
+ } else {
4983
+ const { up, east, north } = scratchAxisVectors;
4984
+ const scale4 = Math.max(Math.abs(origin.x), Math.abs(origin.y));
4985
+ east.set(-origin.y / scale4, origin.x / scale4, 0).normalize();
4986
+ ellipsoid.geodeticSurfaceNormal(origin, up);
4987
+ north.copy(up).cross(east);
4988
+ const { down, west, south } = scratchAxisVectors;
4989
+ down.copy(up).scale(-1);
4990
+ west.copy(east).scale(-1);
4991
+ south.copy(north).scale(-1);
4992
+ firstAxisVector = scratchAxisVectors[firstAxis];
4993
+ secondAxisVector = scratchAxisVectors[secondAxis];
4994
+ thirdAxisVector = scratchAxisVectors[thirdAxis];
4995
+ }
4996
+ const ax = firstAxisVector.x, ay = firstAxisVector.y, az = firstAxisVector.z;
4997
+ const bx = secondAxisVector.x, by = secondAxisVector.y, bz = secondAxisVector.z;
4998
+ const cx = thirdAxisVector.x, cy = thirdAxisVector.y, cz = thirdAxisVector.z;
4999
+ const x = origin.x, y = origin.y, z = origin.z;
5000
+ result[0] = ax;
5001
+ result[1] = ay;
5002
+ result[2] = az;
5003
+ result[3] = 0;
5004
+ result[4] = bx;
5005
+ result[5] = by;
5006
+ result[6] = bz;
5007
+ result[7] = 0;
5008
+ result[8] = cx;
5009
+ result[9] = cy;
5010
+ result[10] = cz;
5011
+ result[11] = 0;
5012
+ result[12] = x;
5013
+ result[13] = y;
5014
+ result[14] = z;
5015
+ result[15] = 1;
5016
+ return result;
5017
+ }
5018
+ var EPSILON142, scratchOrigin, scratchBasis, VECTOR_PRODUCT_LOCAL_FRAME, degeneratePositionLocalFrame, scratchAxisVectors, scratchVector1, scratchVector23, scratchVector32;
5019
+ var init_ellipsoid_transform = __esm({
5020
+ "../../node_modules/@math.gl/geospatial/dist/ellipsoid-helpers/ellipsoid-transform.js"() {
5021
+ init_dist();
5022
+ init_local_frame();
5023
+ EPSILON142 = 1e-14;
5024
+ scratchOrigin = new Vector3();
5025
+ scratchBasis = createLocalFrameBasis();
5026
+ VECTOR_PRODUCT_LOCAL_FRAME = {
5027
+ up: {
5028
+ south: "east",
5029
+ north: "west",
5030
+ west: "south",
5031
+ east: "north"
5032
+ },
5033
+ down: {
5034
+ south: "west",
5035
+ north: "east",
5036
+ west: "north",
5037
+ east: "south"
5038
+ },
5039
+ south: {
5040
+ up: "west",
5041
+ down: "east",
5042
+ west: "down",
5043
+ east: "up"
5044
+ },
5045
+ north: {
5046
+ up: "east",
5047
+ down: "west",
5048
+ west: "up",
5049
+ east: "down"
5050
+ },
5051
+ west: {
5052
+ up: "north",
5053
+ down: "south",
5054
+ north: "down",
5055
+ south: "up"
5056
+ },
5057
+ east: {
5058
+ up: "south",
5059
+ down: "north",
5060
+ north: "up",
5061
+ south: "down"
5062
+ }
5063
+ };
5064
+ degeneratePositionLocalFrame = {
5065
+ north: [-1, 0, 0],
5066
+ east: [0, 1, 0],
5067
+ up: [0, 0, 1],
5068
+ south: [1, 0, 0],
5069
+ west: [0, -1, 0],
5070
+ down: [0, 0, -1]
5071
+ };
5072
+ scratchAxisVectors = {
5073
+ east: new Vector3(),
5074
+ north: new Vector3(),
5075
+ up: new Vector3(),
5076
+ west: new Vector3(),
5077
+ south: new Vector3(),
5078
+ down: new Vector3()
5079
+ };
5080
+ scratchVector1 = new Vector3();
5081
+ scratchVector23 = new Vector3();
5082
+ scratchVector32 = new Vector3();
5083
+ }
5084
+ });
5085
+
5086
+ // ../../node_modules/@math.gl/geospatial/dist/ellipsoid-transforms.js
5087
+ function eastNorthUpToFixedFrame(ellipsoid, origin, result = new Matrix4()) {
5088
+ return localFrameToFixedFrame(ellipsoid, "east", "north", "up", origin, result);
5089
+ }
5090
+ var init_ellipsoid_transforms = __esm({
5091
+ "../../node_modules/@math.gl/geospatial/dist/ellipsoid-transforms.js"() {
5092
+ init_dist();
5093
+ init_ellipsoid_transform();
5094
+ }
5095
+ });
5096
+
4908
5097
  // ../../node_modules/@math.gl/geospatial/dist/entries/ellipsoid.js
4909
5098
  var init_ellipsoid2 = __esm({
4910
5099
  "../../node_modules/@math.gl/geospatial/dist/entries/ellipsoid.js"() {
4911
5100
  init_ellipsoid();
5101
+ init_ellipsoid_transforms();
4912
5102
  }
4913
5103
  });
4914
5104
 
@@ -6585,6 +6775,7 @@ var __exports__ = (() => {
6585
6775
 
6586
6776
  // ../tiles-3d/src/tileset-3d/helpers/transform-utils.ts
6587
6777
  init_dist2();
6778
+ init_ellipsoid2();
6588
6779
  init_dist();
6589
6780
  init_loader_utils();
6590
6781
  function calculateTransformProps(tileHeader, tile) {
@@ -6623,7 +6814,7 @@ var __exports__ = (() => {
6623
6814
  cartesianOrigin,
6624
6815
  new Vector3()
6625
6816
  );
6626
- const fromFixedFrameMatrix = Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin);
6817
+ const fromFixedFrameMatrix = eastNorthUpToFixedFrame(Ellipsoid.WGS84, cartesianOrigin);
6627
6818
  const toFixedFrameMatrix = fromFixedFrameMatrix.invert();
6628
6819
  tile.cartographicModelMatrix = toFixedFrameMatrix.multiplyRight(modelMatrix);
6629
6820
  tile.cartographicOrigin = cartographicOrigin;
@@ -6639,13 +6830,14 @@ var __exports__ = (() => {
6639
6830
  }
6640
6831
  var TRANSLATION_LIMIT_SQUARED = 1e6 ** 2;
6641
6832
  function _getRootNode(tile) {
6642
- const gltf = tile.gltf;
6833
+ const gltf = tile.gltf?.json;
6643
6834
  if (!gltf) {
6644
6835
  return null;
6645
6836
  }
6646
6837
  const sceneIndex = typeof gltf.scene === "number" ? gltf.scene : 0;
6647
6838
  const scene = gltf.scenes?.[sceneIndex];
6648
- const rootNode = scene?.nodes?.[0];
6839
+ const rootNodeIndex = scene?.nodes?.[0];
6840
+ const rootNode = rootNodeIndex === void 0 ? void 0 : gltf.nodes?.[rootNodeIndex];
6649
6841
  if (!rootNode?.matrix) return null;
6650
6842
  const m = rootNode.matrix;
6651
6843
  const translationMagnitude = m[12] * m[12] + m[13] * m[13] + m[14] * m[14];
@@ -6657,7 +6849,8 @@ var __exports__ = (() => {
6657
6849
  init_dist();
6658
6850
  init_culling();
6659
6851
  init_dist2();
6660
- var scratchVector7 = new Vector3();
6852
+ init_ellipsoid2();
6853
+ var scratchVector4 = new Vector3();
6661
6854
  var scratchPosition3 = new Vector3();
6662
6855
  var CAMERA_POSITION_EPSILON = 1e-5;
6663
6856
  var CAMERA_DIRECTION_EPSILON = 1e-7;
@@ -6674,7 +6867,7 @@ var __exports__ = (() => {
6674
6867
  const cameraDirection = viewport.cameraDirection;
6675
6868
  const { metersPerUnit } = viewport.distanceScales;
6676
6869
  const viewportCenterCartesian = worldToCartesian(viewport, viewport.center);
6677
- const enuToFixedTransform = Ellipsoid.WGS84.eastNorthUpToFixedFrame(viewportCenterCartesian);
6870
+ const enuToFixedTransform = eastNorthUpToFixedFrame(Ellipsoid.WGS84, viewportCenterCartesian);
6678
6871
  const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
6679
6872
  const cameraPositionCartesian = Ellipsoid.WGS84.cartographicToCartesian(
6680
6873
  cameraPositionCartographic,
@@ -6782,7 +6975,7 @@ var __exports__ = (() => {
6782
6975
  let i = 0;
6783
6976
  cullingVolume.planes[i++].fromPointNormal(
6784
6977
  nearCenterCartesian,
6785
- scratchVector7.copy(nearCenterCartesian).subtract(cameraCartesian)
6978
+ scratchVector4.copy(nearCenterCartesian).subtract(cameraCartesian)
6786
6979
  );
6787
6980
  for (const dir in frustumPlanes) {
6788
6981
  if (dir === "near") {
@@ -6794,7 +6987,7 @@ var __exports__ = (() => {
6794
6987
  cullingVolume.planes[i++].fromPointNormal(
6795
6988
  cartesianPos,
6796
6989
  // Want the normal to point into the frustum since that's what culling expects
6797
- scratchVector7.copy(nearCenterCartesian).subtract(cartesianPos)
6990
+ scratchVector4.copy(nearCenterCartesian).subtract(cartesianPos)
6798
6991
  );
6799
6992
  }
6800
6993
  }