@math.gl/geospatial 5.0.0-rc.2 → 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
@@ -19,19 +19,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // dist/projection/index.js
20
20
  var index_exports = {};
21
21
  __export(index_exports, {
22
- ConfigurableProjectionEngine: () => ConfigurableProjectionEngine,
22
+ ConfigurableProjectionEngine: () => import_projection_engine.ConfigurableProjectionEngine,
23
23
  FullProjectionEngine: () => FullProjectionEngine,
24
24
  ProjectionPipeline: () => ProjectionPipeline,
25
- ProjectionTransform: () => ProjectionTransform,
26
- TypeScriptCRSError: () => TypeScriptCRSError,
25
+ ProjectionTransform: () => import_typescript_projection.ProjectionTransform,
26
+ TypeScriptCRSError: () => import_types3.TypeScriptCRSError,
27
27
  albersEqualArea: () => albersEqualArea,
28
28
  azimuthalEquidistant: () => azimuthalEquidistant,
29
29
  bonne: () => bonne,
30
30
  cassiniSoldner: () => cassiniSoldner,
31
- checkProjectionCompatibility: () => checkProjectionCompatibility,
31
+ checkProjectionCompatibility: () => import_typescript_projection.checkProjectionCompatibility,
32
32
  createGeoidGrid: () => createGeoidGrid,
33
33
  createProjectionDescriptor: () => createProjectionDescriptor,
34
- createProjectionEngine: () => createProjectionEngine,
34
+ createProjectionEngine: () => import_projection_engine.createProjectionEngine,
35
35
  createVerticalGrid: () => createVerticalGrid,
36
36
  cylindricalEqualArea: () => cylindricalEqualArea,
37
37
  eckertVI: () => eckertVI,
@@ -78,329 +78,8 @@ __export(index_exports, {
78
78
  });
79
79
  module.exports = __toCommonJS(index_exports);
80
80
 
81
- // dist/projection/experimental/rendering-profile/geographic-bounds.js
82
- var RADIANS = Math.PI / 180;
83
- function createAngularRanges(west, south, east, north) {
84
- return [
85
- [west, south],
86
- [east, north]
87
- ];
88
- }
89
- function normalizeLongitude(longitude) {
90
- return longitude >= -180 && longitude < 180 ? longitude : ((longitude + 180) % 360 + 360) % 360 - 180;
91
- }
92
- function createGeographicBounds(west, south, east, north) {
93
- if (![west, south, east, north].every(Number.isFinite) || south < -90 || north > 90 || south > north || east - west < -360 || east - west > 360 + 1e-10)
94
- throw new Error("Invalid geographic coverage");
95
- if (east - west >= 360 - 1e-10)
96
- return [-180, south, 180, north];
97
- const wrappedEast = normalizeLongitude(east);
98
- return [
99
- normalizeLongitude(west),
100
- south,
101
- wrappedEast === -180 && east > west ? 180 : wrappedEast,
102
- north
103
- ];
104
- }
105
- function getLongitudeSpan(bounds) {
106
- const span = bounds[2] - bounds[0];
107
- return span < 0 ? span + 360 : span;
108
- }
109
- function splitGeographicBounds(bounds) {
110
- const [west, south, east, north] = bounds;
111
- return west <= east ? [bounds] : [
112
- [west, south, 180, north],
113
- [-180, south, east, north]
114
- ];
115
- }
116
- function containsGeographicPoint(bounds, point) {
117
- const [west, south, east, north] = bounds;
118
- const longitude = normalizeLongitude(point[0]);
119
- return point[1] >= south && point[1] <= north && (west <= east ? longitude >= west && longitude <= east || longitude === -180 && east === 180 : longitude >= west || longitude <= east);
120
- }
121
- function intersectGeographicBounds(a, b) {
122
- const south = Math.max(a[1], b[1]), north = Math.min(a[3], b[3]);
123
- if (south > north)
124
- return [];
125
- const intervals = [];
126
- for (const left of splitGeographicBounds(a))
127
- for (const right of splitGeographicBounds(b)) {
128
- const west = Math.max(left[0], right[0]), east = Math.min(left[2], right[2]);
129
- if (west <= east)
130
- intervals.push([west, east]);
131
- else if (left[2] === 180 && right[0] === -180 || right[2] === 180 && left[0] === -180)
132
- intervals.push([-180, -180]);
133
- }
134
- intervals.sort((left, right) => left[0] - right[0]);
135
- const merged = [];
136
- for (const interval of intervals) {
137
- const last = merged[merged.length - 1];
138
- if (last && interval[0] <= last[1])
139
- last[1] = Math.max(last[1], interval[1]);
140
- else
141
- merged.push([...interval]);
142
- }
143
- if (merged.length > 1 && merged[0][0] === -180 && merged[merged.length - 1][1] === 180) {
144
- const first = merged.shift(), last = merged.pop();
145
- return [
146
- [last[0], south, first[1], north],
147
- ...merged.map(([west, east]) => [west, south, east, north])
148
- ];
149
- }
150
- return merged.map(([west, east]) => [west, south, east, north]);
151
- }
152
- function clampGeographicPoint(bounds, point) {
153
- let longitude = normalizeLongitude(point[0]);
154
- const latitude = Math.max(bounds[1], Math.min(bounds[3], point[1]));
155
- if (!containsGeographicPoint(bounds, [longitude, latitude])) {
156
- const westDistance = Math.abs(normalizeLongitude(longitude - bounds[0]));
157
- const eastDistance = Math.abs(normalizeLongitude(longitude - bounds[2]));
158
- longitude = westDistance <= eastDistance ? bounds[0] : bounds[2];
159
- }
160
- return [longitude, latitude];
161
- }
162
- function getAngularRanges(bounds, primeMeridian2 = 0, origin = 0) {
163
- const width = getLongitudeSpan(bounds);
164
- const west = bounds[0] * RADIANS - primeMeridian2;
165
- const middle = west + width * RADIANS / 2;
166
- const shift = Math.round((origin - middle) / (2 * Math.PI)) * 2 * Math.PI;
167
- return createAngularRanges(width === 360 ? origin - Math.PI : west + shift, bounds[1] * RADIANS, width === 360 ? origin + Math.PI : west + shift + width * RADIANS, bounds[3] * RADIANS);
168
- }
169
- function getGeographicBounds(ranges, primeMeridian2 = 0) {
170
- return createGeographicBounds((ranges[0][0] + primeMeridian2) / RADIANS, ranges[0][1] / RADIANS, (ranges[1][0] + primeMeridian2) / RADIANS, ranges[1][1] / RADIANS);
171
- }
172
- function unionRenderingBounds(bounds) {
173
- if (!bounds.length)
174
- throw new Error("CRS coverage does not intersect the rendering target");
175
- return [
176
- [0, 1, 2].map((axis) => Math.min(...bounds.map((pair2) => pair2[0][axis]))),
177
- [0, 1, 2].map((axis) => Math.max(...bounds.map((pair2) => pair2[1][axis])))
178
- ];
179
- }
180
-
181
- // dist/projection/experimental/rendering-profile/rendering-profile.js
182
- function resolveRenderingProfile(getRenderingProfile, coverage) {
183
- if (coverage) {
184
- try {
185
- const profile2 = getRenderingProfile(coverage);
186
- return resolveBounds(profile2);
187
- } catch {
188
- }
189
- }
190
- const profile = getRenderingProfile();
191
- return resolveBounds(profile);
192
- }
193
- function resolveBounds(profile) {
194
- var _a2;
195
- const bounds = profile.bounds;
196
- if (bounds.some((corner) => corner.some((value2) => !Number.isFinite(value2))))
197
- throw new Error("Projection rendering bounds must be finite");
198
- return { bounds, normalize: (_a2 = profile.normalize) == null ? void 0 : _a2.bind(profile) };
199
- }
200
- function createAngularNormalization(normalize, primeMeridian2 = 0) {
201
- return (point) => {
202
- const x = point.x * Math.PI / 180 - primeMeridian2;
203
- const y = point.y * Math.PI / 180;
204
- const native = { x, y, z: point.z };
205
- normalize(native);
206
- if (native.x !== x)
207
- point.x = (native.x + primeMeridian2) * 180 / Math.PI;
208
- if (native.y !== y)
209
- point.y = native.y * 180 / Math.PI;
210
- };
211
- }
212
- function combineRenderingProfiles(regions, getProfile) {
213
- const profiles = [];
214
- for (const region of regions) {
215
- const profile = getProfile(region);
216
- if (profile !== null)
217
- profiles.push(resolveBounds(profile));
218
- }
219
- if (!profiles.length)
220
- return null;
221
- if (profiles.length === 1)
222
- return profiles[0];
223
- return {
224
- bounds: unionRenderingBounds(profiles.map((profile) => profile.bounds)),
225
- normalize(point) {
226
- var _a2;
227
- let bestX = point.x, bestY = point.y, best = Infinity;
228
- for (const profile of profiles) {
229
- const candidate = { x: point.x, y: point.y, z: point.z };
230
- (_a2 = profile.normalize) == null ? void 0 : _a2.call(profile, candidate);
231
- const distance = Math.sin((candidate.y - point.y) * Math.PI / 360) ** 2 + Math.cos(point.y * Math.PI / 180) * Math.cos(candidate.y * Math.PI / 180) * Math.sin((candidate.x - point.x) * Math.PI / 360) ** 2;
232
- if (distance < best) {
233
- best = distance;
234
- bestX = candidate.x;
235
- bestY = candidate.y;
236
- }
237
- }
238
- point.x = bestX;
239
- point.y = bestY;
240
- }
241
- };
242
- }
243
-
244
- // dist/projection/experimental/rendering-profile/identity-rendering-profile.js
245
- function getIdentityRenderingProfile() {
246
- return {
247
- bounds: [
248
- [-1, -1, 0],
249
- [1, 1, 0]
250
- ]
251
- };
252
- }
253
-
254
- // dist/projection/experimental/projection-descriptor.js
255
- var CACHE_KEY = /* @__PURE__ */ Symbol.for("@math.gl/projection/projection-implementations");
256
- function cache() {
257
- const scope = globalThis;
258
- scope[CACHE_KEY] || (scope[CACHE_KEY] = /* @__PURE__ */ new WeakMap());
259
- return scope[CACHE_KEY];
260
- }
261
- function getLoadedProjection(projection) {
262
- var _a2;
263
- return "create" in projection ? projection : (_a2 = cache().get(projection)) == null ? void 0 : _a2.implementation;
264
- }
265
- function preloadProjection(projection) {
266
- if ("create" in projection)
267
- return Promise.resolve(projection);
268
- let state = cache().get(projection);
269
- if (!state) {
270
- state = { load: () => projection.preload() };
271
- cache().set(projection, state);
272
- }
273
- if (state.implementation)
274
- return Promise.resolve(state.implementation);
275
- const entry = state;
276
- entry.pending || (entry.pending = Promise.resolve().then(entry.load).then((plugin) => {
277
- const key2 = (value2) => value2.toLowerCase().replace(/[\s_-]/g, "");
278
- const supported = new Set([plugin.name, ...plugin.aliases || []].map(key2));
279
- if (typeof plugin.create !== "function" || ![projection.name, ...projection.aliases || []].every((name) => supported.has(key2(name))))
280
- throw new Error("Loaded projection does not match descriptor: " + projection.name);
281
- entry.implementation = plugin;
282
- return plugin;
283
- }).catch((error) => {
284
- entry.pending = void 0;
285
- throw error;
286
- }));
287
- return entry.pending;
288
- }
289
- function createProjectionDescriptor(metadata, load) {
290
- const descriptor = Object.freeze({
291
- name: metadata.name,
292
- aliases: metadata.aliases && Object.freeze([...metadata.aliases]),
293
- preload: () => preloadProjection(descriptor)
294
- });
295
- cache().set(descriptor, { load });
296
- return descriptor;
297
- }
298
-
299
- // dist/projection/experimental/projection-scratch.js
300
- function createPoint() {
301
- return { x: 0, y: 0, z: 0 };
302
- }
303
- var ProjectionScratch = class {
304
- constructor() {
305
- this.point = createPoint();
306
- this.points = [this.point];
307
- this.active = 0;
308
- }
309
- get depth() {
310
- return this.active;
311
- }
312
- acquire() {
313
- var _a2;
314
- const index = this.active++;
315
- (_a2 = this.points)[index] || (_a2[index] = createPoint());
316
- return this.points[index];
317
- }
318
- release(point) {
319
- if (this.active > 0 && this.points[this.active - 1] === point)
320
- this.active--;
321
- }
322
- };
323
-
324
- // dist/projection/experimental/mutable-projection.js
325
- function createProjection(forward33, inverse33) {
326
- const scratch = new ProjectionScratch();
327
- const scalar = (x, y, operation2) => {
328
- const point = scratch.acquire();
329
- try {
330
- point.x = x;
331
- point.y = y;
332
- point.z = 0;
333
- operation2(point);
334
- return [point.x, point.y];
335
- } finally {
336
- scratch.release(point);
337
- }
338
- };
339
- return {
340
- forward(x, y) {
341
- return scalar(x, y, forward33);
342
- },
343
- inverse(x, y) {
344
- return scalar(x, y, inverse33);
345
- },
346
- forwardInPlace: forward33,
347
- inverseInPlace: inverse33
348
- };
349
- }
350
- function projectionOperation(implementation, inverse33, geocentric2 = false) {
351
- const mutable = inverse33 ? implementation.inverseInPlace : implementation.forwardInPlace;
352
- if (mutable)
353
- return mutable.bind(implementation);
354
- if (geocentric2) {
355
- const operation3 = inverse33 ? implementation.inverse3D : implementation.forward3D;
356
- return (point) => {
357
- const output = operation3.call(implementation, [point.x, point.y, point.z]);
358
- point.x = output[0];
359
- point.y = output[1];
360
- point.z = output[2];
361
- };
362
- }
363
- const operation2 = inverse33 ? implementation.inverse : implementation.forward;
364
- return (point) => {
365
- const output = operation2.call(implementation, point.x, point.y);
366
- point.x = output[0];
367
- point.y = output[1];
368
- };
369
- }
370
-
371
- // dist/projection/experimental/scalar-output.js
372
- var FLOAT32_MAX = 34028234663852886e22;
373
- function validateScalarOutput(coordinate, output, length) {
374
- if (!(Array.isArray(coordinate) || coordinate instanceof Float32Array || coordinate instanceof Float64Array))
375
- throw new Error("Scalar input requires a number array, Float32Array or Float64Array");
376
- if (!(Array.isArray(output) || output instanceof Float32Array || output instanceof Float64Array) || output.length < length)
377
- throw new Error("Scalar output requires a preallocated number array, Float32Array or Float64Array with sufficient capacity");
378
- if (coordinate === output || Array.isArray(coordinate) || Array.isArray(output))
379
- return;
380
- const input = coordinate;
381
- const result = output;
382
- const shared = typeof SharedArrayBuffer !== "undefined" && input.buffer instanceof SharedArrayBuffer && result.buffer instanceof SharedArrayBuffer;
383
- if ((input.buffer === result.buffer || shared) && input.byteOffset < result.byteOffset + length * result.BYTES_PER_ELEMENT && result.byteOffset < input.byteOffset + input.byteLength)
384
- throw new Error("Scalar input/output views overlap; use the same view for in-place projection");
385
- }
386
- function writeScalarOutput(coordinate, output, point, length) {
387
- if (output instanceof Float32Array) {
388
- if (Math.abs(point.x) > FLOAT32_MAX || Math.abs(point.y) > FLOAT32_MAX || length >= 3 && Math.abs(point.z) > FLOAT32_MAX)
389
- throw new Error("Projected coordinate exceeds Float32 range");
390
- for (let i = 3; i < coordinate.length; i++) {
391
- const value2 = coordinate[i];
392
- if (Number.isFinite(value2) && Math.abs(value2) > FLOAT32_MAX)
393
- throw new Error("Trailing ordinate exceeds Float32 range");
394
- }
395
- }
396
- for (let i = 3; i < coordinate.length; i++)
397
- output[i] = coordinate[i];
398
- output[0] = point.x;
399
- output[1] = point.y;
400
- if (length >= 3)
401
- output[2] = point.z;
402
- return output;
403
- }
81
+ // dist/projection/experimental/core.js
82
+ var import_typescript_projection = require("./experimental/typescript-projection.shared.cjs");
404
83
 
405
84
  // dist/crs/spatial-reference.js
406
85
  function inferCRSRepresentation(definition2) {
@@ -546,27 +225,8 @@ function getSourceLocation(source, offset) {
546
225
  return { line, column };
547
226
  }
548
227
 
549
- // dist/projection/experimental/crs/types.js
550
- var _a;
551
- var CRS_ERROR = /* @__PURE__ */ Symbol.for("@math.gl/projection/TypeScriptCRSError");
552
- var TypeScriptCRSError = class _TypeScriptCRSError extends Error {
553
- static [(_a = CRS_ERROR, Symbol.hasInstance)](value2) {
554
- if (this !== _TypeScriptCRSError)
555
- return Function.prototype[Symbol.hasInstance].call(this, value2);
556
- return value2 instanceof Error && value2[CRS_ERROR] === true;
557
- }
558
- constructor(reason, message) {
559
- super(message);
560
- this.reason = reason;
561
- this[_a] = true;
562
- this.name = "TypeScriptCRSError";
563
- }
564
- };
565
- function unsupportedStage(message) {
566
- throw new TypeScriptCRSError("missing-transform-stage", message);
567
- }
568
-
569
228
  // dist/projection/experimental/crs/spatial-reference.js
229
+ var import_types = require("./experimental/crs/types.shared.cjs");
570
230
  function resolveCRSInput(input, options) {
571
231
  if (typeof input === "string" || "type" in input)
572
232
  return { definition: input, lossy: false };
@@ -574,19 +234,19 @@ function resolveCRSInput(input, options) {
574
234
  const spatialReference = "crs" in metadata ? metadata : void 0;
575
235
  const reference = "crs" in metadata ? metadata.crs : metadata;
576
236
  if (reference.state !== "explicit" && reference.state !== "default")
577
- throw new TypeScriptCRSError("unknown-syntax", "Cannot transform an " + reference.state + " CRS reference");
237
+ throw new import_types.TypeScriptCRSError("unknown-syntax", "Cannot transform an " + reference.state + " CRS reference");
578
238
  let lossy = false;
579
239
  if ((spatialReference == null ? void 0 : spatialReference.coordinateEpoch) !== void 0)
580
- unsupportedStage("Coordinate epochs require a time-dependent transformation");
240
+ (0, import_types.unsupportedStage)("Coordinate epochs require a time-dependent transformation");
581
241
  if ((spatialReference == null ? void 0 : spatialReference.vertical) && spatialReference.vertical.state !== "absent") {
582
242
  if (options.mode !== "horizontal")
583
- unsupportedStage("A separately declared vertical CRS requires explicit horizontal extraction");
243
+ (0, import_types.unsupportedStage)("A separately declared vertical CRS requires explicit horizontal extraction");
584
244
  lossy = true;
585
245
  }
586
246
  return { definition: reference.definition, spatialReference, lossy };
587
247
  }
588
248
  function applySpatialReference(crs, reference) {
589
- var _a2;
249
+ var _a;
590
250
  if (!reference)
591
251
  return crs;
592
252
  if (reference.coordinateFrame !== "unknown" && reference.coordinateFrame !== crs.kind)
@@ -611,11 +271,11 @@ function applySpatialReference(crs, reference) {
611
271
  if (storedAxis.length === 2)
612
272
  storedAxis += "u";
613
273
  if (storedAxis.length !== 3 || !storedAxis.includes("e") || !storedAxis.includes("n") || !storedAxis.includes("u"))
614
- unsupportedStage("Unsupported SpatialReference coordinate order");
274
+ (0, import_types.unsupportedStage)("Unsupported SpatialReference coordinate order");
615
275
  if (order.length > 4 || order.length > 3 && !["m", "measure"].includes(order[3]))
616
- unsupportedStage("Unsupported fourth coordinate component");
276
+ (0, import_types.unsupportedStage)("Unsupported fourth coordinate component");
617
277
  }
618
- if ((_a2 = reference.units) == null ? void 0 : _a2.length) {
278
+ if ((_a = reference.units) == null ? void 0 : _a.length) {
619
279
  const units2 = {
620
280
  m: 1,
621
281
  meter: 1,
@@ -635,7 +295,7 @@ function applySpatialReference(crs, reference) {
635
295
  const vertical = (storedAxis || "enu")[i] === "u";
636
296
  const expected = crs.kind === "geocentric" ? crs.toMeter : vertical ? crs.verticalUnit : crs.kind === "geographic" ? crs.angularUnit : crs.toMeter;
637
297
  if (Math.abs((units2[reference.units[i]] ?? NaN) - expected) > 1e-12 || units2[reference.units[i]] === void 0)
638
- unsupportedStage("SpatialReference units disagree with its CRS");
298
+ (0, import_types.unsupportedStage)("SpatialReference units disagree with its CRS");
639
299
  }
640
300
  }
641
301
  return Object.freeze({ ...crs, storedAxis });
@@ -680,8 +340,8 @@ var builtins = {
680
340
  var resolved = /* @__PURE__ */ new WeakMap();
681
341
  var datumNameKey = (name) => name.toLowerCase().replace(/[\s_-]/g, "");
682
342
  function getDatumDefinitions(options) {
683
- var _a2;
684
- if (!((_a2 = options.datumCatalogs) == null ? void 0 : _a2.length))
343
+ var _a;
344
+ if (!((_a = options.datumCatalogs) == null ? void 0 : _a.length))
685
345
  return builtins;
686
346
  const cached = resolved.get(options);
687
347
  if ((cached == null ? void 0 : cached.catalogs) === options.datumCatalogs)
@@ -977,23 +637,8 @@ var linearUnits = {
977
637
  "us-yd": { name: "us-survey-yards", metersPerUnit: 0.914401828803658 }
978
638
  };
979
639
 
980
- // dist/crs/crs-metadata.js
981
- function getCRSSignature(crs) {
982
- return JSON.stringify([
983
- crs.coordinateFrame,
984
- crs.projection,
985
- Object.keys(crs.parameters).sort().map((key2) => [key2, crs.parameters[key2]]),
986
- [crs.ellipsoid.semiMajorAxis, crs.ellipsoid.semiMinorAxis],
987
- crs.axis,
988
- [crs.xUnit.name, crs.xUnit.metersPerUnit, crs.xUnit.degreesPerUnit],
989
- [crs.yUnit.name, crs.yUnit.metersPerUnit, crs.yUnit.degreesPerUnit],
990
- [crs.zUnit.name, crs.zUnit.metersPerUnit, crs.zUnit.degreesPerUnit],
991
- crs.lossy,
992
- crs.areaOfUse
993
- ]);
994
- }
995
-
996
640
  // dist/projection/experimental/crs/normalize.js
641
+ var import_types2 = require("./experimental/crs/types.shared.cjs");
997
642
  var ALIASES = {
998
643
  WGS84: "+proj=longlat +datum=WGS84",
999
644
  "EPSG:4326": "+proj=longlat +datum=WGS84",
@@ -1030,7 +675,6 @@ var CORE_PARAMETERS = [
1030
675
  "over",
1031
676
  "lon_wrap"
1032
677
  ];
1033
- var CORE_FLAGS = ["no_defs", "over"];
1034
678
  var own = (object2, key2) => Object.prototype.hasOwnProperty.call(object2, key2);
1035
679
  var keyOf = (value2) => value2.toLowerCase().replace(/[\s_-]/g, "");
1036
680
  function lookup(table, name) {
@@ -1083,7 +727,7 @@ function resolveLocalCRSDefinition(input, options = {}) {
1083
727
  return definition2;
1084
728
  }
1085
729
  function normalizeCRS(input, options = {}) {
1086
- var _a2;
730
+ var _a;
1087
731
  const datums2 = getDatumDefinitions(options);
1088
732
  const resolved2 = resolveCRSInput(input, options);
1089
733
  const definition2 = resolveLocalCRSDefinition(resolved2.definition, options);
@@ -1097,10 +741,10 @@ function normalizeCRS(input, options = {}) {
1097
741
  }
1098
742
  parsed = { parameters: parameters2 };
1099
743
  } else {
1100
- const parser = (_a2 = options.parsers) == null ? void 0 : _a2.find((candidate) => candidate.canParse(definition2));
744
+ const parser = (_a = options.parsers) == null ? void 0 : _a.find((candidate) => candidate.canParse(definition2));
1101
745
  if (!parser) {
1102
746
  const serialized = ["wkt", "projjson"].includes(inferCRSRepresentation(definition2));
1103
- throw new TypeScriptCRSError(serialized ? "missing-parser" : "unknown-syntax", inferCRSRepresentation(definition2) === "identifier" ? "Unsupported CRS definition: " + definition2 + "; resolve it first" : "Unsupported CRS definition; register a WKT or PROJJSON parser for structured definitions");
747
+ throw new import_types2.TypeScriptCRSError(serialized ? "missing-parser" : "unknown-syntax", inferCRSRepresentation(definition2) === "identifier" ? "Unsupported CRS definition: " + definition2 + "; resolve it first" : "Unsupported CRS definition; register a WKT or PROJJSON parser for structured definitions");
1104
748
  }
1105
749
  parsed = parser.parse(definition2, options);
1106
750
  }
@@ -1141,7 +785,7 @@ function normalizeCRS(input, options = {}) {
1141
785
  const datumName = parameters["datum"];
1142
786
  const datum = datumName && datumName !== "none" ? lookup(datums2, datumName) : void 0;
1143
787
  if (datumName && datumName !== "none" && !datum)
1144
- unsupportedStage("Unknown datum: " + datumName + "; register a datumCatalogs plugin");
788
+ (0, import_types2.unsupportedStage)("Unknown datum: " + datumName + "; register a datumCatalogs plugin");
1145
789
  const ellipsoid = getEllipsoid(parameters, datum == null ? void 0 : datum.ellipse);
1146
790
  const grids = parameters["nadgrids"] ?? (datum == null ? void 0 : datum.nadgrids);
1147
791
  const gridReferences = grids === void 0 ? void 0 : grids.split(",").map((entry) => {
@@ -1231,141 +875,332 @@ function getEllipsoid(parameters, datumEllipsoid) {
1231
875
  });
1232
876
  }
1233
877
 
1234
- // dist/projection/experimental/datum.js
1235
- var import_matrix = require("@math.gl/core/matrix");
1236
- var ARC_SECOND = Math.PI / (180 * 3600);
1237
- var WGS84 = {
1238
- ellipsoid: {
1239
- semiMajorAxis: 6378137,
1240
- semiMinorAxis: 6356752314245179e-9,
1241
- eccentricitySquared: 0.0066943799901413165
1242
- },
1243
- towgs84: [0, 0, 0]
1244
- };
1245
- function geodeticToGeocentricInPlace(point, ellipsoid) {
1246
- if (Math.abs(point.y) > Math.PI / 2)
1247
- throw new Error("Latitude outside geocentric domain");
1248
- if (!(0, import_matrix.spheroidToCartesian)(point, ellipsoid))
1249
- throw new Error("Geocentric coordinate must be finite");
878
+ // dist/projection/experimental/core.js
879
+ var import_types3 = require("./experimental/crs/types.shared.cjs");
880
+
881
+ // dist/projection/experimental/projection-descriptor.js
882
+ var CACHE_KEY = /* @__PURE__ */ Symbol.for("@math.gl/projection/projection-implementations");
883
+ function cache() {
884
+ const scope = globalThis;
885
+ scope[CACHE_KEY] || (scope[CACHE_KEY] = /* @__PURE__ */ new WeakMap());
886
+ return scope[CACHE_KEY];
1250
887
  }
1251
- function geocentricToGeodeticInPlace(point, ellipsoid) {
1252
- const x = point.x, y = point.y, z = point.z;
1253
- const { semiMajorAxis: a, semiMinorAxis: b, eccentricitySquared: es } = ellipsoid;
1254
- if (x === 0 && y === 0 && z === 0)
1255
- throw new Error("Geodetic coordinates are undefined at the Earth center");
1256
- if (es !== 0 && Math.abs(x) < 1e-12 * a && Math.abs(y) < 1e-12 * a && Math.hypot(x, y) < 1e-12 * a) {
1257
- if (!Number.isFinite(Math.hypot(x, y, z)))
1258
- throw new Error("Geocentric radius must be finite");
1259
- point.x = 0;
1260
- point.y = Math.sign(z) * Math.PI / 2;
1261
- point.z = Math.abs(z) - b;
1262
- return;
1263
- }
1264
- if (!(0, import_matrix.cartesianToSpheroid)(point, ellipsoid)) {
1265
- if (!Number.isFinite(Math.hypot(x, y, z)))
1266
- throw new Error("Geocentric radius must be finite");
1267
- throw new Error("Geocentric inverse did not converge");
888
+ function getLoadedProjection(projection) {
889
+ var _a;
890
+ return "create" in projection ? projection : (_a = cache().get(projection)) == null ? void 0 : _a.implementation;
891
+ }
892
+ function preloadProjection(projection) {
893
+ if ("create" in projection)
894
+ return Promise.resolve(projection);
895
+ let state = cache().get(projection);
896
+ if (!state) {
897
+ state = { load: () => projection.preload() };
898
+ cache().set(projection, state);
1268
899
  }
900
+ if (state.implementation)
901
+ return Promise.resolve(state.implementation);
902
+ const entry = state;
903
+ entry.pending || (entry.pending = Promise.resolve().then(entry.load).then((plugin) => {
904
+ const key2 = (value2) => value2.toLowerCase().replace(/[\s_-]/g, "");
905
+ const supported = new Set([plugin.name, ...plugin.aliases || []].map(key2));
906
+ if (typeof plugin.create !== "function" || ![projection.name, ...projection.aliases || []].every((name) => supported.has(key2(name))))
907
+ throw new Error("Loaded projection does not match descriptor: " + projection.name);
908
+ entry.implementation = plugin;
909
+ return plugin;
910
+ }).catch((error) => {
911
+ entry.pending = void 0;
912
+ throw error;
913
+ }));
914
+ return entry.pending;
1269
915
  }
1270
- function createHelmert(values, inverse33) {
1271
- const dx = values[0], dy = values[1], dz = values[2];
1272
- const rx = (values[3] || 0) * ARC_SECOND, ry = (values[4] || 0) * ARC_SECOND, rz = (values[5] || 0) * ARC_SECOND;
1273
- const scale2 = 1 + (values[6] || 0) / 1e6;
1274
- return inverse33 ? (point) => {
1275
- const x = (point.x - dx) / scale2, y = (point.y - dy) / scale2, z = (point.z - dz) / scale2;
1276
- point.x = x + rz * y - ry * z;
1277
- point.y = -rz * x + y + rx * z;
1278
- point.z = ry * x - rx * y + z;
1279
- } : (point) => {
1280
- const x = point.x, y = point.y, z = point.z;
1281
- point.x = scale2 * (x - rz * y + ry * z) + dx;
1282
- point.y = scale2 * (rz * x + y - rx * z) + dy;
1283
- point.z = scale2 * (-ry * x + rx * y + z) + dz;
916
+ function createProjectionDescriptor(metadata, load) {
917
+ const descriptor = Object.freeze({
918
+ name: metadata.name,
919
+ aliases: metadata.aliases && Object.freeze([...metadata.aliases]),
920
+ preload: () => preloadProjection(descriptor)
921
+ });
922
+ cache().set(descriptor, { load });
923
+ return descriptor;
924
+ }
925
+
926
+ // dist/projection/experimental/core.js
927
+ var import_projection_engine = require("./experimental/projection-engine.shared.cjs");
928
+
929
+ // dist/projection/experimental/projection-scratch.js
930
+ function createPoint() {
931
+ return { x: 0, y: 0, z: 0 };
932
+ }
933
+ var ProjectionScratch = class {
934
+ constructor() {
935
+ this.point = createPoint();
936
+ this.points = [this.point];
937
+ this.active = 0;
938
+ }
939
+ get depth() {
940
+ return this.active;
941
+ }
942
+ acquire() {
943
+ var _a;
944
+ const index = this.active++;
945
+ (_a = this.points)[index] || (_a[index] = createPoint());
946
+ return this.points[index];
947
+ }
948
+ release(point) {
949
+ if (this.active > 0 && this.points[this.active - 1] === point)
950
+ this.active--;
951
+ }
952
+ };
953
+
954
+ // dist/projection/experimental/mutable-projection.js
955
+ function createProjection(forward33, inverse33) {
956
+ const scratch = new ProjectionScratch();
957
+ const scalar = (x, y, operation2) => {
958
+ const point = scratch.acquire();
959
+ try {
960
+ point.x = x;
961
+ point.y = y;
962
+ point.z = 0;
963
+ operation2(point);
964
+ return [point.x, point.y];
965
+ } finally {
966
+ scratch.release(point);
967
+ }
968
+ };
969
+ return {
970
+ forward(x, y) {
971
+ return scalar(x, y, forward33);
972
+ },
973
+ inverse(x, y) {
974
+ return scalar(x, y, inverse33);
975
+ },
976
+ forwardInPlace: forward33,
977
+ inverseInPlace: inverse33
1284
978
  };
1285
979
  }
1286
- function shifted(datum) {
1287
- var _a2;
1288
- return Boolean((_a2 = datum.towgs84) == null ? void 0 : _a2.some((value2) => value2 !== 0));
1289
- }
1290
- function createDatumTransform(source, destination) {
1291
- if (!source.towgs84 || !destination.towgs84)
1292
- return void 0;
1293
- if (source.grids || destination.grids) {
1294
- if (source.grids && destination.grids && source.ellipsoid.semiMajorAxis === destination.ellipsoid.semiMajorAxis && source.ellipsoid.eccentricitySquared === destination.ellipsoid.eccentricitySquared && source.grids.length === destination.grids.length && source.grids.every((entry, i) => entry.name === destination.grids[i].name && entry.optional === destination.grids[i].optional && entry.grid === destination.grids[i].grid))
1295
- return void 0;
1296
- const middle = createDatumTransform(source.grids ? WGS84 : source, destination.grids ? WGS84 : destination);
1297
- return (point) => {
1298
- if (source.grids)
1299
- applyDatumGrids(point, source, false);
1300
- middle == null ? void 0 : middle(point);
1301
- if (destination.grids)
1302
- applyDatumGrids(point, destination, true);
1303
- };
1304
- }
1305
- if (shifted(source) || shifted(destination)) {
1306
- const first = convertDatum(source, WGS84), second = convertDatum(WGS84, destination);
980
+ function projectionOperation(implementation, inverse33, geocentric2 = false) {
981
+ const mutable = inverse33 ? implementation.inverseInPlace : implementation.forwardInPlace;
982
+ if (mutable)
983
+ return mutable.bind(implementation);
984
+ if (geocentric2) {
985
+ const operation3 = inverse33 ? implementation.inverse3D : implementation.forward3D;
1307
986
  return (point) => {
1308
- first == null ? void 0 : first(point);
1309
- second == null ? void 0 : second(point);
987
+ const output = operation3.call(implementation, [point.x, point.y, point.z]);
988
+ point.x = output[0];
989
+ point.y = output[1];
990
+ point.z = output[2];
1310
991
  };
1311
992
  }
1312
- return convertDatum(source, destination);
1313
- }
1314
- function convertDatum(from, to) {
1315
- if (!from.towgs84 || !to.towgs84)
1316
- return void 0;
1317
- const a = from.ellipsoid, b = to.ellipsoid;
1318
- let sameParameters = true;
1319
- for (let i = 0; i < 7; i++)
1320
- if ((from.towgs84[i] || 0) !== (to.towgs84[i] || 0))
1321
- sameParameters = false;
1322
- if (a.semiMajorAxis === b.semiMajorAxis && Math.abs(a.eccentricitySquared - b.eccentricitySquared) <= 5e-11 && sameParameters)
1323
- return void 0;
1324
- const sourceShift = shifted(from) ? createHelmert(from.towgs84, false) : void 0, targetShift = shifted(to) ? createHelmert(to.towgs84, true) : void 0;
993
+ const operation2 = inverse33 ? implementation.inverse : implementation.forward;
1325
994
  return (point) => {
1326
- geodeticToGeocentricInPlace(point, a);
1327
- sourceShift == null ? void 0 : sourceShift(point);
1328
- targetShift == null ? void 0 : targetShift(point);
1329
- geocentricToGeodeticInPlace(point, b);
995
+ const output = operation2.call(implementation, point.x, point.y);
996
+ point.x = output[0];
997
+ point.y = output[1];
1330
998
  };
1331
999
  }
1332
- function applyDatumGrids(point, datum, inverse33) {
1333
- for (const reference of datum.grids) {
1334
- if (reference.name === "null")
1335
- return;
1336
- if (!reference.grid) {
1337
- if (reference.optional)
1338
- continue;
1339
- throw new Error("Required datum grid is not registered: " + reference.name);
1000
+
1001
+ // dist/projection/experimental/flat-projection.js
1002
+ function createFlatProjection(forward33, inverse33) {
1003
+ return {
1004
+ ...createProjection(forward33, inverse33),
1005
+ createForwardFlat(context) {
1006
+ return this.forwardInPlace === forward33 ? createFlatOperation(forward33, false, context) : void 0;
1007
+ },
1008
+ createInverseFlat(context) {
1009
+ return this.inverseInPlace === inverse33 ? createFlatOperation(inverse33, true, context) : void 0;
1340
1010
  }
1341
- let found = false;
1342
- if (reference.grid.shiftInPlace)
1343
- found = reference.grid.shiftInPlace(point, inverse33);
1344
- else {
1345
- const output = reference.grid.shift(point.x, point.y, inverse33);
1346
- if (output) {
1347
- point.x = output[0];
1348
- point.y = output[1];
1349
- found = true;
1011
+ };
1012
+ }
1013
+ function createFlatOperation(project, inverse33, { inputScale, outputScale }) {
1014
+ const scratch = new ProjectionScratch();
1015
+ return (coordinates, dimension) => {
1016
+ const point = scratch.acquire();
1017
+ try {
1018
+ const float32 = coordinates instanceof Float32Array;
1019
+ for (let offset = 0; offset < coordinates.length; offset += dimension) {
1020
+ point.x = coordinates[offset];
1021
+ point.y = coordinates[offset + 1];
1022
+ point.z = dimension >= 3 ? coordinates[offset + 2] : 0;
1023
+ if (!Number.isFinite(point.x) || !Number.isFinite(point.y) || !Number.isFinite(point.z))
1024
+ throw new Error("Coordinates must contain finite x, y and optional z values");
1025
+ if (inputScale !== 1) {
1026
+ point.x *= inputScale;
1027
+ point.y *= inputScale;
1028
+ }
1029
+ if (inverse33)
1030
+ project(point);
1031
+ if (Math.abs(point.y) > Math.PI / 2 || !Number.isFinite(point.x) || !Number.isFinite(point.y))
1032
+ throw new Error("Coordinate is outside the geographic domain");
1033
+ point.x += 0;
1034
+ point.x -= 0;
1035
+ if (!inverse33)
1036
+ project(point);
1037
+ if (outputScale !== 1) {
1038
+ point.x /= outputScale;
1039
+ point.y /= outputScale;
1040
+ }
1041
+ if (!Number.isFinite(point.x) || !Number.isFinite(point.y))
1042
+ throw new Error("Projection produced non-finite coordinates");
1043
+ if (float32 && (Math.abs(point.x) > 34028234663852886e22 || Math.abs(point.y) > 34028234663852886e22))
1044
+ throw new Error("Projected coordinate exceeds Float32 range");
1045
+ coordinates[offset] = point.x;
1046
+ coordinates[offset + 1] = point.y;
1350
1047
  }
1048
+ } finally {
1049
+ scratch.release(point);
1351
1050
  }
1352
- if (found) {
1353
- if (!Number.isFinite(point.x) || !Number.isFinite(point.y) || Math.abs(point.y) > Math.PI / 2)
1354
- throw new Error("Datum grid produced a coordinate outside the geographic domain");
1355
- return;
1051
+ };
1052
+ }
1053
+
1054
+ // dist/projection/experimental/rendering-profile/geographic-bounds.js
1055
+ var RADIANS = Math.PI / 180;
1056
+ function createAngularRanges(west, south, east, north) {
1057
+ return [
1058
+ [west, south],
1059
+ [east, north]
1060
+ ];
1061
+ }
1062
+ function normalizeLongitude(longitude) {
1063
+ return longitude >= -180 && longitude < 180 ? longitude : ((longitude + 180) % 360 + 360) % 360 - 180;
1064
+ }
1065
+ function createGeographicBounds(west, south, east, north) {
1066
+ if (![west, south, east, north].every(Number.isFinite) || south < -90 || north > 90 || south > north || east - west < -360 || east - west > 360 + 1e-10)
1067
+ throw new Error("Invalid geographic coverage");
1068
+ if (east - west >= 360 - 1e-10)
1069
+ return [-180, south, 180, north];
1070
+ const wrappedEast = normalizeLongitude(east);
1071
+ return [
1072
+ normalizeLongitude(west),
1073
+ south,
1074
+ wrappedEast === -180 && east > west ? 180 : wrappedEast,
1075
+ north
1076
+ ];
1077
+ }
1078
+ function getLongitudeSpan(bounds) {
1079
+ const span = bounds[2] - bounds[0];
1080
+ return span < 0 ? span + 360 : span;
1081
+ }
1082
+ function splitGeographicBounds(bounds) {
1083
+ const [west, south, east, north] = bounds;
1084
+ return west <= east ? [bounds] : [
1085
+ [west, south, 180, north],
1086
+ [-180, south, east, north]
1087
+ ];
1088
+ }
1089
+ function containsGeographicPoint(bounds, point) {
1090
+ const [west, south, east, north] = bounds;
1091
+ const longitude = normalizeLongitude(point[0]);
1092
+ return point[1] >= south && point[1] <= north && (west <= east ? longitude >= west && longitude <= east || longitude === -180 && east === 180 : longitude >= west || longitude <= east);
1093
+ }
1094
+ function intersectGeographicBounds(a, b) {
1095
+ const south = Math.max(a[1], b[1]), north = Math.min(a[3], b[3]);
1096
+ if (south > north)
1097
+ return [];
1098
+ const intervals = [];
1099
+ for (const left of splitGeographicBounds(a))
1100
+ for (const right of splitGeographicBounds(b)) {
1101
+ const west = Math.max(left[0], right[0]), east = Math.min(left[2], right[2]);
1102
+ if (west <= east)
1103
+ intervals.push([west, east]);
1104
+ else if (left[2] === 180 && right[0] === -180 || right[2] === 180 && left[0] === -180)
1105
+ intervals.push([-180, -180]);
1356
1106
  }
1107
+ intervals.sort((left, right) => left[0] - right[0]);
1108
+ const merged = [];
1109
+ for (const interval of intervals) {
1110
+ const last = merged[merged.length - 1];
1111
+ if (last && interval[0] <= last[1])
1112
+ last[1] = Math.max(last[1], interval[1]);
1113
+ else
1114
+ merged.push([...interval]);
1357
1115
  }
1358
- throw new Error("No datum grid covers coordinate: " + datum.grids.map((grid) => grid.name).join(","));
1116
+ if (merged.length > 1 && merged[0][0] === -180 && merged[merged.length - 1][1] === 180) {
1117
+ const first = merged.shift(), last = merged.pop();
1118
+ return [
1119
+ [last[0], south, first[1], north],
1120
+ ...merged.map(([west, east]) => [west, south, east, north])
1121
+ ];
1122
+ }
1123
+ return merged.map(([west, east]) => [west, south, east, north]);
1359
1124
  }
1360
- function geodeticToGeocentric(coordinate, ellipsoid) {
1361
- const point = { x: coordinate[0], y: coordinate[1], z: coordinate[2] };
1362
- geodeticToGeocentricInPlace(point, ellipsoid);
1363
- return [point.x, point.y, point.z];
1125
+ function clampGeographicPoint(bounds, point) {
1126
+ let longitude = normalizeLongitude(point[0]);
1127
+ const latitude = Math.max(bounds[1], Math.min(bounds[3], point[1]));
1128
+ if (!containsGeographicPoint(bounds, [longitude, latitude])) {
1129
+ const westDistance = Math.abs(normalizeLongitude(longitude - bounds[0]));
1130
+ const eastDistance = Math.abs(normalizeLongitude(longitude - bounds[2]));
1131
+ longitude = westDistance <= eastDistance ? bounds[0] : bounds[2];
1132
+ }
1133
+ return [longitude, latitude];
1364
1134
  }
1365
- function geocentricToGeodetic(coordinate, ellipsoid) {
1366
- const point = { x: coordinate[0], y: coordinate[1], z: coordinate[2] };
1367
- geocentricToGeodeticInPlace(point, ellipsoid);
1368
- return [point.x, point.y, point.z];
1135
+ function getAngularRanges(bounds, primeMeridian2 = 0, origin = 0) {
1136
+ const width = getLongitudeSpan(bounds);
1137
+ const west = bounds[0] * RADIANS - primeMeridian2;
1138
+ const middle = west + width * RADIANS / 2;
1139
+ const shift = Math.round((origin - middle) / (2 * Math.PI)) * 2 * Math.PI;
1140
+ return createAngularRanges(width === 360 ? origin - Math.PI : west + shift, bounds[1] * RADIANS, width === 360 ? origin + Math.PI : west + shift + width * RADIANS, bounds[3] * RADIANS);
1141
+ }
1142
+ function getGeographicBounds(ranges, primeMeridian2 = 0) {
1143
+ return createGeographicBounds((ranges[0][0] + primeMeridian2) / RADIANS, ranges[0][1] / RADIANS, (ranges[1][0] + primeMeridian2) / RADIANS, ranges[1][1] / RADIANS);
1144
+ }
1145
+ function unionRenderingBounds(bounds) {
1146
+ if (!bounds.length)
1147
+ throw new Error("CRS coverage does not intersect the rendering target");
1148
+ return [
1149
+ [0, 1, 2].map((axis) => Math.min(...bounds.map((pair2) => pair2[0][axis]))),
1150
+ [0, 1, 2].map((axis) => Math.max(...bounds.map((pair2) => pair2[1][axis])))
1151
+ ];
1152
+ }
1153
+
1154
+ // dist/projection/experimental/rendering-profile/rendering-profile.js
1155
+ function resolveBounds(profile) {
1156
+ var _a;
1157
+ const bounds = profile.bounds;
1158
+ if (bounds.some((corner) => corner.some((value2) => !Number.isFinite(value2))))
1159
+ throw new Error("Projection rendering bounds must be finite");
1160
+ return { bounds, normalize: (_a = profile.normalize) == null ? void 0 : _a.bind(profile) };
1161
+ }
1162
+ function createAngularNormalization(normalize, primeMeridian2 = 0) {
1163
+ return (point) => {
1164
+ const x = point.x * Math.PI / 180 - primeMeridian2;
1165
+ const y = point.y * Math.PI / 180;
1166
+ const native = { x, y, z: point.z };
1167
+ normalize(native);
1168
+ if (native.x !== x)
1169
+ point.x = (native.x + primeMeridian2) * 180 / Math.PI;
1170
+ if (native.y !== y)
1171
+ point.y = native.y * 180 / Math.PI;
1172
+ };
1173
+ }
1174
+ function combineRenderingProfiles(regions, getProfile) {
1175
+ const profiles = [];
1176
+ for (const region of regions) {
1177
+ const profile = getProfile(region);
1178
+ if (profile !== null)
1179
+ profiles.push(resolveBounds(profile));
1180
+ }
1181
+ if (!profiles.length)
1182
+ return null;
1183
+ if (profiles.length === 1)
1184
+ return profiles[0];
1185
+ return {
1186
+ bounds: unionRenderingBounds(profiles.map((profile) => profile.bounds)),
1187
+ normalize(point) {
1188
+ var _a;
1189
+ let bestX = point.x, bestY = point.y, best = Infinity;
1190
+ for (const profile of profiles) {
1191
+ const candidate = { x: point.x, y: point.y, z: point.z };
1192
+ (_a = profile.normalize) == null ? void 0 : _a.call(profile, candidate);
1193
+ const distance = Math.sin((candidate.y - point.y) * Math.PI / 360) ** 2 + Math.cos(point.y * Math.PI / 180) * Math.cos(candidate.y * Math.PI / 180) * Math.sin((candidate.x - point.x) * Math.PI / 360) ** 2;
1194
+ if (distance < best) {
1195
+ best = distance;
1196
+ bestX = candidate.x;
1197
+ bestY = candidate.y;
1198
+ }
1199
+ }
1200
+ point.x = bestX;
1201
+ point.y = bestY;
1202
+ }
1203
+ };
1369
1204
  }
1370
1205
 
1371
1206
  // dist/projection/experimental/rendering-profile/rectangular-rendering-profile.js
@@ -1484,968 +1319,42 @@ function cylindricalBounds(project, parameters, origin, over = false) {
1484
1319
  const points = longitude.flatMap((x) => latitudes.map((y) => project(origin + x, y)));
1485
1320
  return envelope([Math.min(...points.map((p) => p[0])), Math.max(...points.map((p) => p[0]))], [Math.min(...points.map((p) => p[1])), Math.max(...points.map((p) => p[1]))]);
1486
1321
  }
1487
- function transverseBounds(project, parameters, origin, over = false, equator = 0) {
1488
- const longitude = longitudeRange(parameters, origin, over);
1489
- if (maxAbs(longitude) > Math.PI / 6 + 1e-12)
1490
- throw new Error("Unsupported transverse rendering coverage");
1491
- const longitudes = [
1492
- longitude[0],
1493
- longitude[1],
1494
- Math.max(longitude[0], Math.min(longitude[1], 0))
1495
- ];
1496
- const latitudes = [
1497
- parameters[0][1],
1498
- parameters[1][1],
1499
- Math.max(parameters[0][1], Math.min(parameters[1][1], equator))
1500
- ];
1501
- const points = longitudes.flatMap((x) => latitudes.map((y) => project(origin + x, y)));
1502
- return envelope([Math.min(...points.map((p) => p[0])), Math.max(...points.map((p) => p[0]))], [Math.min(...points.map((p) => p[1])), Math.max(...points.map((p) => p[1]))]);
1503
- }
1504
- function vanDerGrintenBounds(project, parameters, origin, over = false) {
1505
- const longitude = longitudeRange(parameters, origin, over);
1506
- const longitudes = [
1507
- longitude[0],
1508
- longitude[1],
1509
- Math.max(longitude[0], Math.min(longitude[1], 0))
1510
- ];
1511
- const latitudes = [
1512
- parameters[0][1],
1513
- parameters[1][1],
1514
- Math.max(parameters[0][1], Math.min(parameters[1][1], 0))
1515
- ];
1516
- const points = longitudes.flatMap((x) => latitudes.map((y) => project(origin + x, y)));
1517
- return envelope([Math.min(...points.map((p) => p[0])), Math.max(...points.map((p) => p[0]))], [Math.min(...points.map((p) => p[1])), Math.max(...points.map((p) => p[1]))]);
1518
- }
1519
- function conicBounds(project, parameters, origin, cone, x0, centerY, over = false) {
1520
- const angles = scale(longitudeRange(parameters, origin, over), cone);
1521
- const radii = ordered(centerY - project(origin, parameters[0][1])[1], centerY - project(origin, parameters[1][1])[1]);
1522
- return envelope(add([x0, x0], multiply(radii, sine(angles))), add([centerY, centerY], scale(multiply(radii, cosine(angles)), -1)));
1523
- }
1524
-
1525
- // dist/projection/experimental/rendering-profile/geographic-rendering-profile.js
1526
- function createGeographicProfile(parameters, primeMeridian2 = 0) {
1527
- const center = numberParameter(parameters, "lon_wrap", 0) * DEGREES_TO_RADIANS;
1528
- return (coverage) => createRectangleRenderingProfile((ranges) => {
1529
- const longitude = longitudeRange(ranges, center);
1530
- return [
1531
- [center + longitude[0], ranges[0][1], 0],
1532
- [center + longitude[1], ranges[1][1], 0]
1533
- ];
1534
- }, coverage ?? [-180, -90, 180, 90], center, primeMeridian2);
1535
- }
1536
-
1537
- // dist/projection/experimental/vertical-datum.js
1538
- function compileVerticalGrid(names, grids = {}) {
1539
- if (names === void 0)
1540
- return void 0;
1541
- const entries = [];
1542
- for (const entry of names.split(",")) {
1543
- const optional = entry.startsWith("@");
1544
- const name = optional ? entry.slice(1) : entry;
1545
- if (!name || /\s/.test(name))
1546
- throw new Error("Invalid vertical grid name");
1547
- if (name === "null") {
1548
- entries.push(null);
1549
- break;
1550
- }
1551
- const grid = Object.prototype.hasOwnProperty.call(grids, name) ? grids[name] : void 0;
1552
- if (grid) {
1553
- if (typeof grid.getOffset !== "function")
1554
- throw new Error("Invalid vertical grid: " + name);
1555
- entries.push(grid.getOffset.bind(grid));
1556
- } else if (!optional)
1557
- unsupportedStage("Required vertical grid is not registered: " + name);
1558
- }
1559
- return (longitude, latitude) => {
1560
- for (const sample of entries) {
1561
- if (!sample)
1562
- return 0;
1563
- const offset = sample(longitude, latitude);
1564
- if (offset === void 0)
1565
- continue;
1566
- if (!Number.isFinite(offset))
1567
- throw new Error("Vertical grid returned a non-finite offset");
1568
- return offset;
1569
- }
1570
- throw new Error("No vertical grid covers this coordinate");
1571
- };
1572
- }
1573
-
1574
- // dist/projection/experimental/transform-description.js
1575
- function describeCRS(crs) {
1576
- const ellipsoid = Object.freeze({ ...crs.ellipsoid });
1577
- return Object.freeze({
1578
- kind: crs.kind,
1579
- projection: crs.projection,
1580
- parameters: Object.freeze(Object.fromEntries(Object.entries(crs.parameters).map(([name, value2]) => [name, value2 ?? null]))),
1581
- ellipsoid,
1582
- datum: Object.freeze({
1583
- ellipsoid: Object.freeze({ ...crs.datum.ellipsoid }),
1584
- towgs84: crs.datum.towgs84 && Object.freeze([...crs.datum.towgs84]),
1585
- grids: crs.datum.grids && Object.freeze(crs.datum.grids.map((reference) => Object.freeze({
1586
- name: reference.name,
1587
- optional: reference.optional,
1588
- loaded: Boolean(reference.grid)
1589
- })))
1590
- }),
1591
- angularUnit: crs.angularUnit,
1592
- toMeter: crs.toMeter,
1593
- verticalUnit: crs.verticalUnit,
1594
- primeMeridian: crs.primeMeridian,
1595
- axis: crs.axis,
1596
- storedAxis: crs.storedAxis,
1597
- longitudeWrap: crs.longitudeWrap,
1598
- areaOfUse: crs.areaOfUse && Object.freeze([...crs.areaOfUse]),
1599
- lossy: crs.lossy,
1600
- algorithm: crs.algorithm && Object.freeze({ ...crs.algorithm })
1601
- });
1602
- }
1603
- function describeTransform(source, target, forward33, inverse33) {
1604
- const opaqueReasons = [];
1605
- if (!source.algorithm)
1606
- opaqueReasons.push("source-algorithm");
1607
- if (!target.algorithm)
1608
- opaqueReasons.push("target-algorithm");
1609
- if (source.datum.grids || target.datum.grids || source.parameters["geoidgrids"] || target.parameters["geoidgrids"])
1610
- opaqueReasons.push("grid-resource");
1611
- return Object.freeze({
1612
- version: 1,
1613
- source,
1614
- target,
1615
- forward: forward33,
1616
- inverse: inverse33,
1617
- lossy: source.lossy || target.lossy,
1618
- complete: opaqueReasons.length === 0,
1619
- opaqueReasons: Object.freeze(opaqueReasons)
1620
- });
1621
- }
1622
-
1623
- // dist/projection/experimental/typescript-projection.js
1624
- var ProjectionTransform = class _ProjectionTransform {
1625
- /** Resolve required descriptors once, then return an ordinary synchronous instance. */
1626
- static async create(options = {}) {
1627
- const projections = await Promise.all(requiredProjections(options).map(preloadProjection));
1628
- return new _ProjectionTransform({ ...options, projections });
1629
- }
1630
- get targetProfile() {
1631
- return this.getTargetRenderingProfile(this.targetCoverage);
1632
- }
1633
- /** Resolve target rendering policy independently from coordinate conversion. @internal */
1634
- getTargetRenderingProfile(coverage) {
1635
- return this.targetRenderingProfile && resolveRenderingProfile(this.targetRenderingProfile, coverage);
1636
- }
1637
- /** Deferred transforms expose metadata only once their implementations are prepared. */
1638
- get description() {
1639
- var _a2, _b;
1640
- return ((_b = (_a2 = this.deferred) == null ? void 0 : _a2.implementation) == null ? void 0 : _b.description) ?? this.resolvedDescription;
1641
- }
1642
- constructor(options = {}) {
1643
- var _a2, _b, _c;
1644
- this.coordinateScratch = new ProjectionScratch();
1645
- this.targetLongitudeOrigin = 0;
1646
- const registrations = options.projections || [];
1647
- const plugins = registry(registrations);
1648
- if (registrations.some((projection) => !("create" in projection))) {
1649
- const from = normalizeCRS(options.from ?? "WGS84", options);
1650
- const to = normalizeCRS(options.to ?? "WGS84", options);
1651
- this.lossy = from.lossy || to.lossy;
1652
- this.deferred = { options: { ...options, projections: [...registrations] } };
1653
- } else {
1654
- const eager = options;
1655
- const eagerPlugins = plugins;
1656
- const from = compileCRS(eager.from ?? "WGS84", eagerPlugins, eager);
1657
- const to = compileCRS(eager.to ?? "WGS84", eagerPlugins, eager);
1658
- this.targetRenderingProfile = ((_b = (_a2 = to.implementation) == null ? void 0 : _a2.getRenderingProfile) == null ? void 0 : _b.bind(to.implementation)) ?? (to.kind === "geographic" ? createGeographicProfile(to.parameters, to.primeMeridian) : to.kind === "identity" ? getIdentityRenderingProfile : void 0);
1659
- this.targetCoverage = to.areaOfUse;
1660
- this.targetLongitudeOrigin = ((_c = to.implementation) == null ? void 0 : _c.longitudeOrigin) ?? (to.kind === "geographic" ? to.longitudeWrap ?? 0 : 0);
1661
- this.lossy = from.lossy || to.lossy;
1662
- if (this.lossy && (from.kind === "geocentric" || to.kind === "geocentric"))
1663
- unsupportedStage("Horizontal extraction cannot supply ellipsoidal height for geocentric coordinates");
1664
- if (this.lossy && (from.verticalGrid || to.verticalGrid))
1665
- unsupportedStage("Horizontal extraction cannot be combined with vertical grids");
1666
- this.forwardTransform = compileTransform(from, to, Boolean(options.enforceAxis));
1667
- this.inverseTransform = compileTransform(to, from, Boolean(options.enforceAxis));
1668
- this.resolvedDescription = describeTransform(describeCRS(from), describeCRS(to), this.forwardTransform.description, this.inverseTransform.description);
1669
- }
1670
- this.project = this.project.bind(this);
1671
- this.unproject = this.unproject.bind(this);
1672
- this.projectTo = this.projectTo.bind(this);
1673
- this.unprojectTo = this.unprojectTo.bind(this);
1674
- this.projectToSync = this.projectToSync.bind(this);
1675
- this.unprojectToSync = this.unprojectToSync.bind(this);
1676
- this.projectFlat = this.projectFlat.bind(this);
1677
- this.unprojectFlat = this.unprojectFlat.bind(this);
1678
- this.projectSync = this.projectSync.bind(this);
1679
- this.unprojectSync = this.unprojectSync.bind(this);
1680
- this.projectFlatSync = this.projectFlatSync.bind(this);
1681
- this.unprojectFlatSync = this.unprojectFlatSync.bind(this);
1682
- }
1683
- load() {
1684
- const state = this.deferred;
1685
- if (!state)
1686
- return Promise.resolve(this);
1687
- if (state.implementation)
1688
- return Promise.resolve(state.implementation);
1689
- state.pending || (state.pending = _ProjectionTransform.create(state.options).then((projection) => {
1690
- state.implementation = projection;
1691
- return projection;
1692
- }).catch((error) => {
1693
- state.pending = void 0;
1694
- throw error;
1695
- }));
1696
- return state.pending;
1697
- }
1698
- loadSync() {
1699
- const state = this.deferred;
1700
- if (!state)
1701
- return this;
1702
- if (!state.implementation) {
1703
- const projections = requiredProjections(state.options).map((descriptor) => {
1704
- const plugin = getLoadedProjection(descriptor);
1705
- if (!plugin)
1706
- throw new Error("Projection is not preloaded: " + descriptor.name + ". Call preload() first.");
1707
- return plugin;
1708
- });
1709
- state.implementation = new _ProjectionTransform({ ...state.options, projections });
1710
- }
1711
- return state.implementation;
1712
- }
1713
- /** Synchronous variants never import algorithms; descriptors must be preloaded. */
1714
- projectSync(coordinate) {
1715
- return this.deferred ? this.loadSync().project(coordinate) : transformScalar(coordinate, this.forwardTransform, this.coordinateScratch);
1716
- }
1717
- unprojectSync(coordinate) {
1718
- return this.deferred ? this.loadSync().unproject(coordinate) : transformScalar(coordinate, this.inverseTransform, this.coordinateScratch);
1719
- }
1720
- projectFlatSync(coordinates, dimension = 2) {
1721
- return this.deferred ? this.loadSync().projectFlat(coordinates, dimension) : transformInPlace(coordinates, dimension, this.forwardTransform, this.coordinateScratch);
1722
- }
1723
- unprojectFlatSync(coordinates, dimension = 2) {
1724
- return this.deferred ? this.loadSync().unprojectFlat(coordinates, dimension) : transformInPlace(coordinates, dimension, this.inverseTransform, this.coordinateScratch);
1725
- }
1726
- /** Optional warm-up. Coordinate methods also load automatically on first use. */
1727
- async preload() {
1728
- await this.load();
1729
- }
1730
- /** Eager plugins return arrays; descriptor-backed instances return promises. */
1731
- project(coordinate) {
1732
- const result = this.deferred ? this.projectLoaded(coordinate, false) : transformScalar(coordinate, this.forwardTransform, this.coordinateScratch);
1733
- return result;
1734
- }
1735
- unproject(coordinate) {
1736
- const result = this.deferred ? this.projectLoaded(coordinate, true) : transformScalar(coordinate, this.inverseTransform, this.coordinateScratch);
1737
- return result;
1738
- }
1739
- /** Write one coordinate into caller-owned storage; return that same output. */
1740
- projectTo(coordinate, output) {
1741
- return this.deferred ? this.projectToLoaded(coordinate, output, false) : this.projectToSync(coordinate, output);
1742
- }
1743
- unprojectTo(coordinate, output) {
1744
- return this.deferred ? this.projectToLoaded(coordinate, output, true) : this.unprojectToSync(coordinate, output);
1745
- }
1746
- projectToSync(coordinate, output) {
1747
- if (this.deferred)
1748
- return this.loadSync().projectTo(coordinate, output);
1749
- validateScalarOutput(coordinate, output, Math.max(coordinate.length, this.forwardTransform.geocentricOutput ? 3 : 2));
1750
- return transformScalar(coordinate, this.forwardTransform, this.coordinateScratch, output);
1751
- }
1752
- unprojectToSync(coordinate, output) {
1753
- if (this.deferred)
1754
- return this.loadSync().unprojectTo(coordinate, output);
1755
- validateScalarOutput(coordinate, output, Math.max(coordinate.length, this.inverseTransform.geocentricOutput ? 3 : 2));
1756
- return transformScalar(coordinate, this.inverseTransform, this.coordinateScratch, output);
1757
- }
1758
- projectToLoaded(coordinate, output, inverse33) {
1759
- validateScalarOutput(coordinate, output, coordinate.length);
1760
- const input = coordinate.slice();
1761
- return this.load().then((projection) => inverse33 ? projection.unprojectTo(input, output) : projection.projectTo(input, output));
1762
- }
1763
- projectLoaded(coordinate, inverse33) {
1764
- const input = coordinate.slice();
1765
- return this.load().then((projection) => inverse33 ? projection.unproject(input) : projection.project(input));
1766
- }
1767
- /** In-place; descriptor callers must await completion before reusing the buffer. */
1768
- projectFlat(coordinates, dimension = 2) {
1769
- const result = this.deferred ? this.load().then((projection) => projection.projectFlat(coordinates, dimension)) : transformInPlace(coordinates, dimension, this.forwardTransform, this.coordinateScratch);
1770
- return result;
1771
- }
1772
- unprojectFlat(coordinates, dimension = 2) {
1773
- const result = this.deferred ? this.load().then((projection) => projection.unprojectFlat(coordinates, dimension)) : transformInPlace(coordinates, dimension, this.inverseTransform, this.coordinateScratch);
1774
- return result;
1775
- }
1776
- };
1777
- function requiredProjections(options) {
1778
- const available = registry(options.projections || []);
1779
- const required = /* @__PURE__ */ new Set();
1780
- for (const definition2 of [options.from ?? "WGS84", options.to ?? "WGS84"]) {
1781
- const crs = normalizeCRS(definition2, options);
1782
- if (["geographic", "identity"].includes(crs.kind))
1783
- continue;
1784
- const projection = available.get(pluginKey(crs.projection));
1785
- if (!projection)
1786
- throw new TypeScriptCRSError("missing-plugin", "Projection plugin is not registered: " + crs.projection);
1787
- required.add(projection);
1788
- }
1789
- return [...required];
1790
- }
1791
- function checkProjectionCompatibility(definition2, options = {}) {
1792
- try {
1793
- const crs = compileCRS(definition2, registry(options.projections || []), options);
1794
- return { status: "supported", lossy: crs.lossy };
1795
- } catch (error) {
1796
- const reason = error instanceof TypeScriptCRSError ? error.reason : "invalid-definition";
1797
- return {
1798
- status: reason === "unknown-syntax" ? "unknown" : "unsupported",
1799
- lossy: false,
1800
- reason,
1801
- message: error instanceof Error ? error.message : String(error)
1802
- };
1803
- }
1804
- }
1805
- var pluginKey = (name) => name.toLowerCase().replace(/[\s_-]/g, "");
1806
- function registry(projections) {
1807
- const plugins = /* @__PURE__ */ new Map();
1808
- for (const plugin of projections) {
1809
- for (const name of new Set([plugin.name, ...plugin.aliases || []].map(pluginKey))) {
1810
- if (!name || ["longlat", "latlong", "latlon", "lonlat", "identity"].includes(name) || plugins.has(name))
1811
- throw new Error("Duplicate or reserved projection plugin: " + name);
1812
- plugins.set(name, plugin);
1813
- }
1814
- }
1815
- return plugins;
1816
- }
1817
- function compileCRS(definition2, plugins, options) {
1818
- var _a2;
1819
- const crs = normalizeCRS(definition2, options);
1820
- const plugin = plugins.get(pluginKey(crs.projection));
1821
- if (!["geographic", "identity"].includes(crs.kind) && !plugin)
1822
- throw new TypeScriptCRSError("missing-plugin", "Projection plugin is not registered: " + crs.projection);
1823
- const allowed = /* @__PURE__ */ new Set([...CORE_PARAMETERS, ...(plugin == null ? void 0 : plugin.parameters) || []]);
1824
- for (const key2 of Object.keys(crs.parameters)) {
1825
- if (!allowed.has(key2))
1826
- throw new TypeScriptCRSError("missing-transform-stage", "Unsupported PROJ parameter: +" + key2);
1827
- const flag = CORE_FLAGS.includes(key2) || ((_a2 = plugin == null ? void 0 : plugin.flags) == null ? void 0 : _a2.includes(key2));
1828
- if (flag && crs.parameters[key2] !== void 0)
1829
- throw new Error("Expected a flag without a value: +" + key2);
1830
- if (!flag && !crs.parameters[key2])
1831
- throw new Error("PROJ parameter requires a value: +" + key2);
1832
- }
1833
- if (crs.parameters["type"] && crs.parameters["type"] !== "crs")
1834
- throw new Error("Only +type=crs is supported");
1835
- const parameters = pluginKey(crs.projection) === "fasttransversemercator" ? Object.freeze({ ...crs.parameters, approx: void 0 }) : crs.parameters;
1836
- const implementation = plugin == null ? void 0 : plugin.create({
1837
- ...crs.ellipsoid,
1838
- parameters,
1839
- primeMeridian: crs.primeMeridian
1840
- });
1841
- if (crs.kind === "geocentric" && (!(implementation == null ? void 0 : implementation.forward3D) || !(implementation == null ? void 0 : implementation.inverse3D)))
1842
- throw new Error("Geocentric plugin must implement 3D operations");
1843
- const references = crs.datum.grids;
1844
- const nullIndex = (references == null ? void 0 : references.findIndex((reference) => reference.name === "null")) ?? -1;
1845
- const grids = references == null ? void 0 : references.slice(0, nullIndex < 0 ? void 0 : nullIndex + 1).map((reference) => {
1846
- const grid = Object.prototype.hasOwnProperty.call(options.datumGrids || {}, reference.name) ? options.datumGrids[reference.name] : void 0;
1847
- if (grid && typeof grid.shift !== "function")
1848
- throw new Error("Invalid prepared datum grid: " + reference.name);
1849
- return Object.freeze({ ...reference, grid });
1850
- });
1851
- for (const reference of grids || []) {
1852
- if (reference.name === "null")
1853
- break;
1854
- if (!reference.optional && !reference.grid)
1855
- unsupportedStage("Required datum grid is not registered: " + reference.name);
1856
- }
1857
- const datum = grids ? Object.freeze({ ...crs.datum, grids: Object.freeze(grids) }) : crs.datum;
1858
- const verticalGrid = compileVerticalGrid(crs.parameters["geoidgrids"], options.verticalGrids);
1859
- if (verticalGrid && (crs.kind === "geocentric" || crs.kind === "identity" || crs.lossy))
1860
- unsupportedStage("Vertical grids require a non-lossy geographic or projected CRS");
1861
- const algorithm = plugin ? plugin.semantics : { id: "@math.gl/geospatial/" + crs.kind, version: 1 };
1862
- return { ...crs, datum, implementation, verticalGrid, algorithm };
1863
- }
1864
- function finite(point) {
1865
- return Number.isFinite(point.x) && Number.isFinite(point.y) && Number.isFinite(point.z);
1866
- }
1867
- function compileAxis(axis, inverse33) {
1868
- if (axis === "enu")
1869
- return void 0;
1870
- const indexes = [0, 0, 0], signs = [0, 0, 0];
1871
- for (let i = 0; i < 3; i++) {
1872
- const char = axis[i], component = "ew".includes(char) ? 0 : "ns".includes(char) ? 1 : 2;
1873
- indexes[inverse33 ? i : component] = inverse33 ? component : i;
1874
- signs[inverse33 ? i : component] = "wsd".includes(char) ? -1 : 1;
1875
- }
1876
- return (point) => {
1877
- const x = point.x, y = point.y, z = point.z;
1878
- point.x = signs[0] * (indexes[0] === 0 ? x : indexes[0] === 1 ? y : z);
1879
- point.y = signs[1] * (indexes[1] === 0 ? x : indexes[1] === 1 ? y : z);
1880
- point.z = signs[2] * (indexes[2] === 0 ? x : indexes[2] === 1 ? y : z);
1881
- };
1882
- }
1883
- function compileTransform(from, to, enforceAxis) {
1884
- var _a2, _b, _c, _d;
1885
- const fromAxis = from.storedAxis || (enforceAxis ? from.axis : "enu");
1886
- const toAxis = to.storedAxis || (enforceAxis ? to.axis : "enu");
1887
- const inputAxis = compileAxis(fromAxis, false), outputAxis = compileAxis(toAxis, true);
1888
- const source = from.implementation && projectionOperation(from.implementation, true, from.kind === "geocentric");
1889
- const target = to.implementation && projectionOperation(to.implementation, false, to.kind === "geocentric");
1890
- const datum = createDatumTransform(from.datum, to.datum);
1891
- const horizontalOnly = from.lossy || to.lossy;
1892
- const fromGeocentric = from.kind === "geocentric";
1893
- const inputScale = from.kind === "geographic" ? from.angularUnit : from.toMeter;
1894
- const outputScale = to.kind === "geographic" ? to.angularUnit : to.toMeter;
1895
- const inputVerticalScale = fromGeocentric ? 1 : from.verticalUnit, outputVerticalScale = to.kind === "geocentric" ? outputScale : to.verticalUnit;
1896
- const fromPrime = from.primeMeridian, toPrime = to.primeMeridian;
1897
- const longitudeWrap = to.kind === "geographic" ? to.longitudeWrap : void 0;
1898
- let flat;
1899
- if (!datum && !from.verticalGrid && !to.verticalGrid && !horizontalOnly && !inputAxis && !outputAxis && !fromPrime && !toPrime && from.verticalUnit === 1 && to.verticalUnit === 1 && longitudeWrap === void 0) {
1900
- const context = Object.freeze({ inputScale, outputScale });
1901
- if (from.kind === "geographic" && to.kind === "projected")
1902
- flat = (_b = (_a2 = to.implementation) == null ? void 0 : _a2.createForwardFlat) == null ? void 0 : _b.call(_a2, context);
1903
- if (from.kind === "projected" && to.kind === "geographic")
1904
- flat = (_d = (_c = from.implementation) == null ? void 0 : _c.createInverseFlat) == null ? void 0 : _d.call(_c, context);
1905
- }
1906
- const requiresInputZ = Boolean(from.verticalGrid || to.verticalGrid) || from.kind === "geocentric" || /[ud]/.test(fromAxis.slice(0, 2)) || /[ud]/.test(toAxis.slice(0, 2));
1907
- const stages = [];
1908
- if (inputAxis)
1909
- stages.push("input-axis");
1910
- if (horizontalOnly)
1911
- stages.push("discard-height");
1912
- if (inputScale !== 1)
1913
- stages.push("input-scale");
1914
- if (source)
1915
- stages.push("source-inverse");
1916
- if (inputVerticalScale !== 1)
1917
- stages.push("input-height-scale");
1918
- stages.push("geographic-domain-check");
1919
- if (fromPrime)
1920
- stages.push("source-prime-meridian");
1921
- if (from.verticalGrid)
1922
- stages.push("source-vertical-grid");
1923
- if (datum)
1924
- stages.push("datum");
1925
- if (to.verticalGrid)
1926
- stages.push("target-vertical-grid");
1927
- if (toPrime)
1928
- stages.push("target-prime-meridian");
1929
- if (longitudeWrap !== void 0)
1930
- stages.push("longitude-wrap");
1931
- if (target)
1932
- stages.push("target-forward");
1933
- if (outputScale !== 1)
1934
- stages.push("output-scale");
1935
- if (outputVerticalScale !== 1)
1936
- stages.push("output-height-scale");
1937
- if (horizontalOnly)
1938
- stages.push("restore-height");
1939
- if (outputAxis)
1940
- stages.push("output-axis");
1941
- return {
1942
- description: Object.freeze({
1943
- inputAxis: fromAxis,
1944
- outputAxis: toAxis,
1945
- requiresInputZ,
1946
- geocentricOutput: to.kind === "geocentric",
1947
- stages: Object.freeze(stages)
1948
- }),
1949
- flat,
1950
- requiresInputZ,
1951
- geocentricOutput: to.kind === "geocentric",
1952
- run(point) {
1953
- if (!finite(point))
1954
- throw new Error("Coordinates must contain finite x, y and optional z values");
1955
- inputAxis == null ? void 0 : inputAxis(point);
1956
- const preservedHeight = point.z;
1957
- if (horizontalOnly)
1958
- point.z = 0;
1959
- if (inputScale !== 1) {
1960
- point.x *= inputScale;
1961
- point.y *= inputScale;
1962
- if (fromGeocentric)
1963
- point.z *= inputScale;
1964
- }
1965
- source == null ? void 0 : source(point);
1966
- if (inputVerticalScale !== 1)
1967
- point.z *= inputVerticalScale;
1968
- if (Math.abs(point.y) > Math.PI / 2 || !finite(point))
1969
- throw new Error("Coordinate is outside the geographic domain");
1970
- point.x += fromPrime;
1971
- if (from.verticalGrid)
1972
- point.z += from.verticalGrid(point.x, point.y);
1973
- datum == null ? void 0 : datum(point);
1974
- if (to.verticalGrid)
1975
- point.z -= to.verticalGrid(point.x, point.y);
1976
- point.x -= toPrime;
1977
- if (longitudeWrap !== void 0)
1978
- point.x = longitudeWrap + wrapLongitude(point.x - longitudeWrap);
1979
- target == null ? void 0 : target(point);
1980
- if (outputScale !== 1) {
1981
- point.x /= outputScale;
1982
- point.y /= outputScale;
1983
- }
1984
- if (outputVerticalScale !== 1)
1985
- point.z /= outputVerticalScale;
1986
- if (horizontalOnly)
1987
- point.z = preservedHeight;
1988
- outputAxis == null ? void 0 : outputAxis(point);
1989
- if (!finite(point))
1990
- throw new Error("Projection produced non-finite coordinates");
1991
- }
1992
- };
1993
- }
1994
- function transformScalar(coordinate, operation2, scratch, output) {
1995
- if (coordinate.length < 2)
1996
- throw new Error("Coordinates must contain finite x, y and optional z values");
1997
- if (coordinate.length < 3 && operation2.requiresInputZ)
1998
- throw new Error("This transform requires three ordinates");
1999
- const length = Math.max(coordinate.length, operation2.geocentricOutput ? 3 : 2);
2000
- const point = scratch.acquire();
2001
- try {
2002
- point.x = coordinate[0];
2003
- point.y = coordinate[1];
2004
- point.z = coordinate.length >= 3 ? coordinate[2] : 0;
2005
- operation2.run(point);
2006
- if (output)
2007
- return writeScalarOutput(coordinate, output, point, length);
2008
- const result = coordinate.slice();
2009
- result[0] = point.x;
2010
- result[1] = point.y;
2011
- if (coordinate.length >= 3 || operation2.geocentricOutput)
2012
- result[2] = point.z;
2013
- return result;
2014
- } finally {
2015
- scratch.release(point);
2016
- }
2017
- }
2018
- function transformInPlace(coordinates, dimension, operation2, scratch) {
2019
- if (!(coordinates instanceof Float32Array || coordinates instanceof Float64Array))
2020
- throw new Error("In-place projection requires a Float32Array or Float64Array");
2021
- if (!Number.isSafeInteger(dimension) || dimension < 2 || coordinates.length % dimension !== 0)
2022
- throw new Error("Dimension must be an integer >= 2 and divide the typed array length");
2023
- if (dimension < 3 && (operation2.requiresInputZ || operation2.geocentricOutput))
2024
- throw new Error("This transform requires a dimension of at least 3");
2025
- if (operation2.flat) {
2026
- operation2.flat(coordinates, dimension);
2027
- return coordinates;
2028
- }
2029
- const point = scratch.acquire();
2030
- try {
2031
- const float32 = coordinates instanceof Float32Array;
2032
- for (let offset = 0; offset < coordinates.length; offset += dimension) {
2033
- point.x = coordinates[offset];
2034
- point.y = coordinates[offset + 1];
2035
- point.z = dimension >= 3 ? coordinates[offset + 2] : 0;
2036
- operation2.run(point);
2037
- if (float32 && (Math.abs(point.x) > 34028234663852886e22 || Math.abs(point.y) > 34028234663852886e22 || dimension >= 3 && Math.abs(point.z) > 34028234663852886e22))
2038
- throw new Error("Projected coordinate exceeds Float32 range");
2039
- coordinates[offset] = point.x;
2040
- coordinates[offset + 1] = point.y;
2041
- if (dimension >= 3)
2042
- coordinates[offset + 2] = point.z;
2043
- }
2044
- return coordinates;
2045
- } finally {
2046
- scratch.release(point);
2047
- }
2048
- }
2049
-
2050
- // dist/projection/numerical-derivative.js
2051
- var NumericalDerivative = class {
2052
- constructor(sample) {
2053
- this.sample = sample;
2054
- this.result = [0, 0, 0];
2055
- this.samples = Array.from({ length: 4 }, () => [0, 0, 0]);
2056
- this.coarse = [0, 0, 0];
2057
- this.fine = [0, 0, 0];
2058
- }
2059
- evaluate(step, referenceScale, tolerance = 1e-6) {
2060
- if (!this.difference(step, this.coarse) || !this.difference(step / 2, this.fine))
2061
- return false;
2062
- const bound = tolerance * Math.max(referenceScale, Math.abs(this.fine[0]), Math.abs(this.fine[1]), Math.abs(this.fine[2]));
2063
- for (let i = 0; i < 3; i++) {
2064
- if (Math.abs(this.coarse[i] - this.fine[i]) > bound)
2065
- return false;
2066
- this.fine[i] += (this.fine[i] - this.coarse[i]) / 15;
2067
- if (!Number.isFinite(this.fine[i]))
2068
- return false;
2069
- }
2070
- for (let i = 0; i < 3; i++)
2071
- this.result[i] = this.fine[i];
2072
- return true;
2073
- }
2074
- difference(step, output) {
2075
- const [a, b, c, d] = this.samples;
2076
- if (!this.sample(-2 * step, a) || !this.sample(-step, b) || !this.sample(step, c) || !this.sample(2 * step, d))
2077
- return false;
2078
- for (let i = 0; i < 3; i++) {
2079
- output[i] = (a[i] - d[i] + 8 * (c[i] - b[i])) / (12 * step);
2080
- if (!Number.isFinite(output[i]))
2081
- return false;
2082
- }
2083
- return true;
2084
- }
2085
- };
2086
-
2087
- // dist/projection/experimental/crs-rendering-scale.js
2088
- var RADIANS2 = Math.PI / 180;
2089
- var WGS842 = normalizeCRS("WGS84").ellipsoid;
2090
- function isEarth(ellipsoid) {
2091
- return Math.abs(ellipsoid.semiMajorAxis - 6375e3) < 7e-3 * 6375e3;
2092
- }
2093
- function validateScale(scale2) {
2094
- if (scale2.length !== 3 || scale2.some((value2) => !Number.isFinite(value2) || value2 <= 0))
2095
- throw new Error("Invalid CRS rendering scale");
2096
- return scale2;
2097
- }
2098
- function createRenderingScale(crs, projection, axis, center) {
2099
- if (crs.kind === "geocentric")
2100
- return validateScale([crs.toMeter, crs.toMeter, crs.toMeter]);
2101
- if (crs.kind === "identity") {
2102
- return validateScale([...axis].map((direction) => /[ud]/.test(direction) ? crs.verticalUnit : crs.toMeter));
2103
- }
2104
- const anchor = [0, 0, 0], input = [0, 0, 0], geographic = [0, 0, 0], sample = [0, 0, 0];
2105
- const derivatives = Array.from({ length: 3 }, () => [0, 0, 0]);
2106
- const body = isEarth(crs.ellipsoid) ? WGS842 : crs.ellipsoid;
2107
- let component = 0, longitudeMeters = 0, latitudeMeters = 0, busy = false;
2108
- const numerical = new NumericalDerivative((offset, output) => {
2109
- for (let i = 0; i < 3; i++)
2110
- input[i] = anchor[i];
2111
- input[component] += offset;
2112
- projection.unprojectTo(input, sample);
2113
- const rawDelta = sample[0] - geographic[0];
2114
- const delta = Math.abs(rawDelta) <= 180 ? rawDelta : ((rawDelta + 180) % 360 + 360) % 360 - 180;
2115
- if (Math.abs(sample[1]) >= 90)
2116
- return false;
2117
- output[0] = delta * longitudeMeters;
2118
- output[1] = (sample[1] - geographic[1]) * latitudeMeters;
2119
- output[2] = sample[2] - geographic[2];
2120
- return output.every(Number.isFinite);
2121
- });
2122
- return (coordinate) => {
2123
- if (busy || coordinate.length < 2)
2124
- return null;
2125
- busy = true;
2126
- let scale2;
2127
- try {
2128
- anchor[0] = coordinate[0];
2129
- anchor[1] = coordinate[1];
2130
- anchor[2] = coordinate[2] ?? 0;
2131
- if (!anchor.every(Number.isFinite))
2132
- return null;
2133
- projection.unprojectTo(anchor, geographic);
2134
- const latitude = geographic[1] * RADIANS2;
2135
- const a = body.semiMajorAxis, es = body.eccentricitySquared;
2136
- const denominator = 1 - es * Math.sin(latitude) ** 2;
2137
- longitudeMeters = a * Math.cos(latitude) / Math.sqrt(denominator) * RADIANS2;
2138
- latitudeMeters = a * (1 - es) / denominator ** 1.5 * RADIANS2;
2139
- if (!(longitudeMeters > a * RADIANS2 * 1e-8) || !(latitudeMeters > 0))
2140
- return null;
2141
- const offset = ((geographic[0] - center + 180) % 360 + 360) % 360 - 180;
2142
- const hasLongitudeSeam = crs.kind === "geographic" ? crs.longitudeWrap !== void 0 : !Object.prototype.hasOwnProperty.call(crs.parameters, "over");
2143
- if (hasLongitudeSeam && Math.abs(offset) + 2 / longitudeMeters >= 180 || Math.abs(geographic[1]) + 2 / latitudeMeters >= 90)
2144
- return null;
2145
- for (component = 0; component < 3; component++) {
2146
- const direction = axis[component];
2147
- const nominalMeters = /[ud]/.test(direction) ? crs.verticalUnit : crs.kind === "geographic" ? (/[ew]/.test(direction) ? longitudeMeters : latitudeMeters) * crs.angularUnit / RADIANS2 : crs.toMeter;
2148
- if (!numerical.evaluate(1 / nominalMeters, nominalMeters))
2149
- return null;
2150
- for (let i = 0; i < 3; i++)
2151
- derivatives[component][i] = numerical.result[i];
2152
- }
2153
- scale2 = derivatives.map((derivative) => Math.hypot(...derivative));
2154
- if (crs.kind === "projected") {
2155
- const east = derivatives[axis.search(/[ew]/)];
2156
- const north = derivatives[axis.search(/[ns]/)];
2157
- const inverseArea = Math.abs(east[0] * north[1] - east[1] * north[0]) / crs.toMeter ** 2;
2158
- scale2[axis.search(/[ud]/)] = crs.verticalUnit * Math.sqrt(inverseArea);
2159
- }
2160
- } catch {
2161
- return null;
2162
- } finally {
2163
- busy = false;
2164
- }
2165
- return validateScale(scale2);
2166
- };
2167
- }
2168
-
2169
- // dist/projection/experimental/crs-descriptor.js
2170
- var ANGULAR_UNITS = {
2171
- degrees: Math.PI / 180,
2172
- radians: 1,
2173
- gradians: Math.PI / 200
2174
- };
2175
- var LINEAR_UNITS = {
2176
- ...Object.fromEntries(Object.values(linearUnits).map((unit2) => [unit2.name, unit2.metersPerUnit]))
2177
- };
2178
- async function resolveCRSDescriptor(engine, definition2, normalization, options = {}, useDefinitionSignature = false, prepareInput) {
2179
- const captured = typeof definition2 === "string" ? definition2 : JSON.parse(JSON.stringify(definition2));
2180
- const conventions = {
2181
- enforceAxis: normalization.enforceAxis,
2182
- mode: normalization.mode,
2183
- ...options,
2184
- converters: options.converters && [...options.converters]
2185
- };
2186
- const input = prepareInput ? await prepareInput(captured, { ...normalization, ...conventions }) : captured;
2187
- const crs = normalizeCRS(input, { ...normalization, ...conventions });
2188
- const projection = await engine.createProjectionAsync({
2189
- ...conventions,
2190
- from: "WGS84",
2191
- to: input
2192
- });
2193
- const axis = crs.storedAxis || (conventions.enforceAxis ? crs.axis : "enu");
2194
- const horizontalUnit = getUnit(crs.kind === "geographic" ? crs.angularUnit : crs.toMeter, crs.kind === "geographic");
2195
- const heightUnit = getUnit(crs.verticalUnit, false);
2196
- const units2 = [...axis].map((direction) => crs.kind !== "geocentric" && /[ud]/.test(direction) ? heightUnit : horizontalUnit);
2197
- const profile = projection.targetProfile;
2198
- if (!profile)
2199
- throw new Error("Projection must define a rendering profile for CRS retrieval");
2200
- const center = (projection.targetLongitudeOrigin + crs.primeMeridian) * 180 / Math.PI;
2201
- const bounds = adaptBounds(profile, crs, axis);
2202
- const normalizeWGS84 = createNormalization(profile.normalize);
2203
- const renderingScale = createRenderingScale(crs, projection, axis, center);
2204
- const sources = [.../* @__PURE__ */ new Set(["WGS84", ...conventions.converters || []])];
2205
- if (sources.some((source) => typeof source !== "string" || !source.trim()))
2206
- throw new Error("Converter source CRS must be a nonempty string");
2207
- const entries = await Promise.all(sources.map(async (source) => {
2208
- if (source === "WGS84")
2209
- return [source, createConverter(projection, normalizeWGS84)];
2210
- const [pair2, geographic] = await Promise.all([
2211
- engine.createProjectionAsync({ ...conventions, from: source, to: input }),
2212
- engine.createProjectionAsync({ ...conventions, from: "WGS84", to: source })
2213
- ]);
2214
- return [
2215
- source,
2216
- createConverter(pair2, createSourceNormalization(geographic, normalizeWGS84))
2217
- ];
2218
- }));
2219
- const converter = Object.assign(/* @__PURE__ */ Object.create(null), Object.fromEntries(entries));
2220
- const metadata = {
2221
- coordinateFrame: crs.kind,
2222
- projection: crs.projection,
2223
- parameters: crs.parameters,
2224
- ellipsoid: {
2225
- semiMajorAxis: crs.ellipsoid.semiMajorAxis,
2226
- semiMinorAxis: crs.ellipsoid.semiMinorAxis
2227
- },
2228
- axis,
2229
- xUnit: units2[0],
2230
- yUnit: units2[1],
2231
- zUnit: units2[2],
2232
- areaOfUse: crs.areaOfUse,
2233
- lossy: crs.lossy
2234
- };
2235
- return {
2236
- ...metadata,
2237
- // Exact caller identity is sufficient under default execution conventions.
2238
- // Additional source converters do not change the target CRS.
2239
- signature: useDefinitionSignature && typeof input === "string" && !conventions.enforceAxis && !crs.lossy ? input : getCRSSignature(metadata),
2240
- renderingBounds: bounds,
2241
- renderingScale,
2242
- getRenderingScale: (coordinate) => typeof renderingScale === "function" ? renderingScale(coordinate) : renderingScale,
2243
- converter
2244
- };
2245
- }
2246
- function createConverter(projection, normalize) {
2247
- return {
2248
- from: createConversion(projection.project.bind(projection), projection.projectTo.bind(projection)),
2249
- to: createConversion(projection.unproject.bind(projection), projection.unprojectTo.bind(projection)),
2250
- normalize
2251
- };
2252
- }
2253
- function createSourceNormalization(geographic, normalizeWGS84) {
2254
- function normalize(coordinate, output) {
2255
- if (output !== void 0)
2256
- validateScalarOutput(coordinate, output, coordinate.length);
2257
- const wgs842 = geographic.unproject(Array.from(coordinate));
2258
- const [longitude, latitude, altitude] = wgs842;
2259
- normalizeWGS84(wgs842, wgs842);
2260
- if (wgs842[0] === longitude && wgs842[1] === latitude && wgs842[2] === altitude) {
2261
- return output === void 0 ? Array.from(coordinate) : writeScalarOutput(coordinate, output, { x: coordinate[0], y: coordinate[1], z: coordinate[2] ?? 0 }, coordinate.length);
2262
- }
2263
- return output === void 0 ? geographic.project(wgs842) : geographic.projectTo(wgs842, output);
2264
- }
2265
- return normalize;
2266
- }
2267
- function createConversion(allocate, write) {
2268
- function convert(coordinate, output) {
2269
- return output === void 0 ? allocate(Array.isArray(coordinate) ? coordinate : Array.from(coordinate)) : write(coordinate, output);
2270
- }
2271
- return convert;
2272
- }
2273
- function createNormalization(normalizeDomain) {
2274
- function normalize(coordinate, output) {
2275
- const result = output ?? new Array(coordinate.length);
2276
- validateScalarOutput(coordinate, result, coordinate.length);
2277
- const longitude = coordinate[0], latitude = coordinate[1], altitude = coordinate[2] ?? 0;
2278
- if (coordinate.length < 2 || !Number.isFinite(longitude) || !Number.isFinite(latitude) || !Number.isFinite(altitude))
2279
- throw new Error("Normalization requires finite longitude, latitude and altitude");
2280
- const point = { x: longitude, y: latitude, z: altitude };
2281
- normalizeDomain == null ? void 0 : normalizeDomain(point);
2282
- return writeScalarOutput(coordinate, result, point, coordinate.length);
2283
- }
2284
- return normalize;
2285
- }
2286
- function adaptBounds(profile, crs, axis) {
2287
- const horizontalUnit = crs.kind === "geographic" ? crs.angularUnit : crs.toMeter;
2288
- const units2 = [
2289
- horizontalUnit,
2290
- horizontalUnit,
2291
- crs.kind === "geocentric" ? crs.toMeter : crs.verticalUnit
2292
- ];
2293
- const bounds = profile.bounds;
2294
- const limits = [...axis].map((direction) => {
2295
- const index = /[ew]/.test(direction) ? 0 : /[ns]/.test(direction) ? 1 : 2;
2296
- const minimum = bounds[0][index] / units2[index];
2297
- const maximum = bounds[1][index] / units2[index];
2298
- return /[wsd]/.test(direction) ? [-maximum, -minimum] : [minimum, maximum];
2299
- });
2300
- return [
2301
- [limits[0][0], limits[1][0], limits[2][0]],
2302
- [limits[0][1], limits[1][1], limits[2][1]]
2303
- ];
2304
- }
2305
- function getUnit(factor, angular2) {
2306
- const units2 = angular2 ? ANGULAR_UNITS : LINEAR_UNITS;
2307
- const name = Object.keys(units2).find((candidate) => units2[candidate] === factor) || "custom";
2308
- return angular2 ? { name, degreesPerUnit: factor / ANGULAR_UNITS["degrees"] } : { name, metersPerUnit: factor };
2309
- }
2310
-
2311
- // dist/projection/experimental/engine-options.js
2312
- function snapshotEngineOptions(options) {
2313
- return {
2314
- ...options,
2315
- projections: options.projections && [...options.projections],
2316
- parsers: options.parsers && [...options.parsers],
2317
- datumCatalogs: options.datumCatalogs && [...options.datumCatalogs],
2318
- aliases: options.aliases && JSON.parse(JSON.stringify(options.aliases)),
2319
- datumGrids: options.datumGrids && { ...options.datumGrids },
2320
- verticalGrids: options.verticalGrids && { ...options.verticalGrids }
2321
- };
2322
- }
2323
- function hasCRSOverrides(options) {
2324
- return Boolean(options.projections || options.parsers || options.datumCatalogs || options.aliases || options.datumGrids || options.verticalGrids || options.resolver);
2325
- }
2326
-
2327
- // dist/projection/experimental/crs/resolve.js
2328
- async function prepareEngineOptions(options) {
2329
- const captured = {
2330
- ...options,
2331
- from: capture(options.from ?? "WGS84"),
2332
- to: capture(options.to ?? "WGS84")
2333
- };
2334
- const [from, to] = await Promise.all([
2335
- prepareCRSInput(captured.from, captured),
2336
- prepareCRSInput(captured.to, captured)
2337
- ]);
2338
- return { ...captured, from, to };
2339
- }
2340
- async function prepareCRSInput(captured, options) {
2341
- var _a2;
2342
- const source = resolveCRSInput(captured, options);
2343
- const local = resolveLocalCRSDefinition(source.definition, options);
2344
- const reference = typeof captured === "string" || "type" in captured ? void 0 : "crs" in captured ? captured.crs : captured;
2345
- const representation = local === source.definition && reference ? reference.representation : inferCRSRepresentation(local);
2346
- if (representation !== "identifier" || ((_a2 = options.parsers) == null ? void 0 : _a2.some((p) => p.canParse(local)))) {
2347
- return captured;
2348
- }
2349
- const result = await options.resolver.resolve({
2350
- state: "explicit",
2351
- provenance: (reference == null ? void 0 : reference.provenance) ?? "unknown",
2352
- definition: local,
2353
- representation
2354
- });
2355
- const definition2 = resolveCRSInput(result.input, options).definition;
2356
- if (!reference)
2357
- return definition2;
2358
- const metadata = captured;
2359
- const resolved2 = {
2360
- ...reference,
2361
- definition: definition2,
2362
- representation: inferCRSRepresentation(definition2),
2363
- alternatives: [
2364
- { definition: reference.definition, representation: reference.representation },
2365
- ...reference.alternatives ?? []
2366
- ]
2367
- };
2368
- return "crs" in metadata ? { ...metadata, crs: resolved2 } : resolved2;
2369
- }
2370
- function capture(input) {
2371
- return typeof input === "string" ? input : JSON.parse(JSON.stringify(input));
2372
- }
2373
-
2374
- // dist/projection/experimental/projection-engine.js
2375
- var ConfigurableProjectionEngine = class {
2376
- constructor(options = {}) {
2377
- this.options = snapshotEngineOptions(options);
2378
- this.useDefinitionSignature = !hasCRSOverrides(options);
2379
- }
2380
- /** Resolve a CRS and load only its required algorithms before exposing sync conversions. */
2381
- getCRS(definition2, options = {}) {
2382
- return resolveCRSDescriptor(this, definition2, this.options, options, this.useDefinitionSignature, this.options.resolver ? prepareCRSInput : void 0);
2383
- }
2384
- /** Compile a CRS pair. Lazy descriptors remain unloaded until the transform is used. */
2385
- createProjection(options = {}) {
2386
- return new ProjectionTransform({ ...this.options, ...options });
2387
- }
2388
- /** Load only the algorithms required by this CRS pair and return a synchronous transform. */
2389
- async createProjectionAsync(options = {}) {
2390
- const config = { ...this.options, ...options };
2391
- return ProjectionTransform.create(config.resolver ? await prepareEngineOptions(config) : config);
2392
- }
2393
- };
2394
- function createProjectionEngine(options = {}) {
2395
- return new ConfigurableProjectionEngine(options);
1322
+ function transverseBounds(project, parameters, origin, over = false, equator = 0) {
1323
+ const longitude = longitudeRange(parameters, origin, over);
1324
+ if (maxAbs(longitude) > Math.PI / 6 + 1e-12)
1325
+ throw new Error("Unsupported transverse rendering coverage");
1326
+ const longitudes = [
1327
+ longitude[0],
1328
+ longitude[1],
1329
+ Math.max(longitude[0], Math.min(longitude[1], 0))
1330
+ ];
1331
+ const latitudes = [
1332
+ parameters[0][1],
1333
+ parameters[1][1],
1334
+ Math.max(parameters[0][1], Math.min(parameters[1][1], equator))
1335
+ ];
1336
+ const points = longitudes.flatMap((x) => latitudes.map((y) => project(origin + x, y)));
1337
+ return envelope([Math.min(...points.map((p) => p[0])), Math.max(...points.map((p) => p[0]))], [Math.min(...points.map((p) => p[1])), Math.max(...points.map((p) => p[1]))]);
2396
1338
  }
2397
-
2398
- // dist/projection/experimental/flat-projection.js
2399
- function createFlatProjection(forward33, inverse33) {
2400
- return {
2401
- ...createProjection(forward33, inverse33),
2402
- createForwardFlat(context) {
2403
- return this.forwardInPlace === forward33 ? createFlatOperation(forward33, false, context) : void 0;
2404
- },
2405
- createInverseFlat(context) {
2406
- return this.inverseInPlace === inverse33 ? createFlatOperation(inverse33, true, context) : void 0;
2407
- }
2408
- };
1339
+ function vanDerGrintenBounds(project, parameters, origin, over = false) {
1340
+ const longitude = longitudeRange(parameters, origin, over);
1341
+ const longitudes = [
1342
+ longitude[0],
1343
+ longitude[1],
1344
+ Math.max(longitude[0], Math.min(longitude[1], 0))
1345
+ ];
1346
+ const latitudes = [
1347
+ parameters[0][1],
1348
+ parameters[1][1],
1349
+ Math.max(parameters[0][1], Math.min(parameters[1][1], 0))
1350
+ ];
1351
+ const points = longitudes.flatMap((x) => latitudes.map((y) => project(origin + x, y)));
1352
+ return envelope([Math.min(...points.map((p) => p[0])), Math.max(...points.map((p) => p[0]))], [Math.min(...points.map((p) => p[1])), Math.max(...points.map((p) => p[1]))]);
2409
1353
  }
2410
- function createFlatOperation(project, inverse33, { inputScale, outputScale }) {
2411
- const scratch = new ProjectionScratch();
2412
- return (coordinates, dimension) => {
2413
- const point = scratch.acquire();
2414
- try {
2415
- const float32 = coordinates instanceof Float32Array;
2416
- for (let offset = 0; offset < coordinates.length; offset += dimension) {
2417
- point.x = coordinates[offset];
2418
- point.y = coordinates[offset + 1];
2419
- point.z = dimension >= 3 ? coordinates[offset + 2] : 0;
2420
- if (!Number.isFinite(point.x) || !Number.isFinite(point.y) || !Number.isFinite(point.z))
2421
- throw new Error("Coordinates must contain finite x, y and optional z values");
2422
- if (inputScale !== 1) {
2423
- point.x *= inputScale;
2424
- point.y *= inputScale;
2425
- }
2426
- if (inverse33)
2427
- project(point);
2428
- if (Math.abs(point.y) > Math.PI / 2 || !Number.isFinite(point.x) || !Number.isFinite(point.y))
2429
- throw new Error("Coordinate is outside the geographic domain");
2430
- point.x += 0;
2431
- point.x -= 0;
2432
- if (!inverse33)
2433
- project(point);
2434
- if (outputScale !== 1) {
2435
- point.x /= outputScale;
2436
- point.y /= outputScale;
2437
- }
2438
- if (!Number.isFinite(point.x) || !Number.isFinite(point.y))
2439
- throw new Error("Projection produced non-finite coordinates");
2440
- if (float32 && (Math.abs(point.x) > 34028234663852886e22 || Math.abs(point.y) > 34028234663852886e22))
2441
- throw new Error("Projected coordinate exceeds Float32 range");
2442
- coordinates[offset] = point.x;
2443
- coordinates[offset + 1] = point.y;
2444
- }
2445
- } finally {
2446
- scratch.release(point);
2447
- }
2448
- };
1354
+ function conicBounds(project, parameters, origin, cone, x0, centerY, over = false) {
1355
+ const angles = scale(longitudeRange(parameters, origin, over), cone);
1356
+ const radii = ordered(centerY - project(origin, parameters[0][1])[1], centerY - project(origin, parameters[1][1])[1]);
1357
+ return envelope(add([x0, x0], multiply(radii, sine(angles))), add([centerY, centerY], scale(multiply(radii, cosine(angles)), -1)));
2449
1358
  }
2450
1359
 
2451
1360
  // dist/projection/experimental/projections/mercator.js
@@ -4672,6 +3581,101 @@ var universalTransverseMercator = {
4672
3581
  }
4673
3582
  };
4674
3583
 
3584
+ // dist/projection/experimental/rendering-profile/geographic-rendering-profile.js
3585
+ function createGeographicProfile(parameters, primeMeridian2 = 0) {
3586
+ const center = numberParameter(parameters, "lon_wrap", 0) * DEGREES_TO_RADIANS;
3587
+ return (coverage) => createRectangleRenderingProfile((ranges) => {
3588
+ const longitude = longitudeRange(ranges, center);
3589
+ return [
3590
+ [center + longitude[0], ranges[0][1], 0],
3591
+ [center + longitude[1], ranges[1][1], 0]
3592
+ ];
3593
+ }, coverage ?? [-180, -90, 180, 90], center, primeMeridian2);
3594
+ }
3595
+
3596
+ // dist/projection/experimental/datum.js
3597
+ var import_matrix = require("@math.gl/core/matrix");
3598
+ var ARC_SECOND = Math.PI / (180 * 3600);
3599
+ function geodeticToGeocentricInPlace(point, ellipsoid) {
3600
+ if (Math.abs(point.y) > Math.PI / 2)
3601
+ throw new Error("Latitude outside geocentric domain");
3602
+ if (!(0, import_matrix.spheroidToCartesian)(point, ellipsoid))
3603
+ throw new Error("Geocentric coordinate must be finite");
3604
+ }
3605
+ function geocentricToGeodeticInPlace(point, ellipsoid) {
3606
+ const x = point.x, y = point.y, z = point.z;
3607
+ const { semiMajorAxis: a, semiMinorAxis: b, eccentricitySquared: es } = ellipsoid;
3608
+ if (x === 0 && y === 0 && z === 0)
3609
+ throw new Error("Geodetic coordinates are undefined at the Earth center");
3610
+ if (es !== 0 && Math.abs(x) < 1e-12 * a && Math.abs(y) < 1e-12 * a && Math.hypot(x, y) < 1e-12 * a) {
3611
+ if (!Number.isFinite(Math.hypot(x, y, z)))
3612
+ throw new Error("Geocentric radius must be finite");
3613
+ point.x = 0;
3614
+ point.y = Math.sign(z) * Math.PI / 2;
3615
+ point.z = Math.abs(z) - b;
3616
+ return;
3617
+ }
3618
+ if (!(0, import_matrix.cartesianToSpheroid)(point, ellipsoid)) {
3619
+ if (!Number.isFinite(Math.hypot(x, y, z)))
3620
+ throw new Error("Geocentric radius must be finite");
3621
+ throw new Error("Geocentric inverse did not converge");
3622
+ }
3623
+ }
3624
+ function createHelmert(values, inverse33) {
3625
+ const dx = values[0], dy = values[1], dz = values[2];
3626
+ const rx = (values[3] || 0) * ARC_SECOND, ry = (values[4] || 0) * ARC_SECOND, rz = (values[5] || 0) * ARC_SECOND;
3627
+ const scale2 = 1 + (values[6] || 0) / 1e6;
3628
+ return inverse33 ? (point) => {
3629
+ const x = (point.x - dx) / scale2, y = (point.y - dy) / scale2, z = (point.z - dz) / scale2;
3630
+ point.x = x + rz * y - ry * z;
3631
+ point.y = -rz * x + y + rx * z;
3632
+ point.z = ry * x - rx * y + z;
3633
+ } : (point) => {
3634
+ const x = point.x, y = point.y, z = point.z;
3635
+ point.x = scale2 * (x - rz * y + ry * z) + dx;
3636
+ point.y = scale2 * (rz * x + y - rx * z) + dy;
3637
+ point.z = scale2 * (-ry * x + rx * y + z) + dz;
3638
+ };
3639
+ }
3640
+ function applyDatumGrids(point, datum, inverse33) {
3641
+ for (const reference of datum.grids) {
3642
+ if (reference.name === "null")
3643
+ return;
3644
+ if (!reference.grid) {
3645
+ if (reference.optional)
3646
+ continue;
3647
+ throw new Error("Required datum grid is not registered: " + reference.name);
3648
+ }
3649
+ let found = false;
3650
+ if (reference.grid.shiftInPlace)
3651
+ found = reference.grid.shiftInPlace(point, inverse33);
3652
+ else {
3653
+ const output = reference.grid.shift(point.x, point.y, inverse33);
3654
+ if (output) {
3655
+ point.x = output[0];
3656
+ point.y = output[1];
3657
+ found = true;
3658
+ }
3659
+ }
3660
+ if (found) {
3661
+ if (!Number.isFinite(point.x) || !Number.isFinite(point.y) || Math.abs(point.y) > Math.PI / 2)
3662
+ throw new Error("Datum grid produced a coordinate outside the geographic domain");
3663
+ return;
3664
+ }
3665
+ }
3666
+ throw new Error("No datum grid covers coordinate: " + datum.grids.map((grid) => grid.name).join(","));
3667
+ }
3668
+ function geodeticToGeocentric(coordinate, ellipsoid) {
3669
+ const point = { x: coordinate[0], y: coordinate[1], z: coordinate[2] };
3670
+ geodeticToGeocentricInPlace(point, ellipsoid);
3671
+ return [point.x, point.y, point.z];
3672
+ }
3673
+ function geocentricToGeodetic(coordinate, ellipsoid) {
3674
+ const point = { x: coordinate[0], y: coordinate[1], z: coordinate[2] };
3675
+ geocentricToGeodeticInPlace(point, ellipsoid);
3676
+ return [point.x, point.y, point.z];
3677
+ }
3678
+
4675
3679
  // dist/projection/experimental/projections/geocentric.js
4676
3680
  var geocentric = {
4677
3681
  name: "geocent",
@@ -9104,6 +8108,7 @@ var vanDerGrinten = {
9104
8108
  };
9105
8109
 
9106
8110
  // dist/projection/experimental/projections/ob-tran.js
8111
+ var import_types4 = require("./experimental/crs/types.shared.cjs");
9107
8112
  var rotationParameters = [
9108
8113
  "o_proj",
9109
8114
  "o_alpha",
@@ -9161,12 +8166,12 @@ function obliqueTransformation(wrapped) {
9161
8166
  parameters: [...rotationParameters, "lon_0", ...geographic ? [] : wrapped.parameters],
9162
8167
  flags: geographic ? [] : wrapped.flags,
9163
8168
  create(context) {
9164
- var _a2;
8169
+ var _a;
9165
8170
  const { parameters } = context;
9166
8171
  const requested = parameters["o_proj"];
9167
8172
  const accepted = geographic ? ["longlat", "latlong", "lonlat", "latlon", "identity"] : [wrapped.name, ...wrapped.aliases || []];
9168
8173
  if (requested && !accepted.map(normalizedName).includes(normalizedName(requested)))
9169
- throw new TypeScriptCRSError("missing-plugin", "Oblique transformation dependency does not match +o_proj=" + requested);
8174
+ throw new import_types4.TypeScriptCRSError("missing-plugin", "Oblique transformation dependency does not match +o_proj=" + requested);
9170
8175
  const { lamp, phip } = rotation(parameters);
9171
8176
  const cphip = Math.cos(phip), sphip = Math.sin(phip), oblique = Math.abs(phip) > 1e-10;
9172
8177
  const longitudeOrigin = radians(parameters, "lon_0");
@@ -9215,18 +8220,18 @@ function obliqueTransformation(wrapped) {
9215
8220
  inverse33(point);
9216
8221
  unrotate(point);
9217
8222
  });
9218
- const getChildProfile = geographic ? createGeographicProfile(innerParameters) : (_a2 = inner.getRenderingProfile) == null ? void 0 : _a2.bind(inner);
8223
+ const getChildProfile = geographic ? createGeographicProfile(innerParameters) : (_a = inner.getRenderingProfile) == null ? void 0 : _a.bind(inner);
9219
8224
  if (!getChildProfile)
9220
8225
  return implementation;
9221
8226
  const wrapProfile = (child2, coverage) => {
9222
8227
  const source = coverage && createRectangleRenderingProfile(() => child2.bounds, coverage, longitudeOrigin, context.primeMeridian ?? 0, over);
9223
8228
  const normalizeRotated = createAngularNormalization((point) => {
9224
- var _a3;
8229
+ var _a2;
9225
8230
  const longitude = point.x, latitude = point.y;
9226
8231
  rotate(point);
9227
8232
  const x = point.x * 180 / Math.PI, y = point.y * 180 / Math.PI;
9228
8233
  const rotated = { x, y, z: point.z };
9229
- (_a3 = child2.normalize) == null ? void 0 : _a3.call(child2, rotated);
8234
+ (_a2 = child2.normalize) == null ? void 0 : _a2.call(child2, rotated);
9230
8235
  if (rotated.x === x && rotated.y === y) {
9231
8236
  point.x = longitude;
9232
8237
  point.y = latitude;
@@ -9288,8 +8293,8 @@ var WKTCRSSyntaxError = class extends SyntaxError {
9288
8293
  var WKTCRSValidationError = class extends Error {
9289
8294
  /** Create an error from one or more validation issues. */
9290
8295
  constructor(issues) {
9291
- var _a2;
9292
- super(((_a2 = issues[0]) == null ? void 0 : _a2.message) || "WKT validation failed");
8296
+ var _a;
8297
+ super(((_a = issues[0]) == null ? void 0 : _a.message) || "WKT validation failed");
9293
8298
  this.name = "WKTCRSValidationError";
9294
8299
  this.issues = issues;
9295
8300
  }
@@ -9482,8 +8487,8 @@ function parseWKTCRS(text, options) {
9482
8487
  return ast;
9483
8488
  }
9484
8489
  function validateWKTCRS(ast, options) {
9485
- var _a2;
9486
- if (!ast || ast.type !== "wkt-crs" || ((_a2 = ast.root) == null ? void 0 : _a2.type) !== "node") {
8490
+ var _a;
8491
+ if (!ast || ast.type !== "wkt-crs" || ((_a = ast.root) == null ? void 0 : _a.type) !== "node") {
9487
8492
  throw new TypeError("validateWKTCRS expects a WKTCRSAst");
9488
8493
  }
9489
8494
  const profile = resolveProfile(ast.root.keyword, (options == null ? void 0 : options.profile) || "auto");
@@ -9775,7 +8780,11 @@ function getSourceLocation2(source, offset) {
9775
8780
  return { line, column };
9776
8781
  }
9777
8782
 
8783
+ // dist/projection/experimental/crs/wkt.js
8784
+ var import_types6 = require("./experimental/crs/types.shared.cjs");
8785
+
9778
8786
  // dist/projection/experimental/crs/structured.js
8787
+ var import_types5 = require("./experimental/crs/types.shared.cjs");
9779
8788
  function object(value2) {
9780
8789
  if (!value2 || typeof value2 !== "object" || Array.isArray(value2))
9781
8790
  throw new Error("Expected a CRS object");
@@ -9787,7 +8796,7 @@ function array(value2) {
9787
8796
  function key(value2) {
9788
8797
  return String(value2 || "").toLowerCase().replace(/[^a-z0-9]/g, "");
9789
8798
  }
9790
- function finite2(value2) {
8799
+ function finite(value2) {
9791
8800
  if (typeof value2 !== "number" || !Number.isFinite(value2))
9792
8801
  throw new Error("Expected a finite CRS parameter");
9793
8802
  return value2;
@@ -9796,7 +8805,7 @@ function unit(value2, fallback) {
9796
8805
  if (value2 === void 0)
9797
8806
  return fallback;
9798
8807
  if (typeof value2 === "object") {
9799
- const factor2 = finite2(object(value2)["conversion_factor"]);
8808
+ const factor2 = finite(object(value2)["conversion_factor"]);
9800
8809
  if (factor2 <= 0)
9801
8810
  throw new Error("Unit conversion factor must be positive");
9802
8811
  return factor2;
@@ -9817,7 +8826,7 @@ function unit(value2, fallback) {
9817
8826
  };
9818
8827
  const factor = factors2[key(value2)];
9819
8828
  if (!factor)
9820
- unsupportedStage("Unsupported CRS unit: " + String(value2));
8829
+ (0, import_types5.unsupportedStage)("Unsupported CRS unit: " + String(value2));
9821
8830
  return factor;
9822
8831
  }
9823
8832
  var METHODS = {
@@ -9942,12 +8951,12 @@ var DIRECTIONS = {
9942
8951
  geocentricz: "u"
9943
8952
  };
9944
8953
  function readStructuredCRS(crs, options) {
9945
- var _a2, _b, _c;
8954
+ var _a, _b, _c;
9946
8955
  const type = String(crs["type"]);
9947
8956
  const areaOfUse = readAreaOfUse(crs["bbox"]);
9948
8957
  if (type === "CompoundCRS") {
9949
8958
  if (options.mode !== "horizontal")
9950
- unsupportedStage("CompoundCRS requires explicit horizontal extraction");
8959
+ (0, import_types5.unsupportedStage)("CompoundCRS requires explicit horizontal extraction");
9951
8960
  const components = array(crs["components"]).map(object).filter((value2) => ["ProjectedCRS", "GeographicCRS", "GeodeticCRS", "BoundCRS"].includes(String(value2["type"])));
9952
8961
  if (components.length !== 1)
9953
8962
  throw new Error("CompoundCRS requires exactly one horizontal component");
@@ -9958,14 +8967,14 @@ function readStructuredCRS(crs, options) {
9958
8967
  const source = readStructuredCRS(object(crs["source_crs"]), options);
9959
8968
  const target = readStructuredCRS(object(crs["target_crs"]), options);
9960
8969
  if (target.parameters["datum"] !== "WGS84" || !["longlat", "geocent"].includes(target.parameters["proj"]) || Number(target.parameters["pm"] || 0) !== 0 || target.parameters["towgs84"] || Number(target.parameters["a"]) !== 6378137 || !(Math.abs(Number(target.parameters["rf"]) - 298.257223563) <= 1e-9 || Math.abs(Number(target.parameters["b"]) - 6356752314245179e-9) <= 1e-6))
9961
- unsupportedStage("BoundCRS requires a WGS84 target");
8970
+ (0, import_types5.unsupportedStage)("BoundCRS requires a WGS84 target");
9962
8971
  const operation2 = object(crs["transformation"]);
9963
8972
  const method = key(object(operation2["method"])["name"]);
9964
8973
  const translation = method === "geocentrictranslations" || /^geocentrictranslationsgeog[23]ddomain$/.test(method);
9965
8974
  const position = /^positionvector(?:transformation)?(?:geog[23]ddomain|geocentricdomain)?$/.test(method);
9966
8975
  const frame = /^coordinateframe(?:rotation)?(?:geog[23]ddomain|geocentricdomain)?$/.test(method);
9967
8976
  if (!translation && !position && !frame)
9968
- unsupportedStage("Unsupported BoundCRS transformation: " + method);
8977
+ (0, import_types5.unsupportedStage)("Unsupported BoundCRS transformation: " + method);
9969
8978
  const names2 = [
9970
8979
  "xaxistranslation",
9971
8980
  "yaxistranslation",
@@ -9979,9 +8988,9 @@ function readStructuredCRS(crs, options) {
9979
8988
  for (const entry of array(operation2["parameters"])) {
9980
8989
  const parameter = object(entry), index = names2.indexOf(key(parameter["name"]));
9981
8990
  if (index < 0 || index >= values.length || values[index] !== void 0)
9982
- unsupportedStage("Unsupported or duplicate Helmert parameter: " + String(parameter["name"]));
8991
+ (0, import_types5.unsupportedStage)("Unsupported or duplicate Helmert parameter: " + String(parameter["name"]));
9983
8992
  const base2 = index < 3 ? 1 : index < 6 ? DEGREES_TO_RADIANS / 3600 : 1e-6;
9984
- values[index] = finite2(parameter["value"]) * unit(parameter["unit"], base2) / base2 * (frame && index >= 3 && index < 6 ? -1 : 1);
8993
+ values[index] = finite(parameter["value"]) * unit(parameter["unit"], base2) / base2 * (frame && index >= 3 && index < 6 ? -1 : 1);
9985
8994
  }
9986
8995
  if (values.some((value2) => value2 === void 0))
9987
8996
  throw new Error("Incomplete BoundCRS Helmert transformation");
@@ -9993,21 +9002,21 @@ function readStructuredCRS(crs, options) {
9993
9002
  return { ...source, parameters: parameters2, areaOfUse: areaOfUse ?? source.areaOfUse };
9994
9003
  }
9995
9004
  if (!["ProjectedCRS", "GeographicCRS", "GeodeticCRS"].includes(type))
9996
- unsupportedStage("Unsupported CRS type: " + type);
9005
+ (0, import_types5.unsupportedStage)("Unsupported CRS type: " + type);
9997
9006
  const base = type === "ProjectedCRS" ? object(crs["base_crs"]) : crs;
9998
9007
  const datum = object(base["datum"] || base["datum_ensemble"]);
9999
9008
  if (datum["type"] === "DynamicGeodeticReferenceFrame" || datum["frame_reference_epoch"] !== void 0 || crs["coordinate_epoch"] !== void 0)
10000
- unsupportedStage("Time-dependent datum transformations are not implemented");
9009
+ (0, import_types5.unsupportedStage)("Time-dependent datum transformations are not implemented");
10001
9010
  const ellipsoid = object(datum["ellipsoid"]);
10002
- const major = finite2(ellipsoid["semi_major_axis"] ?? ellipsoid["radius"]);
9011
+ const major = finite(ellipsoid["semi_major_axis"] ?? ellipsoid["radius"]);
10003
9012
  const parameters = {
10004
9013
  proj: "longlat",
10005
9014
  a: String(major * unit(ellipsoid["unit"], 1))
10006
9015
  };
10007
9016
  if (ellipsoid["inverse_flattening"] !== void 0)
10008
- parameters["rf"] = String(finite2(ellipsoid["inverse_flattening"]));
9017
+ parameters["rf"] = String(finite(ellipsoid["inverse_flattening"]));
10009
9018
  else if (ellipsoid["semi_minor_axis"] !== void 0)
10010
- parameters["b"] = String(finite2(ellipsoid["semi_minor_axis"]) * unit(ellipsoid["unit"], 1));
9019
+ parameters["b"] = String(finite(ellipsoid["semi_minor_axis"]) * unit(ellipsoid["unit"], 1));
10011
9020
  else if (ellipsoid["radius"] !== void 0)
10012
9021
  parameters["b"] = parameters["a"];
10013
9022
  else
@@ -10059,26 +9068,26 @@ function readStructuredCRS(crs, options) {
10059
9068
  parameters["datum"] = authorityDatum;
10060
9069
  }
10061
9070
  if (datum["towgs84"] !== void 0) {
10062
- parameters["towgs84"] = array(datum["towgs84"]).map(finite2).join(",");
9071
+ parameters["towgs84"] = array(datum["towgs84"]).map(finite).join(",");
10063
9072
  delete parameters["datum"];
10064
9073
  }
10065
9074
  const cs = crs["coordinate_system"] ? object(crs["coordinate_system"]) : {};
10066
9075
  const axes = array(cs["axis"]).map(object);
10067
9076
  const geocentric2 = key(cs["subtype"]) === "cartesian" && type === "GeodeticCRS";
10068
9077
  if (type !== "ProjectedCRS" && !geocentric2 && cs["subtype"] && key(cs["subtype"]) !== "ellipsoidal")
10069
- unsupportedStage("Unsupported coordinate system subtype");
9078
+ (0, import_types5.unsupportedStage)("Unsupported coordinate system subtype");
10070
9079
  if (geocentric2)
10071
9080
  parameters["proj"] = "geocent";
10072
9081
  const angularUnit = unit(base["angular_unit"], DEGREES_TO_RADIANS);
10073
- const factor = unit((_a2 = axes[0]) == null ? void 0 : _a2["unit"], type === "ProjectedCRS" || geocentric2 ? 1 : angularUnit);
9082
+ const factor = unit((_a = axes[0]) == null ? void 0 : _a["unit"], type === "ProjectedCRS" || geocentric2 ? 1 : angularUnit);
10074
9083
  if (axes[1] && unit(axes[1]["unit"], factor) !== factor)
10075
- unsupportedStage("Mixed horizontal axis units are not supported");
9084
+ (0, import_types5.unsupportedStage)("Mixed horizontal axis units are not supported");
10076
9085
  if (geocentric2 && axes[2] && unit(axes[2]["unit"], factor) !== factor)
10077
- unsupportedStage("Mixed geocentric axis units are not supported");
9086
+ (0, import_types5.unsupportedStage)("Mixed geocentric axis units are not supported");
10078
9087
  const pm = base["prime_meridian"] || datum["prime_meridian"];
10079
9088
  if (pm) {
10080
9089
  const meridian = object(pm);
10081
- parameters["pm"] = String(finite2(meridian["longitude"]) * unit(meridian["unit"], angularUnit) / DEGREES_TO_RADIANS);
9090
+ parameters["pm"] = String(finite(meridian["longitude"]) * unit(meridian["unit"], angularUnit) / DEGREES_TO_RADIANS);
10082
9091
  }
10083
9092
  if (type === "ProjectedCRS") {
10084
9093
  const conversion = object(crs["conversion"]), method = key(object(conversion["method"])["name"]);
@@ -10095,12 +9104,12 @@ function readStructuredCRS(crs, options) {
10095
9104
  if (projection !== "krovak" || esriKrovak.length !== 3 || new Set(esriKrovak.map((parameter) => key(parameter["name"]))).size !== 3 || esriKrovak.some((parameter) => {
10096
9105
  const name = key(parameter["name"]);
10097
9106
  const factor2 = name === "xyplanerotation" ? unit(parameter["unit"], angularUnit) / DEGREES_TO_RADIANS : unit(parameter["unit"], 1);
10098
- return Math.abs(finite2(parameter["value"]) * factor2 - expected[name]) > 1e-10;
9107
+ return Math.abs(finite(parameter["value"]) * factor2 - expected[name]) > 1e-10;
10099
9108
  }))
10100
- unsupportedStage("Unsupported ESRI Krovak axis adjustment");
9109
+ (0, import_types5.unsupportedStage)("Unsupported ESRI Krovak axis adjustment");
10101
9110
  }
10102
9111
  if (!projection || projection.startsWith("unsupported"))
10103
- unsupportedStage("Unsupported projection method: " + String(object(conversion["method"])["name"]));
9112
+ (0, import_types5.unsupportedStage)("Unsupported projection method: " + String(object(conversion["method"])["name"]));
10104
9113
  parameters["proj"] = projection === "webmerc" ? "merc" : projection;
10105
9114
  let hasSemiMinor = false;
10106
9115
  for (const parameter of conversionParameters) {
@@ -10113,14 +9122,14 @@ function readStructuredCRS(crs, options) {
10113
9122
  if (hasSemiMinor)
10114
9123
  throw new Error("Duplicate conversion parameter: semi_minor");
10115
9124
  hasSemiMinor = true;
10116
- const radius2 = finite2(parameter["value"]) * unit(parameter["unit"], 1);
9125
+ const radius2 = finite(parameter["value"]) * unit(parameter["unit"], 1);
10117
9126
  if (Math.abs(radius2 - Number(parameters["a"])) > 4 * Number.EPSILON * Number(parameters["a"]))
10118
- unsupportedStage("Pseudo-Mercator semi_minor must equal the semi-major axis");
9127
+ (0, import_types5.unsupportedStage)("Pseudo-Mercator semi_minor must equal the semi-major axis");
10119
9128
  continue;
10120
9129
  }
10121
9130
  let name = ((_b = METHOD_PARAMETERS[projection]) == null ? void 0 : _b[parameterName]) || PARAMETERS[parameterName];
10122
9131
  if (!name)
10123
- unsupportedStage("Unsupported conversion parameter: " + String(parameter["name"]));
9132
+ (0, import_types5.unsupportedStage)("Unsupported conversion parameter: " + String(parameter["name"]));
10124
9133
  if (name === "lat_1" && method === "stereographicnorthpole" && !polarTrueScale)
10125
9134
  name = "lat_0";
10126
9135
  else if (name === "lat_1" && ["merc", "webmerc", "eqc", "stere", "cea"].includes(projection))
@@ -10131,7 +9140,7 @@ function readStructuredCRS(crs, options) {
10131
9140
  continue;
10132
9141
  const angle = name.startsWith("lat") || name.startsWith("lon") || name === "alpha" || name === "gamma";
10133
9142
  const length = name === "x_0" || name === "y_0";
10134
- let converted = finite2(parameter["value"]) * unit(parameter["unit"], angle ? angularUnit : length ? factor : 1) / (angle ? DEGREES_TO_RADIANS : 1);
9143
+ let converted = finite(parameter["value"]) * unit(parameter["unit"], angle ? angularUnit : length ? factor : 1) / (angle ? DEGREES_TO_RADIANS : 1);
10135
9144
  if (name.startsWith("lat") && Math.abs(Math.abs(converted) - 90) <= 4 * Number.EPSILON * 90)
10136
9145
  converted = Math.sign(converted) * 90;
10137
9146
  parameters[name] = String(converted);
@@ -10144,7 +9153,7 @@ function readStructuredCRS(crs, options) {
10144
9153
  parameters["no_uoff"] = void 0;
10145
9154
  if (projection === "omerc" && parameters["lon_0"] !== void 0 && parameters["lonc"] !== void 0) {
10146
9155
  if (Math.abs(Number(parameters["lon_0"]) - Number(parameters["lonc"])) > 1e-10)
10147
- unsupportedStage("Oblique Mercator central meridian conflicts with projection centre");
9156
+ (0, import_types5.unsupportedStage)("Oblique Mercator central meridian conflicts with projection centre");
10148
9157
  delete parameters["lon_0"];
10149
9158
  }
10150
9159
  if (method === "stereographicnorthpole" && Math.abs(Number(parameters["lat_0"])) === 90)
@@ -10169,7 +9178,7 @@ function readStructuredCRS(crs, options) {
10169
9178
  if (axis.length === 2)
10170
9179
  axis += "u";
10171
9180
  if (!geocentric2 && /[ud]/.test(axis.slice(0, 2)))
10172
- unsupportedStage("Structured CRS vertical-first axes require an explicit PROJ axis definition");
9181
+ (0, import_types5.unsupportedStage)("Structured CRS vertical-first axes require an explicit PROJ axis definition");
10173
9182
  if (axis)
10174
9183
  parameters["axis"] = axis;
10175
9184
  if (type === "ProjectedCRS" || geocentric2)
@@ -10185,8 +9194,8 @@ function readAreaOfUse(bbox) {
10185
9194
  let areaOfUse;
10186
9195
  if (bbox !== void 0) {
10187
9196
  const extent = object(bbox);
10188
- const west = finite2(extent["west_longitude"]), south = finite2(extent["south_latitude"]);
10189
- const east = finite2(extent["east_longitude"]), north = finite2(extent["north_latitude"]);
9197
+ const west = finite(extent["west_longitude"]), south = finite(extent["south_latitude"]);
9198
+ const east = finite(extent["east_longitude"]), north = finite(extent["north_latitude"]);
10190
9199
  if (west < -180 || west > 180 || east < -180 || east > 180 || south < -90 || north > 90 || south >= north || west === east)
10191
9200
  throw new Error("Invalid CRS geographic bounding box");
10192
9201
  areaOfUse = [west, south, east, north];
@@ -10194,7 +9203,7 @@ function readAreaOfUse(bbox) {
10194
9203
  return areaOfUse;
10195
9204
  }
10196
9205
  function readAxisDirection(entry, parameters, projected) {
10197
- var _a2;
9206
+ var _a;
10198
9207
  let direction = String(entry["direction"]);
10199
9208
  let meridian = entry["meridian"];
10200
9209
  const along = /^(north|south) along ([+-]?(?:\d+(?:\.\d*)?|\.\d+)) deg(?: (east|west))?$/i.exec(direction);
@@ -10203,25 +9212,25 @@ function readAxisDirection(entry, parameters, projected) {
10203
9212
  throw new Error("Duplicate axis meridian");
10204
9213
  direction = along[1];
10205
9214
  meridian = {
10206
- longitude: Number(along[2]) * (((_a2 = along[3]) == null ? void 0 : _a2.toLowerCase()) === "west" ? -1 : 1)
9215
+ longitude: Number(along[2]) * (((_a = along[3]) == null ? void 0 : _a.toLowerCase()) === "west" ? -1 : 1)
10207
9216
  };
10208
9217
  }
10209
9218
  if (meridian !== void 0) {
10210
9219
  const latitude = Number(parameters["lat_0"]);
10211
9220
  const north = latitude === 90;
10212
9221
  if (!projected || parameters["proj"] !== "stere" || Math.abs(latitude) !== 90 || key(direction) !== (north ? "south" : "north"))
10213
- unsupportedStage("Axis meridians require an outward-facing polar stereographic axis");
9222
+ (0, import_types5.unsupportedStage)("Axis meridians require an outward-facing polar stereographic axis");
10214
9223
  const longitude = object(meridian)["longitude"];
10215
- const degrees2 = typeof longitude === "number" ? finite2(longitude) : finite2(object(longitude)["value"]) * unit(object(longitude)["unit"], DEGREES_TO_RADIANS) / DEGREES_TO_RADIANS;
10216
- const quarterTurns = finite2((degrees2 - Number(parameters["lon_0"] || 0)) / 90);
9224
+ const degrees2 = typeof longitude === "number" ? finite(longitude) : finite(object(longitude)["value"]) * unit(object(longitude)["unit"], DEGREES_TO_RADIANS) / DEGREES_TO_RADIANS;
9225
+ const quarterTurns = finite((degrees2 - Number(parameters["lon_0"] || 0)) / 90);
10217
9226
  if (Math.abs(quarterTurns - Math.round(quarterTurns)) > 1e-12)
10218
- unsupportedStage("Non-cardinal axis meridians require an orientation operation");
9227
+ (0, import_types5.unsupportedStage)("Non-cardinal axis meridians require an orientation operation");
10219
9228
  const quadrant = (Math.round(quarterTurns) % 4 + 4) % 4;
10220
9229
  return (north ? "senw" : "nesw")[quadrant];
10221
9230
  }
10222
9231
  const result = DIRECTIONS[key(direction)];
10223
9232
  if (!result)
10224
- unsupportedStage("Unsupported axis direction: " + direction);
9233
+ (0, import_types5.unsupportedStage)("Unsupported axis direction: " + direction);
10225
9234
  return result;
10226
9235
  }
10227
9236
 
@@ -10260,7 +9269,7 @@ function operation(node) {
10260
9269
  if (!method)
10261
9270
  throw new Error("WKT conversion requires a METHOD or PROJECTION");
10262
9271
  if (child(node, "PARAMETERFILE"))
10263
- unsupportedStage("Grid-based WKT operation is not implemented");
9272
+ (0, import_types6.unsupportedStage)("Grid-based WKT operation is not implemented");
10264
9273
  return {
10265
9274
  method: { name: value(method) },
10266
9275
  parameters: children(node, "PARAMETER").map((parameter) => ({
@@ -10315,9 +9324,9 @@ function readWKT(node) {
10315
9324
  "GEOCCS"
10316
9325
  ].includes(keyword);
10317
9326
  if (!projected && !geographic)
10318
- unsupportedStage("Unsupported WKT CRS: " + keyword);
9327
+ (0, import_types6.unsupportedStage)("Unsupported WKT CRS: " + keyword);
10319
9328
  if (child(node, "DYNAMIC", "DERIVINGCONVERSION", "VELOCITYGRID", "EXTENSION"))
10320
- unsupportedStage("Unsupported WKT dynamic/extension operation");
9329
+ (0, import_types6.unsupportedStage)("Unsupported WKT dynamic/extension operation");
10321
9330
  const cs = child(node, "CS");
10322
9331
  const geocentric2 = keyword === "GEOCCS" || String(value(cs || node)).toLowerCase() === "cartesian" && !projected;
10323
9332
  const localUnit = child(node, projected || geocentric2 ? "LENGTHUNIT" : "ANGLEUNIT", "UNIT");
@@ -10359,7 +9368,7 @@ function readWKT(node) {
10359
9368
  if (!datum)
10360
9369
  throw new Error("WKT requires a geodetic datum");
10361
9370
  if (child(datum, "EXTENSION", "DYNAMIC"))
10362
- unsupportedStage("Unsupported datum extension");
9371
+ (0, import_types6.unsupportedStage)("Unsupported datum extension");
10363
9372
  const ellipsoid = child(datum, "SPHEROID", "ELLIPSOID");
10364
9373
  if (!ellipsoid)
10365
9374
  throw new Error("WKT datum requires an ellipsoid");
@@ -10551,7 +9560,7 @@ function parseNTv2Grid(data, options = {}) {
10551
9560
 
10552
9561
  // dist/projection/experimental/grids/geotiff.js
10553
9562
  async function loadGeoTIFFGrid(tiff) {
10554
- var _a2;
9563
+ var _a;
10555
9564
  const count = await tiff.getImageCount();
10556
9565
  if (!Number.isSafeInteger(count) || count < 1)
10557
9566
  throw new Error("GeoTIFF requires at least one image");
@@ -10571,7 +9580,7 @@ async function loadGeoTIFFGrid(tiff) {
10571
9580
  const rasters = await image.readRasters(), latitude = rasters[0], longitude = rasters[1];
10572
9581
  if (!latitude || !longitude || typeof latitude === "number" || typeof longitude === "number" || latitude.length !== width * height || longitude.length !== width * height)
10573
9582
  throw new Error("GeoTIFF requires latitude and longitude offset bands");
10574
- const nodata = (_a2 = image.getGDALNoData) == null ? void 0 : _a2.call(image);
9583
+ const nodata = (_a = image.getGDALNoData) == null ? void 0 : _a.call(image);
10575
9584
  const shifts = new Float64Array(width * height * 2);
10576
9585
  let node = 0;
10577
9586
  for (let row = height - 1; row >= 0; row--)
@@ -10704,7 +9713,7 @@ function vector(value2, length) {
10704
9713
  return result;
10705
9714
  }
10706
9715
  async function prepareScalarGeoTIFFGrids(tiff) {
10707
- var _a2;
9716
+ var _a;
10708
9717
  const count = "images" in tiff ? tiff.images.length : await tiff.getImageCount();
10709
9718
  if (!Number.isSafeInteger(count) || count < 1)
10710
9719
  throw new Error("Vertical GeoTIFF requires at least one image");
@@ -10754,7 +9763,7 @@ async function prepareScalarGeoTIFFGrids(tiff) {
10754
9763
  const values = rasters[0];
10755
9764
  if (!values || typeof values === "number" || values.length !== width * height)
10756
9765
  throw new Error("Vertical GeoTIFF requires a complete non-interleaved height band");
10757
- const declaredNoData = (_a2 = image.getGDALNoData) == null ? void 0 : _a2.call(image);
9766
+ const declaredNoData = (_a = image.getGDALNoData) == null ? void 0 : _a.call(image);
10758
9767
  const nodata = values instanceof Float32Array && typeof declaredNoData === "number" ? Math.fround(declaredNoData) : declaredNoData;
10759
9768
  const offsets = new Float64Array(width * height);
10760
9769
  for (let row = 0; row < height; row++)
@@ -10798,6 +9807,9 @@ async function loadVerticalGeoTIFFGrid(tiff) {
10798
9807
  });
10799
9808
  }
10800
9809
 
9810
+ // dist/projection/experimental/projection-pipeline.js
9811
+ var import_types8 = require("./experimental/crs/types.shared.cjs");
9812
+
10801
9813
  // dist/projection/experimental/numeric-flat.js
10802
9814
  function createNumericFlat(steps) {
10803
9815
  const program = new Float64Array(steps.length * 7);
@@ -10849,6 +9861,40 @@ function createNumericFlat(steps) {
10849
9861
  };
10850
9862
  }
10851
9863
 
9864
+ // dist/projection/experimental/scalar-output.js
9865
+ var FLOAT32_MAX = 34028234663852886e22;
9866
+ function validateScalarOutput(coordinate, output, length) {
9867
+ if (!(Array.isArray(coordinate) || coordinate instanceof Float32Array || coordinate instanceof Float64Array))
9868
+ throw new Error("Scalar input requires a number array, Float32Array or Float64Array");
9869
+ if (!(Array.isArray(output) || output instanceof Float32Array || output instanceof Float64Array) || output.length < length)
9870
+ throw new Error("Scalar output requires a preallocated number array, Float32Array or Float64Array with sufficient capacity");
9871
+ if (coordinate === output || Array.isArray(coordinate) || Array.isArray(output))
9872
+ return;
9873
+ const input = coordinate;
9874
+ const result = output;
9875
+ const shared = typeof SharedArrayBuffer !== "undefined" && input.buffer instanceof SharedArrayBuffer && result.buffer instanceof SharedArrayBuffer;
9876
+ if ((input.buffer === result.buffer || shared) && input.byteOffset < result.byteOffset + length * result.BYTES_PER_ELEMENT && result.byteOffset < input.byteOffset + input.byteLength)
9877
+ throw new Error("Scalar input/output views overlap; use the same view for in-place projection");
9878
+ }
9879
+ function writeScalarOutput(coordinate, output, point, length) {
9880
+ if (output instanceof Float32Array) {
9881
+ if (Math.abs(point.x) > FLOAT32_MAX || Math.abs(point.y) > FLOAT32_MAX || length >= 3 && Math.abs(point.z) > FLOAT32_MAX)
9882
+ throw new Error("Projected coordinate exceeds Float32 range");
9883
+ for (let i = 3; i < coordinate.length; i++) {
9884
+ const value2 = coordinate[i];
9885
+ if (Number.isFinite(value2) && Math.abs(value2) > FLOAT32_MAX)
9886
+ throw new Error("Trailing ordinate exceeds Float32 range");
9887
+ }
9888
+ }
9889
+ for (let i = 3; i < coordinate.length; i++)
9890
+ output[i] = coordinate[i];
9891
+ output[0] = point.x;
9892
+ output[1] = point.y;
9893
+ if (length >= 3)
9894
+ output[2] = point.z;
9895
+ return output;
9896
+ }
9897
+
10852
9898
  // dist/projection/experimental/helmert-flat.js
10853
9899
  function createHelmertFlat(coefficients, inverse33, exact) {
10854
9900
  const dx = coefficients[9], dy = coefficients[10], dz = coefficients[11], scale2 = coefficients[12];
@@ -11062,6 +10108,44 @@ function createKinematicHelmert(translation, rotation2, scalePPM, rates, referen
11062
10108
  };
11063
10109
  }
11064
10110
 
10111
+ // dist/projection/experimental/vertical-datum.js
10112
+ var import_types7 = require("./experimental/crs/types.shared.cjs");
10113
+ function compileVerticalGrid(names, grids = {}) {
10114
+ if (names === void 0)
10115
+ return void 0;
10116
+ const entries = [];
10117
+ for (const entry of names.split(",")) {
10118
+ const optional = entry.startsWith("@");
10119
+ const name = optional ? entry.slice(1) : entry;
10120
+ if (!name || /\s/.test(name))
10121
+ throw new Error("Invalid vertical grid name");
10122
+ if (name === "null") {
10123
+ entries.push(null);
10124
+ break;
10125
+ }
10126
+ const grid = Object.prototype.hasOwnProperty.call(grids, name) ? grids[name] : void 0;
10127
+ if (grid) {
10128
+ if (typeof grid.getOffset !== "function")
10129
+ throw new Error("Invalid vertical grid: " + name);
10130
+ entries.push(grid.getOffset.bind(grid));
10131
+ } else if (!optional)
10132
+ (0, import_types7.unsupportedStage)("Required vertical grid is not registered: " + name);
10133
+ }
10134
+ return (longitude, latitude) => {
10135
+ for (const sample of entries) {
10136
+ if (!sample)
10137
+ return 0;
10138
+ const offset = sample(longitude, latitude);
10139
+ if (offset === void 0)
10140
+ continue;
10141
+ if (!Number.isFinite(offset))
10142
+ throw new Error("Vertical grid returned a non-finite offset");
10143
+ return offset;
10144
+ }
10145
+ throw new Error("No vertical grid covers this coordinate");
10146
+ };
10147
+ }
10148
+
11065
10149
  // dist/projection/experimental/projection-pipeline.js
11066
10150
  var EMPTY_STACK = new Float64Array(0);
11067
10151
  var ordinaryByteLength = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
@@ -11093,7 +10177,7 @@ function keys(value2, allowed) {
11093
10177
  throw new Error("Expected operation object");
11094
10178
  for (const name of Object.keys(value2))
11095
10179
  if (!allowed.includes(name))
11096
- unsupportedStage("Unsupported pipeline parameter: " + name);
10180
+ (0, import_types8.unsupportedStage)("Unsupported pipeline parameter: " + name);
11097
10181
  }
11098
10182
  function definition(name, parameters = {}) {
11099
10183
  if (!/^[a-z][a-z0-9_]*$/i.test(name))
@@ -11104,7 +10188,7 @@ function definition(name, parameters = {}) {
11104
10188
  return " +" + key2 + (value2 === void 0 ? "" : "=" + value2);
11105
10189
  }).join("");
11106
10190
  }
11107
- function finite3(point) {
10191
+ function finite2(point) {
11108
10192
  if (!Number.isFinite(point.x) || !Number.isFinite(point.y) || !Number.isFinite(point.z))
11109
10193
  throw new Error("Pipeline coordinate must be finite");
11110
10194
  }
@@ -11238,7 +10322,7 @@ var ProjectionPipeline = class {
11238
10322
  return;
11239
10323
  for (const registration of this.required)
11240
10324
  if (!getLoadedProjection(registration))
11241
- unsupportedStage("Pipeline projection requires preload(): " + registration.name);
10325
+ (0, import_types8.unsupportedStage)("Pipeline projection requires preload(): " + registration.name);
11242
10326
  const forward33 = this.forwardFactories.map((factory) => factory()), inverse33 = this.inverseFactories.map((factory) => factory());
11243
10327
  this.compiled = {
11244
10328
  forward: forward33.map((pair2) => pair2.forward),
@@ -11252,7 +10336,7 @@ var ProjectionPipeline = class {
11252
10336
  return inverse33 ? this.compiled.inverse : this.compiled.forward;
11253
10337
  }
11254
10338
  scalar(coordinate, inverse33, epoch, output) {
11255
- var _a2;
10339
+ var _a;
11256
10340
  this.coordinateEpoch(epoch);
11257
10341
  if (coordinate.length < (this.requiresZ ? 3 : 2))
11258
10342
  throw new Error("Pipeline requires " + (this.requiresZ ? "XYZ" : "XY") + " coordinates");
@@ -11265,7 +10349,7 @@ var ProjectionPipeline = class {
11265
10349
  let stack = EMPTY_STACK;
11266
10350
  if (this.stackSize) {
11267
10351
  const depth = this.coordinateScratch.depth - 1;
11268
- stack = (_a2 = this.coordinateStacks)[depth] || (_a2[depth] = new Float64Array(this.stackSize));
10352
+ stack = (_a = this.coordinateStacks)[depth] || (_a[depth] = new Float64Array(this.stackSize));
11269
10353
  }
11270
10354
  this.run(point, operations, stack, epoch);
11271
10355
  if (output)
@@ -11281,7 +10365,7 @@ var ProjectionPipeline = class {
11281
10365
  }
11282
10366
  }
11283
10367
  flat(coordinates, dimension, inverse33, epochs) {
11284
- var _a2;
10368
+ var _a;
11285
10369
  if (!(coordinates instanceof Float32Array || coordinates instanceof Float64Array) || !Number.isSafeInteger(dimension) || dimension < (this.requiresZ ? 3 : 2) || coordinates.length % dimension)
11286
10370
  throw new Error("Pipeline requires Float32Array/Float64Array and a valid XY/XYZ stride");
11287
10371
  if (epochs === void 0)
@@ -11306,7 +10390,7 @@ var ProjectionPipeline = class {
11306
10390
  let stack = EMPTY_STACK;
11307
10391
  if (this.stackSize) {
11308
10392
  const depth = this.coordinateScratch.depth - 1;
11309
- stack = (_a2 = this.coordinateStacks)[depth] || (_a2[depth] = new Float64Array(this.stackSize));
10393
+ stack = (_a = this.coordinateStacks)[depth] || (_a[depth] = new Float64Array(this.stackSize));
11310
10394
  }
11311
10395
  const epochBuffer = typeof epochs === "number" ? void 0 : epochs;
11312
10396
  let epoch = typeof epochs === "number" ? epochs : void 0;
@@ -11339,10 +10423,10 @@ var ProjectionPipeline = class {
11339
10423
  throw new Error("Coordinate epoch must be a finite decimal year");
11340
10424
  }
11341
10425
  run(point, operations, stack, epoch) {
11342
- finite3(point);
10426
+ finite2(point);
11343
10427
  for (const operation2 of operations) {
11344
10428
  operation2(point, stack, epoch);
11345
- finite3(point);
10429
+ finite2(point);
11346
10430
  }
11347
10431
  }
11348
10432
  balanced(state) {
@@ -11350,7 +10434,7 @@ var ProjectionPipeline = class {
11350
10434
  throw new Error("Pipeline stack has unbalanced push/pop operations");
11351
10435
  }
11352
10436
  prepare(step, state, options, cache2) {
11353
- var _a2, _b, _c;
10437
+ var _a, _b, _c;
11354
10438
  const allowed = {
11355
10439
  unitconvert: ["xy", "z"],
11356
10440
  axisswap: ["order"],
@@ -11372,7 +10456,7 @@ var ProjectionPipeline = class {
11372
10456
  vgridshift: ["grids", "multiplier"]
11373
10457
  };
11374
10458
  if (!step || !own2(allowed, step.type))
11375
- unsupportedStage("Unsupported pipeline operation: " + (step == null ? void 0 : step.type));
10459
+ (0, import_types8.unsupportedStage)("Unsupported pipeline operation: " + (step == null ? void 0 : step.type));
11376
10460
  keys(step, ["type", "inverse", "omitForward", "omitInverse", ...allowed[step.type]]);
11377
10461
  if (step.inverse !== void 0 && typeof step.inverse !== "boolean")
11378
10462
  throw new Error("Invalid pipeline inverse flag");
@@ -11470,34 +10554,34 @@ var ProjectionPipeline = class {
11470
10554
  const key2 = (name) => name.toLowerCase().replace(/[\s_-]/g, "");
11471
10555
  if (typeof step.name !== "string")
11472
10556
  throw new Error("Invalid projection name");
11473
- const registration = (_a2 = options.projections) == null ? void 0 : _a2.find((p) => [p.name, ...p.aliases || []].some((name) => key2(name) === key2(step.name)));
10557
+ const registration = (_a = options.projections) == null ? void 0 : _a.find((p) => [p.name, ...p.aliases || []].some((name) => key2(name) === key2(step.name)));
11474
10558
  if (!registration)
11475
- unsupportedStage("Pipeline projection is not registered: " + step.name);
10559
+ (0, import_types8.unsupportedStage)("Pipeline projection is not registered: " + step.name);
11476
10560
  if (!this.required.includes(registration))
11477
10561
  this.required.push(registration);
11478
10562
  const parameters = { ...step.parameters };
11479
10563
  for (const name of Object.keys(parameters))
11480
10564
  if (CORE_PARAMETERS.includes(name) && !geometryKeys.includes(name) && name !== "over")
11481
- unsupportedStage("Unsupported pipeline parameter: " + name);
10565
+ (0, import_types8.unsupportedStage)("Unsupported pipeline parameter: " + name);
11482
10566
  const oblique = key2(registration.name) === "obtran";
11483
10567
  const geographicChild = ["longlat", "latlong", "latlon", "lonlat", "identity"].includes(key2(parameters["o_proj"] || ""));
11484
10568
  if (oblique && (!step.output || !parameters["o_proj"]))
11485
- unsupportedStage("Oblique helper pipelines require an explicit output-unit contract and o_proj");
10569
+ (0, import_types8.unsupportedStage)("Oblique helper pipelines require an explicit output-unit contract and o_proj");
11486
10570
  if ((oblique && geographicChild) !== (output.space === "geographic"))
11487
10571
  throw new Error("Projection output contract does not match its algorithm");
11488
10572
  const scale2 = geographicChild && output.unit === "rad" ? Math.PI / 180 : 1;
11489
10573
  const normalized = normalizeCRS(definition(registration.name, parameters));
11490
10574
  if (normalized.kind !== "projected")
11491
- unsupportedStage("Use a cart step for geocentric conversion");
10575
+ (0, import_types8.unsupportedStage)("Use a cart step for geocentric conversion");
11492
10576
  return () => {
11493
- var _a3;
10577
+ var _a2;
11494
10578
  if (cache2.pair)
11495
10579
  return orient(cache2.pair);
11496
10580
  const plugin = getLoadedProjection(registration);
11497
10581
  if (!plugin)
11498
- unsupportedStage("Pipeline projection requires preload(): " + registration.name);
10582
+ (0, import_types8.unsupportedStage)("Pipeline projection requires preload(): " + registration.name);
11499
10583
  if (key2(plugin.name) === "obtran" !== oblique)
11500
- unsupportedStage("Pipeline projection requires a matching projected-metre output contract: " + plugin.name);
10584
+ (0, import_types8.unsupportedStage)("Pipeline projection requires a matching projected-metre output contract: " + plugin.name);
11501
10585
  if ([
11502
10586
  "geocent",
11503
10587
  "geocentric",
@@ -11507,10 +10591,10 @@ var ProjectionPipeline = class {
11507
10591
  "latlon",
11508
10592
  "lonlat"
11509
10593
  ].includes(key2(plugin.name)))
11510
- unsupportedStage("Pipeline projection requires a projected-metre output contract: " + plugin.name);
10594
+ (0, import_types8.unsupportedStage)("Pipeline projection requires a projected-metre output contract: " + plugin.name);
11511
10595
  keys(parameters, [...geometryKeys, "over", ...plugin.parameters]);
11512
10596
  for (const [name, value2] of Object.entries(parameters)) {
11513
- const flag = name === "over" || ((_a3 = plugin.flags) == null ? void 0 : _a3.includes(name));
10597
+ const flag = name === "over" || ((_a2 = plugin.flags) == null ? void 0 : _a2.includes(name));
11514
10598
  if (flag && value2 !== void 0)
11515
10599
  throw new Error("Expected a flag without a value: " + name);
11516
10600
  if (!flag && value2 === void 0)
@@ -11682,7 +10766,7 @@ var ProjectionPipeline = class {
11682
10766
  const grids = crs.datum.grids.map((reference) => {
11683
10767
  const grid = own2(options.datumGrids || {}, reference.name) ? options.datumGrids[reference.name] : void 0;
11684
10768
  if (reference.name !== "null" && !grid && !reference.optional)
11685
- unsupportedStage("Required datum grid is not registered: " + reference.name);
10769
+ (0, import_types8.unsupportedStage)("Required datum grid is not registered: " + reference.name);
11686
10770
  if (grid && typeof grid.shift !== "function")
11687
10771
  throw new Error("Invalid datum grid: " + reference.name);
11688
10772
  return { ...reference, grid };
@@ -11711,6 +10795,9 @@ var ProjectionPipeline = class {
11711
10795
  }
11712
10796
  };
11713
10797
 
10798
+ // dist/projection/lib/projection.js
10799
+ var import_projection_engine2 = require("./experimental/projection-engine.shared.cjs");
10800
+
11714
10801
  // dist/projection/experimental/crs/datum-table.js
11715
10802
  var datums = {
11716
10803
  ch1903: {
@@ -13153,7 +12240,7 @@ function defaultProjections() {
13153
12240
  preset = [...projections, oblique];
13154
12241
  return preset;
13155
12242
  }
13156
- var FullProjectionEngine = class extends ConfigurableProjectionEngine {
12243
+ var FullProjectionEngine = class extends import_projection_engine2.ConfigurableProjectionEngine {
13157
12244
  constructor(options = {}) {
13158
12245
  super({
13159
12246
  ...options,
@@ -13161,7 +12248,7 @@ var FullProjectionEngine = class extends ConfigurableProjectionEngine {
13161
12248
  parsers: options.parsers ?? compatibilityParsers,
13162
12249
  datumCatalogs: options.datumCatalogs ?? [datumCatalog]
13163
12250
  });
13164
- this.useDefinitionSignature = !hasCRSOverrides(options);
12251
+ this.useDefinitionSignature = !(0, import_projection_engine2.hasCRSOverrides)(options);
13165
12252
  }
13166
12253
  };
13167
12254
  var projectionEngine = new FullProjectionEngine();