@math.gl/geospatial 5.0.0-rc.1 → 5.0.0

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 (232) hide show
  1. package/README.md +6 -6
  2. package/dist/coordinates.cjs +2523 -0
  3. package/dist/coordinates.cjs.map +6 -0
  4. package/dist/coordinates.d.ts +4 -0
  5. package/dist/coordinates.d.ts.map +1 -1
  6. package/dist/coordinates.js +2 -0
  7. package/dist/coordinates.js.map +1 -1
  8. package/dist/entries/ellipsoid.cjs +1209 -0
  9. package/dist/entries/ellipsoid.cjs.map +6 -0
  10. package/dist/entries/ellipsoid.d.ts +3 -19
  11. package/dist/entries/ellipsoid.d.ts.map +1 -1
  12. package/dist/entries/ellipsoid.js +1 -9
  13. package/dist/entries/ellipsoid.js.map +1 -1
  14. package/dist/expressions.cjs +726 -0
  15. package/dist/expressions.cjs.map +6 -0
  16. package/dist/geodesics.cjs +3195 -0
  17. package/dist/geodesics.cjs.map +6 -0
  18. package/dist/geodesics.d.ts +18 -0
  19. package/dist/geodesics.d.ts.map +1 -0
  20. package/dist/geodesics.js +13 -0
  21. package/dist/geodesics.js.map +1 -0
  22. package/dist/geographic-atlas/sampling.d.ts +1 -1
  23. package/dist/geographic-atlas/sampling.d.ts.map +1 -1
  24. package/dist/geographic-atlas/sampling.js +1 -1
  25. package/dist/geographic-atlas/sampling.js.map +1 -1
  26. package/dist/geographic-cuts.cjs +4160 -0
  27. package/dist/geographic-cuts.cjs.map +6 -0
  28. package/dist/geographic-cuts.d.ts +2 -0
  29. package/dist/geographic-cuts.d.ts.map +1 -1
  30. package/dist/geographic-cuts.js +1 -0
  31. package/dist/geographic-cuts.js.map +1 -1
  32. package/dist/geographic-seams/subdivide-cut.d.ts +1 -1
  33. package/dist/geographic-seams/subdivide-cut.d.ts.map +1 -1
  34. package/dist/geographic-seams/subdivide-cut.js +1 -1
  35. package/dist/geographic-seams/subdivide-cut.js.map +1 -1
  36. package/dist/geographic-seams/types.shared.cjs +32 -0
  37. package/dist/geographic-seams/types.shared.cjs.map +6 -0
  38. package/dist/globe.cjs +4223 -0
  39. package/dist/globe.cjs.map +6 -0
  40. package/dist/index.d.ts +2 -0
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +2 -0
  43. package/dist/index.js.map +1 -1
  44. package/dist/maps/map-transition.shared.cjs +364 -0
  45. package/dist/maps/map-transition.shared.cjs.map +6 -0
  46. package/dist/maps/myriahedral/unfold.d.ts +1 -1
  47. package/dist/maps/myriahedral/unfold.d.ts.map +1 -1
  48. package/dist/maps/myriahedral/unfold.js +1 -1
  49. package/dist/maps/myriahedral/unfold.js.map +1 -1
  50. package/dist/maps/presets.cjs +2 -2
  51. package/dist/maps/presets.cjs.map +2 -2
  52. package/dist/maps/transitions.cjs +3 -342
  53. package/dist/maps/transitions.cjs.map +3 -3
  54. package/dist/maps.cjs +15 -319
  55. package/dist/maps.cjs.map +3 -3
  56. package/dist/projection/experimental/core.cjs +63 -1317
  57. package/dist/projection/experimental/core.cjs.map +3 -3
  58. package/dist/projection/experimental/core.d.ts +1 -1
  59. package/dist/projection/experimental/core.d.ts.map +1 -1
  60. package/dist/projection/experimental/crs/projjson.cjs +26 -45
  61. package/dist/projection/experimental/crs/projjson.cjs.map +3 -3
  62. package/dist/projection/experimental/crs/types.shared.cjs +44 -0
  63. package/dist/projection/experimental/crs/types.shared.cjs.map +6 -0
  64. package/dist/projection/experimental/crs/wkt.cjs +36 -52
  65. package/dist/projection/experimental/crs/wkt.cjs.map +3 -3
  66. package/dist/projection/experimental/entries/projections/ob_tran.cjs +9 -23
  67. package/dist/projection/experimental/entries/projections/ob_tran.cjs.map +3 -3
  68. package/dist/projection/experimental/lazy-projections/aea.cjs +1 -1
  69. package/dist/projection/experimental/lazy-projections/aea.js +1 -1
  70. package/dist/projection/experimental/lazy-projections/aeqd.cjs +1 -1
  71. package/dist/projection/experimental/lazy-projections/aeqd.js +1 -1
  72. package/dist/projection/experimental/lazy-projections/bonne.cjs +1 -1
  73. package/dist/projection/experimental/lazy-projections/bonne.js +1 -1
  74. package/dist/projection/experimental/lazy-projections/cass.cjs +1 -1
  75. package/dist/projection/experimental/lazy-projections/cass.js +1 -1
  76. package/dist/projection/experimental/lazy-projections/cea.cjs +1 -1
  77. package/dist/projection/experimental/lazy-projections/cea.js +1 -1
  78. package/dist/projection/experimental/lazy-projections/eck6.cjs +1 -1
  79. package/dist/projection/experimental/lazy-projections/eck6.js +1 -1
  80. package/dist/projection/experimental/lazy-projections/eqc.cjs +1 -1
  81. package/dist/projection/experimental/lazy-projections/eqc.js +1 -1
  82. package/dist/projection/experimental/lazy-projections/eqdc.cjs +1 -1
  83. package/dist/projection/experimental/lazy-projections/eqdc.js +1 -1
  84. package/dist/projection/experimental/lazy-projections/eqearth.cjs +1 -1
  85. package/dist/projection/experimental/lazy-projections/eqearth.js +1 -1
  86. package/dist/projection/experimental/lazy-projections/equi.cjs +1 -1
  87. package/dist/projection/experimental/lazy-projections/equi.js +1 -1
  88. package/dist/projection/experimental/lazy-projections/etmerc.cjs +1 -1
  89. package/dist/projection/experimental/lazy-projections/etmerc.js +1 -1
  90. package/dist/projection/experimental/lazy-projections/geocent.cjs +1 -1
  91. package/dist/projection/experimental/lazy-projections/geocent.js +1 -1
  92. package/dist/projection/experimental/lazy-projections/geos.cjs +1 -1
  93. package/dist/projection/experimental/lazy-projections/geos.js +1 -1
  94. package/dist/projection/experimental/lazy-projections/gnom.cjs +1 -1
  95. package/dist/projection/experimental/lazy-projections/gnom.js +1 -1
  96. package/dist/projection/experimental/lazy-projections/gstmerc.cjs +1 -1
  97. package/dist/projection/experimental/lazy-projections/gstmerc.js +1 -1
  98. package/dist/projection/experimental/lazy-projections/index.cjs +60 -903
  99. package/dist/projection/experimental/lazy-projections/index.cjs.map +3 -3
  100. package/dist/projection/experimental/lazy-projections/krovak.cjs +1 -1
  101. package/dist/projection/experimental/lazy-projections/krovak.js +1 -1
  102. package/dist/projection/experimental/lazy-projections/laea.cjs +1 -1
  103. package/dist/projection/experimental/lazy-projections/laea.js +1 -1
  104. package/dist/projection/experimental/lazy-projections/lcc.cjs +1 -1
  105. package/dist/projection/experimental/lazy-projections/lcc.js +1 -1
  106. package/dist/projection/experimental/lazy-projections/merc.cjs +1 -1
  107. package/dist/projection/experimental/lazy-projections/merc.js +1 -1
  108. package/dist/projection/experimental/lazy-projections/mill.cjs +1 -1
  109. package/dist/projection/experimental/lazy-projections/mill.js +1 -1
  110. package/dist/projection/experimental/lazy-projections/moll.cjs +1 -1
  111. package/dist/projection/experimental/lazy-projections/moll.js +1 -1
  112. package/dist/projection/experimental/lazy-projections/nzmg.cjs +1 -1
  113. package/dist/projection/experimental/lazy-projections/nzmg.js +1 -1
  114. package/dist/projection/experimental/lazy-projections/ob_tran.cjs +1 -1
  115. package/dist/projection/experimental/lazy-projections/ob_tran.js +1 -1
  116. package/dist/projection/experimental/lazy-projections/omerc.cjs +1 -1
  117. package/dist/projection/experimental/lazy-projections/omerc.js +1 -1
  118. package/dist/projection/experimental/lazy-projections/ortho.cjs +1 -1
  119. package/dist/projection/experimental/lazy-projections/ortho.js +1 -1
  120. package/dist/projection/experimental/lazy-projections/poly.cjs +1 -1
  121. package/dist/projection/experimental/lazy-projections/poly.js +1 -1
  122. package/dist/projection/experimental/lazy-projections/qsc.cjs +1 -1
  123. package/dist/projection/experimental/lazy-projections/qsc.js +1 -1
  124. package/dist/projection/experimental/lazy-projections/robin.cjs +1 -1
  125. package/dist/projection/experimental/lazy-projections/robin.js +1 -1
  126. package/dist/projection/experimental/lazy-projections/sinu.cjs +1 -1
  127. package/dist/projection/experimental/lazy-projections/sinu.js +1 -1
  128. package/dist/projection/experimental/lazy-projections/somerc.cjs +1 -1
  129. package/dist/projection/experimental/lazy-projections/somerc.js +1 -1
  130. package/dist/projection/experimental/lazy-projections/stere.cjs +1 -1
  131. package/dist/projection/experimental/lazy-projections/stere.js +1 -1
  132. package/dist/projection/experimental/lazy-projections/sterea.cjs +1 -1
  133. package/dist/projection/experimental/lazy-projections/sterea.js +1 -1
  134. package/dist/projection/experimental/lazy-projections/tmerc.cjs +1 -1
  135. package/dist/projection/experimental/lazy-projections/tmerc.js +1 -1
  136. package/dist/projection/experimental/lazy-projections/tpers.cjs +1 -1
  137. package/dist/projection/experimental/lazy-projections/tpers.js +1 -1
  138. package/dist/projection/experimental/lazy-projections/utm.cjs +1 -1
  139. package/dist/projection/experimental/lazy-projections/utm.js +1 -1
  140. package/dist/projection/experimental/lazy-projections/vandg.cjs +1 -1
  141. package/dist/projection/experimental/lazy-projections/vandg.js +1 -1
  142. package/dist/projection/experimental/projection-engine.shared.cjs +1184 -0
  143. package/dist/projection/experimental/projection-engine.shared.cjs.map +6 -0
  144. package/dist/projection/experimental/typescript-projection.shared.cjs +1703 -0
  145. package/dist/projection/experimental/typescript-projection.shared.cjs.map +6 -0
  146. package/dist/projection/index.cjs +622 -1535
  147. package/dist/projection/index.cjs.map +3 -3
  148. package/dist/projection/pipeline.cjs +44 -58
  149. package/dist/projection/pipeline.cjs.map +3 -3
  150. package/dist/projection/transform-analysis.cjs +20 -936
  151. package/dist/projection/transform-analysis.cjs.map +3 -3
  152. package/dist/subdivide-geodesic-polyline.d.ts +1 -1
  153. package/dist/subdivide-geodesic-polyline.d.ts.map +1 -1
  154. package/dist/subdivide-geodesic-polyline.js +1 -1
  155. package/dist/subdivide-geodesic-polyline.js.map +1 -1
  156. package/dist/subdivide-globe-mesh.d.ts +1 -1
  157. package/dist/subdivide-globe-mesh.d.ts.map +1 -1
  158. package/dist/subdivide-globe-mesh.js +1 -1
  159. package/dist/subdivide-globe-mesh.js.map +1 -1
  160. package/dist/subdivide-rhumb-polyline.d.ts +1 -1
  161. package/dist/subdivide-rhumb-polyline.d.ts.map +1 -1
  162. package/dist/subdivide-rhumb-polyline.js +1 -1
  163. package/dist/subdivide-rhumb-polyline.js.map +1 -1
  164. package/dist/tasks/index.cjs +808 -2993
  165. package/dist/tasks/index.cjs.map +3 -3
  166. package/dist/terrain/geometry.d.ts +1 -1
  167. package/dist/terrain/geometry.d.ts.map +1 -1
  168. package/dist/terrain/geometry.js +1 -1
  169. package/dist/terrain/geometry.js.map +1 -1
  170. package/dist/terrain/index.cjs +2 -2
  171. package/dist/terrain/index.cjs.map +1 -1
  172. package/dist/tiles.cjs +354 -0
  173. package/dist/tiles.cjs.map +6 -0
  174. package/package.json +139 -117
  175. package/src/coordinates.ts +5 -0
  176. package/src/entries/ellipsoid.ts +7 -32
  177. package/src/geodesics.ts +40 -0
  178. package/src/geographic-atlas/sampling.ts +1 -1
  179. package/src/geographic-cuts.ts +21 -0
  180. package/src/geographic-seams/subdivide-cut.ts +1 -1
  181. package/src/index.ts +2 -0
  182. package/src/maps/myriahedral/unfold.ts +1 -1
  183. package/src/projection/experimental/core.ts +1 -1
  184. package/src/projection/experimental/lazy-projections/aea.ts +1 -1
  185. package/src/projection/experimental/lazy-projections/aeqd.ts +1 -1
  186. package/src/projection/experimental/lazy-projections/bonne.ts +1 -1
  187. package/src/projection/experimental/lazy-projections/cass.ts +1 -1
  188. package/src/projection/experimental/lazy-projections/cea.ts +1 -1
  189. package/src/projection/experimental/lazy-projections/eck6.ts +1 -1
  190. package/src/projection/experimental/lazy-projections/eqc.ts +1 -1
  191. package/src/projection/experimental/lazy-projections/eqdc.ts +1 -1
  192. package/src/projection/experimental/lazy-projections/eqearth.ts +1 -1
  193. package/src/projection/experimental/lazy-projections/equi.ts +1 -1
  194. package/src/projection/experimental/lazy-projections/etmerc.ts +1 -1
  195. package/src/projection/experimental/lazy-projections/geocent.ts +1 -1
  196. package/src/projection/experimental/lazy-projections/geos.ts +1 -1
  197. package/src/projection/experimental/lazy-projections/gnom.ts +1 -1
  198. package/src/projection/experimental/lazy-projections/gstmerc.ts +1 -1
  199. package/src/projection/experimental/lazy-projections/krovak.ts +1 -1
  200. package/src/projection/experimental/lazy-projections/laea.ts +1 -1
  201. package/src/projection/experimental/lazy-projections/lcc.ts +1 -1
  202. package/src/projection/experimental/lazy-projections/merc.ts +1 -1
  203. package/src/projection/experimental/lazy-projections/mill.ts +1 -1
  204. package/src/projection/experimental/lazy-projections/moll.ts +1 -1
  205. package/src/projection/experimental/lazy-projections/nzmg.ts +1 -1
  206. package/src/projection/experimental/lazy-projections/ob_tran.ts +1 -1
  207. package/src/projection/experimental/lazy-projections/omerc.ts +1 -1
  208. package/src/projection/experimental/lazy-projections/ortho.ts +1 -1
  209. package/src/projection/experimental/lazy-projections/poly.ts +1 -1
  210. package/src/projection/experimental/lazy-projections/qsc.ts +1 -1
  211. package/src/projection/experimental/lazy-projections/robin.ts +1 -1
  212. package/src/projection/experimental/lazy-projections/sinu.ts +1 -1
  213. package/src/projection/experimental/lazy-projections/somerc.ts +1 -1
  214. package/src/projection/experimental/lazy-projections/stere.ts +1 -1
  215. package/src/projection/experimental/lazy-projections/sterea.ts +1 -1
  216. package/src/projection/experimental/lazy-projections/tmerc.ts +1 -1
  217. package/src/projection/experimental/lazy-projections/tpers.ts +1 -1
  218. package/src/projection/experimental/lazy-projections/utm.ts +1 -1
  219. package/src/projection/experimental/lazy-projections/vandg.ts +1 -1
  220. package/src/subdivide-geodesic-polyline.ts +2 -2
  221. package/src/subdivide-globe-mesh.ts +2 -2
  222. package/src/subdivide-rhumb-polyline.ts +2 -2
  223. package/src/terrain/geometry.ts +1 -1
  224. package/dist/index.cjs +0 -18674
  225. package/dist/index.cjs.map +0 -6
  226. package/dist/turf-expressions.cjs +0 -1997
  227. package/dist/turf-expressions.cjs.map +0 -6
  228. package/dist/turf-expressions.d.ts +0 -3
  229. package/dist/turf-expressions.d.ts.map +0 -1
  230. package/dist/turf-expressions.js +0 -7
  231. package/dist/turf-expressions.js.map +0 -1
  232. package/src/turf-expressions.ts +0 -7
@@ -0,0 +1,1209 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // dist/entries/ellipsoid.js
20
+ var ellipsoid_exports = {};
21
+ __export(ellipsoid_exports, {
22
+ Ellipsoid: () => Ellipsoid,
23
+ EllipsoidMetrics: () => EllipsoidMetrics,
24
+ EllipsoidTangentPlane: () => EllipsoidTangentPlane,
25
+ TriaxialEllipsoid: () => TriaxialEllipsoid,
26
+ isWGS84: () => isWGS84
27
+ });
28
+ module.exports = __toCommonJS(ellipsoid_exports);
29
+
30
+ // dist/ellipsoid.js
31
+ var import_matrix3 = require("@math.gl/core/matrix");
32
+ var import_matrix4 = require("@math.gl/core/matrix");
33
+
34
+ // dist/constants.js
35
+ var WGS84_RADIUS_X = 6378137;
36
+ var WGS84_RADIUS_Y = 6378137;
37
+ var WGS84_RADIUS_Z = 6356752314245179e-9;
38
+ var WGS84_CONSTANTS = {
39
+ radii: [WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z],
40
+ radiiSquared: [
41
+ WGS84_RADIUS_X * WGS84_RADIUS_X,
42
+ WGS84_RADIUS_Y * WGS84_RADIUS_Y,
43
+ WGS84_RADIUS_Z * WGS84_RADIUS_Z
44
+ ],
45
+ oneOverRadii: [1 / WGS84_RADIUS_X, 1 / WGS84_RADIUS_Y, 1 / WGS84_RADIUS_Z],
46
+ oneOverRadiiSquared: [
47
+ 1 / (WGS84_RADIUS_X * WGS84_RADIUS_X),
48
+ 1 / (WGS84_RADIUS_Y * WGS84_RADIUS_Y),
49
+ 1 / (WGS84_RADIUS_Z * WGS84_RADIUS_Z)
50
+ ],
51
+ maximumRadius: Math.max(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z),
52
+ centerToleranceSquared: 0.1
53
+ // EPSILON1;
54
+ };
55
+
56
+ // dist/type-utils.js
57
+ var import_matrix = require("@math.gl/core/matrix");
58
+ function identity(x) {
59
+ return x;
60
+ }
61
+ var scratchVector = new import_matrix.Vector3();
62
+ function fromCartographic(cartographic, result = [], map = identity) {
63
+ if ("longitude" in cartographic) {
64
+ result[0] = map(cartographic.longitude);
65
+ result[1] = map(cartographic.latitude);
66
+ result[2] = cartographic.height;
67
+ } else if ("x" in cartographic) {
68
+ result[0] = map(cartographic.x);
69
+ result[1] = map(cartographic.y);
70
+ result[2] = cartographic.z;
71
+ } else {
72
+ result[0] = map(cartographic[0]);
73
+ result[1] = map(cartographic[1]);
74
+ result[2] = cartographic[2];
75
+ }
76
+ return result;
77
+ }
78
+ function fromCartographicToRadians(cartographic, vector2 = []) {
79
+ return fromCartographic(cartographic, vector2, import_matrix.config._cartographicRadians ? identity : import_matrix.toRadians);
80
+ }
81
+ function toCartographicFromRadiansComponents(longitude, latitude, height, cartographic) {
82
+ const map = import_matrix.config._cartographicRadians ? identity : import_matrix.toDegrees;
83
+ const mappedLongitude = map(longitude), mappedLatitude = map(latitude);
84
+ if ("longitude" in cartographic) {
85
+ cartographic.longitude = mappedLongitude;
86
+ cartographic.latitude = mappedLatitude;
87
+ cartographic.height = height;
88
+ } else if ("x" in cartographic) {
89
+ cartographic.x = mappedLongitude;
90
+ cartographic.y = mappedLatitude;
91
+ cartographic.z = height;
92
+ } else {
93
+ cartographic[0] = mappedLongitude;
94
+ cartographic[1] = mappedLatitude;
95
+ cartographic[2] = height;
96
+ }
97
+ return cartographic;
98
+ }
99
+ function isWGS84(vector2) {
100
+ if (!vector2) {
101
+ return false;
102
+ }
103
+ scratchVector.from(vector2);
104
+ const { oneOverRadiiSquared, centerToleranceSquared } = WGS84_CONSTANTS;
105
+ const x2 = vector2[0] * vector2[0] * oneOverRadiiSquared[0];
106
+ const y2 = vector2[1] * vector2[1] * oneOverRadiiSquared[1];
107
+ const z2 = vector2[2] * vector2[2] * oneOverRadiiSquared[2];
108
+ return Math.abs(x2 + y2 + z2 - 1) < centerToleranceSquared;
109
+ }
110
+
111
+ // dist/ellipsoid-helpers/scale-to-geodetic-surface.js
112
+ var import_matrix2 = require("@math.gl/core/matrix");
113
+
114
+ // dist/ellipsoid-helpers/exact-nearest-surface.js
115
+ function exactNearestSurface(x, y, z, a, b, c, result) {
116
+ const values = [a, b, c, Math.abs(x), Math.abs(y), Math.abs(z)];
117
+ const parts = values.map((value) => {
118
+ const bits = value.toString(2);
119
+ const dot = bits.indexOf(".");
120
+ return {
121
+ integer: BigInt("0b" + bits.replace(".", "")),
122
+ exponent: dot < 0 ? 0 : dot + 1 - bits.length
123
+ };
124
+ });
125
+ const exponent = Math.min(...parts.filter((p) => p.integer !== 0n).map((p) => p.exponent));
126
+ const integers = parts.map((p) => p.integer << BigInt(p.exponent - exponent));
127
+ const squares = integers.slice(0, 3).map((v) => v * v);
128
+ const minimum = squares.reduce((p, v) => p < v ? p : v);
129
+ const offsets = squares.map((v) => v - minimum);
130
+ const products = squares.map((_, i) => integers[i] * integers[i + 3]);
131
+ let precision = 64;
132
+ if (!products.some((u3, i) => offsets[i] === 0n && u3 !== 0n)) {
133
+ let numerator = -1n, denominator = 1n;
134
+ for (let i = 0; i < 3; i++) {
135
+ if (offsets[i] === 0n)
136
+ continue;
137
+ const d2 = offsets[i] * offsets[i];
138
+ numerator = numerator * d2 + products[i] * products[i] * denominator;
139
+ denominator *= d2;
140
+ }
141
+ if (numerator < 0n)
142
+ return false;
143
+ if (numerator === 0n) {
144
+ return commit(0n, 1n);
145
+ }
146
+ const positive = offsets.filter((d2) => d2 > 0n);
147
+ const least = positive.reduce((p, v) => p < v ? p : v);
148
+ precision = Math.max(64, (2n * (denominator + numerator)).toString(2).length - (numerator * least).toString(2).length + 128);
149
+ }
150
+ const unit2 = 1n << BigInt(precision);
151
+ const d = offsets.map((v) => v * unit2);
152
+ const u = products.map((v) => v * unit2);
153
+ const u2 = u.map((v) => v * v);
154
+ let lower = 0n, upper = u.reduce((sum, v) => sum + v, 0n);
155
+ if (upper === 0n)
156
+ return false;
157
+ for (let iteration = 0; iteration < 4096; iteration++) {
158
+ const t = lower + upper >> 1n;
159
+ if (t === lower)
160
+ return false;
161
+ const dx = d[0] + t, dy = d[1] + t, dz = d[2] + t;
162
+ const xx = dx * dx, yy = dy * dy, zz = dz * dz;
163
+ const sign = u2[0] * yy * zz + u2[1] * xx * zz + u2[2] * xx * yy - xx * yy * zz;
164
+ if (sign === 0n)
165
+ return commit(t, unit2);
166
+ if (sign > 0n)
167
+ lower = t;
168
+ else
169
+ upper = t;
170
+ if (lower > 0n && upper - lower <= lower >> 60n)
171
+ return commit(lower + upper >> 1n, unit2);
172
+ }
173
+ return false;
174
+ function commit(t, unit3) {
175
+ const output = squares.map((r2, i) => {
176
+ const denominator = offsets[i] * unit3 + t;
177
+ return denominator === 0n ? 0 : ratio(r2 * integers[i + 3] * unit3, denominator, exponent);
178
+ });
179
+ if (!output.every(Number.isFinite))
180
+ return false;
181
+ const qx = Math.sign(x) * output[0], qy = Math.sign(y) * output[1], qz = Math.sign(z) * output[2];
182
+ result.x = qx;
183
+ result.y = qy;
184
+ result.z = qz;
185
+ return true;
186
+ }
187
+ }
188
+ function ratio(n, d, exponent) {
189
+ if (n === 0n)
190
+ return 0;
191
+ const shift = 52 - (n.toString(2).length - d.toString(2).length);
192
+ const numerator = shift >= 0 ? n << BigInt(shift) : n;
193
+ const denominator = shift >= 0 ? d : d << BigInt(-shift);
194
+ let quotient = numerator / denominator;
195
+ const remainder = numerator % denominator;
196
+ if (2n * remainder > denominator || 2n * remainder === denominator && quotient & 1n)
197
+ quotient++;
198
+ const power = exponent - shift;
199
+ const first = Math.max(-1022, Math.min(1023, power));
200
+ return Number(quotient) * 2 ** first * 2 ** (power - first);
201
+ }
202
+
203
+ // dist/ellipsoid-helpers/nearest-surface.js
204
+ function nearestSurface(x, y, z, a, b, c, result) {
205
+ const minimum = Math.min(a, b, c);
206
+ const minimumSquared = minimum * minimum;
207
+ const aa = a * a, bb = b * b, cc = c * c;
208
+ if (!(minimum > 0) || !(minimumSquared > 0) || !Number.isFinite(Math.max(aa, bb, cc)))
209
+ return false;
210
+ const minimumError = productError(minimum, minimum, minimumSquared);
211
+ const dx = aa - minimumSquared, dy = bb - minimumSquared, dz = cc - minimumSquared;
212
+ const ex = sumError(aa, -minimumSquared, dx) + productError(a, a, aa) - minimumError;
213
+ const ey = sumError(bb, -minimumSquared, dy) + productError(b, b, bb) - minimumError;
214
+ const ez = sumError(cc, -minimumSquared, dz) + productError(c, c, cc) - minimumError;
215
+ const ux = a * Math.abs(x), uy = b * Math.abs(y), uz = c * Math.abs(z);
216
+ if (minimumSquared < 2 ** -1022 || x !== 0 && ux < 2 ** -1022 || y !== 0 && uy < 2 ** -1022 || z !== 0 && uz < 2 ** -1022)
217
+ return exactNearestSurface(x, y, z, a, b, c, result);
218
+ const fx = productError(a, Math.abs(x), ux);
219
+ const fy = productError(b, Math.abs(y), uy);
220
+ const fz = productError(c, Math.abs(z), uz);
221
+ 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));
222
+ if (limit <= 1 + 64 * Number.EPSILON)
223
+ return exactNearestSurface(x, y, z, a, b, c, result);
224
+ if ((x !== 0 ? 1 : 0) + (y !== 0 ? 1 : 0) + (z !== 0 ? 1 : 0) === 1) {
225
+ result.x = x === 0 ? x : Math.sign(x) * a;
226
+ result.y = y === 0 ? y : Math.sign(y) * b;
227
+ result.z = z === 0 ? z : Math.sign(z) * c;
228
+ return true;
229
+ }
230
+ let lower = Math.hypot(dx === 0 ? ux : 0, dy === 0 ? uy : 0, dz === 0 ? uz : 0);
231
+ let upper = Math.hypot(ux, uy, uz);
232
+ if (!(upper > 0) || !Number.isFinite(upper))
233
+ return exactNearestSurface(x, y, z, a, b, c, result);
234
+ let t = lower > 0 ? lower : upper;
235
+ for (let iteration = 0; iteration < 512; iteration++) {
236
+ const hx = dx + t, hy = dy + t, hz = dz + t;
237
+ const lx = sumError(dx, t, hx) + ex;
238
+ const ly = sumError(dy, t, hy) + ey;
239
+ const lz = sumError(dz, t, hz) + ez;
240
+ const vx = ux / hx, vy = uy / hy, vz = uz / hz;
241
+ let term, rest;
242
+ if (vx >= vy && vx >= vz) {
243
+ term = offset(ux, fx, dx, ex, t, hx) * (vx + 1);
244
+ rest = (vy * (1 - ly / hy)) ** 2 + (vz * (1 - lz / hz)) ** 2;
245
+ } else if (vy >= vz) {
246
+ term = offset(uy, fy, dy, ey, t, hy) * (vy + 1);
247
+ rest = (vx * (1 - lx / hx)) ** 2 + (vz * (1 - lz / hz)) ** 2;
248
+ } else {
249
+ term = offset(uz, fz, dz, ez, t, hz) * (vz + 1);
250
+ rest = (vx * (1 - lx / hx)) ** 2 + (vy * (1 - ly / hy)) ** 2;
251
+ }
252
+ const derivative = -2 * (vx * vx / hx + vy * vy / hy + vz * vz / hz);
253
+ const roundoff = 4 * Number.EPSILON * (Math.abs(term) + rest);
254
+ const residual = term + rest;
255
+ if (!Number.isFinite(residual))
256
+ return exactNearestSurface(x, y, z, a, b, c, result);
257
+ if (Math.abs(residual) <= 4 * Number.EPSILON * (Math.abs(term) + rest) || upper - lower <= 4 * Number.EPSILON * t) {
258
+ const uncertainty = roundoff / Math.abs(derivative);
259
+ if (!Number.isFinite(derivative) || !(Math.abs(derivative) > 0) || uncertainty > 2e-13 * t)
260
+ return exactNearestSurface(x, y, z, a, b, c, result);
261
+ const qx = Math.sign(x) * a * (vx * (1 - lx / hx));
262
+ const qy = Math.sign(y) * b * (vy * (1 - ly / hy));
263
+ const qz = Math.sign(z) * c * (vz * (1 - lz / hz));
264
+ const displacement = 2 * uncertainty * Math.max(Math.abs(qx / hx), Math.abs(qy / hy), Math.abs(qz / hz));
265
+ if (!Number.isFinite(displacement) || displacement > 2e-13 * Math.max(a, b, c))
266
+ return exactNearestSurface(x, y, z, a, b, c, result);
267
+ if (!Number.isFinite(qx) || !Number.isFinite(qy) || !Number.isFinite(qz))
268
+ return exactNearestSurface(x, y, z, a, b, c, result);
269
+ result.x = qx;
270
+ result.y = qy;
271
+ result.z = qz;
272
+ return true;
273
+ }
274
+ if (residual > 0)
275
+ lower = t;
276
+ else
277
+ upper = t;
278
+ const candidate = t - residual / derivative;
279
+ const next = candidate > lower && candidate < upper ? candidate : lower + (upper - lower) / 2;
280
+ if (next === t)
281
+ return exactNearestSurface(x, y, z, a, b, c, result);
282
+ t = next;
283
+ }
284
+ return exactNearestSurface(x, y, z, a, b, c, result);
285
+ }
286
+ function offset(u, error, d, dError, t, denominator) {
287
+ const difference = u - d;
288
+ const correction = sumError(u, -d, difference) + error - dError;
289
+ const base = difference + correction;
290
+ const low = sumError(difference, correction, base);
291
+ const shifted = base - t;
292
+ return (shifted + (sumError(base, -t, shifted) + low)) / denominator;
293
+ }
294
+ function sumError(x, y, sum) {
295
+ const part = sum - x;
296
+ return x - (sum - part) + (y - part);
297
+ }
298
+ function productError(x, y, product) {
299
+ const sx = 134217729 * x, sy = 134217729 * y;
300
+ if (!Number.isFinite(sx) || !Number.isFinite(sy))
301
+ return 0;
302
+ const hx = sx - (sx - x), hy = sy - (sy - y);
303
+ const lx = x - hx, ly = y - hy;
304
+ return hx * hy - product + hx * ly + lx * hy + lx * ly;
305
+ }
306
+
307
+ // dist/ellipsoid-helpers/scale-to-geodetic-surface.js
308
+ var surface = { x: 0, y: 0, z: 0 };
309
+ function scaleToGeodeticSurface(cartesian, ellipsoid, result = []) {
310
+ const object = cartesian;
311
+ const x = "x" in cartesian ? object.x : cartesian[0];
312
+ const y = "x" in cartesian ? object.y : cartesian[1];
313
+ const z = "x" in cartesian ? object.z : cartesian[2];
314
+ if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z))
315
+ return void 0;
316
+ if (!Number.isFinite(x * x + y * y + z * z))
317
+ return void 0;
318
+ const { radii } = ellipsoid;
319
+ if (!nearestSurface(x, y, z, radii.x, radii.y, radii.z, surface))
320
+ return void 0;
321
+ return writeResult(result, surface.x, surface.y, surface.z);
322
+ }
323
+ function writeResult(result, x, y, z) {
324
+ if ((0, import_matrix2.isArray)(result)) {
325
+ result[0] = x;
326
+ result[1] = y;
327
+ result[2] = z;
328
+ } else {
329
+ const point = result;
330
+ point.x = x;
331
+ point.y = y;
332
+ point.z = z;
333
+ }
334
+ return result;
335
+ }
336
+
337
+ // dist/ellipsoid.js
338
+ var spheroidScratch = { x: 0, y: 0, z: 0 };
339
+ var scratchVector2 = new import_matrix3.Vector3();
340
+ var scratchNormal = new import_matrix3.Vector3();
341
+ var scratchPosition = new import_matrix3.Vector3();
342
+ var scratchCartesian = new import_matrix3.Vector3();
343
+ var Ellipsoid = class _Ellipsoid {
344
+ /** Construct from two-axis geometry, including normalized projection ellipsoids.
345
+ * The equatorial X/Y radii are equal; no CRS or datum information is inferred.
346
+ */
347
+ static fromSpheroid(parameters) {
348
+ const { semiMajorAxis, semiMinorAxis } = parameters;
349
+ validateSpheroid(semiMajorAxis, semiMinorAxis);
350
+ return new _Ellipsoid(semiMajorAxis, semiMajorAxis, semiMinorAxis);
351
+ }
352
+ constructor(x = 0, y = 0, z = 0) {
353
+ this.centerToleranceSquared = import_matrix3._MathUtils.EPSILON1;
354
+ (0, import_matrix3.assert)(Number.isFinite(x) && x >= 0);
355
+ (0, import_matrix3.assert)(Number.isFinite(y) && y >= 0);
356
+ (0, import_matrix3.assert)(Number.isFinite(z) && z >= 0);
357
+ this.radii = new import_matrix3.Vector3(x, y, z);
358
+ this.radiiSquared = new import_matrix3.Vector3(x * x, y * y, z * z);
359
+ this.radiiToTheFourth = new import_matrix3.Vector3(x * x * x * x, y * y * y * y, z * z * z * z);
360
+ this.oneOverRadii = new import_matrix3.Vector3(x === 0 ? 0 : 1 / x, y === 0 ? 0 : 1 / y, z === 0 ? 0 : 1 / z);
361
+ this.oneOverRadiiSquared = new import_matrix3.Vector3(x === 0 ? 0 : 1 / (x * x), y === 0 ? 0 : 1 / (y * y), z === 0 ? 0 : 1 / (z * z));
362
+ this.minimumRadius = Math.min(x, y, z);
363
+ this.maximumRadius = Math.max(x, y, z);
364
+ if (z !== 0) {
365
+ this.squaredXOverSquaredZ = (x / z) ** 2;
366
+ }
367
+ if (x === y && z > 0 && z <= x && Number.isFinite(this.radiiSquared.x) && this.radiiSquared.z > 0)
368
+ this.spheroidGeometry = Object.freeze({
369
+ semiMajorAxis: x,
370
+ semiMinorAxis: z,
371
+ eccentricitySquared: 1 - (z / x) ** 2
372
+ });
373
+ Object.freeze(this.radii);
374
+ Object.freeze(this.radiiSquared);
375
+ Object.freeze(this.radiiToTheFourth);
376
+ Object.freeze(this.oneOverRadii);
377
+ Object.freeze(this.oneOverRadiiSquared);
378
+ Object.freeze(this);
379
+ }
380
+ /** Return an owned geometry snapshot for a sphere or oblate spheroid.
381
+ * Triaxial, prolate and degenerate ellipsoids cannot be represented by this contract.
382
+ * Call during setup, outside coordinate loops.
383
+ */
384
+ toSpheroid() {
385
+ const { x, y, z } = this.radii;
386
+ if (x !== y)
387
+ throw new Error("Spheroid requires equal X/Y radii");
388
+ validateSpheroid(x, z);
389
+ return Object.freeze({ semiMajorAxis: x, semiMinorAxis: z });
390
+ }
391
+ /** Compares this Ellipsoid against the provided Ellipsoid componentwise */
392
+ equals(right) {
393
+ return this === right || Boolean(right && this.radii.equals(right.radii));
394
+ }
395
+ /** Creates a string representing this Ellipsoid in the format '[radii.x, radii.y, radii.z]'. */
396
+ toString() {
397
+ return this.radii.toString();
398
+ }
399
+ cartographicToCartesian(cartographic, result = [0, 0, 0]) {
400
+ const llh = fromCartographicToRadians(cartographic, scratchCartesian);
401
+ const longitude = llh[0], latitude = llh[1], height = llh[2];
402
+ if (!Number.isFinite(longitude) || !Number.isFinite(latitude) || !Number.isFinite(height) || !(this.minimumRadius > 0) || !Number.isFinite(this.maximumRadius * this.maximumRadius))
403
+ return void 0;
404
+ if (this.spheroidGeometry && (import_matrix3.config._cartographicRadians || Math.abs(latitude) <= Math.PI / 4)) {
405
+ spheroidScratch.x = longitude;
406
+ spheroidScratch.y = latitude;
407
+ spheroidScratch.z = height;
408
+ if (!(0, import_matrix4.spheroidToCartesian)(spheroidScratch, this.spheroidGeometry))
409
+ return void 0;
410
+ return writeResult(result, spheroidScratch.x, spheroidScratch.y, spheroidScratch.z);
411
+ }
412
+ const normal = scratchNormal;
413
+ this.geodeticSurfaceNormalCartographic(cartographic, normal);
414
+ const nx = normal.x, ny = normal.y, nz = normal.z;
415
+ const rx = this.radii.x, ry = this.radii.y, rz = this.radii.z;
416
+ const gamma = Math.hypot(rx * nx, ry * ny, rz * nz);
417
+ const x = rx * (rx * nx / gamma) + height * nx;
418
+ const y = ry * (ry * ny / gamma) + height * ny;
419
+ const z = rz * (rz * nz / gamma) + height * nz;
420
+ if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z))
421
+ return void 0;
422
+ return writeResult(result, x, y, z);
423
+ }
424
+ cartesianToCartographic(cartesian, result = [0, 0, 0]) {
425
+ const object = cartesian;
426
+ const x = "x" in cartesian ? object.x : cartesian[0];
427
+ const y = "x" in cartesian ? object.y : cartesian[1];
428
+ const z = "x" in cartesian ? object.z : cartesian[2];
429
+ if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z))
430
+ return void 0;
431
+ if (this.spheroidGeometry && Number.isFinite(x * x + y * y + z * z) && Number.isFinite(this.oneOverRadiiSquared.x) && Number.isFinite(this.oneOverRadiiSquared.z)) {
432
+ spheroidScratch.x = x;
433
+ spheroidScratch.y = y;
434
+ spheroidScratch.z = z;
435
+ const shape = this.spheroidGeometry;
436
+ const nearBoundary = z === 0 && shape.semiMinorAxis < shape.semiMajorAxis && Math.abs(Math.hypot(x, y) - shape.semiMajorAxis * shape.eccentricitySquared) <= 64 * Number.EPSILON * shape.semiMajorAxis;
437
+ if (!nearBoundary && (0, import_matrix4.cartesianToSpheroid)(spheroidScratch, shape)) {
438
+ const longitude2 = x === 0 && y === 0 ? Math.atan2(y, x) : spheroidScratch.x;
439
+ return toCartographicFromRadiansComponents(longitude2, spheroidScratch.y, spheroidScratch.z, result);
440
+ }
441
+ }
442
+ if (!(this.minimumRadius > 0) || !Number.isFinite(this.maximumRadius * this.maximumRadius) || !Number.isFinite(1 / (this.minimumRadius * this.minimumRadius)))
443
+ return void 0;
444
+ scratchCartesian.set(x, y, z);
445
+ const point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition);
446
+ if (!point) {
447
+ return void 0;
448
+ }
449
+ const gx = point[0] * this.oneOverRadiiSquared.x;
450
+ const gy = point[1] * this.oneOverRadiiSquared.y;
451
+ const gz = point[2] * this.oneOverRadiiSquared.z;
452
+ const length = Math.hypot(gx, gy, gz);
453
+ if (!(length > 0) || !Number.isFinite(length))
454
+ return void 0;
455
+ const nx = gx / length, ny = gy / length, nz = gz / length;
456
+ const longitude = Math.atan2(ny, nx);
457
+ const latitude = Math.atan2(nz, Math.hypot(nx, ny));
458
+ const height = (x - point[0]) * nx + (y - point[1]) * ny + (z - point[2]) * nz;
459
+ return toCartographicFromRadiansComponents(longitude, latitude, height, result);
460
+ }
461
+ geocentricSurfaceNormal(cartesian, result = [0, 0, 0]) {
462
+ fromCartographic(cartesian, scratchVector2);
463
+ const point = scratchVector2;
464
+ return normalResult(point.x, point.y, point.z, result);
465
+ }
466
+ geodeticSurfaceNormalCartographic(cartographic, result = [0, 0, 0]) {
467
+ const point = fromCartographic(cartographic, scratchCartesian);
468
+ const longitude = import_matrix3.config._cartographicRadians ? point[0] : point[0] * Math.PI / 180;
469
+ const latitude = import_matrix3.config._cartographicRadians ? point[1] : point[1] * Math.PI / 180;
470
+ const polarDegrees = !import_matrix3.config._cartographicRadians && Math.abs(point[1]) > 45;
471
+ const complement = (90 - Math.abs(point[1])) * Math.PI / 180;
472
+ const cosLatitude = polarDegrees ? Math.sin(complement) : Math.abs(latitude) === Math.PI / 2 ? 0 : Math.cos(latitude);
473
+ const sinLatitude = polarDegrees ? Math.sign(point[1]) * Math.cos(complement) : Math.sin(latitude);
474
+ return normalResult(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), sinLatitude, result);
475
+ }
476
+ geodeticSurfaceNormal(cartesian, result = [0, 0, 0]) {
477
+ if (!(this.minimumRadius > 0))
478
+ return void 0;
479
+ fromCartographic(cartesian, scratchVector2);
480
+ const point = scratchVector2;
481
+ const scale = Math.max(Math.abs(point.x), Math.abs(point.y), Math.abs(point.z));
482
+ if (!(scale > 0) || !Number.isFinite(scale))
483
+ return void 0;
484
+ const nx = point.x / scale * (this.minimumRadius / this.radii.x) ** 2;
485
+ const ny = point.y / scale * (this.minimumRadius / this.radii.y) ** 2;
486
+ const nz = point.z / scale * (this.minimumRadius / this.radii.z) ** 2;
487
+ 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))
488
+ return normalResult(nx, ny, nz, result);
489
+ const ex = point.x === 0 ? 0 : Math.min(1023, Math.floor(Math.log2(Math.abs(point.x))));
490
+ const ey = point.y === 0 ? 0 : Math.min(1023, Math.floor(Math.log2(Math.abs(point.y))));
491
+ const ez = point.z === 0 ? 0 : Math.min(1023, Math.floor(Math.log2(Math.abs(point.z))));
492
+ const ax = Math.min(1023, Math.floor(Math.log2(this.radii.x)));
493
+ const ay = Math.min(1023, Math.floor(Math.log2(this.radii.y)));
494
+ const az = Math.min(1023, Math.floor(Math.log2(this.radii.z)));
495
+ 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);
496
+ 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);
497
+ }
498
+ /** Scales the provided Cartesian position along the geodetic surface normal
499
+ * so that it is on the surface of this ellipsoid. If the position is
500
+ * at the center of the ellipsoid, this function returns undefined. */
501
+ scaleToGeodeticSurface(cartesian, result) {
502
+ return scaleToGeodeticSurface(cartesian, this, result);
503
+ }
504
+ /** Scales the provided Cartesian position along the geocentric surface normal
505
+ * so that it is on the surface of this ellipsoid. */
506
+ scaleToGeocentricSurface(cartesian, result = [0, 0, 0]) {
507
+ fromCartographic(cartesian, scratchPosition);
508
+ const point = scratchPosition;
509
+ const scale = Math.max(Math.abs(point.x), Math.abs(point.y), Math.abs(point.z));
510
+ if (!(this.minimumRadius > 0) || !(scale > 0) || !Number.isFinite(scale))
511
+ return void 0;
512
+ const squared = point.x * point.x * this.oneOverRadiiSquared.x + point.y * point.y * this.oneOverRadiiSquared.y + point.z * point.z * this.oneOverRadiiSquared.z;
513
+ if (squared >= 2 ** -1022 && Number.isFinite(squared) && scale * scale >= 2 ** -1022 && Number.isFinite(scale * scale)) {
514
+ const beta = 1 / Math.sqrt(squared);
515
+ return writeResult(result, point.x * beta, point.y * beta, point.z * beta);
516
+ }
517
+ const x = point.x / scale, y = point.y / scale, z = point.z / scale;
518
+ const norm = Math.hypot(x / this.radii.x, y / this.radii.y, z / this.radii.z);
519
+ if (!(norm > 0) || !Number.isFinite(norm))
520
+ return void 0;
521
+ return writeResult(result, x / norm, y / norm, z / norm);
522
+ }
523
+ /** Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying
524
+ * its components by the result of `Ellipsoid#oneOverRadii` */
525
+ transformPositionToScaledSpace(position, result = [0, 0, 0]) {
526
+ fromCartographic(position, scratchPosition);
527
+ const point = scratchPosition.scale(this.oneOverRadii);
528
+ return writeResult(result, point.x, point.y, point.z);
529
+ }
530
+ /** Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying
531
+ * its components by the result of `Ellipsoid#radii`. */
532
+ transformPositionFromScaledSpace(position, result = [0, 0, 0]) {
533
+ fromCartographic(position, scratchPosition);
534
+ const point = scratchPosition.scale(this.radii);
535
+ return writeResult(result, point.x, point.y, point.z);
536
+ }
537
+ /** Computes a point which is the intersection of the surface normal with the z-axis. */
538
+ getSurfaceNormalIntersectionWithZAxis(position, buffer = 0, result = [0, 0, 0]) {
539
+ (0, import_matrix3.assert)(this.radii.x === this.radii.y && this.minimumRadius > 0);
540
+ fromCartographic(position, scratchPosition);
541
+ if (!Number.isFinite(scratchPosition.x) || !Number.isFinite(scratchPosition.y) || !Number.isFinite(scratchPosition.z) || !Number.isFinite(buffer))
542
+ return void 0;
543
+ const z = scratchPosition.z * (1 - this.squaredXOverSquaredZ);
544
+ if (!Number.isFinite(z))
545
+ return void 0;
546
+ if (Math.abs(z) >= this.radii.z - buffer) {
547
+ return void 0;
548
+ }
549
+ return writeResult(result, 0, 0, z);
550
+ }
551
+ };
552
+ Ellipsoid.WGS84 = new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z);
553
+ function validateSpheroid(a, b) {
554
+ if (!Number.isFinite(a) || !Number.isFinite(b) || a <= 0 || b <= 0 || b > a)
555
+ throw new Error("Spheroid requires finite positive axes with semiMinorAxis <= semiMajorAxis");
556
+ }
557
+ function normalResult(x, y, z, result) {
558
+ const scale = Math.max(Math.abs(x), Math.abs(y), Math.abs(z));
559
+ if (!(scale > 0) || !Number.isFinite(scale))
560
+ return void 0;
561
+ const nx = x / scale, ny = y / scale, nz = z / scale;
562
+ const length = Math.hypot(nx, ny, nz);
563
+ return writeResult(result, nx / length, ny / length, nz / length);
564
+ }
565
+
566
+ // dist/ellipsoid-tangent-plane.js
567
+ var import_matrix5 = require("@math.gl/core/matrix");
568
+ var import_culling = require("@math.gl/geometry/culling");
569
+
570
+ // dist/ellipsoid-helpers/tangent-plane-numerics.js
571
+ var SPLITTER = 134217729;
572
+ function productError2(a, b, product) {
573
+ const ca = SPLITTER * a, cb = SPLITTER * b;
574
+ const ah = ca - (ca - a), al = a - ah;
575
+ const bh = cb - (cb - b), bl = b - bh;
576
+ return ah * bh - product + ah * bl + al * bh + al * bl;
577
+ }
578
+ function sumError2(a, b, sum) {
579
+ const v = sum - a;
580
+ return a - (sum - v) + (b - v);
581
+ }
582
+ function binaryScale(value) {
583
+ return 2 ** Math.min(1023, Math.floor(Math.log2(value)));
584
+ }
585
+ function compensatedDot3(x, y, z, a, b, c) {
586
+ const magnitude = Math.max(Math.abs(x), Math.abs(y), Math.abs(z));
587
+ if (magnitude === 0)
588
+ return 0;
589
+ const scale = binaryScale(magnitude);
590
+ const sx = x / scale, sy = y / scale, sz = z / scale;
591
+ const p = sx * a, q = sy * b, r = sz * c;
592
+ const s = p + q, t = s + r;
593
+ return (t + (sumError2(p, q, s) + sumError2(s, r, t) + productError2(sx, a, p) + productError2(sy, b, q) + productError2(sz, c, r))) * scale;
594
+ }
595
+ function exactNormalIntersection(radii, origin, east, north, normal, point, sphereRadius) {
596
+ const values = sphereRadius ? [
597
+ sphereRadius,
598
+ sphereRadius,
599
+ sphereRadius,
600
+ sphereRadius,
601
+ 0,
602
+ 0,
603
+ 0,
604
+ 1,
605
+ 0,
606
+ 0,
607
+ 0,
608
+ 1,
609
+ 1,
610
+ 0,
611
+ 0,
612
+ point[0],
613
+ point[1]
614
+ ] : [...radii, ...origin, ...east, ...north, ...normal, ...point];
615
+ const v = values.map((value2) => {
616
+ const [whole, fraction = ""] = Math.abs(value2).toString(2).split(".");
617
+ return (value2 < 0 ? -1n : 1n) * BigInt("0b" + whole + fraction) << BigInt(1074 - fraction.length);
618
+ });
619
+ const unit2 = 1n << 1074n, q = 1n << 64n;
620
+ const factors = [v[1] * v[2], v[0] * v[2], v[0] * v[1]];
621
+ const p = [0, 1, 2].map((i) => (v[3 + i] * unit2 + v[6 + i] * v[15] + v[9 + i] * v[16]) * factors[i]);
622
+ const n = v.slice(12, 15).map((x, i) => x * factors[i]);
623
+ const dot = (x, y) => x.reduce((s, v2, i) => s + v2 * y[i], 0n);
624
+ const a = dot(n, n), b = dot(n, p), c = dot(p, p) - (v[0] * v[1] * v[2] * unit2) ** 2n;
625
+ const discriminant = b * b - a * c;
626
+ if (a === 0n || discriminant < 0n)
627
+ return void 0;
628
+ const value = discriminant << 128n;
629
+ let root = value === 0n ? 0n : 1n << BigInt(Math.ceil(value.toString(2).length / 2));
630
+ if (root)
631
+ for (; ; ) {
632
+ const next = root + value / root >> 1n;
633
+ if (next >= root)
634
+ break;
635
+ root = next;
636
+ }
637
+ const output = p.map((x, i) => signedRatio(x * a * q + n[i] * (root - b * q), a * q * factors[i]));
638
+ return sphereRadius ? output.map((_, i) => east[i] * output[1] + north[i] * output[2] + normal[i] * output[0]) : output;
639
+ }
640
+ function signedRatio(n, d) {
641
+ return Math.sign(Number(n)) * ratio(n < 0n ? -n : n, d, -2148);
642
+ }
643
+
644
+ // dist/ellipsoid-tangent-plane.js
645
+ var EllipsoidTangentPlane = class {
646
+ /**
647
+ * Creates a new plane tangent to an ellipsoid at the provided origin.
648
+ * If origin is not on the surface of the ellipsoid, its surface projection will be used.
649
+ *
650
+ * @param origin A nonzero Cartesian point on or near the ellipsoid.
651
+ * @param ellipsoid The ellipsoid to which the origin belongs. Defaults to WGS84.
652
+ */
653
+ constructor(origin, ellipsoid = Ellipsoid.WGS84) {
654
+ finiteInput(origin, 3);
655
+ this.radii = Object.freeze(Array.from(ellipsoid.radii));
656
+ if (this.radii[0] === this.radii[1] && this.radii[1] === this.radii[2])
657
+ this.radius = this.radii[0];
658
+ if (!this.radii.every((radius) => radius > 0 && Number.isFinite(radius))) {
659
+ throw new RangeError("Tangent plane requires positive finite ellipsoid radii");
660
+ }
661
+ const originOnSurface = ellipsoid.scaleToGeodeticSurface(Array.from(origin), new import_matrix5.Vector3());
662
+ if (!originOnSurface)
663
+ throw new RangeError("Origin has no unique ellipsoid surface point");
664
+ this.anchor = new import_matrix5.Vector3(originOnSurface);
665
+ const normal = new import_matrix5.Vector3(ellipsoid.geodeticSurfaceNormal(originOnSurface));
666
+ if (!normal.every(Number.isFinite) || !(normal.len() > 0)) {
667
+ throw new RangeError("Cannot resolve tangent-plane normal");
668
+ }
669
+ normal.normalize();
670
+ const horizontal = Math.hypot(normal[0], normal[1]);
671
+ this.east = horizontal > 0 ? new import_matrix5.Vector3(-normal[1] / horizontal, normal[0] / horizontal, 0) : new import_matrix5.Vector3(0, 1, 0);
672
+ this.north = new import_matrix5.Vector3(normal).cross(this.east).normalize();
673
+ this._plane = new import_culling.Plane().fromPointNormal(this.anchor, normal);
674
+ }
675
+ /**
676
+ * Computes the projection of the provided 3D position onto the 2D plane, along the plane normal.
677
+ *
678
+ * @param cartesian The fixed Cartesian point to project.
679
+ * @param result The optional object in which to store the local east-north coordinates.
680
+ * @returns The supplied result or a new Vector2.
681
+ */
682
+ projectPointToNearestOnPlane(cartesian, result = new import_matrix5.Vector2()) {
683
+ finiteInput(cartesian, 3);
684
+ const x = cartesian[0] - this.anchor[0];
685
+ const y = cartesian[1] - this.anchor[1];
686
+ const z = cartesian[2] - this.anchor[2];
687
+ const projected = writePlanePoint(this, x, y, z, result, this.radius);
688
+ if (!projected)
689
+ throw new RangeError("Tangent-plane projection overflow");
690
+ return projected;
691
+ }
692
+ /** Project along the outward ray from the ellipsoid center.
693
+ * Back-facing, horizon and nonfinite intersections return undefined without writing result.
694
+ */
695
+ projectPointRadiallyOntoPlane(cartesian, result = new import_matrix5.Vector2()) {
696
+ finiteInput(cartesian, 3);
697
+ const scale = Math.max(Math.abs(cartesian[0]), Math.abs(cartesian[1]), Math.abs(cartesian[2]));
698
+ if (scale === 0)
699
+ return void 0;
700
+ const sx = cartesian[0] / scale, sy = cartesian[1] / scale, sz = cartesian[2] / scale;
701
+ const length = Math.hypot(sx, sy, sz);
702
+ const x = sx / length;
703
+ const y = sy / length;
704
+ const z = sz / length;
705
+ const n = this.zAxis;
706
+ const denominator = x * n[0] + y * n[1] + z * n[2];
707
+ if (denominator <= 1e-14)
708
+ return void 0;
709
+ const distance = this.anchor.dot(n) / denominator;
710
+ return writePlanePoint(this, x * distance - this.anchor[0], y * distance - this.anchor[1], z * distance - this.anchor[2], result, this.radius);
711
+ }
712
+ /** Lift a local east/north point to the ellipsoid. Radial is the inverse of radial
713
+ * projection. Normal selects the nearest-facing line intersection and can miss.
714
+ * Neither operation restores a source point's height. Failure leaves result untouched.
715
+ */
716
+ projectPointOntoEllipsoid(point, mode = "radial", result = new import_matrix5.Vector3()) {
717
+ finiteInput(point, 2);
718
+ checkMode(mode);
719
+ const [rx, ry, rz] = this.radii;
720
+ if (mode === "radial") {
721
+ const scale = Math.max(Math.abs(this.anchor[0]), Math.abs(this.anchor[1]), Math.abs(this.anchor[2]), Math.abs(point[0]), Math.abs(point[1]));
722
+ const u = point[0] / scale, v = point[1] / scale;
723
+ const x = this.anchor[0] / scale + this.east[0] * u + this.north[0] * v;
724
+ const y = this.anchor[1] / scale + this.east[1] * u + this.north[1] * v;
725
+ const z = this.anchor[2] / scale + this.east[2] * u + this.north[2] * v;
726
+ const minimum = Math.min(rx, ry, rz);
727
+ const ax2 = x * (minimum / rx), ay2 = y * (minimum / ry), az2 = z * (minimum / rz);
728
+ const length = Math.hypot(ax2, ay2, az2);
729
+ if (!(length > 0 && Number.isFinite(length)))
730
+ return void 0;
731
+ return writeSurfacePoint(rx * (ax2 / length), ry * (ay2 / length), rz * (az2 / length), result);
732
+ }
733
+ const n = this.zAxis;
734
+ const p = [
735
+ this.anchor[0] + this.east[0] * point[0] + this.north[0] * point[1],
736
+ this.anchor[1] + this.east[1] * point[0] + this.north[1] * point[1],
737
+ this.anchor[2] + this.east[2] * point[0] + this.north[2] * point[1]
738
+ ];
739
+ if (!p.every(Number.isFinite))
740
+ return void 0;
741
+ const ax = n[0] / rx, ay = n[1] / ry, az = n[2] / rz;
742
+ const px = p[0] / rx, py = p[1] / ry, pz = p[2] / rz;
743
+ const a = ax * ax + ay * ay + az * az;
744
+ const b = ax * px + ay * py + az * pz;
745
+ const c = px * px + py * py + pz * pz - 1;
746
+ const squaredB = b * b, ac = a * c;
747
+ const error = 1e-6 * (Math.abs(squaredB) + Math.abs(ac));
748
+ const discriminant = squaredB - ac;
749
+ if (!(a > 0) || !Number.isFinite(discriminant) || Math.abs(discriminant) <= error) {
750
+ const exact = exactNormalIntersection(this.radii, this.anchor, this.east, this.north, n, point, this.radius);
751
+ return exact && writeSurfacePoint(exact[0], exact[1], exact[2], result);
752
+ }
753
+ if (discriminant < 0)
754
+ return void 0;
755
+ const root = Math.sqrt(Math.max(0, discriminant));
756
+ const t = b > 0 ? -c / (b + root) : (-b + root) / a;
757
+ return writeSurfacePoint(p[0] + t * n[0], p[1] + t * n[1], p[2] + t * n[2], result);
758
+ }
759
+ /** Packed XYZ to packed east/north. Invalid radial points produce NaN pairs and a zero mask.
760
+ * Optional output must have exactly two components per point and must not overlap input.
761
+ */
762
+ projectPointsFlat(input, mode = "normal", output) {
763
+ checkMode(mode);
764
+ if (input.length % 3)
765
+ throw new RangeError("Expected packed XYZ coordinates");
766
+ const count = input.length / 3;
767
+ const positions = output || new Float64Array(count * 2);
768
+ if (positions.length !== count * 2)
769
+ throw new RangeError("Invalid tangent-plane output length");
770
+ if (ArrayBuffer.isView(input) && input.buffer === positions.buffer && input.byteOffset < positions.byteOffset + positions.byteLength && positions.byteOffset < input.byteOffset + input.byteLength) {
771
+ throw new RangeError("Input and output buffers must not overlap");
772
+ }
773
+ for (let i = 0; i < input.length; i++) {
774
+ if (!Number.isFinite(input[i]))
775
+ throw new RangeError("Expected finite coordinates");
776
+ }
777
+ const valid = new Uint8Array(count);
778
+ const point = new import_matrix5.Vector3();
779
+ const projected = new import_matrix5.Vector2();
780
+ for (let i = 0; i < count; i++) {
781
+ point.set(input[i * 3], input[i * 3 + 1], input[i * 3 + 2]);
782
+ const value = mode === "normal" ? this.projectPointToNearestOnPlane(point, projected) : this.projectPointRadiallyOntoPlane(point, projected);
783
+ valid[i] = value ? 1 : 0;
784
+ positions[i * 2] = value ? value[0] : NaN;
785
+ positions[i * 2 + 1] = value ? value[1] : NaN;
786
+ }
787
+ return { positions, valid };
788
+ }
789
+ get plane() {
790
+ return this._plane;
791
+ }
792
+ get origin() {
793
+ return this.anchor;
794
+ }
795
+ get xAxis() {
796
+ return this.east;
797
+ }
798
+ get yAxis() {
799
+ return this.north;
800
+ }
801
+ get zAxis() {
802
+ return this._plane.normal;
803
+ }
804
+ };
805
+ function finiteInput(point, length) {
806
+ if (point.length !== length)
807
+ throw new RangeError(`Expected ${length} finite coordinates`);
808
+ for (let i = 0; i < length; i++) {
809
+ if (!Number.isFinite(point[i]))
810
+ throw new RangeError(`Expected ${length} finite coordinates`);
811
+ }
812
+ }
813
+ function checkMode(mode) {
814
+ if (mode !== "normal" && mode !== "radial")
815
+ throw new RangeError("Invalid tangent-plane mode");
816
+ }
817
+ function writePlanePoint(plane, x, y, z, result, radius) {
818
+ let east = x * plane.xAxis[0] + y * plane.xAxis[1] + z * plane.xAxis[2];
819
+ let north = x * plane.yAxis[0] + y * plane.yAxis[1] + z * plane.yAxis[2];
820
+ if (radius !== void 0 && Math.abs((east / radius) ** 2 + (north / radius) ** 2 - 1) <= 32 * Number.EPSILON) {
821
+ east = compensatedDot3(x, y, z, plane.xAxis[0], plane.xAxis[1], plane.xAxis[2]);
822
+ north = compensatedDot3(x, y, z, plane.yAxis[0], plane.yAxis[1], plane.yAxis[2]);
823
+ }
824
+ if (!Number.isFinite(east) || !Number.isFinite(north))
825
+ return void 0;
826
+ return result.set(east, north);
827
+ }
828
+ function writeSurfacePoint(x, y, z, result) {
829
+ if (![x, y, z].every(Number.isFinite))
830
+ return void 0;
831
+ return result.set(x, y, z);
832
+ }
833
+
834
+ // dist/ellipsoid-metrics.js
835
+ var DEG = Math.PI / 180;
836
+ var NODES = [
837
+ 0.09501250983763744,
838
+ 0.2816035507792589,
839
+ 0.4580167776572274,
840
+ 0.6178762444026438,
841
+ 0.755404408355003,
842
+ 0.8656312023878318,
843
+ 0.9445750230732326,
844
+ 0.9894009349916499
845
+ ];
846
+ var WEIGHTS = [
847
+ 0.1894506104550685,
848
+ 0.1826034150449236,
849
+ 0.16915651939500254,
850
+ 0.14959598881657674,
851
+ 0.12462897125553388,
852
+ 0.09515851168249279,
853
+ 0.06225352393864789,
854
+ 0.027152459411754096
855
+ ];
856
+ var KINDS = [
857
+ "geocentric",
858
+ "parametric",
859
+ "rectifying",
860
+ "authalic",
861
+ "conformal",
862
+ "isometric"
863
+ ];
864
+ var EllipsoidMetrics = class {
865
+ constructor({ semiMajorAxis: a, semiMinorAxis: b }) {
866
+ const r = b / a;
867
+ if (!(Number.isFinite(a) && Number.isFinite(b) && a > 0 && b > 0 && r >= 0.5 && r <= 2)) {
868
+ throw new Error("Ellipsoid metrics require finite positive axes with 0.5 <= b/a <= 2");
869
+ }
870
+ this.semiMajorAxis = a;
871
+ this.semiMinorAxis = b;
872
+ this.ratio = r;
873
+ this.e2 = (1 - r) * (1 + r);
874
+ this.qPole = 1 + r * r * this.eccentricIntegral(1);
875
+ this.quarter = integrate((t) => this.meridianIntegrand(t), 0, Math.PI / 2);
876
+ this.quarterMeridian = a * this.quarter;
877
+ this.surfaceArea = 2 * Math.PI * a * a * this.qPole;
878
+ this.volume = 4 * Math.PI / 3 * a * b * a;
879
+ if (![this.quarterMeridian, this.surfaceArea, this.volume].every((v) => Number.isFinite(v) && v > 0)) {
880
+ throw new Error("Ellipsoid metrics exceed representable length/area/volume range");
881
+ }
882
+ Object.freeze(this);
883
+ }
884
+ meridianDistance(latitude) {
885
+ validateLatitude(latitude);
886
+ return Math.sign(latitude) * this.semiMajorAxis * this.meridian(Math.abs(latitude));
887
+ }
888
+ meridionalCurvatureRadius(latitude) {
889
+ validateLatitude(latitude);
890
+ return this.semiMajorAxis * this.meridianIntegrand(latitude * DEG);
891
+ }
892
+ transverseCurvatureRadius(latitude) {
893
+ validateLatitude(latitude);
894
+ const [s, c] = sincos(latitude);
895
+ return this.semiMajorAxis / Math.hypot(c, this.ratio * s);
896
+ }
897
+ normalCurvatureRadius(latitude, azimuth) {
898
+ if (!Number.isFinite(azimuth))
899
+ throw new Error("Azimuth must be finite");
900
+ const [s, c] = sincos(azimuth % 180);
901
+ return 1 / (c * c / this.meridionalCurvatureRadius(latitude) + s * s / this.transverseCurvatureRadius(latitude));
902
+ }
903
+ latitudeToAuxiliary(latitude, kind) {
904
+ validateKind(kind);
905
+ validateLatitude(latitude);
906
+ if (latitude === 0)
907
+ return latitude;
908
+ if (Math.abs(latitude) === 90)
909
+ return kind === "isometric" ? Math.sign(latitude) * Infinity : latitude;
910
+ if (this.ratio === 1 && kind !== "isometric")
911
+ return latitude;
912
+ const sign = Math.sign(latitude);
913
+ const phi = Math.abs(latitude);
914
+ const [s, c] = sincos(phi);
915
+ switch (kind) {
916
+ case "geocentric":
917
+ return sign * angle(this.ratio * this.ratio * s, c);
918
+ case "parametric":
919
+ return sign * angle(this.ratio * s, c);
920
+ case "rectifying":
921
+ return sign * (phi <= 45 ? this.meridian(phi) / this.quarter * 90 : 90 - integrate((t) => this.meridianIntegrand(Math.PI / 2 - t), 0, (90 - phi) * DEG) / this.quarter * 90);
922
+ case "authalic": {
923
+ if (phi <= 45) {
924
+ const q = this.ratio ** 2 * (s / (c * c + (this.ratio * s) ** 2) + this.eccentricIntegral(s));
925
+ return sign * Math.asin(q / this.qPole) / DEG;
926
+ }
927
+ const cap = integrate((t) => {
928
+ const st = Math.sin(t), ct = Math.cos(t);
929
+ const d = st * st + (this.ratio * ct) ** 2;
930
+ return 2 * this.ratio ** 2 * st / (d * d);
931
+ }, 0, (90 - phi) * DEG);
932
+ return sign * (90 - 2 * Math.asin(Math.sqrt(cap / (2 * this.qPole))) / DEG);
933
+ }
934
+ default: {
935
+ const psi = Math.asinh(s / c) - this.e2 * this.eccentricIntegral(s);
936
+ return sign * (kind === "isometric" ? psi / DEG : psi < 1 ? Math.atan(Math.sinh(psi)) / DEG : 90 - 2 * Math.atan(Math.exp(-psi)) / DEG);
937
+ }
938
+ }
939
+ }
940
+ latitudeFromAuxiliary(latitude, kind) {
941
+ validateKind(kind);
942
+ if (kind === "isometric" && Math.abs(latitude) === Infinity)
943
+ return Math.sign(latitude) * 90;
944
+ if (kind !== "isometric")
945
+ validateLatitude(latitude);
946
+ else if (!Number.isFinite(latitude))
947
+ throw new Error("Isometric latitude must be finite or a pole infinity");
948
+ if (latitude === 0)
949
+ return latitude;
950
+ if (kind !== "isometric" && Math.abs(latitude) === 90)
951
+ return latitude;
952
+ if (this.ratio === 1 && kind !== "isometric")
953
+ return latitude;
954
+ const sign = Math.sign(latitude), target = Math.abs(latitude);
955
+ if (kind === "geocentric" || kind === "parametric") {
956
+ const [s, c] = sincos(target);
957
+ return sign * angle(s, c * (kind === "geocentric" ? this.ratio ** 2 : this.ratio));
958
+ }
959
+ let lo = 0, hi = 90;
960
+ for (let i = 0; i < 64; ++i) {
961
+ const mid = (lo + hi) / 2;
962
+ if (mid === lo || mid === hi)
963
+ break;
964
+ if (this.latitudeToAuxiliary(mid, kind) < target)
965
+ lo = mid;
966
+ else
967
+ hi = mid;
968
+ }
969
+ return sign * ((lo + hi) / 2);
970
+ }
971
+ eccentricIntegral(s) {
972
+ const e = Math.sqrt(Math.abs(this.e2));
973
+ return e === 0 ? s : (this.e2 > 0 ? Math.atanh(e * s) : Math.atan(e * s)) / e;
974
+ }
975
+ meridianIntegrand(t) {
976
+ return this.ratio ** 2 / Math.hypot(Math.cos(t), this.ratio * Math.sin(t)) ** 3;
977
+ }
978
+ meridian(phi) {
979
+ return phi <= 45 ? integrate((t) => this.meridianIntegrand(t), 0, phi * DEG) : this.quarter - integrate((t) => this.meridianIntegrand(Math.PI / 2 - t), 0, (90 - phi) * DEG);
980
+ }
981
+ };
982
+ function validateLatitude(value) {
983
+ if (!(Number.isFinite(value) && Math.abs(value) <= 90))
984
+ throw new Error("Latitude must be in [-90, 90] degrees");
985
+ }
986
+ function validateKind(kind) {
987
+ if (!KINDS.includes(kind))
988
+ throw new Error("Unknown auxiliary latitude");
989
+ }
990
+ function sincos(degrees) {
991
+ const a = Math.abs(degrees);
992
+ if (a <= 45)
993
+ return [Math.sin(degrees * DEG), Math.cos(degrees * DEG)];
994
+ return [Math.sign(degrees) * Math.cos((90 - a) * DEG), Math.sin((90 - a) * DEG)];
995
+ }
996
+ function angle(s, c) {
997
+ return s > c ? 90 - Math.atan2(c, s) / DEG : Math.atan2(s, c) / DEG;
998
+ }
999
+ function integrate(f, lo, hi) {
1000
+ let sum = 0;
1001
+ for (let j = 0; j < 8; ++j) {
1002
+ const h = (hi - lo) / 16, mid = lo + (2 * j + 1) * h;
1003
+ let part = 0;
1004
+ for (let i = 0; i < 8; ++i)
1005
+ part += WEIGHTS[i] * (f(mid - h * NODES[i]) + f(mid + h * NODES[i]));
1006
+ sum += h * part;
1007
+ }
1008
+ return sum;
1009
+ }
1010
+
1011
+ // dist/triaxial/integrate.js
1012
+ var C = [0, 1 / 5, 3 / 10, 4 / 5, 8 / 9, 1, 1];
1013
+ var A = [
1014
+ [],
1015
+ [1 / 5],
1016
+ [3 / 40, 9 / 40],
1017
+ [44 / 45, -56 / 15, 32 / 9],
1018
+ [19372 / 6561, -25360 / 2187, 64448 / 6561, -212 / 729],
1019
+ [9017 / 3168, -355 / 33, 46732 / 5247, 49 / 176, -5103 / 18656],
1020
+ [35 / 384, 0, 500 / 1113, 125 / 192, -2187 / 6784, 11 / 84]
1021
+ ];
1022
+ var B = [35 / 384, 0, 500 / 1113, 125 / 192, -2187 / 6784, 11 / 84, 0];
1023
+ var ERROR = [
1024
+ 35 / 384 - 5179 / 57600,
1025
+ 0,
1026
+ 500 / 1113 - 7571 / 16695,
1027
+ 125 / 192 - 393 / 640,
1028
+ -2187 / 6784 + 92097 / 339200,
1029
+ 11 / 84 - 187 / 2100,
1030
+ -1 / 40
1031
+ ];
1032
+ function integrateGeodesic(initial, q, distance) {
1033
+ let state = Array.from(initial), done = 0, step = Math.sign(distance) * Math.min(0.01, Math.abs(distance));
1034
+ const derivative = (y) => {
1035
+ const normal = [q[0] * y[0], q[1] * y[1], q[2] * y[2]];
1036
+ const curvature = (q[0] * y[3] ** 2 + q[1] * y[4] ** 2 + q[2] * y[5] ** 2) / (normal[0] ** 2 + normal[1] ** 2 + normal[2] ** 2);
1037
+ return [
1038
+ y[3],
1039
+ y[4],
1040
+ y[5],
1041
+ -curvature * normal[0],
1042
+ -curvature * normal[1],
1043
+ -curvature * normal[2]
1044
+ ];
1045
+ };
1046
+ for (let attempt = 0; attempt < 5e4; attempt++) {
1047
+ if (done === distance)
1048
+ return state;
1049
+ if (Math.abs(step) > Math.abs(distance - done))
1050
+ step = distance - done;
1051
+ const stages = [];
1052
+ for (let j = 0; j < C.length; j++) {
1053
+ const y = state.map((v, i) => v + step * A[j].reduce((sum, a, k) => sum + a * stages[k][i], 0));
1054
+ stages.push(derivative(y));
1055
+ }
1056
+ const next = state.map((v, i) => v + step * B.reduce((sum, b, j) => sum + b * stages[j][i], 0));
1057
+ let error = 0;
1058
+ for (let i = 0; i < 6; i++)
1059
+ error = Math.max(error, Math.abs(step * ERROR.reduce((sum, e, j) => sum + e * stages[j][i], 0)));
1060
+ const tolerance = 2e-15;
1061
+ if (error <= tolerance) {
1062
+ state = next;
1063
+ done += step;
1064
+ const surface2 = Math.sqrt(q[0] * state[0] ** 2 + q[1] * state[1] ** 2 + q[2] * state[2] ** 2);
1065
+ for (let i = 0; i < 3; i++)
1066
+ state[i] /= surface2;
1067
+ const normal = state.slice(0, 3).map((x, i) => q[i] * x), nn = normal.reduce((s, x) => s + x * x, 0);
1068
+ const dot = normal.reduce((s, x, i) => s + x * state[i + 3], 0) / nn;
1069
+ for (let i = 0; i < 3; i++)
1070
+ state[i + 3] -= normal[i] * dot;
1071
+ const speed = Math.hypot(state[3], state[4], state[5]);
1072
+ for (let i = 3; i < 6; i++)
1073
+ state[i] /= speed;
1074
+ }
1075
+ step *= Math.max(0.2, Math.min(4, 0.9 * (tolerance / Math.max(error, 1e-300)) ** 0.2));
1076
+ if (done + step === done)
1077
+ throw new RangeError("Triaxial integration step underflow");
1078
+ }
1079
+ throw new RangeError("Triaxial integration work limit exceeded");
1080
+ }
1081
+
1082
+ // dist/triaxial.js
1083
+ function unit(v) {
1084
+ const scale = Math.max(Math.abs(v[0]), Math.abs(v[1]), Math.abs(v[2]));
1085
+ if (!(scale > 0 && Number.isFinite(scale)))
1086
+ throw new RangeError("Expected nonzero finite direction");
1087
+ const x = v[0] / scale, y = v[1] / scale, z = v[2] / scale, n = Math.hypot(x, y, z);
1088
+ return [x / n, y / n, z / n];
1089
+ }
1090
+ function vector(v) {
1091
+ if (v.length !== 3 || !v.every(Number.isFinite))
1092
+ throw new RangeError("Expected three finite coordinates");
1093
+ }
1094
+ function system(s) {
1095
+ if (!["geodetic", "parametric", "geocentric"].includes(s))
1096
+ throw new RangeError("Unknown triaxial coordinate system");
1097
+ }
1098
+ function trig(degrees) {
1099
+ const x = (degrees % 360 + 540) % 360 - 180;
1100
+ return {
1101
+ s: x === 0 || Math.abs(x) === 180 ? 0 : Math.sin(x * Math.PI / 180),
1102
+ c: Math.abs(x) === 90 ? 0 : Math.cos(x * Math.PI / 180)
1103
+ };
1104
+ }
1105
+ var TriaxialEllipsoid = class {
1106
+ constructor({ radii }) {
1107
+ if (radii.length !== 3 || !radii.every((x) => Number.isFinite(x) && x >= 1e-60 && x <= 1e60) || Math.min(...radii) / Math.max(...radii) < 0.25)
1108
+ throw new RangeError("Triaxial axes require [1e-60,1e60] and min/max >= 0.25");
1109
+ this.snapshot = Object.freeze([...radii]);
1110
+ this.scale = Math.max(...radii);
1111
+ this.axes = Object.freeze(radii.map((r) => r / this.scale));
1112
+ }
1113
+ get radii() {
1114
+ return this.snapshot;
1115
+ }
1116
+ /** Area-uniform surface point from independent uniform [0,1) random draws.
1117
+ * Rejection corrects the linear sphere-to-ellipsoid area Jacobian; work is bounded.
1118
+ */
1119
+ sampleSurface(random = Math.random) {
1120
+ const draw = () => {
1121
+ const u = random();
1122
+ if (!Number.isFinite(u) || u < 0 || u >= 1)
1123
+ throw new RangeError("Random draws must be in [0,1)");
1124
+ return u;
1125
+ };
1126
+ const minimum = Math.min(...this.axes);
1127
+ for (let attempt = 0; attempt < 1024; attempt++) {
1128
+ const z = 2 * draw() - 1, angle2 = 2 * Math.PI * draw(), radius = Math.sqrt((1 - z) * (1 + z));
1129
+ const u = [radius * Math.cos(angle2), radius * Math.sin(angle2), z];
1130
+ const acceptance = minimum === 1 ? 1 : Math.min(1, minimum * Math.hypot(...u.map((x, i) => x / this.axes[i])));
1131
+ if (draw() < acceptance)
1132
+ return u.map((x, i) => x * this.radii[i]);
1133
+ }
1134
+ throw new RangeError("Surface sampling work limit exceeded");
1135
+ }
1136
+ toCartesian(latitude, longitude, coordinates = "geodetic") {
1137
+ system(coordinates);
1138
+ if (!Number.isFinite(latitude) || Math.abs(latitude) > 90 || !Number.isFinite(longitude))
1139
+ throw new RangeError("Invalid triaxial latitude/longitude");
1140
+ const p = trig(latitude), l = trig(longitude), n = [p.c * l.c, p.c * l.s, p.s], r = this.axes;
1141
+ if (coordinates === "parametric")
1142
+ return n.map((x, i) => x * this.radii[i]);
1143
+ const denominator = coordinates === "geodetic" ? Math.hypot(...n.map((x, i) => x * r[i])) : Math.hypot(...n.map((x, i) => x / r[i]));
1144
+ return n.map((x, i) => this.scale * x * (coordinates === "geodetic" ? r[i] * r[i] : 1) / denominator);
1145
+ }
1146
+ fromCartesian(position, coordinates = "geodetic") {
1147
+ system(coordinates);
1148
+ const p = this.surface(position);
1149
+ const v = p.map((x, i) => coordinates === "geodetic" ? x / this.axes[i] ** 2 : coordinates === "parametric" ? x / this.axes[i] : x);
1150
+ return {
1151
+ latitude: Math.atan2(v[2], Math.hypot(v[0], v[1])) * 180 / Math.PI,
1152
+ longitude: v[0] === 0 && v[1] === 0 ? 0 : Math.atan2(v[1], v[0]) * 180 / Math.PI
1153
+ };
1154
+ }
1155
+ directionToCartesian(position, azimuth) {
1156
+ if (!Number.isFinite(azimuth))
1157
+ throw new RangeError("Invalid triaxial bearing");
1158
+ const { north, east } = this.basis(position), a = trig(azimuth);
1159
+ return unit(north.map((x, i) => x * a.c + east[i] * a.s));
1160
+ }
1161
+ directionFromCartesian(position, direction) {
1162
+ vector(direction);
1163
+ const { north, east, normal } = this.basis(position), v = unit(direction);
1164
+ if (Math.abs(v.reduce((s, x, i) => s + x * normal[i], 0)) > 2e-12)
1165
+ throw new RangeError("Direction must be tangent");
1166
+ return Math.atan2(v.reduce((s, x, i) => s + x * east[i], 0), v.reduce((s, x, i) => s + x * north[i], 0)) * 180 / Math.PI;
1167
+ }
1168
+ surface(position) {
1169
+ vector(position);
1170
+ const p = Array.from(position, (x) => x / this.scale);
1171
+ const residual = p.reduce((s, x, i) => s + (x / this.axes[i]) ** 2, 0);
1172
+ if (!Number.isFinite(residual) || Math.abs(residual - 1) > 2e-12)
1173
+ throw new RangeError("Point must lie on the ellipsoid surface");
1174
+ return p;
1175
+ }
1176
+ basis(position) {
1177
+ const p = this.surface(position), normal = unit(p.map((x, i) => x / this.axes[i] ** 2));
1178
+ const horizontal = Math.hypot(p[0], p[1]), meridian = horizontal ? [-p[1] / horizontal, p[0] / horizontal, 0] : [0, 1, 0];
1179
+ const cross = (a, b) => [
1180
+ a[1] * b[2] - a[2] * b[1],
1181
+ a[2] * b[0] - a[0] * b[2],
1182
+ a[0] * b[1] - a[1] * b[0]
1183
+ ];
1184
+ const north = unit(cross(normal, meridian)), east = unit(cross(north, normal));
1185
+ return { north, east, normal };
1186
+ }
1187
+ /** Cartesian initial-value geodesic. No global triaxial inverse is implied. */
1188
+ line(position, direction) {
1189
+ const p = this.surface(position);
1190
+ this.directionFromCartesian(position, direction);
1191
+ const v = unit(direction), initial = Object.freeze([...p, ...v]), q = this.axes.map((r) => 1 / (r * r)), scale = this.scale;
1192
+ return {
1193
+ position: (distance) => {
1194
+ if (!Number.isFinite(distance) || Math.abs(distance) > 2 * Math.PI * scale)
1195
+ throw new RangeError("Triaxial distance exceeds one max-axis circuit");
1196
+ const y = distance === 0 ? Array.from(initial) : integrateGeodesic(initial, q, distance / scale);
1197
+ return {
1198
+ position: y.slice(0, 3).map((x) => x * scale),
1199
+ direction: y.slice(3),
1200
+ distance
1201
+ };
1202
+ }
1203
+ };
1204
+ }
1205
+ direct(position, direction, distance) {
1206
+ return this.line(position, direction).position(distance);
1207
+ }
1208
+ };
1209
+ //# sourceMappingURL=ellipsoid.cjs.map