@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,726 @@
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/expressions.js
20
+ var expressions_exports = {};
21
+ __export(expressions_exports, {
22
+ GEOSPATIAL_FUNCTION_LIBRARY: () => GEOSPATIAL_FUNCTION_LIBRARY
23
+ });
24
+ module.exports = __toCommonJS(expressions_exports);
25
+
26
+ // dist/ellipsoid-transforms.js
27
+ var import_matrix3 = require("@math.gl/core/matrix");
28
+
29
+ // dist/ellipsoid-helpers/ellipsoid-transform.js
30
+ var import_matrix = require("@math.gl/core/matrix");
31
+ var import_matrix2 = require("@math.gl/core/matrix");
32
+ var EPSILON14 = 1e-14;
33
+ var scratchOrigin = new import_matrix.Vector3();
34
+ var scratchBasis = (0, import_matrix2.createLocalFrameBasis)();
35
+ var VECTOR_PRODUCT_LOCAL_FRAME = {
36
+ up: {
37
+ south: "east",
38
+ north: "west",
39
+ west: "south",
40
+ east: "north"
41
+ },
42
+ down: {
43
+ south: "west",
44
+ north: "east",
45
+ west: "north",
46
+ east: "south"
47
+ },
48
+ south: {
49
+ up: "west",
50
+ down: "east",
51
+ west: "down",
52
+ east: "up"
53
+ },
54
+ north: {
55
+ up: "east",
56
+ down: "west",
57
+ west: "up",
58
+ east: "down"
59
+ },
60
+ west: {
61
+ up: "north",
62
+ down: "south",
63
+ north: "down",
64
+ south: "up"
65
+ },
66
+ east: {
67
+ up: "south",
68
+ down: "north",
69
+ north: "up",
70
+ south: "down"
71
+ }
72
+ };
73
+ var degeneratePositionLocalFrame = {
74
+ north: [-1, 0, 0],
75
+ east: [0, 1, 0],
76
+ up: [0, 0, 1],
77
+ south: [1, 0, 0],
78
+ west: [0, -1, 0],
79
+ down: [0, 0, -1]
80
+ };
81
+ var scratchAxisVectors = {
82
+ east: new import_matrix.Vector3(),
83
+ north: new import_matrix.Vector3(),
84
+ up: new import_matrix.Vector3(),
85
+ west: new import_matrix.Vector3(),
86
+ south: new import_matrix.Vector3(),
87
+ down: new import_matrix.Vector3()
88
+ };
89
+ var scratchVector1 = new import_matrix.Vector3();
90
+ var scratchVector2 = new import_matrix.Vector3();
91
+ var scratchVector3 = new import_matrix.Vector3();
92
+ function localFrameToFixedFrame(ellipsoid, firstAxis, secondAxis, thirdAxis, cartesianOrigin, result) {
93
+ const thirdAxisInferred = VECTOR_PRODUCT_LOCAL_FRAME[firstAxis] && VECTOR_PRODUCT_LOCAL_FRAME[firstAxis][secondAxis];
94
+ (0, import_matrix.assert)(thirdAxisInferred && (!thirdAxis || thirdAxis === thirdAxisInferred));
95
+ let firstAxisVector;
96
+ let secondAxisVector;
97
+ let thirdAxisVector;
98
+ const origin = scratchOrigin.copy(cartesianOrigin);
99
+ if (!Number.isFinite(origin.x) || !Number.isFinite(origin.y) || !Number.isFinite(origin.z) || !Array.isArray(result) && result.length < 16)
100
+ throw new Error("Unsupported local frame");
101
+ const poleTolerance = EPSILON14 * Math.min(1, ellipsoid.maximumRadius);
102
+ const atPole = Math.abs(origin.x) <= poleTolerance && Math.abs(origin.y) <= poleTolerance;
103
+ const radii = ellipsoid.radii;
104
+ if (radii.x === radii.y && radii.x > 0 && radii.z > 0 && radii.z <= radii.x && (!atPole || origin.z !== 0)) {
105
+ const { east, up } = scratchAxisVectors;
106
+ if (atPole) {
107
+ east.set(0, 1, 0);
108
+ up.set(0, 0, Math.sign(origin.z));
109
+ } else {
110
+ const scale = Math.max(Math.abs(origin.x), Math.abs(origin.y));
111
+ east.set(-origin.y / scale, origin.x / scale, 0).normalize();
112
+ ellipsoid.geodeticSurfaceNormal(origin, up);
113
+ }
114
+ if (!(0, import_matrix2.eastNorthUpBasisFromDirections)(east, up, scratchBasis) || !(0, import_matrix2.localFrameToMatrix)(scratchBasis, origin, firstAxis, secondAxis, thirdAxis, result))
115
+ throw new Error("Unsupported local frame");
116
+ return result;
117
+ }
118
+ if (atPole) {
119
+ const sign = Math.sign(origin.z);
120
+ firstAxisVector = scratchVector1.fromArray(degeneratePositionLocalFrame[firstAxis]);
121
+ if (firstAxis !== "east" && firstAxis !== "west") {
122
+ firstAxisVector.scale(sign);
123
+ }
124
+ secondAxisVector = scratchVector2.fromArray(degeneratePositionLocalFrame[secondAxis]);
125
+ if (secondAxis !== "east" && secondAxis !== "west") {
126
+ secondAxisVector.scale(sign);
127
+ }
128
+ thirdAxisVector = scratchVector3.fromArray(degeneratePositionLocalFrame[thirdAxis]);
129
+ if (thirdAxis !== "east" && thirdAxis !== "west") {
130
+ thirdAxisVector.scale(sign);
131
+ }
132
+ } else {
133
+ const { up, east, north } = scratchAxisVectors;
134
+ const scale = Math.max(Math.abs(origin.x), Math.abs(origin.y));
135
+ east.set(-origin.y / scale, origin.x / scale, 0).normalize();
136
+ ellipsoid.geodeticSurfaceNormal(origin, up);
137
+ north.copy(up).cross(east);
138
+ const { down, west, south } = scratchAxisVectors;
139
+ down.copy(up).scale(-1);
140
+ west.copy(east).scale(-1);
141
+ south.copy(north).scale(-1);
142
+ firstAxisVector = scratchAxisVectors[firstAxis];
143
+ secondAxisVector = scratchAxisVectors[secondAxis];
144
+ thirdAxisVector = scratchAxisVectors[thirdAxis];
145
+ }
146
+ const ax = firstAxisVector.x, ay = firstAxisVector.y, az = firstAxisVector.z;
147
+ const bx = secondAxisVector.x, by = secondAxisVector.y, bz = secondAxisVector.z;
148
+ const cx = thirdAxisVector.x, cy = thirdAxisVector.y, cz = thirdAxisVector.z;
149
+ const x = origin.x, y = origin.y, z = origin.z;
150
+ result[0] = ax;
151
+ result[1] = ay;
152
+ result[2] = az;
153
+ result[3] = 0;
154
+ result[4] = bx;
155
+ result[5] = by;
156
+ result[6] = bz;
157
+ result[7] = 0;
158
+ result[8] = cx;
159
+ result[9] = cy;
160
+ result[10] = cz;
161
+ result[11] = 0;
162
+ result[12] = x;
163
+ result[13] = y;
164
+ result[14] = z;
165
+ result[15] = 1;
166
+ return result;
167
+ }
168
+
169
+ // dist/ellipsoid-transforms.js
170
+ function eastNorthUpToFixedFrame(ellipsoid, origin, result = new import_matrix3.Matrix4()) {
171
+ return localFrameToFixedFrame(ellipsoid, "east", "north", "up", origin, result);
172
+ }
173
+
174
+ // dist/ellipsoid.js
175
+ var import_matrix6 = require("@math.gl/core/matrix");
176
+ var import_matrix7 = require("@math.gl/core/matrix");
177
+
178
+ // dist/constants.js
179
+ var WGS84_RADIUS_X = 6378137;
180
+ var WGS84_RADIUS_Y = 6378137;
181
+ var WGS84_RADIUS_Z = 6356752314245179e-9;
182
+ var WGS84_CONSTANTS = {
183
+ radii: [WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z],
184
+ radiiSquared: [
185
+ WGS84_RADIUS_X * WGS84_RADIUS_X,
186
+ WGS84_RADIUS_Y * WGS84_RADIUS_Y,
187
+ WGS84_RADIUS_Z * WGS84_RADIUS_Z
188
+ ],
189
+ oneOverRadii: [1 / WGS84_RADIUS_X, 1 / WGS84_RADIUS_Y, 1 / WGS84_RADIUS_Z],
190
+ oneOverRadiiSquared: [
191
+ 1 / (WGS84_RADIUS_X * WGS84_RADIUS_X),
192
+ 1 / (WGS84_RADIUS_Y * WGS84_RADIUS_Y),
193
+ 1 / (WGS84_RADIUS_Z * WGS84_RADIUS_Z)
194
+ ],
195
+ maximumRadius: Math.max(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z),
196
+ centerToleranceSquared: 0.1
197
+ // EPSILON1;
198
+ };
199
+
200
+ // dist/type-utils.js
201
+ var import_matrix4 = require("@math.gl/core/matrix");
202
+ function identity(x) {
203
+ return x;
204
+ }
205
+ var scratchVector = new import_matrix4.Vector3();
206
+ function fromCartographic(cartographic, result = [], map = identity) {
207
+ if ("longitude" in cartographic) {
208
+ result[0] = map(cartographic.longitude);
209
+ result[1] = map(cartographic.latitude);
210
+ result[2] = cartographic.height;
211
+ } else if ("x" in cartographic) {
212
+ result[0] = map(cartographic.x);
213
+ result[1] = map(cartographic.y);
214
+ result[2] = cartographic.z;
215
+ } else {
216
+ result[0] = map(cartographic[0]);
217
+ result[1] = map(cartographic[1]);
218
+ result[2] = cartographic[2];
219
+ }
220
+ return result;
221
+ }
222
+ function fromCartographicToRadians(cartographic, vector = []) {
223
+ return fromCartographic(cartographic, vector, import_matrix4.config._cartographicRadians ? identity : import_matrix4.toRadians);
224
+ }
225
+ function toCartographicFromRadiansComponents(longitude, latitude, height, cartographic) {
226
+ const map = import_matrix4.config._cartographicRadians ? identity : import_matrix4.toDegrees;
227
+ const mappedLongitude = map(longitude), mappedLatitude = map(latitude);
228
+ if ("longitude" in cartographic) {
229
+ cartographic.longitude = mappedLongitude;
230
+ cartographic.latitude = mappedLatitude;
231
+ cartographic.height = height;
232
+ } else if ("x" in cartographic) {
233
+ cartographic.x = mappedLongitude;
234
+ cartographic.y = mappedLatitude;
235
+ cartographic.z = height;
236
+ } else {
237
+ cartographic[0] = mappedLongitude;
238
+ cartographic[1] = mappedLatitude;
239
+ cartographic[2] = height;
240
+ }
241
+ return cartographic;
242
+ }
243
+ function isWGS84(vector) {
244
+ if (!vector) {
245
+ return false;
246
+ }
247
+ scratchVector.from(vector);
248
+ const { oneOverRadiiSquared, centerToleranceSquared } = WGS84_CONSTANTS;
249
+ const x2 = vector[0] * vector[0] * oneOverRadiiSquared[0];
250
+ const y2 = vector[1] * vector[1] * oneOverRadiiSquared[1];
251
+ const z2 = vector[2] * vector[2] * oneOverRadiiSquared[2];
252
+ return Math.abs(x2 + y2 + z2 - 1) < centerToleranceSquared;
253
+ }
254
+
255
+ // dist/ellipsoid-helpers/scale-to-geodetic-surface.js
256
+ var import_matrix5 = require("@math.gl/core/matrix");
257
+
258
+ // dist/ellipsoid-helpers/exact-nearest-surface.js
259
+ function exactNearestSurface(x, y, z, a, b, c, result) {
260
+ const values = [a, b, c, Math.abs(x), Math.abs(y), Math.abs(z)];
261
+ const parts = values.map((value) => {
262
+ const bits = value.toString(2);
263
+ const dot = bits.indexOf(".");
264
+ return {
265
+ integer: BigInt("0b" + bits.replace(".", "")),
266
+ exponent: dot < 0 ? 0 : dot + 1 - bits.length
267
+ };
268
+ });
269
+ const exponent = Math.min(...parts.filter((p) => p.integer !== 0n).map((p) => p.exponent));
270
+ const integers = parts.map((p) => p.integer << BigInt(p.exponent - exponent));
271
+ const squares = integers.slice(0, 3).map((v) => v * v);
272
+ const minimum = squares.reduce((p, v) => p < v ? p : v);
273
+ const offsets = squares.map((v) => v - minimum);
274
+ const products = squares.map((_, i) => integers[i] * integers[i + 3]);
275
+ let precision = 64;
276
+ if (!products.some((u3, i) => offsets[i] === 0n && u3 !== 0n)) {
277
+ let numerator = -1n, denominator = 1n;
278
+ for (let i = 0; i < 3; i++) {
279
+ if (offsets[i] === 0n)
280
+ continue;
281
+ const d2 = offsets[i] * offsets[i];
282
+ numerator = numerator * d2 + products[i] * products[i] * denominator;
283
+ denominator *= d2;
284
+ }
285
+ if (numerator < 0n)
286
+ return false;
287
+ if (numerator === 0n) {
288
+ return commit(0n, 1n);
289
+ }
290
+ const positive = offsets.filter((d2) => d2 > 0n);
291
+ const least = positive.reduce((p, v) => p < v ? p : v);
292
+ precision = Math.max(64, (2n * (denominator + numerator)).toString(2).length - (numerator * least).toString(2).length + 128);
293
+ }
294
+ const unit = 1n << BigInt(precision);
295
+ const d = offsets.map((v) => v * unit);
296
+ const u = products.map((v) => v * unit);
297
+ const u2 = u.map((v) => v * v);
298
+ let lower = 0n, upper = u.reduce((sum, v) => sum + v, 0n);
299
+ if (upper === 0n)
300
+ return false;
301
+ for (let iteration = 0; iteration < 4096; iteration++) {
302
+ const t = lower + upper >> 1n;
303
+ if (t === lower)
304
+ return false;
305
+ const dx = d[0] + t, dy = d[1] + t, dz = d[2] + t;
306
+ const xx = dx * dx, yy = dy * dy, zz = dz * dz;
307
+ const sign = u2[0] * yy * zz + u2[1] * xx * zz + u2[2] * xx * yy - xx * yy * zz;
308
+ if (sign === 0n)
309
+ return commit(t, unit);
310
+ if (sign > 0n)
311
+ lower = t;
312
+ else
313
+ upper = t;
314
+ if (lower > 0n && upper - lower <= lower >> 60n)
315
+ return commit(lower + upper >> 1n, unit);
316
+ }
317
+ return false;
318
+ function commit(t, unit2) {
319
+ const output = squares.map((r2, i) => {
320
+ const denominator = offsets[i] * unit2 + t;
321
+ return denominator === 0n ? 0 : ratio(r2 * integers[i + 3] * unit2, denominator, exponent);
322
+ });
323
+ if (!output.every(Number.isFinite))
324
+ return false;
325
+ const qx = Math.sign(x) * output[0], qy = Math.sign(y) * output[1], qz = Math.sign(z) * output[2];
326
+ result.x = qx;
327
+ result.y = qy;
328
+ result.z = qz;
329
+ return true;
330
+ }
331
+ }
332
+ function ratio(n, d, exponent) {
333
+ if (n === 0n)
334
+ return 0;
335
+ const shift = 52 - (n.toString(2).length - d.toString(2).length);
336
+ const numerator = shift >= 0 ? n << BigInt(shift) : n;
337
+ const denominator = shift >= 0 ? d : d << BigInt(-shift);
338
+ let quotient = numerator / denominator;
339
+ const remainder = numerator % denominator;
340
+ if (2n * remainder > denominator || 2n * remainder === denominator && quotient & 1n)
341
+ quotient++;
342
+ const power = exponent - shift;
343
+ const first = Math.max(-1022, Math.min(1023, power));
344
+ return Number(quotient) * 2 ** first * 2 ** (power - first);
345
+ }
346
+
347
+ // dist/ellipsoid-helpers/nearest-surface.js
348
+ function nearestSurface(x, y, z, a, b, c, result) {
349
+ const minimum = Math.min(a, b, c);
350
+ const minimumSquared = minimum * minimum;
351
+ const aa = a * a, bb = b * b, cc = c * c;
352
+ if (!(minimum > 0) || !(minimumSquared > 0) || !Number.isFinite(Math.max(aa, bb, cc)))
353
+ return false;
354
+ const minimumError = productError(minimum, minimum, minimumSquared);
355
+ const dx = aa - minimumSquared, dy = bb - minimumSquared, dz = cc - minimumSquared;
356
+ const ex = sumError(aa, -minimumSquared, dx) + productError(a, a, aa) - minimumError;
357
+ const ey = sumError(bb, -minimumSquared, dy) + productError(b, b, bb) - minimumError;
358
+ const ez = sumError(cc, -minimumSquared, dz) + productError(c, c, cc) - minimumError;
359
+ const ux = a * Math.abs(x), uy = b * Math.abs(y), uz = c * Math.abs(z);
360
+ if (minimumSquared < 2 ** -1022 || x !== 0 && ux < 2 ** -1022 || y !== 0 && uy < 2 ** -1022 || z !== 0 && uz < 2 ** -1022)
361
+ return exactNearestSurface(x, y, z, a, b, c, result);
362
+ const fx = productError(a, Math.abs(x), ux);
363
+ const fy = productError(b, Math.abs(y), uy);
364
+ const fz = productError(c, Math.abs(z), uz);
365
+ 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));
366
+ if (limit <= 1 + 64 * Number.EPSILON)
367
+ return exactNearestSurface(x, y, z, a, b, c, result);
368
+ if ((x !== 0 ? 1 : 0) + (y !== 0 ? 1 : 0) + (z !== 0 ? 1 : 0) === 1) {
369
+ result.x = x === 0 ? x : Math.sign(x) * a;
370
+ result.y = y === 0 ? y : Math.sign(y) * b;
371
+ result.z = z === 0 ? z : Math.sign(z) * c;
372
+ return true;
373
+ }
374
+ let lower = Math.hypot(dx === 0 ? ux : 0, dy === 0 ? uy : 0, dz === 0 ? uz : 0);
375
+ let upper = Math.hypot(ux, uy, uz);
376
+ if (!(upper > 0) || !Number.isFinite(upper))
377
+ return exactNearestSurface(x, y, z, a, b, c, result);
378
+ let t = lower > 0 ? lower : upper;
379
+ for (let iteration = 0; iteration < 512; iteration++) {
380
+ const hx = dx + t, hy = dy + t, hz = dz + t;
381
+ const lx = sumError(dx, t, hx) + ex;
382
+ const ly = sumError(dy, t, hy) + ey;
383
+ const lz = sumError(dz, t, hz) + ez;
384
+ const vx = ux / hx, vy = uy / hy, vz = uz / hz;
385
+ let term, rest;
386
+ if (vx >= vy && vx >= vz) {
387
+ term = offset(ux, fx, dx, ex, t, hx) * (vx + 1);
388
+ rest = (vy * (1 - ly / hy)) ** 2 + (vz * (1 - lz / hz)) ** 2;
389
+ } else if (vy >= vz) {
390
+ term = offset(uy, fy, dy, ey, t, hy) * (vy + 1);
391
+ rest = (vx * (1 - lx / hx)) ** 2 + (vz * (1 - lz / hz)) ** 2;
392
+ } else {
393
+ term = offset(uz, fz, dz, ez, t, hz) * (vz + 1);
394
+ rest = (vx * (1 - lx / hx)) ** 2 + (vy * (1 - ly / hy)) ** 2;
395
+ }
396
+ const derivative = -2 * (vx * vx / hx + vy * vy / hy + vz * vz / hz);
397
+ const roundoff = 4 * Number.EPSILON * (Math.abs(term) + rest);
398
+ const residual = term + rest;
399
+ if (!Number.isFinite(residual))
400
+ return exactNearestSurface(x, y, z, a, b, c, result);
401
+ if (Math.abs(residual) <= 4 * Number.EPSILON * (Math.abs(term) + rest) || upper - lower <= 4 * Number.EPSILON * t) {
402
+ const uncertainty = roundoff / Math.abs(derivative);
403
+ if (!Number.isFinite(derivative) || !(Math.abs(derivative) > 0) || uncertainty > 2e-13 * t)
404
+ return exactNearestSurface(x, y, z, a, b, c, result);
405
+ const qx = Math.sign(x) * a * (vx * (1 - lx / hx));
406
+ const qy = Math.sign(y) * b * (vy * (1 - ly / hy));
407
+ const qz = Math.sign(z) * c * (vz * (1 - lz / hz));
408
+ const displacement = 2 * uncertainty * Math.max(Math.abs(qx / hx), Math.abs(qy / hy), Math.abs(qz / hz));
409
+ if (!Number.isFinite(displacement) || displacement > 2e-13 * Math.max(a, b, c))
410
+ return exactNearestSurface(x, y, z, a, b, c, result);
411
+ if (!Number.isFinite(qx) || !Number.isFinite(qy) || !Number.isFinite(qz))
412
+ return exactNearestSurface(x, y, z, a, b, c, result);
413
+ result.x = qx;
414
+ result.y = qy;
415
+ result.z = qz;
416
+ return true;
417
+ }
418
+ if (residual > 0)
419
+ lower = t;
420
+ else
421
+ upper = t;
422
+ const candidate = t - residual / derivative;
423
+ const next = candidate > lower && candidate < upper ? candidate : lower + (upper - lower) / 2;
424
+ if (next === t)
425
+ return exactNearestSurface(x, y, z, a, b, c, result);
426
+ t = next;
427
+ }
428
+ return exactNearestSurface(x, y, z, a, b, c, result);
429
+ }
430
+ function offset(u, error, d, dError, t, denominator) {
431
+ const difference = u - d;
432
+ const correction = sumError(u, -d, difference) + error - dError;
433
+ const base = difference + correction;
434
+ const low = sumError(difference, correction, base);
435
+ const shifted = base - t;
436
+ return (shifted + (sumError(base, -t, shifted) + low)) / denominator;
437
+ }
438
+ function sumError(x, y, sum) {
439
+ const part = sum - x;
440
+ return x - (sum - part) + (y - part);
441
+ }
442
+ function productError(x, y, product) {
443
+ const sx = 134217729 * x, sy = 134217729 * y;
444
+ if (!Number.isFinite(sx) || !Number.isFinite(sy))
445
+ return 0;
446
+ const hx = sx - (sx - x), hy = sy - (sy - y);
447
+ const lx = x - hx, ly = y - hy;
448
+ return hx * hy - product + hx * ly + lx * hy + lx * ly;
449
+ }
450
+
451
+ // dist/ellipsoid-helpers/scale-to-geodetic-surface.js
452
+ var surface = { x: 0, y: 0, z: 0 };
453
+ function scaleToGeodeticSurface(cartesian, ellipsoid, result = []) {
454
+ const object = cartesian;
455
+ const x = "x" in cartesian ? object.x : cartesian[0];
456
+ const y = "x" in cartesian ? object.y : cartesian[1];
457
+ const z = "x" in cartesian ? object.z : cartesian[2];
458
+ if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z))
459
+ return void 0;
460
+ if (!Number.isFinite(x * x + y * y + z * z))
461
+ return void 0;
462
+ const { radii } = ellipsoid;
463
+ if (!nearestSurface(x, y, z, radii.x, radii.y, radii.z, surface))
464
+ return void 0;
465
+ return writeResult(result, surface.x, surface.y, surface.z);
466
+ }
467
+ function writeResult(result, x, y, z) {
468
+ if ((0, import_matrix5.isArray)(result)) {
469
+ result[0] = x;
470
+ result[1] = y;
471
+ result[2] = z;
472
+ } else {
473
+ const point = result;
474
+ point.x = x;
475
+ point.y = y;
476
+ point.z = z;
477
+ }
478
+ return result;
479
+ }
480
+
481
+ // dist/ellipsoid.js
482
+ var spheroidScratch = { x: 0, y: 0, z: 0 };
483
+ var scratchVector4 = new import_matrix6.Vector3();
484
+ var scratchNormal = new import_matrix6.Vector3();
485
+ var scratchPosition = new import_matrix6.Vector3();
486
+ var scratchCartesian = new import_matrix6.Vector3();
487
+ var Ellipsoid = class _Ellipsoid {
488
+ /** Construct from two-axis geometry, including normalized projection ellipsoids.
489
+ * The equatorial X/Y radii are equal; no CRS or datum information is inferred.
490
+ */
491
+ static fromSpheroid(parameters) {
492
+ const { semiMajorAxis, semiMinorAxis } = parameters;
493
+ validateSpheroid(semiMajorAxis, semiMinorAxis);
494
+ return new _Ellipsoid(semiMajorAxis, semiMajorAxis, semiMinorAxis);
495
+ }
496
+ constructor(x = 0, y = 0, z = 0) {
497
+ this.centerToleranceSquared = import_matrix6._MathUtils.EPSILON1;
498
+ (0, import_matrix6.assert)(Number.isFinite(x) && x >= 0);
499
+ (0, import_matrix6.assert)(Number.isFinite(y) && y >= 0);
500
+ (0, import_matrix6.assert)(Number.isFinite(z) && z >= 0);
501
+ this.radii = new import_matrix6.Vector3(x, y, z);
502
+ this.radiiSquared = new import_matrix6.Vector3(x * x, y * y, z * z);
503
+ this.radiiToTheFourth = new import_matrix6.Vector3(x * x * x * x, y * y * y * y, z * z * z * z);
504
+ this.oneOverRadii = new import_matrix6.Vector3(x === 0 ? 0 : 1 / x, y === 0 ? 0 : 1 / y, z === 0 ? 0 : 1 / z);
505
+ this.oneOverRadiiSquared = new import_matrix6.Vector3(x === 0 ? 0 : 1 / (x * x), y === 0 ? 0 : 1 / (y * y), z === 0 ? 0 : 1 / (z * z));
506
+ this.minimumRadius = Math.min(x, y, z);
507
+ this.maximumRadius = Math.max(x, y, z);
508
+ if (z !== 0) {
509
+ this.squaredXOverSquaredZ = (x / z) ** 2;
510
+ }
511
+ if (x === y && z > 0 && z <= x && Number.isFinite(this.radiiSquared.x) && this.radiiSquared.z > 0)
512
+ this.spheroidGeometry = Object.freeze({
513
+ semiMajorAxis: x,
514
+ semiMinorAxis: z,
515
+ eccentricitySquared: 1 - (z / x) ** 2
516
+ });
517
+ Object.freeze(this.radii);
518
+ Object.freeze(this.radiiSquared);
519
+ Object.freeze(this.radiiToTheFourth);
520
+ Object.freeze(this.oneOverRadii);
521
+ Object.freeze(this.oneOverRadiiSquared);
522
+ Object.freeze(this);
523
+ }
524
+ /** Return an owned geometry snapshot for a sphere or oblate spheroid.
525
+ * Triaxial, prolate and degenerate ellipsoids cannot be represented by this contract.
526
+ * Call during setup, outside coordinate loops.
527
+ */
528
+ toSpheroid() {
529
+ const { x, y, z } = this.radii;
530
+ if (x !== y)
531
+ throw new Error("Spheroid requires equal X/Y radii");
532
+ validateSpheroid(x, z);
533
+ return Object.freeze({ semiMajorAxis: x, semiMinorAxis: z });
534
+ }
535
+ /** Compares this Ellipsoid against the provided Ellipsoid componentwise */
536
+ equals(right) {
537
+ return this === right || Boolean(right && this.radii.equals(right.radii));
538
+ }
539
+ /** Creates a string representing this Ellipsoid in the format '[radii.x, radii.y, radii.z]'. */
540
+ toString() {
541
+ return this.radii.toString();
542
+ }
543
+ cartographicToCartesian(cartographic, result = [0, 0, 0]) {
544
+ const llh = fromCartographicToRadians(cartographic, scratchCartesian);
545
+ const longitude = llh[0], latitude = llh[1], height = llh[2];
546
+ if (!Number.isFinite(longitude) || !Number.isFinite(latitude) || !Number.isFinite(height) || !(this.minimumRadius > 0) || !Number.isFinite(this.maximumRadius * this.maximumRadius))
547
+ return void 0;
548
+ if (this.spheroidGeometry && (import_matrix6.config._cartographicRadians || Math.abs(latitude) <= Math.PI / 4)) {
549
+ spheroidScratch.x = longitude;
550
+ spheroidScratch.y = latitude;
551
+ spheroidScratch.z = height;
552
+ if (!(0, import_matrix7.spheroidToCartesian)(spheroidScratch, this.spheroidGeometry))
553
+ return void 0;
554
+ return writeResult(result, spheroidScratch.x, spheroidScratch.y, spheroidScratch.z);
555
+ }
556
+ const normal = scratchNormal;
557
+ this.geodeticSurfaceNormalCartographic(cartographic, normal);
558
+ const nx = normal.x, ny = normal.y, nz = normal.z;
559
+ const rx = this.radii.x, ry = this.radii.y, rz = this.radii.z;
560
+ const gamma = Math.hypot(rx * nx, ry * ny, rz * nz);
561
+ const x = rx * (rx * nx / gamma) + height * nx;
562
+ const y = ry * (ry * ny / gamma) + height * ny;
563
+ const z = rz * (rz * nz / gamma) + height * nz;
564
+ if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z))
565
+ return void 0;
566
+ return writeResult(result, x, y, z);
567
+ }
568
+ cartesianToCartographic(cartesian, result = [0, 0, 0]) {
569
+ const object = cartesian;
570
+ const x = "x" in cartesian ? object.x : cartesian[0];
571
+ const y = "x" in cartesian ? object.y : cartesian[1];
572
+ const z = "x" in cartesian ? object.z : cartesian[2];
573
+ if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z))
574
+ return void 0;
575
+ if (this.spheroidGeometry && Number.isFinite(x * x + y * y + z * z) && Number.isFinite(this.oneOverRadiiSquared.x) && Number.isFinite(this.oneOverRadiiSquared.z)) {
576
+ spheroidScratch.x = x;
577
+ spheroidScratch.y = y;
578
+ spheroidScratch.z = z;
579
+ const shape = this.spheroidGeometry;
580
+ const nearBoundary = z === 0 && shape.semiMinorAxis < shape.semiMajorAxis && Math.abs(Math.hypot(x, y) - shape.semiMajorAxis * shape.eccentricitySquared) <= 64 * Number.EPSILON * shape.semiMajorAxis;
581
+ if (!nearBoundary && (0, import_matrix7.cartesianToSpheroid)(spheroidScratch, shape)) {
582
+ const longitude2 = x === 0 && y === 0 ? Math.atan2(y, x) : spheroidScratch.x;
583
+ return toCartographicFromRadiansComponents(longitude2, spheroidScratch.y, spheroidScratch.z, result);
584
+ }
585
+ }
586
+ if (!(this.minimumRadius > 0) || !Number.isFinite(this.maximumRadius * this.maximumRadius) || !Number.isFinite(1 / (this.minimumRadius * this.minimumRadius)))
587
+ return void 0;
588
+ scratchCartesian.set(x, y, z);
589
+ const point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition);
590
+ if (!point) {
591
+ return void 0;
592
+ }
593
+ const gx = point[0] * this.oneOverRadiiSquared.x;
594
+ const gy = point[1] * this.oneOverRadiiSquared.y;
595
+ const gz = point[2] * this.oneOverRadiiSquared.z;
596
+ const length = Math.hypot(gx, gy, gz);
597
+ if (!(length > 0) || !Number.isFinite(length))
598
+ return void 0;
599
+ const nx = gx / length, ny = gy / length, nz = gz / length;
600
+ const longitude = Math.atan2(ny, nx);
601
+ const latitude = Math.atan2(nz, Math.hypot(nx, ny));
602
+ const height = (x - point[0]) * nx + (y - point[1]) * ny + (z - point[2]) * nz;
603
+ return toCartographicFromRadiansComponents(longitude, latitude, height, result);
604
+ }
605
+ geocentricSurfaceNormal(cartesian, result = [0, 0, 0]) {
606
+ fromCartographic(cartesian, scratchVector4);
607
+ const point = scratchVector4;
608
+ return normalResult(point.x, point.y, point.z, result);
609
+ }
610
+ geodeticSurfaceNormalCartographic(cartographic, result = [0, 0, 0]) {
611
+ const point = fromCartographic(cartographic, scratchCartesian);
612
+ const longitude = import_matrix6.config._cartographicRadians ? point[0] : point[0] * Math.PI / 180;
613
+ const latitude = import_matrix6.config._cartographicRadians ? point[1] : point[1] * Math.PI / 180;
614
+ const polarDegrees = !import_matrix6.config._cartographicRadians && Math.abs(point[1]) > 45;
615
+ const complement = (90 - Math.abs(point[1])) * Math.PI / 180;
616
+ const cosLatitude = polarDegrees ? Math.sin(complement) : Math.abs(latitude) === Math.PI / 2 ? 0 : Math.cos(latitude);
617
+ const sinLatitude = polarDegrees ? Math.sign(point[1]) * Math.cos(complement) : Math.sin(latitude);
618
+ return normalResult(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), sinLatitude, result);
619
+ }
620
+ geodeticSurfaceNormal(cartesian, result = [0, 0, 0]) {
621
+ if (!(this.minimumRadius > 0))
622
+ return void 0;
623
+ fromCartographic(cartesian, scratchVector4);
624
+ const point = scratchVector4;
625
+ const scale = Math.max(Math.abs(point.x), Math.abs(point.y), Math.abs(point.z));
626
+ if (!(scale > 0) || !Number.isFinite(scale))
627
+ return void 0;
628
+ const nx = point.x / scale * (this.minimumRadius / this.radii.x) ** 2;
629
+ const ny = point.y / scale * (this.minimumRadius / this.radii.y) ** 2;
630
+ const nz = point.z / scale * (this.minimumRadius / this.radii.z) ** 2;
631
+ 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))
632
+ return normalResult(nx, ny, nz, result);
633
+ const ex = point.x === 0 ? 0 : Math.min(1023, Math.floor(Math.log2(Math.abs(point.x))));
634
+ const ey = point.y === 0 ? 0 : Math.min(1023, Math.floor(Math.log2(Math.abs(point.y))));
635
+ const ez = point.z === 0 ? 0 : Math.min(1023, Math.floor(Math.log2(Math.abs(point.z))));
636
+ const ax = Math.min(1023, Math.floor(Math.log2(this.radii.x)));
637
+ const ay = Math.min(1023, Math.floor(Math.log2(this.radii.y)));
638
+ const az = Math.min(1023, Math.floor(Math.log2(this.radii.z)));
639
+ 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);
640
+ 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);
641
+ }
642
+ /** Scales the provided Cartesian position along the geodetic surface normal
643
+ * so that it is on the surface of this ellipsoid. If the position is
644
+ * at the center of the ellipsoid, this function returns undefined. */
645
+ scaleToGeodeticSurface(cartesian, result) {
646
+ return scaleToGeodeticSurface(cartesian, this, result);
647
+ }
648
+ /** Scales the provided Cartesian position along the geocentric surface normal
649
+ * so that it is on the surface of this ellipsoid. */
650
+ scaleToGeocentricSurface(cartesian, result = [0, 0, 0]) {
651
+ fromCartographic(cartesian, scratchPosition);
652
+ const point = scratchPosition;
653
+ const scale = Math.max(Math.abs(point.x), Math.abs(point.y), Math.abs(point.z));
654
+ if (!(this.minimumRadius > 0) || !(scale > 0) || !Number.isFinite(scale))
655
+ return void 0;
656
+ const squared = point.x * point.x * this.oneOverRadiiSquared.x + point.y * point.y * this.oneOverRadiiSquared.y + point.z * point.z * this.oneOverRadiiSquared.z;
657
+ if (squared >= 2 ** -1022 && Number.isFinite(squared) && scale * scale >= 2 ** -1022 && Number.isFinite(scale * scale)) {
658
+ const beta = 1 / Math.sqrt(squared);
659
+ return writeResult(result, point.x * beta, point.y * beta, point.z * beta);
660
+ }
661
+ const x = point.x / scale, y = point.y / scale, z = point.z / scale;
662
+ const norm = Math.hypot(x / this.radii.x, y / this.radii.y, z / this.radii.z);
663
+ if (!(norm > 0) || !Number.isFinite(norm))
664
+ return void 0;
665
+ return writeResult(result, x / norm, y / norm, z / norm);
666
+ }
667
+ /** Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying
668
+ * its components by the result of `Ellipsoid#oneOverRadii` */
669
+ transformPositionToScaledSpace(position, result = [0, 0, 0]) {
670
+ fromCartographic(position, scratchPosition);
671
+ const point = scratchPosition.scale(this.oneOverRadii);
672
+ return writeResult(result, point.x, point.y, point.z);
673
+ }
674
+ /** Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying
675
+ * its components by the result of `Ellipsoid#radii`. */
676
+ transformPositionFromScaledSpace(position, result = [0, 0, 0]) {
677
+ fromCartographic(position, scratchPosition);
678
+ const point = scratchPosition.scale(this.radii);
679
+ return writeResult(result, point.x, point.y, point.z);
680
+ }
681
+ /** Computes a point which is the intersection of the surface normal with the z-axis. */
682
+ getSurfaceNormalIntersectionWithZAxis(position, buffer = 0, result = [0, 0, 0]) {
683
+ (0, import_matrix6.assert)(this.radii.x === this.radii.y && this.minimumRadius > 0);
684
+ fromCartographic(position, scratchPosition);
685
+ if (!Number.isFinite(scratchPosition.x) || !Number.isFinite(scratchPosition.y) || !Number.isFinite(scratchPosition.z) || !Number.isFinite(buffer))
686
+ return void 0;
687
+ const z = scratchPosition.z * (1 - this.squaredXOverSquaredZ);
688
+ if (!Number.isFinite(z))
689
+ return void 0;
690
+ if (Math.abs(z) >= this.radii.z - buffer) {
691
+ return void 0;
692
+ }
693
+ return writeResult(result, 0, 0, z);
694
+ }
695
+ };
696
+ Ellipsoid.WGS84 = new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z);
697
+ function validateSpheroid(a, b) {
698
+ if (!Number.isFinite(a) || !Number.isFinite(b) || a <= 0 || b <= 0 || b > a)
699
+ throw new Error("Spheroid requires finite positive axes with semiMinorAxis <= semiMajorAxis");
700
+ }
701
+ function normalResult(x, y, z, result) {
702
+ const scale = Math.max(Math.abs(x), Math.abs(y), Math.abs(z));
703
+ if (!(scale > 0) || !Number.isFinite(scale))
704
+ return void 0;
705
+ const nx = x / scale, ny = y / scale, nz = z / scale;
706
+ const length = Math.hypot(nx, ny, nz);
707
+ return writeResult(result, nx / length, ny / length, nz / length);
708
+ }
709
+
710
+ // dist/expressions.js
711
+ var import_matrix8 = require("@math.gl/core/matrix");
712
+ var GEOSPATIAL_FUNCTION_LIBRARY = {
713
+ cartesianToCartographic: (cartesian, result) => Ellipsoid.WGS84.cartesianToCartographic(cartesian, result),
714
+ cartographicToCartesian: (cartographic, result) => Ellipsoid.WGS84.cartographicToCartesian(cartographic, result),
715
+ eastNorthUpToFixedFrame: (origin, result) => eastNorthUpToFixedFrame(Ellipsoid.WGS84, origin, result),
716
+ geodeticSurfaceNormal: (cartesian, result) => Ellipsoid.WGS84.geodeticSurfaceNormal(cartesian, result),
717
+ geodeticSurfaceNormalCartographic: (cartographic, result) => Ellipsoid.WGS84.geodeticSurfaceNormalCartographic(cartographic, result),
718
+ isWGS84,
719
+ scaleToGeocentricSurface: (cartesian, result) => Ellipsoid.WGS84.scaleToGeocentricSurface(cartesian, result),
720
+ scaleToGeodeticSurface: (cartesian, result) => Ellipsoid.WGS84.scaleToGeodeticSurface(cartesian, result),
721
+ toDegrees: import_matrix8.toDegrees,
722
+ toRadians: import_matrix8.toRadians,
723
+ transformPositionFromScaledSpace: (position, result) => Ellipsoid.WGS84.transformPositionFromScaledSpace(position, result),
724
+ transformPositionToScaledSpace: (position, result) => Ellipsoid.WGS84.transformPositionToScaledSpace(position, result)
725
+ };
726
+ //# sourceMappingURL=expressions.cjs.map