@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
@@ -0,0 +1,2523 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // dist/coordinates.js
20
+ var coordinates_exports = {};
21
+ __export(coordinates_exports, {
22
+ LocalReferenceFrame: () => LocalReferenceFrame,
23
+ eastNorthUpToFixedFrame: () => eastNorthUpToFixedFrame,
24
+ formatAngle: () => formatAngle,
25
+ formatGeographicCoordinates: () => formatGeographicCoordinates,
26
+ formatMGRS: () => formatMGRS,
27
+ formatMGRSZone: () => formatMGRSZone,
28
+ localFrameToFixedFrame: () => localFrameToFixedFrame2,
29
+ parseAngle: () => parseAngle,
30
+ parseGeographicCoordinates: () => parseGeographicCoordinates,
31
+ parseMGRS: () => parseMGRS,
32
+ parseMGRSZone: () => parseMGRSZone,
33
+ projectGrid: () => projectGrid,
34
+ standardGridZone: () => standardGridZone,
35
+ transferGrid: () => transferGrid,
36
+ unprojectGrid: () => unprojectGrid
37
+ });
38
+ module.exports = __toCommonJS(coordinates_exports);
39
+
40
+ // dist/coordinates/angles.js
41
+ function validate(value, axis) {
42
+ if (!["angle", "latitude", "longitude"].includes(axis) || !Number.isFinite(value) || Math.abs(value) > (axis === "latitude" ? 90 : axis === "longitude" ? 180 : 1e6))
43
+ throw new RangeError("Angle is outside the requested axis domain");
44
+ }
45
+ function parseAngle(text, axis = "angle") {
46
+ if (typeof text !== "string" || text.length > 256)
47
+ throw new RangeError("Invalid angle text");
48
+ let value = text.trim().replace(/−/g, "-").toUpperCase(), hemisphere = "";
49
+ if (/^[NSEW]/.test(value)) {
50
+ hemisphere = value[0];
51
+ value = value.slice(1).trim();
52
+ }
53
+ if (/[NSEW]$/.test(value)) {
54
+ if (hemisphere)
55
+ throw new RangeError("Use one hemisphere");
56
+ hemisphere = value.slice(-1);
57
+ value = value.slice(0, -1).trim();
58
+ }
59
+ if (hemisphere && /^[+-]/.test(value))
60
+ throw new RangeError("Use a sign or hemisphere, not both");
61
+ if (axis === "latitude" && /[EW]/.test(hemisphere) || axis === "longitude" && /[NS]/.test(hemisphere))
62
+ throw new RangeError("Hemisphere does not match axis");
63
+ value = value.replace(/\s*([:D°'′"″])\s*/g, "$1");
64
+ const number = "(\\d+(?:\\.\\d*)?|\\.\\d+)";
65
+ const component = new RegExp("^([+-]?)" + number + `(['\u2032]|["\u2033])$`).exec(value);
66
+ if (component) {
67
+ if (Number(component[2]) >= 60)
68
+ throw new RangeError("Invalid DMS components");
69
+ const result2 = (component[1] === "-" || /[SW]/.test(hemisphere) ? -1 : 1) * Number(component[2]) / (/[′']/.test(component[3]) ? 60 : 3600);
70
+ validate(result2, axis);
71
+ return result2;
72
+ }
73
+ const decimal = new RegExp("^([+-]?)" + number + "[D\xB0]?$").exec(value);
74
+ const colon = new RegExp("^([+-]?)" + number + ":" + number + "(?::" + number + ")?$").exec(value);
75
+ const marked = new RegExp("^([+-]?)" + number + "[D\xB0]" + number + "['\u2032](?:" + number + '["\u2033])?$').exec(value);
76
+ const parts = decimal ?? colon ?? marked;
77
+ if (!parts)
78
+ throw new RangeError("Expected decimal degrees, colon DMS or marked DMS");
79
+ const degrees = Number(parts[2]), minutes = Number(parts[3] ?? 0), seconds = Number(parts[4] ?? 0);
80
+ if (minutes >= 60 || seconds >= 60 || parts[3] !== void 0 && !Number.isInteger(degrees) || parts[4] !== void 0 && !Number.isInteger(minutes))
81
+ throw new RangeError("Invalid DMS components");
82
+ const sign = parts[1] === "-" || /[SW]/.test(hemisphere) ? -1 : 1;
83
+ const result = sign * (degrees + minutes / 60 + seconds / 3600);
84
+ validate(result, axis);
85
+ return result;
86
+ }
87
+ function formatAngle(value, options = {}) {
88
+ const axis = options.axis ?? "angle", format = options.format ?? "dms", precision = options.precision ?? 3;
89
+ validate(value, axis);
90
+ if (!Number.isInteger(precision) || precision < 0 || precision > 6 || !["degrees", "dm", "dms"].includes(format))
91
+ throw new RangeError("Invalid angle format or precision");
92
+ const negative = value < 0 || Object.is(value, -0), suffix = axis === "latitude" ? negative ? "S" : "N" : axis === "longitude" ? negative ? "W" : "E" : "";
93
+ const prefix = axis === "angle" && negative ? "-" : "";
94
+ if (format === "degrees")
95
+ return prefix + Math.abs(value).toFixed(precision) + "\xB0" + suffix;
96
+ if (format === "dm") {
97
+ const factor2 = 10 ** precision, ticks2 = Math.round(Math.abs(value) * 60 * factor2);
98
+ if (!Number.isSafeInteger(ticks2))
99
+ throw new RangeError("DM precision exceeds exact integer range");
100
+ return prefix + Math.floor(ticks2 / (60 * factor2)) + "\xB0" + (ticks2 % (60 * factor2) / factor2).toFixed(precision).padStart(precision ? 3 + precision : 2, "0") + "\u2032" + suffix;
101
+ }
102
+ const factor = 10 ** precision, ticks = Math.round(Math.abs(value) * 3600 * factor);
103
+ if (!Number.isSafeInteger(ticks))
104
+ throw new RangeError("DMS precision exceeds exact integer range");
105
+ const degrees = Math.floor(ticks / (3600 * factor)), minutes = Math.floor(ticks / (60 * factor)) % 60, seconds = ticks % (60 * factor) / factor;
106
+ return prefix + degrees + "\xB0" + String(minutes).padStart(2, "0") + "\u2032" + seconds.toFixed(precision).padStart(precision ? 3 + precision : 2, "0") + "\u2033" + suffix;
107
+ }
108
+ function parseGeographicCoordinates(text, options = {}) {
109
+ if (typeof text !== "string" || text.length > 512)
110
+ throw new RangeError("Invalid coordinate text");
111
+ const pair = text.split(",");
112
+ if (pair.length !== 2)
113
+ throw new RangeError("Use latitude, longitude");
114
+ const [lat, lon] = options.longitudeFirst ? [pair[1], pair[0]] : pair;
115
+ return {
116
+ latitude: parseAngle(lat, "latitude"),
117
+ longitude: parseAngle(lon, "longitude")
118
+ };
119
+ }
120
+ function formatGeographicCoordinates(latitude, longitude, options = {}) {
121
+ const lat = formatAngle(latitude, { ...options, axis: "latitude" }), lon = formatAngle(longitude, { ...options, axis: "longitude" });
122
+ return (options.longitudeFirst ? [lon, lat] : [lat, lon]).join(", ");
123
+ }
124
+
125
+ // dist/projection/experimental/parameters.js
126
+ var DEGREES_TO_RADIANS = Math.PI / 180;
127
+ function numberParameter(parameters, name, fallback) {
128
+ if (!Object.prototype.hasOwnProperty.call(parameters, name))
129
+ return fallback;
130
+ const value = parameters[name];
131
+ if (typeof value !== "string" || !/^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i.test(value)) {
132
+ throw new Error(`Invalid numeric PROJ parameter: +${name}`);
133
+ }
134
+ const number = Number(value);
135
+ if (!Number.isFinite(number))
136
+ throw new Error(`Invalid numeric PROJ parameter: +${name}`);
137
+ return number;
138
+ }
139
+ function wrapLongitude(longitude, over = false) {
140
+ if (over || Math.abs(longitude) <= Math.PI)
141
+ return longitude;
142
+ const circle = 2 * Math.PI;
143
+ return ((longitude + Math.PI) % circle + circle) % circle - Math.PI;
144
+ }
145
+
146
+ // dist/projection/experimental/rendering-profile/rendering-bounds.js
147
+ var ordered = (a, b) => [Math.min(a, b), Math.max(a, b)];
148
+ var add = (a, b) => [a[0] + b[0], a[1] + b[1]];
149
+ var scale = (a, value) => ordered(a[0] * value, a[1] * value);
150
+ var maxAbs = (a) => Math.max(Math.abs(a[0]), Math.abs(a[1]));
151
+ function envelope(x, y) {
152
+ const padding = (range) => Math.max(1, maxAbs(range)) * 1e-12;
153
+ if (![...x, ...y].every(Number.isFinite))
154
+ throw new Error("Projection rendering bounds are not finite");
155
+ return [
156
+ [x[0] - padding(x), y[0] - padding(y), 0],
157
+ [x[1] + padding(x), y[1] + padding(y), 0]
158
+ ];
159
+ }
160
+ function longitudeRange(parameters, origin, over = false) {
161
+ const low = parameters[0][0] - origin, high = parameters[1][0] - origin;
162
+ if (over)
163
+ return [low, high];
164
+ const span = high - low;
165
+ if (span >= 2 * Math.PI - 1e-12)
166
+ return [-Math.PI, Math.PI];
167
+ let west = wrapLongitude(low);
168
+ if (span > 0 && Math.abs(west - Math.PI) < 1e-12)
169
+ west = -Math.PI;
170
+ const east = west + span;
171
+ return east > Math.PI + 1e-12 ? [-Math.PI, Math.PI] : [west, Math.min(east, Math.PI)];
172
+ }
173
+ function transverseBounds(project, parameters, origin, over = false, equator = 0) {
174
+ const longitude = longitudeRange(parameters, origin, over);
175
+ if (maxAbs(longitude) > Math.PI / 6 + 1e-12)
176
+ throw new Error("Unsupported transverse rendering coverage");
177
+ const longitudes = [
178
+ longitude[0],
179
+ longitude[1],
180
+ Math.max(longitude[0], Math.min(longitude[1], 0))
181
+ ];
182
+ const latitudes = [
183
+ parameters[0][1],
184
+ parameters[1][1],
185
+ Math.max(parameters[0][1], Math.min(parameters[1][1], equator))
186
+ ];
187
+ const points = longitudes.flatMap((x) => latitudes.map((y) => project(origin + x, y)));
188
+ 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]))]);
189
+ }
190
+
191
+ // dist/projection/experimental/rendering-profile/geographic-bounds.js
192
+ var RADIANS = Math.PI / 180;
193
+ function createAngularRanges(west, south, east, north) {
194
+ return [
195
+ [west, south],
196
+ [east, north]
197
+ ];
198
+ }
199
+ function normalizeLongitude(longitude) {
200
+ return longitude >= -180 && longitude < 180 ? longitude : ((longitude + 180) % 360 + 360) % 360 - 180;
201
+ }
202
+ function createGeographicBounds(west, south, east, north) {
203
+ if (![west, south, east, north].every(Number.isFinite) || south < -90 || north > 90 || south > north || east - west < -360 || east - west > 360 + 1e-10)
204
+ throw new Error("Invalid geographic coverage");
205
+ if (east - west >= 360 - 1e-10)
206
+ return [-180, south, 180, north];
207
+ const wrappedEast = normalizeLongitude(east);
208
+ return [
209
+ normalizeLongitude(west),
210
+ south,
211
+ wrappedEast === -180 && east > west ? 180 : wrappedEast,
212
+ north
213
+ ];
214
+ }
215
+ function getLongitudeSpan(bounds) {
216
+ const span = bounds[2] - bounds[0];
217
+ return span < 0 ? span + 360 : span;
218
+ }
219
+ function splitGeographicBounds(bounds) {
220
+ const [west, south, east, north] = bounds;
221
+ return west <= east ? [bounds] : [
222
+ [west, south, 180, north],
223
+ [-180, south, east, north]
224
+ ];
225
+ }
226
+ function containsGeographicPoint(bounds, point) {
227
+ const [west, south, east, north] = bounds;
228
+ const longitude = normalizeLongitude(point[0]);
229
+ return point[1] >= south && point[1] <= north && (west <= east ? longitude >= west && longitude <= east || longitude === -180 && east === 180 : longitude >= west || longitude <= east);
230
+ }
231
+ function intersectGeographicBounds(a, b) {
232
+ const south = Math.max(a[1], b[1]), north = Math.min(a[3], b[3]);
233
+ if (south > north)
234
+ return [];
235
+ const intervals = [];
236
+ for (const left of splitGeographicBounds(a))
237
+ for (const right of splitGeographicBounds(b)) {
238
+ const west = Math.max(left[0], right[0]), east = Math.min(left[2], right[2]);
239
+ if (west <= east)
240
+ intervals.push([west, east]);
241
+ else if (left[2] === 180 && right[0] === -180 || right[2] === 180 && left[0] === -180)
242
+ intervals.push([-180, -180]);
243
+ }
244
+ intervals.sort((left, right) => left[0] - right[0]);
245
+ const merged = [];
246
+ for (const interval of intervals) {
247
+ const last = merged[merged.length - 1];
248
+ if (last && interval[0] <= last[1])
249
+ last[1] = Math.max(last[1], interval[1]);
250
+ else
251
+ merged.push([...interval]);
252
+ }
253
+ if (merged.length > 1 && merged[0][0] === -180 && merged[merged.length - 1][1] === 180) {
254
+ const first = merged.shift(), last = merged.pop();
255
+ return [
256
+ [last[0], south, first[1], north],
257
+ ...merged.map(([west, east]) => [west, south, east, north])
258
+ ];
259
+ }
260
+ return merged.map(([west, east]) => [west, south, east, north]);
261
+ }
262
+ function clampGeographicPoint(bounds, point) {
263
+ let longitude = normalizeLongitude(point[0]);
264
+ const latitude = Math.max(bounds[1], Math.min(bounds[3], point[1]));
265
+ if (!containsGeographicPoint(bounds, [longitude, latitude])) {
266
+ const westDistance = Math.abs(normalizeLongitude(longitude - bounds[0]));
267
+ const eastDistance = Math.abs(normalizeLongitude(longitude - bounds[2]));
268
+ longitude = westDistance <= eastDistance ? bounds[0] : bounds[2];
269
+ }
270
+ return [longitude, latitude];
271
+ }
272
+ function getAngularRanges(bounds, primeMeridian = 0, origin = 0) {
273
+ const width = getLongitudeSpan(bounds);
274
+ const west = bounds[0] * RADIANS - primeMeridian;
275
+ const middle = west + width * RADIANS / 2;
276
+ const shift = Math.round((origin - middle) / (2 * Math.PI)) * 2 * Math.PI;
277
+ return createAngularRanges(width === 360 ? origin - Math.PI : west + shift, bounds[1] * RADIANS, width === 360 ? origin + Math.PI : west + shift + width * RADIANS, bounds[3] * RADIANS);
278
+ }
279
+ function getGeographicBounds(ranges, primeMeridian = 0) {
280
+ return createGeographicBounds((ranges[0][0] + primeMeridian) / RADIANS, ranges[0][1] / RADIANS, (ranges[1][0] + primeMeridian) / RADIANS, ranges[1][1] / RADIANS);
281
+ }
282
+ function unionRenderingBounds(bounds) {
283
+ if (!bounds.length)
284
+ throw new Error("CRS coverage does not intersect the rendering target");
285
+ return [
286
+ [0, 1, 2].map((axis) => Math.min(...bounds.map((pair) => pair[0][axis]))),
287
+ [0, 1, 2].map((axis) => Math.max(...bounds.map((pair) => pair[1][axis])))
288
+ ];
289
+ }
290
+
291
+ // dist/projection/experimental/rendering-profile/rendering-profile.js
292
+ function resolveBounds(profile) {
293
+ var _a;
294
+ const bounds = profile.bounds;
295
+ if (bounds.some((corner) => corner.some((value) => !Number.isFinite(value))))
296
+ throw new Error("Projection rendering bounds must be finite");
297
+ return { bounds, normalize: (_a = profile.normalize) == null ? void 0 : _a.bind(profile) };
298
+ }
299
+ function createAngularNormalization(normalize, primeMeridian = 0) {
300
+ return (point) => {
301
+ const x = point.x * Math.PI / 180 - primeMeridian;
302
+ const y = point.y * Math.PI / 180;
303
+ const native = { x, y, z: point.z };
304
+ normalize(native);
305
+ if (native.x !== x)
306
+ point.x = (native.x + primeMeridian) * 180 / Math.PI;
307
+ if (native.y !== y)
308
+ point.y = native.y * 180 / Math.PI;
309
+ };
310
+ }
311
+ function combineRenderingProfiles(regions, getProfile) {
312
+ const profiles = [];
313
+ for (const region of regions) {
314
+ const profile = getProfile(region);
315
+ if (profile !== null)
316
+ profiles.push(resolveBounds(profile));
317
+ }
318
+ if (!profiles.length)
319
+ return null;
320
+ if (profiles.length === 1)
321
+ return profiles[0];
322
+ return {
323
+ bounds: unionRenderingBounds(profiles.map((profile) => profile.bounds)),
324
+ normalize(point) {
325
+ var _a;
326
+ let bestX = point.x, bestY = point.y, best = Infinity;
327
+ for (const profile of profiles) {
328
+ const candidate = { x: point.x, y: point.y, z: point.z };
329
+ (_a = profile.normalize) == null ? void 0 : _a.call(profile, candidate);
330
+ 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;
331
+ if (distance < best) {
332
+ best = distance;
333
+ bestX = candidate.x;
334
+ bestY = candidate.y;
335
+ }
336
+ }
337
+ point.x = bestX;
338
+ point.y = bestY;
339
+ }
340
+ };
341
+ }
342
+
343
+ // dist/projection/experimental/rendering-profile/rectangular-rendering-profile.js
344
+ function normalizeCoverage(point, coverage, center = 0, over = false) {
345
+ const span = getLongitudeSpan(coverage);
346
+ const west = span === 360 ? center - 180 : coverage[0] + Math.round((center - coverage[0] - span / 2) / 360) * 360;
347
+ const east = west + span;
348
+ if (over) {
349
+ point.x = Math.max(west, Math.min(east, point.x));
350
+ point.y = Math.max(coverage[1], Math.min(coverage[3], point.y));
351
+ return;
352
+ }
353
+ const best = clampGeographicPoint(coverage, [point.x, point.y]);
354
+ let longitude = best[0];
355
+ if (best[0] === normalizeLongitude(point.x) && point.x >= west && point.x <= east)
356
+ longitude = point.x;
357
+ else if (longitude < west || longitude > east)
358
+ longitude += Math.round(((west + east) / 2 - longitude) / 360) * 360;
359
+ const offset2 = longitude - center;
360
+ point.x = Math.abs(offset2) <= 180 ? longitude : center + normalizeLongitude(offset2);
361
+ point.y = best[1];
362
+ }
363
+ function createRectangleRenderingProfile(resolveBounds2, coverage, origin = 0, primeMeridian = 0, over = false) {
364
+ const center = (origin + primeMeridian) * 180 / Math.PI;
365
+ return {
366
+ get bounds() {
367
+ return resolveBounds2(getAngularRanges(coverage, primeMeridian, origin));
368
+ },
369
+ normalize(point) {
370
+ normalizeCoverage(point, coverage, center, over);
371
+ }
372
+ };
373
+ }
374
+ function createRegionsRenderingProfile(resolveBounds2, regions, origin, primeMeridian, over) {
375
+ const profile = combineRenderingProfiles(regions, (region) => createRectangleRenderingProfile(resolveBounds2, region, origin, primeMeridian, over));
376
+ if (!profile)
377
+ throw new Error("CRS coverage does not intersect the rendering target");
378
+ return profile;
379
+ }
380
+ function withRectangleRenderingProfile(implementation, parameters, resolveBounds2, primeMeridian = 0, over = false) {
381
+ const origin = (parameters[0][0] + parameters[1][0]) / 2;
382
+ const defaults = getGeographicBounds(parameters, primeMeridian);
383
+ const center = (origin + primeMeridian) * 180 / Math.PI;
384
+ return {
385
+ ...implementation,
386
+ longitudeOrigin: origin,
387
+ getRenderingProfile(coverage) {
388
+ if (!coverage)
389
+ return {
390
+ bounds: resolveBounds2(parameters),
391
+ normalize(point) {
392
+ normalizeCoverage(point, defaults, center, over);
393
+ }
394
+ };
395
+ try {
396
+ const profile = createRectangleRenderingProfile(resolveBounds2, coverage, origin, primeMeridian, over);
397
+ const bounds = profile.bounds;
398
+ return { bounds, normalize: profile.normalize };
399
+ } catch {
400
+ return createRegionsRenderingProfile(resolveBounds2, intersectGeographicBounds(coverage, defaults), origin, primeMeridian, over);
401
+ }
402
+ }
403
+ };
404
+ }
405
+
406
+ // dist/projection/experimental/projection-scratch.js
407
+ function createPoint() {
408
+ return { x: 0, y: 0, z: 0 };
409
+ }
410
+ var ProjectionScratch = class {
411
+ constructor() {
412
+ this.point = createPoint();
413
+ this.points = [this.point];
414
+ this.active = 0;
415
+ }
416
+ get depth() {
417
+ return this.active;
418
+ }
419
+ acquire() {
420
+ var _a;
421
+ const index = this.active++;
422
+ (_a = this.points)[index] || (_a[index] = createPoint());
423
+ return this.points[index];
424
+ }
425
+ release(point) {
426
+ if (this.active > 0 && this.points[this.active - 1] === point)
427
+ this.active--;
428
+ }
429
+ };
430
+
431
+ // dist/projection/experimental/mutable-projection.js
432
+ function createProjection(forward4, inverse4) {
433
+ const scratch = new ProjectionScratch();
434
+ const scalar = (x, y, operation) => {
435
+ const point = scratch.acquire();
436
+ try {
437
+ point.x = x;
438
+ point.y = y;
439
+ point.z = 0;
440
+ operation(point);
441
+ return [point.x, point.y];
442
+ } finally {
443
+ scratch.release(point);
444
+ }
445
+ };
446
+ return {
447
+ forward(x, y) {
448
+ return scalar(x, y, forward4);
449
+ },
450
+ inverse(x, y) {
451
+ return scalar(x, y, inverse4);
452
+ },
453
+ forwardInPlace: forward4,
454
+ inverseInPlace: inverse4
455
+ };
456
+ }
457
+ function projectionOperation(implementation, inverse4, geocentric = false) {
458
+ const mutable = inverse4 ? implementation.inverseInPlace : implementation.forwardInPlace;
459
+ if (mutable)
460
+ return mutable.bind(implementation);
461
+ if (geocentric) {
462
+ const operation2 = inverse4 ? implementation.inverse3D : implementation.forward3D;
463
+ return (point) => {
464
+ const output = operation2.call(implementation, [point.x, point.y, point.z]);
465
+ point.x = output[0];
466
+ point.y = output[1];
467
+ point.z = output[2];
468
+ };
469
+ }
470
+ const operation = inverse4 ? implementation.inverse : implementation.forward;
471
+ return (point) => {
472
+ const output = operation.call(implementation, point.x, point.y);
473
+ point.x = output[0];
474
+ point.y = output[1];
475
+ };
476
+ }
477
+
478
+ // dist/projection/experimental/kernel.js
479
+ var ORIGIN_PARAMETERS = ["lon_0", "lat_0", "x_0", "y_0"];
480
+ var SCALE_PARAMETERS = ["k", "k_0"];
481
+ function angleParameter(parameters, name, fallback = 0) {
482
+ const degrees = numberParameter(parameters, name, fallback);
483
+ if (name !== "lon_0" && Math.abs(degrees) > 90) {
484
+ throw new Error("Latitude parameter must be between -90 and 90 degrees: +" + name);
485
+ }
486
+ return degrees * DEGREES_TO_RADIANS;
487
+ }
488
+ function flagParameter(parameters, name) {
489
+ const present = Object.prototype.hasOwnProperty.call(parameters, name);
490
+ if (present && parameters[name] !== void 0)
491
+ throw new Error("Expected a flag without a value: +" + name);
492
+ return present;
493
+ }
494
+ function kernelParameters({ semiMajorAxis: a, eccentricitySquared: es, parameters, primeMeridian = 0 }) {
495
+ const k0 = numberParameter(parameters, "k_0", numberParameter(parameters, "k", 1));
496
+ if (k0 <= 0)
497
+ throw new Error("Projection scale must be positive");
498
+ return {
499
+ primeMeridian,
500
+ a,
501
+ b: a * Math.sqrt(1 - es),
502
+ es,
503
+ e: Math.sqrt(es),
504
+ ep2: es / (1 - es),
505
+ sphere: es === 0,
506
+ over: flagParameter(parameters, "over"),
507
+ long0: angleParameter(parameters, "lon_0"),
508
+ lat0: angleParameter(parameters, "lat_0"),
509
+ lat1: angleParameter(parameters, "lat_1"),
510
+ lat2: angleParameter(parameters, "lat_2", numberParameter(parameters, "lat_1", 0)),
511
+ lat_ts: angleParameter(parameters, "lat_ts", NaN),
512
+ x0: numberParameter(parameters, "x_0", 0),
513
+ y0: numberParameter(parameters, "y_0", 0),
514
+ k0
515
+ };
516
+ }
517
+ function bindKernel(name, state, forward4, inverse4, adapt = createProjection) {
518
+ const run = (operation, point) => {
519
+ const result = operation(state, point);
520
+ if (!result || typeof result !== "object" || !Number.isFinite(result.x) || !Number.isFinite(result.y))
521
+ throw new Error(name + ": coordinate outside projection domain or inverse did not converge");
522
+ point.x = result.x;
523
+ point.y = result.y;
524
+ };
525
+ return adapt((point) => run(forward4, point), (point) => run(inverse4, point));
526
+ }
527
+ function guardAzimuthalDomain(base, implementation) {
528
+ const forward4 = projectionOperation(implementation, false);
529
+ return createProjection((point) => {
530
+ const longitude = point.x, latitude = point.y;
531
+ const delta = Math.atan2(Math.sin(longitude - base.long0), Math.cos(longitude - base.long0));
532
+ const polar = Math.abs(Math.abs(base.lat0) - Math.PI / 2) < 1e-10;
533
+ if (Math.abs(latitude + base.lat0) < 1e-10 && (polar || Math.abs(Math.abs(delta) - Math.PI) < 1e-10))
534
+ throw new Error("Azimuthal projection is undefined at the antipode");
535
+ forward4(point);
536
+ }, projectionOperation(implementation, true));
537
+ }
538
+
539
+ // dist/projection/experimental/flat-projection.js
540
+ function createFlatProjection(forward4, inverse4) {
541
+ return {
542
+ ...createProjection(forward4, inverse4),
543
+ createForwardFlat(context) {
544
+ return this.forwardInPlace === forward4 ? createFlatOperation(forward4, false, context) : void 0;
545
+ },
546
+ createInverseFlat(context) {
547
+ return this.inverseInPlace === inverse4 ? createFlatOperation(inverse4, true, context) : void 0;
548
+ }
549
+ };
550
+ }
551
+ function createFlatOperation(project, inverse4, { inputScale, outputScale }) {
552
+ const scratch = new ProjectionScratch();
553
+ return (coordinates, dimension) => {
554
+ const point = scratch.acquire();
555
+ try {
556
+ const float32 = coordinates instanceof Float32Array;
557
+ for (let offset2 = 0; offset2 < coordinates.length; offset2 += dimension) {
558
+ point.x = coordinates[offset2];
559
+ point.y = coordinates[offset2 + 1];
560
+ point.z = dimension >= 3 ? coordinates[offset2 + 2] : 0;
561
+ if (!Number.isFinite(point.x) || !Number.isFinite(point.y) || !Number.isFinite(point.z))
562
+ throw new Error("Coordinates must contain finite x, y and optional z values");
563
+ if (inputScale !== 1) {
564
+ point.x *= inputScale;
565
+ point.y *= inputScale;
566
+ }
567
+ if (inverse4)
568
+ project(point);
569
+ if (Math.abs(point.y) > Math.PI / 2 || !Number.isFinite(point.x) || !Number.isFinite(point.y))
570
+ throw new Error("Coordinate is outside the geographic domain");
571
+ point.x += 0;
572
+ point.x -= 0;
573
+ if (!inverse4)
574
+ project(point);
575
+ if (outputScale !== 1) {
576
+ point.x /= outputScale;
577
+ point.y /= outputScale;
578
+ }
579
+ if (!Number.isFinite(point.x) || !Number.isFinite(point.y))
580
+ throw new Error("Projection produced non-finite coordinates");
581
+ if (float32 && (Math.abs(point.x) > 34028234663852886e22 || Math.abs(point.y) > 34028234663852886e22))
582
+ throw new Error("Projected coordinate exceeds Float32 range");
583
+ coordinates[offset2] = point.x;
584
+ coordinates[offset2 + 1] = point.y;
585
+ }
586
+ } finally {
587
+ scratch.release(point);
588
+ }
589
+ };
590
+ }
591
+
592
+ // dist/projection/experimental/common/sinh.js
593
+ function sinh_default(x) {
594
+ var r = Math.exp(x);
595
+ r = (r - 1 / r) / 2;
596
+ return r;
597
+ }
598
+
599
+ // dist/projection/experimental/common/hypot.js
600
+ function hypot_default(x, y) {
601
+ x = Math.abs(x);
602
+ y = Math.abs(y);
603
+ var a = Math.max(x, y);
604
+ var b = Math.min(x, y) / (a ? a : 1);
605
+ return a * Math.sqrt(1 + Math.pow(b, 2));
606
+ }
607
+
608
+ // dist/projection/experimental/common/log1py.js
609
+ function log1py_default(x) {
610
+ var y = 1 + x;
611
+ var z = y - 1;
612
+ return z === 0 ? x : x * Math.log(y) / z;
613
+ }
614
+
615
+ // dist/projection/experimental/common/asinhy.js
616
+ function asinhy_default(x) {
617
+ var y = Math.abs(x);
618
+ y = log1py_default(y * (1 + y / (hypot_default(1, y) + 1)));
619
+ return x < 0 ? -y : y;
620
+ }
621
+
622
+ // dist/projection/experimental/common/gatg.js
623
+ function gatg_default(pp, B) {
624
+ var cos_2B = 2 * Math.cos(2 * B);
625
+ var i = pp.length - 1;
626
+ var h1 = pp[i];
627
+ var h2 = 0;
628
+ var h;
629
+ while (--i >= 0) {
630
+ h = -h2 + cos_2B * h1 + pp[i];
631
+ h2 = h1;
632
+ h1 = h;
633
+ }
634
+ return B + h * Math.sin(2 * B);
635
+ }
636
+
637
+ // dist/projection/experimental/common/clens.js
638
+ function clens_default(pp, arg_r) {
639
+ var r = 2 * Math.cos(arg_r);
640
+ var i = pp.length - 1;
641
+ var hr1 = pp[i];
642
+ var hr2 = 0;
643
+ var hr;
644
+ while (--i >= 0) {
645
+ hr = -hr2 + r * hr1 + pp[i];
646
+ hr2 = hr1;
647
+ hr1 = hr;
648
+ }
649
+ return Math.sin(arg_r) * hr;
650
+ }
651
+
652
+ // dist/projection/experimental/common/cosh.js
653
+ function cosh_default(x) {
654
+ var r = Math.exp(x);
655
+ r = (r + 1 / r) / 2;
656
+ return r;
657
+ }
658
+
659
+ // dist/projection/experimental/common/clens_cmplx.js
660
+ function clens_cmplx_default(pp, arg_r, arg_i, output) {
661
+ var sin_arg_r = Math.sin(arg_r);
662
+ var cos_arg_r = Math.cos(arg_r);
663
+ var sinh_arg_i = sinh_default(arg_i);
664
+ var cosh_arg_i = cosh_default(arg_i);
665
+ var r = 2 * cos_arg_r * cosh_arg_i;
666
+ var i = -2 * sin_arg_r * sinh_arg_i;
667
+ var j = pp.length - 1;
668
+ var hr = pp[j];
669
+ var hi1 = 0;
670
+ var hr1 = 0;
671
+ var hi = 0;
672
+ var hr2;
673
+ var hi2;
674
+ while (--j >= 0) {
675
+ hr2 = hr1;
676
+ hi2 = hi1;
677
+ hr1 = hr;
678
+ hi1 = hi;
679
+ hr = -hr2 + r * hr1 - i * hi1 + pp[j];
680
+ hi = -hi2 + i * hr1 + r * hi1;
681
+ }
682
+ r = sin_arg_r * cosh_arg_i;
683
+ i = cos_arg_r * sinh_arg_i;
684
+ output.x = r * hr - i * hi;
685
+ output.y = r * hi + i * hr;
686
+ }
687
+
688
+ // dist/projection/experimental/common/constants.js
689
+ var EPSLN = 1e-10;
690
+ var HALF_PI = Math.PI / 2;
691
+ var FORTPI = Math.PI / 4;
692
+ var TWO_PI = Math.PI * 2;
693
+ var SPI = 3.14159265359;
694
+ var D2R = Math.PI / 180;
695
+ var R2D = 180 / Math.PI;
696
+ var SEC_TO_RAD = Math.PI / (180 * 3600);
697
+
698
+ // dist/projection/experimental/common/sign.js
699
+ function sign_default(x) {
700
+ return x < 0 ? -1 : 1;
701
+ }
702
+
703
+ // dist/projection/experimental/common/adjust_lon.js
704
+ function adjust_lon_default(x, skipAdjust) {
705
+ if (skipAdjust) {
706
+ return x;
707
+ }
708
+ return Math.abs(x) <= SPI ? x : x - sign_default(x) * TWO_PI;
709
+ }
710
+
711
+ // dist/projection/experimental/kernels/etmerc.js
712
+ function initialize(state) {
713
+ state.x0 = state.x0 !== void 0 ? state.x0 : 0;
714
+ state.y0 = state.y0 !== void 0 ? state.y0 : 0;
715
+ state.long0 = state.long0 !== void 0 ? state.long0 : 0;
716
+ state.lat0 = state.lat0 !== void 0 ? state.lat0 : 0;
717
+ state.k0 = state.k0 !== void 0 ? state.k0 : 1;
718
+ state.cgb = [];
719
+ state.cbg = [];
720
+ state.utg = [];
721
+ state.gtu = [];
722
+ var f = state.es / (1 + Math.sqrt(1 - state.es));
723
+ var n = f / (2 - f);
724
+ var np = n;
725
+ state.cgb[0] = n * (2 + n * (-2 / 3 + n * (-2 + n * (116 / 45 + n * (26 / 45 + n * (-2854 / 675))))));
726
+ state.cbg[0] = n * (-2 + n * (2 / 3 + n * (4 / 3 + n * (-82 / 45 + n * (32 / 45 + n * (4642 / 4725))))));
727
+ np = np * n;
728
+ state.cgb[1] = np * (7 / 3 + n * (-8 / 5 + n * (-227 / 45 + n * (2704 / 315 + n * (2323 / 945)))));
729
+ state.cbg[1] = np * (5 / 3 + n * (-16 / 15 + n * (-13 / 9 + n * (904 / 315 + n * (-1522 / 945)))));
730
+ np = np * n;
731
+ state.cgb[2] = np * (56 / 15 + n * (-136 / 35 + n * (-1262 / 105 + n * (73814 / 2835))));
732
+ state.cbg[2] = np * (-26 / 15 + n * (34 / 21 + n * (8 / 5 + n * (-12686 / 2835))));
733
+ np = np * n;
734
+ state.cgb[3] = np * (4279 / 630 + n * (-332 / 35 + n * (-399572 / 14175)));
735
+ state.cbg[3] = np * (1237 / 630 + n * (-12 / 5 + n * (-24832 / 14175)));
736
+ np = np * n;
737
+ state.cgb[4] = np * (4174 / 315 + n * (-144838 / 6237));
738
+ state.cbg[4] = np * (-734 / 315 + n * (109598 / 31185));
739
+ np = np * n;
740
+ state.cgb[5] = np * (601676 / 22275);
741
+ state.cbg[5] = np * (444337 / 155925);
742
+ np = Math.pow(n, 2);
743
+ state.Qn = state.k0 / (1 + n) * (1 + np * (1 / 4 + np * (1 / 64 + np / 256)));
744
+ state.utg[0] = n * (-0.5 + n * (2 / 3 + n * (-37 / 96 + n * (1 / 360 + n * (81 / 512 + n * (-96199 / 604800))))));
745
+ state.gtu[0] = n * (0.5 + n * (-2 / 3 + n * (5 / 16 + n * (41 / 180 + n * (-127 / 288 + n * (7891 / 37800))))));
746
+ state.utg[1] = np * (-1 / 48 + n * (-1 / 15 + n * (437 / 1440 + n * (-46 / 105 + n * (1118711 / 3870720)))));
747
+ state.gtu[1] = np * (13 / 48 + n * (-3 / 5 + n * (557 / 1440 + n * (281 / 630 + n * (-1983433 / 1935360)))));
748
+ np = np * n;
749
+ state.utg[2] = np * (-17 / 480 + n * (37 / 840 + n * (209 / 4480 + n * (-5569 / 90720))));
750
+ state.gtu[2] = np * (61 / 240 + n * (-103 / 140 + n * (15061 / 26880 + n * (167603 / 181440))));
751
+ np = np * n;
752
+ state.utg[3] = np * (-4397 / 161280 + n * (11 / 504 + n * (830251 / 7257600)));
753
+ state.gtu[3] = np * (49561 / 161280 + n * (-179 / 168 + n * (6601661 / 7257600)));
754
+ np = np * n;
755
+ state.utg[4] = np * (-4583 / 161280 + n * (108847 / 3991680));
756
+ state.gtu[4] = np * (34729 / 80640 + n * (-3418889 / 1995840));
757
+ np = np * n;
758
+ state.utg[5] = np * (-20648693 / 638668800);
759
+ state.gtu[5] = np * (212378941 / 319334400);
760
+ var Z = gatg_default(state.cbg, state.lat0);
761
+ state.Zb = -state.Qn * (Z + clens_default(state.gtu, 2 * Z));
762
+ }
763
+ function forward(state, p) {
764
+ var Ce = adjust_lon_default(p.x - state.long0, state.over);
765
+ var Cn = p.y;
766
+ Cn = gatg_default(state.cbg, Cn);
767
+ var sin_Cn = Math.sin(Cn);
768
+ var cos_Cn = Math.cos(Cn);
769
+ var sin_Ce = Math.sin(Ce);
770
+ var cos_Ce = Math.cos(Ce);
771
+ Cn = Math.atan2(sin_Cn, cos_Ce * cos_Cn);
772
+ Ce = Math.atan2(sin_Ce * cos_Cn, hypot_default(sin_Cn, cos_Cn * cos_Ce));
773
+ Ce = asinhy_default(Math.tan(Ce));
774
+ clens_cmplx_default(state.gtu, 2 * Cn, 2 * Ce, p);
775
+ Cn = Cn + p.x;
776
+ Ce = Ce + p.y;
777
+ var x;
778
+ var y;
779
+ if (Math.abs(Ce) <= 2.623395162778) {
780
+ x = state.a * (state.Qn * Ce) + state.x0;
781
+ y = state.a * (state.Qn * Cn + state.Zb) + state.y0;
782
+ } else {
783
+ x = Infinity;
784
+ y = Infinity;
785
+ }
786
+ p.x = x;
787
+ p.y = y;
788
+ return p;
789
+ }
790
+ function inverse(state, p) {
791
+ var Ce = (p.x - state.x0) * (1 / state.a);
792
+ var Cn = (p.y - state.y0) * (1 / state.a);
793
+ Cn = (Cn - state.Zb) / state.Qn;
794
+ Ce = Ce / state.Qn;
795
+ var lon;
796
+ var lat;
797
+ if (Math.abs(Ce) <= 2.623395162778) {
798
+ clens_cmplx_default(state.utg, 2 * Cn, 2 * Ce, p);
799
+ Cn = Cn + p.x;
800
+ Ce = Ce + p.y;
801
+ Ce = Math.atan(sinh_default(Ce));
802
+ var sin_Cn = Math.sin(Cn);
803
+ var cos_Cn = Math.cos(Cn);
804
+ var sin_Ce = Math.sin(Ce);
805
+ var cos_Ce = Math.cos(Ce);
806
+ Cn = Math.atan2(sin_Cn * cos_Ce, hypot_default(sin_Ce, cos_Ce * cos_Cn));
807
+ Ce = Math.atan2(sin_Ce, cos_Ce * cos_Cn);
808
+ lon = adjust_lon_default(Ce + state.long0, state.over);
809
+ lat = gatg_default(state.cgb, Cn);
810
+ } else {
811
+ lon = Infinity;
812
+ lat = Infinity;
813
+ }
814
+ p.x = lon;
815
+ p.y = lat;
816
+ return p;
817
+ }
818
+ function createState(base) {
819
+ const state = {
820
+ ...base,
821
+ cgb: [],
822
+ cbg: [],
823
+ utg: [],
824
+ gtu: [],
825
+ Qn: 0,
826
+ Zb: 0
827
+ };
828
+ initialize(state);
829
+ return state;
830
+ }
831
+
832
+ // dist/projection/experimental/common/pj_enfn.js
833
+ var C00 = 1;
834
+ var C02 = 0.25;
835
+ var C04 = 0.046875;
836
+ var C06 = 0.01953125;
837
+ var C08 = 0.01068115234375;
838
+ var C22 = 0.75;
839
+ var C44 = 0.46875;
840
+ var C46 = 0.013020833333333334;
841
+ var C48 = 0.007120768229166667;
842
+ var C66 = 0.3645833333333333;
843
+ var C68 = 0.005696614583333333;
844
+ var C88 = 0.3076171875;
845
+ function pj_enfn_default(es) {
846
+ var en = [];
847
+ en[0] = C00 - es * (C02 + es * (C04 + es * (C06 + es * C08)));
848
+ en[1] = es * (C22 - es * (C04 + es * (C06 + es * C08)));
849
+ var t = es * es;
850
+ en[2] = t * (C44 - es * (C46 + es * C48));
851
+ t *= es;
852
+ en[3] = t * (C66 - es * C68);
853
+ en[4] = t * es * C88;
854
+ return en;
855
+ }
856
+
857
+ // dist/projection/experimental/common/pj_mlfn.js
858
+ function pj_mlfn_default(phi, sphi, cphi, en) {
859
+ cphi *= sphi;
860
+ sphi *= sphi;
861
+ return en[0] * phi - cphi * (en[1] + sphi * (en[2] + sphi * (en[3] + sphi * en[4])));
862
+ }
863
+
864
+ // dist/projection/experimental/common/pj_inv_mlfn.js
865
+ var MAX_ITER = 20;
866
+ function pj_inv_mlfn_default(arg, es, en) {
867
+ var k = 1 / (1 - es);
868
+ var phi = arg;
869
+ for (var i = MAX_ITER; i; --i) {
870
+ var s = Math.sin(phi);
871
+ var t = 1 - es * s * s;
872
+ t = (pj_mlfn_default(phi, s, Math.cos(phi), en) - arg) * (t * Math.sqrt(t)) * k;
873
+ phi -= t;
874
+ if (Math.abs(t) < EPSLN) {
875
+ return phi;
876
+ }
877
+ }
878
+ return phi;
879
+ }
880
+
881
+ // dist/projection/experimental/kernels/tmerc.js
882
+ function initialize2(state) {
883
+ state.x0 = state.x0 !== void 0 ? state.x0 : 0;
884
+ state.y0 = state.y0 !== void 0 ? state.y0 : 0;
885
+ state.long0 = state.long0 !== void 0 ? state.long0 : 0;
886
+ state.lat0 = state.lat0 !== void 0 ? state.lat0 : 0;
887
+ if (state.es) {
888
+ state.en = pj_enfn_default(state.es);
889
+ state.ml0 = pj_mlfn_default(state.lat0, Math.sin(state.lat0), Math.cos(state.lat0), state.en);
890
+ }
891
+ }
892
+ function forward2(state, p) {
893
+ var lon = p.x;
894
+ var lat = p.y;
895
+ var delta_lon = adjust_lon_default(lon - state.long0, state.over);
896
+ var con;
897
+ var x, y;
898
+ var sin_phi = Math.sin(lat);
899
+ var cos_phi = Math.cos(lat);
900
+ if (!state.es) {
901
+ var b = cos_phi * Math.sin(delta_lon);
902
+ if (Math.abs(Math.abs(b) - 1) < EPSLN) {
903
+ return 93;
904
+ } else {
905
+ x = 0.5 * state.a * state.k0 * Math.log((1 + b) / (1 - b)) + state.x0;
906
+ y = cos_phi * Math.cos(delta_lon) / Math.sqrt(1 - Math.pow(b, 2));
907
+ b = Math.abs(y);
908
+ if (b >= 1) {
909
+ if (b - 1 > EPSLN) {
910
+ return 93;
911
+ } else {
912
+ y = 0;
913
+ }
914
+ } else {
915
+ y = Math.acos(y);
916
+ }
917
+ if (lat < 0) {
918
+ y = -y;
919
+ }
920
+ y = state.a * state.k0 * (y - state.lat0) + state.y0;
921
+ }
922
+ } else {
923
+ var al = cos_phi * delta_lon;
924
+ var als = Math.pow(al, 2);
925
+ var c = state.ep2 * Math.pow(cos_phi, 2);
926
+ var cs = Math.pow(c, 2);
927
+ var tq = Math.abs(cos_phi) > EPSLN ? Math.tan(lat) : 0;
928
+ var t = Math.pow(tq, 2);
929
+ var ts = Math.pow(t, 2);
930
+ con = 1 - state.es * Math.pow(sin_phi, 2);
931
+ al = al / Math.sqrt(con);
932
+ var ml = pj_mlfn_default(lat, sin_phi, cos_phi, state.en);
933
+ x = state.a * (state.k0 * al * (1 + als / 6 * (1 - t + c + als / 20 * (5 - 18 * t + ts + 14 * c - 58 * t * c + als / 42 * (61 + 179 * ts - ts * t - 479 * t))))) + state.x0;
934
+ y = state.a * (state.k0 * (ml - state.ml0 + sin_phi * delta_lon * al / 2 * (1 + als / 12 * (5 - t + 9 * c + 4 * cs + als / 30 * (61 + ts - 58 * t + 270 * c - 330 * t * c + als / 56 * (1385 + 543 * ts - ts * t - 3111 * t)))))) + state.y0;
935
+ }
936
+ p.x = x;
937
+ p.y = y;
938
+ return p;
939
+ }
940
+ function inverse2(state, p) {
941
+ var con, phi;
942
+ var lat, lon;
943
+ var x = (p.x - state.x0) * (1 / state.a);
944
+ var y = (p.y - state.y0) * (1 / state.a);
945
+ if (!state.es) {
946
+ var f = Math.exp(x / state.k0);
947
+ var g = 0.5 * (f - 1 / f);
948
+ var temp = state.lat0 + y / state.k0;
949
+ var h = Math.cos(temp);
950
+ con = Math.sqrt((1 - Math.pow(h, 2)) / (1 + Math.pow(g, 2)));
951
+ lat = Math.asin(con);
952
+ if (Math.sin(temp) < 0) {
953
+ lat = -lat;
954
+ }
955
+ if (g === 0 && h === 0) {
956
+ lon = 0;
957
+ } else {
958
+ lon = adjust_lon_default(Math.atan2(g, h) + state.long0, state.over);
959
+ }
960
+ } else {
961
+ con = state.ml0 + y / state.k0;
962
+ phi = pj_inv_mlfn_default(con, state.es, state.en);
963
+ if (Math.abs(phi) < HALF_PI) {
964
+ var sin_phi = Math.sin(phi);
965
+ var cos_phi = Math.cos(phi);
966
+ var tan_phi = Math.abs(cos_phi) > EPSLN ? Math.tan(phi) : 0;
967
+ var c = state.ep2 * Math.pow(cos_phi, 2);
968
+ var cs = Math.pow(c, 2);
969
+ var t = Math.pow(tan_phi, 2);
970
+ var ts = Math.pow(t, 2);
971
+ con = 1 - state.es * Math.pow(sin_phi, 2);
972
+ var d = x * Math.sqrt(con) / state.k0;
973
+ var ds = Math.pow(d, 2);
974
+ con = con * tan_phi;
975
+ lat = phi - con * ds / (1 - state.es) * 0.5 * (1 - ds / 12 * (5 + 3 * t - 9 * c * t + c - 4 * cs - ds / 30 * (61 + 90 * t - 252 * c * t + 45 * ts + 46 * c - ds / 56 * (1385 + 3633 * t + 4095 * ts + 1574 * ts * t))));
976
+ lon = adjust_lon_default(state.long0 + d * (1 - ds / 6 * (1 + 2 * t + c - ds / 20 * (5 + 28 * t + 24 * ts + 8 * c * t + 6 * c - ds / 42 * (61 + 662 * t + 1320 * ts + 720 * ts * t)))) / cos_phi, state.over);
977
+ } else {
978
+ lat = HALF_PI * sign_default(y);
979
+ lon = 0;
980
+ }
981
+ }
982
+ p.x = lon;
983
+ p.y = lat;
984
+ return p;
985
+ }
986
+ function createState2(base) {
987
+ const state = {
988
+ ...base,
989
+ en: [],
990
+ ml0: 0
991
+ };
992
+ initialize2(state);
993
+ return state;
994
+ }
995
+
996
+ // dist/projection/experimental/projections/transverse-mercator.js
997
+ function createTransverseMercator(context) {
998
+ const base = kernelParameters(context);
999
+ const render = (implementation) => withRectangleRenderingProfile(implementation, createAngularRanges(base.long0 - Math.PI / 6, -Math.PI / 2, base.long0 + Math.PI / 6, Math.PI / 2), (ranges) => transverseBounds(implementation.forward, ranges, base.long0, base.over), base.primeMeridian, base.over);
1000
+ if (flagParameter(context.parameters, "approx")) {
1001
+ return render({
1002
+ ...bindKernel("tmerc +approx", createState2(base), forward2, inverse2, createFlatProjection)
1003
+ });
1004
+ }
1005
+ if (base.sphere)
1006
+ throw new Error("Spherical transverse Mercator requires +approx");
1007
+ return render({
1008
+ ...bindKernel("etmerc", createState(base), forward, inverse, createFlatProjection)
1009
+ });
1010
+ }
1011
+ var transverseMercator = {
1012
+ name: "tmerc",
1013
+ aliases: [
1014
+ "Fast_Transverse_Mercator",
1015
+ "Fast Transverse Mercator",
1016
+ "Transverse_Mercator",
1017
+ "Transverse Mercator",
1018
+ "Gauss Kruger",
1019
+ "Gauss_Kruger"
1020
+ ],
1021
+ parameters: [...ORIGIN_PARAMETERS, ...SCALE_PARAMETERS, "approx"],
1022
+ flags: ["approx"],
1023
+ create: createTransverseMercator
1024
+ };
1025
+ var extendedTransverseMercator = {
1026
+ name: "etmerc",
1027
+ aliases: ["Extended_Transverse_Mercator", "Extended Transverse Mercator"],
1028
+ parameters: [...ORIGIN_PARAMETERS, ...SCALE_PARAMETERS, "approx"],
1029
+ flags: ["approx"],
1030
+ create: createTransverseMercator
1031
+ };
1032
+
1033
+ // dist/projection/experimental/projections/utm.js
1034
+ var universalTransverseMercator = {
1035
+ name: "utm",
1036
+ aliases: ["Universal Transverse Mercator System"],
1037
+ parameters: ["zone", "south", "approx"],
1038
+ flags: ["south", "approx"],
1039
+ create(context) {
1040
+ const zone = numberParameter(context.parameters, "zone", NaN);
1041
+ if (!Number.isInteger(zone) || zone < 1 || zone > 60) {
1042
+ throw new Error("UTM requires an integer +zone from 1 to 60");
1043
+ }
1044
+ const south = flagParameter(context.parameters, "south");
1045
+ const implementation = createTransverseMercator({
1046
+ ...context,
1047
+ parameters: {
1048
+ ...context.parameters,
1049
+ lat_0: "0",
1050
+ lon_0: String(6 * zone - 183),
1051
+ x_0: "500000",
1052
+ y_0: south ? "10000000" : "0",
1053
+ k_0: "0.9996"
1054
+ }
1055
+ });
1056
+ const center = (6 * zone - 183) * Math.PI / 180;
1057
+ return withRectangleRenderingProfile(implementation, createAngularRanges(center - Math.PI / 60, south ? -80 * Math.PI / 180 : 0, center + Math.PI / 60, south ? 0 : 84 * Math.PI / 180), (ranges) => transverseBounds(implementation.forward, ranges, center), context.primeMeridian ?? 0, Object.prototype.hasOwnProperty.call(context.parameters, "over"));
1058
+ }
1059
+ };
1060
+
1061
+ // dist/projection/experimental/rendering-profile/spherical-rendering-domain.js
1062
+ function geographicVector(longitude, latitude) {
1063
+ return [
1064
+ Math.cos(latitude) * Math.cos(longitude),
1065
+ Math.cos(latitude) * Math.sin(longitude),
1066
+ Math.sin(latitude)
1067
+ ];
1068
+ }
1069
+ var dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
1070
+ function trigonometricRoots(a, b, c, low, high) {
1071
+ const radius = Math.hypot(a, b);
1072
+ if (!radius || Math.abs(c) > radius + 1e-14)
1073
+ return [];
1074
+ const angle = Math.atan2(b, a);
1075
+ const offset2 = Math.acos(Math.max(-1, Math.min(1, c / radius)));
1076
+ const roots = [];
1077
+ for (const phase of [angle - offset2, angle + offset2]) {
1078
+ for (let k = Math.ceil((low - phase) / (2 * Math.PI)); k <= Math.floor((high - phase) / (2 * Math.PI)); k++) {
1079
+ roots.push(phase + k * 2 * Math.PI);
1080
+ }
1081
+ }
1082
+ return roots;
1083
+ }
1084
+ function sphericalExtremum(vector, parameters, domain, maximize = true) {
1085
+ const [[west, south], [east, north]] = parameters;
1086
+ const center = (west + east) / 2;
1087
+ const axis = domain ? [Math.cos(domain.latitude), 0, Math.sin(domain.latitude)] : [1, 0, 0];
1088
+ const limit = domain ? Math.cos(domain.distance) : -1;
1089
+ let best = maximize ? -Infinity : Infinity;
1090
+ let point = [NaN, NaN];
1091
+ const consider = (longitude, latitude) => {
1092
+ longitude = center + wrapLongitude(longitude - center);
1093
+ if (longitude < west - 1e-12 || longitude > east + 1e-12 || latitude < south - 1e-12 || latitude > north + 1e-12)
1094
+ return;
1095
+ const position = geographicVector(longitude, latitude);
1096
+ if (domain && dot(axis, position) < limit - 1e-13)
1097
+ return;
1098
+ const value = dot(vector, position);
1099
+ if (maximize ? value > best : value < best) {
1100
+ best = value;
1101
+ point = [longitude, latitude];
1102
+ }
1103
+ };
1104
+ const longitudes = [west, east, ...trigonometricRoots(-vector[1], vector[0], 0, west, east)];
1105
+ for (const longitude of longitudes) {
1106
+ const coefficient = vector[0] * Math.cos(longitude) + vector[1] * Math.sin(longitude);
1107
+ for (const latitude of [
1108
+ south,
1109
+ north,
1110
+ ...trigonometricRoots(vector[2], -coefficient, 0, south, north)
1111
+ ])
1112
+ consider(longitude, latitude);
1113
+ }
1114
+ if (domain) {
1115
+ const [a, , c] = axis;
1116
+ for (const latitude of [south, north]) {
1117
+ for (const longitude of trigonometricRoots(a * Math.cos(latitude), 0, limit - c * Math.sin(latitude), west, east))
1118
+ consider(longitude, latitude);
1119
+ }
1120
+ for (const longitude of [west, east]) {
1121
+ for (const latitude of trigonometricRoots(a * Math.cos(longitude), c, limit, south, north))
1122
+ consider(longitude, latitude);
1123
+ }
1124
+ const parallel = dot(vector, axis);
1125
+ let tangent = vector.map((value, index) => value - parallel * axis[index]);
1126
+ let length = Math.hypot(...tangent);
1127
+ if (length <= 1e-14) {
1128
+ tangent = [-axis[2], 0, axis[0]];
1129
+ length = 1;
1130
+ }
1131
+ if (length > 1e-14) {
1132
+ for (const sign of [-1, 1]) {
1133
+ const position = axis.map((value, index) => value * limit + sign * tangent[index] * Math.sin(domain.distance) / length);
1134
+ consider(Math.atan2(position[1], position[0]), Math.atan2(position[2], Math.hypot(position[0], position[1])));
1135
+ }
1136
+ }
1137
+ }
1138
+ if (!Number.isFinite(best))
1139
+ throw new Error("CRS coverage does not intersect the rendering domain");
1140
+ return { value: best, point };
1141
+ }
1142
+ function sphericalRange(vector, parameters, domain) {
1143
+ return [
1144
+ sphericalExtremum(vector, parameters, domain, false).value,
1145
+ sphericalExtremum(vector, parameters, domain).value
1146
+ ];
1147
+ }
1148
+ function sphericalRatioRange(numerator, denominator, constant, parameters, domain) {
1149
+ const n = sphericalRange(numerator, parameters, domain);
1150
+ const d = sphericalRange(denominator, parameters, domain).map((value) => value + constant);
1151
+ if (d[0] <= 0)
1152
+ throw new Error("Projection rendering denominator is not positive");
1153
+ const quotients = n.flatMap((value) => d.map((divisor) => value / divisor));
1154
+ return [false, true].map((maximize) => {
1155
+ let low = Math.min(...quotients), high = Math.max(...quotients);
1156
+ for (let iteration = 0; iteration < 60; iteration++) {
1157
+ const middle = (low + high) / 2;
1158
+ const vector = numerator.map((value, index) => value - middle * denominator[index]);
1159
+ const residual = sphericalExtremum(vector, parameters, domain, maximize).value - middle * constant;
1160
+ if (residual > 0)
1161
+ low = middle;
1162
+ else
1163
+ high = middle;
1164
+ }
1165
+ return maximize ? high : low;
1166
+ });
1167
+ }
1168
+
1169
+ // dist/projection/experimental/rendering-profile/angular-rendering-profile.js
1170
+ function createAngularRenderingProfile(base, maximumDistance, resolveBounds2, horizon = Math.PI) {
1171
+ const full = [-180, -90, 180, 90];
1172
+ const create = (coverage, declared) => {
1173
+ const parameters = getAngularRanges(coverage, base.primeMeridian, base.long0);
1174
+ const local = createAngularRanges(parameters[0][0] - base.long0, parameters[0][1], parameters[1][0] - base.long0, parameters[1][1]);
1175
+ const axis = [Math.cos(base.lat0), 0, Math.sin(base.lat0)];
1176
+ const minimum = declared ? sphericalExtremum(axis, local, void 0, false).value : -1;
1177
+ const clipped = !declared || minimum <= Math.cos(horizon) + 1e-13;
1178
+ const domain = clipped ? { latitude: base.lat0, distance: maximumDistance } : void 0;
1179
+ const rectangle = createRectangleRenderingProfile(() => resolveBounds2(local, domain), coverage, base.long0, base.primeMeridian);
1180
+ const polar = Math.abs(Math.cos(base.lat0)) < 1e-12;
1181
+ const polarLatitude = (Math.PI / 2 - maximumDistance) * 180 / Math.PI;
1182
+ const normalizeCap = domain && !polar && createAngularNormalization((point) => {
1183
+ const target = geographicVector(point.x - base.long0, point.y);
1184
+ if (target[0] * Math.cos(base.lat0) + target[2] * Math.sin(base.lat0) >= Math.cos(domain.distance) - 1e-14)
1185
+ return;
1186
+ if (Math.hypot(target[0] + axis[0], target[1], target[2] + axis[2]) < 1e-12) {
1187
+ const angle = base.lat0 + domain.distance;
1188
+ const center = (local[0][0] + local[1][0]) / 2;
1189
+ const longitude = center + wrapLongitude((Math.cos(angle) < 0 ? Math.PI : 0) - center);
1190
+ const latitude = Math.atan2(Math.sin(angle), Math.abs(Math.cos(angle)));
1191
+ if (longitude >= local[0][0] && longitude <= local[1][0] && latitude >= local[0][1] && latitude <= local[1][1]) {
1192
+ point.x = longitude + base.long0;
1193
+ point.y = latitude;
1194
+ return;
1195
+ }
1196
+ }
1197
+ const result = sphericalExtremum(target, local, domain);
1198
+ [point.x, point.y] = [result.point[0] + base.long0, result.point[1]];
1199
+ }, base.primeMeridian);
1200
+ return {
1201
+ get bounds() {
1202
+ return resolveBounds2(local, domain);
1203
+ },
1204
+ normalize(point) {
1205
+ rectangle.normalize(point);
1206
+ if (domain && polar) {
1207
+ point.y = base.lat0 > 0 ? Math.max(polarLatitude, point.y) : Math.min(-polarLatitude, point.y);
1208
+ } else
1209
+ normalizeCap == null ? void 0 : normalizeCap(point);
1210
+ const center = (base.long0 + base.primeMeridian) * 180 / Math.PI;
1211
+ const offset2 = point.x - center;
1212
+ if (Math.abs(offset2) > 180)
1213
+ point.x = center + normalizeLongitude(offset2);
1214
+ }
1215
+ };
1216
+ };
1217
+ return (coverage) => create(coverage ?? full, Boolean(coverage));
1218
+ }
1219
+ function withAngularRenderingProfile(implementation, base, distance, resolveBounds2, horizon = Math.PI) {
1220
+ return {
1221
+ ...implementation,
1222
+ longitudeOrigin: base.long0,
1223
+ getRenderingProfile: createAngularRenderingProfile(base, distance, resolveBounds2, horizon)
1224
+ };
1225
+ }
1226
+
1227
+ // dist/projection/experimental/rendering-profile/azimuthal-rendering-bounds.js
1228
+ function sphericalAzimuthalBounds(base, parameters, domain, kind) {
1229
+ const north = [-Math.sin(base.lat0), 0, Math.cos(base.lat0)];
1230
+ const center = [Math.cos(base.lat0), 0, Math.sin(base.lat0)];
1231
+ const east = [0, 1, 0];
1232
+ const constant = kind === "stere" ? 1 : 0;
1233
+ const range = (vector) => kind === "ortho" ? sphericalRange(vector, parameters, domain) : sphericalRatioRange(vector, center, constant, parameters, domain);
1234
+ const factor = base.a * (kind === "stere" ? 2 * base.k0 : 1);
1235
+ return envelope(add([base.x0, base.x0], scale(range(east), factor)), add([base.y0, base.y0], scale(range(north), factor)));
1236
+ }
1237
+ function ellipsoidalStereographicBounds(base, conformalLatitude, centerLatitude, radius, parameters, domain, longitudeScale = 1, latitudeError = base.e * Math.atanh(base.e)) {
1238
+ const region = createAngularRanges(parameters[0][0] * longitudeScale, conformalLatitude(parameters[0][1]), parameters[1][0] * longitudeScale, conformalLatitude(parameters[1][1]));
1239
+ const padding = 2 * latitudeError + Math.PI * Math.abs(longitudeScale - 1);
1240
+ const capDistance = domain && longitudeScale === 1 ? Math.min(domain.distance + padding, Math.PI - (1 - base.es) * (Math.PI - domain.distance)) : domain && domain.distance + padding;
1241
+ const cap = capDistance && capDistance < Math.PI ? { latitude: centerLatitude, distance: capDistance } : void 0;
1242
+ const center = [Math.cos(centerLatitude), 0, Math.sin(centerLatitude)];
1243
+ const north = [-Math.sin(centerLatitude), 0, Math.cos(centerLatitude)];
1244
+ const longitudeWidth = region[1][0] - region[0][0];
1245
+ const wrapped = longitudeWidth >= 2 * Math.PI ? createAngularRanges(-Math.PI, region[0][1], Math.PI, region[1][1]) : region;
1246
+ const x = sphericalRatioRange([0, 1, 0], center, 1, wrapped, cap);
1247
+ const y = sphericalRatioRange(north, center, 1, wrapped, cap);
1248
+ return envelope(add([base.x0, base.x0], scale(x, radius)), add([base.y0, base.y0], scale(y, radius)));
1249
+ }
1250
+
1251
+ // dist/projection/experimental/inverse-spherical-latitude.js
1252
+ function inverseSphericalLatitude(sin0, cos0, sinDistance, cosDistance, x, y, radius) {
1253
+ const east = x * sinDistance / radius;
1254
+ const meridian = cosDistance * cos0 - y * sinDistance * sin0 / radius;
1255
+ const vertical = cosDistance * sin0 + y * sinDistance * cos0 / radius;
1256
+ return Math.atan2(vertical, Math.hypot(east, meridian));
1257
+ }
1258
+
1259
+ // dist/projection/experimental/common/msfnz.js
1260
+ function msfnz_default(eccent, sinphi, cosphi) {
1261
+ var con = eccent * sinphi;
1262
+ return cosphi / Math.sqrt(1 - con * con);
1263
+ }
1264
+
1265
+ // dist/projection/experimental/common/tsfnz.js
1266
+ function tsfnz_default(eccent, phi, sinphi) {
1267
+ const cosphi = Math.cos(phi);
1268
+ return Math.exp(eccent * Math.atanh(eccent * sinphi)) * (sinphi > 0 ? cosphi / (1 + sinphi) : (1 - sinphi) / cosphi);
1269
+ }
1270
+
1271
+ // dist/projection/experimental/common/phi2z.js
1272
+ function phi2z_default(eccent, ts) {
1273
+ var eccnth = 0.5 * eccent;
1274
+ var con, dphi;
1275
+ var phi = HALF_PI - 2 * Math.atan(ts);
1276
+ for (var i = 0; i <= 15; i++) {
1277
+ con = eccent * Math.sin(phi);
1278
+ dphi = HALF_PI - 2 * Math.atan(ts * Math.pow((1 - con) / (1 + con), eccnth)) - phi;
1279
+ phi += dphi;
1280
+ if (Math.abs(dphi) <= 1e-10) {
1281
+ return phi;
1282
+ }
1283
+ }
1284
+ return -9999;
1285
+ }
1286
+
1287
+ // dist/projection/experimental/kernels/stere.js
1288
+ function ssfn_(phit, sinphi, eccen) {
1289
+ sinphi *= eccen;
1290
+ return Math.tan(0.5 * (HALF_PI + phit)) * Math.pow((1 - sinphi) / (1 + sinphi), 0.5 * eccen);
1291
+ }
1292
+ function initialize3(state) {
1293
+ state.x0 = state.x0 || 0;
1294
+ state.y0 = state.y0 || 0;
1295
+ state.lat0 = state.lat0 || 0;
1296
+ state.long0 = state.long0 || 0;
1297
+ state.coslat0 = Math.cos(state.lat0);
1298
+ state.sinlat0 = Math.sin(state.lat0);
1299
+ if (state.sphere) {
1300
+ if (!Number.isNaN(state.lat_ts) && Math.abs(state.coslat0) <= EPSLN) {
1301
+ state.k0 = 0.5 * (1 + sign_default(state.lat0) * Math.sin(state.lat_ts));
1302
+ }
1303
+ } else {
1304
+ if (Math.abs(state.coslat0) <= EPSLN) {
1305
+ if (state.lat0 > 0) {
1306
+ state.con = 1;
1307
+ } else {
1308
+ state.con = -1;
1309
+ }
1310
+ }
1311
+ state.cons = Math.sqrt(Math.pow(1 + state.e, 1 + state.e) * Math.pow(1 - state.e, 1 - state.e));
1312
+ if (!Number.isNaN(state.lat_ts) && Math.abs(state.coslat0) <= EPSLN && Math.abs(Math.cos(state.lat_ts)) > EPSLN) {
1313
+ state.k0 = 0.5 * state.cons * msfnz_default(state.e, Math.sin(state.lat_ts), Math.cos(state.lat_ts)) / tsfnz_default(state.e, state.con * state.lat_ts, state.con * Math.sin(state.lat_ts));
1314
+ }
1315
+ state.ms1 = msfnz_default(state.e, state.sinlat0, state.coslat0);
1316
+ state.X0 = 2 * Math.atan(ssfn_(state.lat0, state.sinlat0, state.e)) - HALF_PI;
1317
+ state.cosX0 = Math.cos(state.X0);
1318
+ state.sinX0 = Math.sin(state.X0);
1319
+ }
1320
+ }
1321
+ function forward3(state, p) {
1322
+ var lon = p.x;
1323
+ var lat = p.y;
1324
+ var sinlat = Math.sin(lat);
1325
+ var coslat = Math.cos(lat);
1326
+ var A2, X, sinX, cosX, ts, rh;
1327
+ var dlon = adjust_lon_default(lon - state.long0, state.over);
1328
+ if (Math.abs(Math.abs(lon - state.long0) - Math.PI) <= EPSLN && Math.abs(lat + state.lat0) <= EPSLN) {
1329
+ p.x = NaN;
1330
+ p.y = NaN;
1331
+ return p;
1332
+ }
1333
+ if (state.sphere && Math.abs(state.coslat0) <= EPSLN) {
1334
+ const sign = state.lat0 > 0 ? 1 : -1;
1335
+ const radius = 2 * state.a * state.k0 * Math.tan(Math.PI / 4 - sign * lat / 2);
1336
+ p.x = state.x0 + radius * Math.sin(dlon);
1337
+ p.y = state.y0 - sign * radius * Math.cos(dlon);
1338
+ return p;
1339
+ }
1340
+ if (state.sphere) {
1341
+ A2 = 2 * state.k0 / (1 + state.sinlat0 * sinlat + state.coslat0 * coslat * Math.cos(dlon));
1342
+ p.x = state.a * A2 * coslat * Math.sin(dlon) + state.x0;
1343
+ p.y = state.a * A2 * (state.coslat0 * sinlat - state.sinlat0 * coslat * Math.cos(dlon)) + state.y0;
1344
+ return p;
1345
+ } else {
1346
+ X = 2 * Math.atan(ssfn_(lat, sinlat, state.e)) - HALF_PI;
1347
+ cosX = Math.cos(X);
1348
+ sinX = Math.sin(X);
1349
+ if (Math.abs(state.coslat0) <= EPSLN) {
1350
+ ts = tsfnz_default(state.e, lat * state.con, state.con * sinlat);
1351
+ rh = 2 * state.a * state.k0 * ts / state.cons;
1352
+ p.x = state.x0 + rh * Math.sin(lon - state.long0);
1353
+ p.y = state.y0 - state.con * rh * Math.cos(lon - state.long0);
1354
+ return p;
1355
+ } else if (Math.abs(state.sinlat0) < EPSLN) {
1356
+ A2 = 2 * state.a * state.k0 / (1 + cosX * Math.cos(dlon));
1357
+ p.y = A2 * sinX + state.y0;
1358
+ } else {
1359
+ A2 = 2 * state.a * state.k0 * state.ms1 / (state.cosX0 * (1 + state.sinX0 * sinX + state.cosX0 * cosX * Math.cos(dlon)));
1360
+ p.y = A2 * (state.cosX0 * sinX - state.sinX0 * cosX * Math.cos(dlon)) + state.y0;
1361
+ }
1362
+ p.x = A2 * cosX * Math.sin(dlon) + state.x0;
1363
+ }
1364
+ return p;
1365
+ }
1366
+ function inverse3(state, p) {
1367
+ p.x -= state.x0;
1368
+ p.y -= state.y0;
1369
+ var lon, lat, ts, ce, Chi;
1370
+ var rh = Math.sqrt(p.x * p.x + p.y * p.y);
1371
+ if (state.sphere) {
1372
+ var c = 2 * Math.atan(rh / (2 * state.a * state.k0));
1373
+ lon = state.long0;
1374
+ lat = state.lat0;
1375
+ if (rh <= EPSLN) {
1376
+ p.x = lon;
1377
+ p.y = lat;
1378
+ return p;
1379
+ }
1380
+ lat = inverseSphericalLatitude(state.sinlat0, state.coslat0, Math.sin(c), Math.cos(c), p.x, p.y, rh);
1381
+ if (Math.abs(state.coslat0) < EPSLN) {
1382
+ if (state.lat0 > 0) {
1383
+ lon = adjust_lon_default(state.long0 + Math.atan2(p.x, -1 * p.y), state.over);
1384
+ } else {
1385
+ lon = adjust_lon_default(state.long0 + Math.atan2(p.x, p.y), state.over);
1386
+ }
1387
+ } else {
1388
+ lon = adjust_lon_default(state.long0 + Math.atan2(p.x * Math.sin(c), rh * state.coslat0 * Math.cos(c) - p.y * state.sinlat0 * Math.sin(c)), state.over);
1389
+ }
1390
+ p.x = lon;
1391
+ p.y = lat;
1392
+ return p;
1393
+ } else {
1394
+ if (Math.abs(state.coslat0) <= EPSLN) {
1395
+ if (rh <= EPSLN) {
1396
+ lat = state.lat0;
1397
+ lon = state.long0;
1398
+ p.x = lon;
1399
+ p.y = lat;
1400
+ return p;
1401
+ }
1402
+ p.x *= state.con;
1403
+ p.y *= state.con;
1404
+ ts = rh * state.cons / (2 * state.a * state.k0);
1405
+ lat = state.con * phi2z_default(state.e, ts);
1406
+ lon = state.con * adjust_lon_default(state.con * state.long0 + Math.atan2(p.x, -1 * p.y), state.over);
1407
+ } else {
1408
+ ce = 2 * Math.atan(rh * state.cosX0 / (2 * state.a * state.k0 * state.ms1));
1409
+ lon = state.long0;
1410
+ if (rh <= EPSLN) {
1411
+ Chi = state.X0;
1412
+ } else {
1413
+ Chi = inverseSphericalLatitude(state.sinX0, state.cosX0, Math.sin(ce), Math.cos(ce), p.x, p.y, rh);
1414
+ lon = adjust_lon_default(state.long0 + Math.atan2(p.x * Math.sin(ce), rh * state.cosX0 * Math.cos(ce) - p.y * state.sinX0 * Math.sin(ce)), state.over);
1415
+ }
1416
+ lat = -1 * phi2z_default(state.e, Math.tan(0.5 * (HALF_PI + Chi)));
1417
+ }
1418
+ }
1419
+ p.x = lon;
1420
+ p.y = lat;
1421
+ return p;
1422
+ }
1423
+ function createState3(base) {
1424
+ const state = {
1425
+ ...base,
1426
+ coslat0: 0,
1427
+ sinlat0: 0,
1428
+ con: 0,
1429
+ cons: 0,
1430
+ ms1: 0,
1431
+ X0: 0,
1432
+ cosX0: 0,
1433
+ sinX0: 0
1434
+ };
1435
+ initialize3(state);
1436
+ return state;
1437
+ }
1438
+
1439
+ // dist/projection/experimental/projections/stere.js
1440
+ var stereographic = {
1441
+ name: "stere",
1442
+ aliases: [
1443
+ "Stereographic_South_Pole",
1444
+ "Polar_Stereographic_variant_A",
1445
+ "Polar_Stereographic_variant_B",
1446
+ "Polar_Stereographic"
1447
+ ],
1448
+ parameters: [...ORIGIN_PARAMETERS, ...SCALE_PARAMETERS, "lat_ts"],
1449
+ create(context) {
1450
+ const base = kernelParameters(context);
1451
+ const state = createState3(base);
1452
+ const projection2 = guardAzimuthalDomain(base, bindKernel("stere", state, forward3, inverse3));
1453
+ return withAngularRenderingProfile(projection2, base, 150 * Math.PI / 180, (region, domain) => state.sphere ? sphericalAzimuthalBounds(state, region, domain, "stere") : ellipsoidalStereographicBounds(state, (latitude) => 2 * Math.atan(Math.tan(Math.PI / 4 + latitude / 2) * Math.pow((1 - state.e * Math.sin(latitude)) / (1 + state.e * Math.sin(latitude)), state.e / 2)) - Math.PI / 2, state.X0, 2 * state.a * state.k0 * (Math.abs(state.coslat0) < 1e-10 ? 1 / state.cons : state.ms1 / state.cosX0), region, domain));
1454
+ }
1455
+ };
1456
+
1457
+ // dist/coordinates/grid.js
1458
+ var DEG = Math.PI / 180;
1459
+ var A = 6378137;
1460
+ var F = 1 / 298.257223563;
1461
+ function standardGridZone(latitude, longitude) {
1462
+ if (!Number.isFinite(latitude) || Math.abs(latitude) > 90 || !Number.isFinite(longitude) || Math.abs(longitude) > 180)
1463
+ throw new RangeError("Expected latitude/longitude degrees in [-90,90]/[-180,180]");
1464
+ if (latitude < -80 || latitude >= 84)
1465
+ return 0;
1466
+ const lon = longitude === 180 ? -180 : longitude;
1467
+ let zone = Math.floor((Math.floor(lon) + 186) / 6);
1468
+ if (latitude >= 56 && latitude < 64 && lon >= 3 && lon < 12)
1469
+ zone = 32;
1470
+ if (latitude >= 72 && lon >= 0 && lon < 42)
1471
+ zone = 2 * Math.floor((Math.floor(lon) + 183) / 12) + 1;
1472
+ return zone;
1473
+ }
1474
+ var prepared = /* @__PURE__ */ new Map();
1475
+ function projection(zone, north) {
1476
+ if (!Number.isInteger(zone) || zone < 0 || zone > 60 || typeof north !== "boolean")
1477
+ throw new RangeError("Invalid UTM/UPS zone or hemisphere");
1478
+ const key = 2 * zone + Number(north), cached = prepared.get(key);
1479
+ if (cached)
1480
+ return cached;
1481
+ const parameters = zone ? { zone: String(zone), ...north ? {} : { south: void 0 } } : {
1482
+ lat_0: north ? "90" : "-90",
1483
+ k_0: "0.994",
1484
+ x_0: "2000000",
1485
+ y_0: "2000000"
1486
+ };
1487
+ const result = (zone ? universalTransverseMercator : stereographic).create({
1488
+ semiMajorAxis: A,
1489
+ eccentricitySquared: F * (2 - F),
1490
+ parameters
1491
+ });
1492
+ prepared.set(key, result);
1493
+ return result;
1494
+ }
1495
+ function projectGrid(latitude, longitude, options = {}) {
1496
+ const standard = standardGridZone(latitude, longitude), zone = options.zone ?? standard, naturalNorth = !(latitude < 0 || Object.is(latitude, -0)), north = options.north ?? naturalNorth;
1497
+ validateZone(zone, north);
1498
+ if (zone === 0 && (Math.abs(latitude) < 70 || north !== naturalNorth))
1499
+ throw new RangeError("UPS requires its matching polar hemisphere");
1500
+ if (zone && Math.abs((longitude - (6 * zone - 183) + 540) % 360 - 180) > 60)
1501
+ throw new RangeError("Longitude too far from UTM central meridian");
1502
+ if (zone === 0 && Math.abs(latitude) === 90)
1503
+ return { zone, north, easting: 2e6, northing: 2e6 };
1504
+ const p = projection(zone, north).forward(longitude * DEG, latitude * DEG);
1505
+ if (zone === 0) {
1506
+ if (longitude % 180 === 0)
1507
+ p[0] = 2e6;
1508
+ if (Math.abs(longitude) === 90)
1509
+ p[1] = 2e6;
1510
+ }
1511
+ const result = { zone, north, easting: p[0], northing: p[1] };
1512
+ validateGrid(result, options.extended === true);
1513
+ return result;
1514
+ }
1515
+ function validateZone(zone, north) {
1516
+ if (!Number.isInteger(zone) || zone < 0 || zone > 60 || typeof north !== "boolean")
1517
+ throw new RangeError("Invalid UTM/UPS zone or hemisphere");
1518
+ }
1519
+ function validateGrid({ zone, north, easting, northing }, extended) {
1520
+ validateZone(zone, north);
1521
+ const polar = zone === 0, slop = extended ? 1e5 : 0, low = polar ? north ? 13e5 : 8e5 : 1e5, high = polar ? north ? 27e5 : 32e5 : 9e5, lowY = polar ? low : north ? extended ? -9e6 : 0 : 1e6, highY = polar ? high : north ? 95e5 : extended ? 195e5 : 1e7;
1522
+ if (!Number.isFinite(easting) || !Number.isFinite(northing) || easting < low - slop || easting > high + slop || northing < lowY - slop || northing > highY + slop)
1523
+ throw new RangeError("Grid coordinates outside the supported envelope");
1524
+ }
1525
+ function unprojectGrid(grid, options = {}) {
1526
+ validateGrid(grid, options.extended === true);
1527
+ const p = projection(grid.zone, grid.north).inverse(grid.easting, grid.northing);
1528
+ return { latitude: p[1] / DEG, longitude: p[0] / DEG };
1529
+ }
1530
+ function transferGrid(grid, options = {}) {
1531
+ validateGrid(grid, options.extended === true);
1532
+ const zone = options.zone ?? grid.zone, north = options.north ?? grid.north;
1533
+ validateZone(zone, north);
1534
+ if (zone === grid.zone) {
1535
+ if (zone === 0 && north !== grid.north)
1536
+ throw new RangeError("Cannot transfer UPS hemispheres");
1537
+ const result = {
1538
+ ...grid,
1539
+ north,
1540
+ northing: north === grid.north ? grid.northing : grid.northing + (north ? -1e7 : 1e7)
1541
+ };
1542
+ validateGrid(result, options.extended === true);
1543
+ return result;
1544
+ }
1545
+ const p = unprojectGrid(grid, options);
1546
+ return projectGrid(p.latitude, p.longitude, { ...options, zone, north });
1547
+ }
1548
+
1549
+ // dist/coordinates/mgrs.js
1550
+ var COLUMNS = ["ABCDEFGH", "JKLMNPQR", "STUVWXYZ"];
1551
+ var ROWS = "ABCDEFGHJKLMNPQRSTUV";
1552
+ var BANDS = "CDEFGHJKLMNPQRSTUVWX";
1553
+ var UPS_COLUMNS = ["JKLPQRSTUXYZ", "ABCFGHJKLPQR", "RSTUXYZ", "ABCFGHJ"];
1554
+ var UPS_ROWS = ["ABCDEFGHJKLMNPQRSTUVWXYZ", "ABCDEFGHJKLMNP"];
1555
+ var UPS_BANDS = "ABYZ";
1556
+ var TILE = 1e5;
1557
+ function utmRow(band, column, row) {
1558
+ const c = 100 * (8 * band + 4) / 90, north = band >= 0;
1559
+ const min = band > -10 ? Math.floor(c - 4.3 - (north ? 0.1 : 0)) : -90, max = band < 9 ? Math.floor(c + 4.4 - (north ? 0.1 : 0)) : 94;
1560
+ const base = Math.trunc((min + max) / 2) - 10;
1561
+ row = ((row - base + 100) % 20 + 20) % 20 + base;
1562
+ if (row < min || row > max) {
1563
+ const b = band >= 0 ? band : -band - 1, r = row >= 0 ? row : -row - 1, col = column < 4 ? column : 7 - column;
1564
+ if (!(r === 70 && b === 8 && col >= 2 || r === 71 && b === 7 && col <= 2 || r === 79 && b === 9 && col >= 1 || r === 80 && b === 8 && col <= 1))
1565
+ throw new RangeError("MGRS square does not intersect its latitude band");
1566
+ }
1567
+ return row;
1568
+ }
1569
+ function formatMGRS(latitude, longitude, precision = 5, options = {}) {
1570
+ if (!Number.isInteger(precision) || precision < 0 || precision > 11)
1571
+ throw new RangeError("MGRS precision must be in [0,11]");
1572
+ const grid = projectGrid(latitude, longitude, options), { zone, north, easting: x } = grid;
1573
+ let y = grid.northing;
1574
+ if (zone && !north && y === 1e7)
1575
+ y -= 2 ** -28;
1576
+ const column = Math.floor(x / TILE), row = Math.floor(y / TILE);
1577
+ let prefix;
1578
+ if (zone) {
1579
+ const band = Math.abs(latitude) < 2 ** -46 ? north ? 0 : -1 : Math.max(-10, Math.min(9, Math.floor((Math.floor(latitude) + 80) / 8) - 10));
1580
+ if (column < 1 || column > 8 || utmRow(band, column - 1, row % 20) !== row - (north ? 0 : 100))
1581
+ throw new RangeError("Grid outside MGRS domain");
1582
+ prefix = String(zone).padStart(2, "0") + BANDS[band + 10] + COLUMNS[(zone - 1) % 3][column - 1] + ROWS[(row + ((zone - 1) % 2 ? 5 : 0)) % 20];
1583
+ } else {
1584
+ const band = (north ? 2 : 0) + (column >= 20 ? 1 : 0), origin = north ? 13 : 8;
1585
+ const col = column - (column >= 20 ? 20 : origin), r = row - origin;
1586
+ if (col < 0 || col >= UPS_COLUMNS[band].length || r < 0 || r >= UPS_ROWS[Number(north)].length)
1587
+ throw new RangeError("Grid outside MGRS domain");
1588
+ prefix = UPS_BANDS[band] + UPS_COLUMNS[band][col] + UPS_ROWS[Number(north)][r];
1589
+ }
1590
+ const unit = 10 ** (11 - precision);
1591
+ const digits = (value, tile) => String(Math.floor((Math.floor(value * 1e6) - tile * 1e11) / unit)).padStart(precision, "0");
1592
+ return prefix + (precision ? digits(x, column) + digits(y, row) : "");
1593
+ }
1594
+ function parseMGRS(text, options = {}) {
1595
+ if (typeof text !== "string" || text.length > 128)
1596
+ throw new RangeError("Invalid MGRS text");
1597
+ const match = /^(\d{1,2})?([C-HJ-NP-XABYZ])([A-HJ-NP-Z])([A-HJ-NP-Z])(\d*)$/.exec(text.replace(/\s/g, "").toUpperCase());
1598
+ if (!match || match[5].length % 2 || match[5].length > 22)
1599
+ throw new RangeError("Expected a complete MGRS cell with 0\u201311 digit pairs");
1600
+ const zone = match[1] ? Number(match[1]) : 0, bandText = match[2], precision = match[5].length / 2;
1601
+ let north, column, row;
1602
+ if (match[1]) {
1603
+ if (zone < 1 || zone > 60)
1604
+ throw new RangeError("Invalid MGRS zone");
1605
+ const band = BANDS.indexOf(bandText) - 10;
1606
+ if (band < -10)
1607
+ throw new RangeError("Invalid UTM band");
1608
+ north = band >= 0;
1609
+ column = COLUMNS[(zone - 1) % 3].indexOf(match[3]);
1610
+ row = ROWS.indexOf(match[4]);
1611
+ if (column < 0 || row < 0)
1612
+ throw new RangeError("Invalid MGRS square");
1613
+ row = utmRow(band, column, (row + ((zone - 1) % 2 ? 15 : 0)) % 20) + (north ? 0 : 100);
1614
+ column++;
1615
+ } else {
1616
+ const band = UPS_BANDS.indexOf(bandText);
1617
+ if (band < 0)
1618
+ throw new RangeError("Invalid UPS band");
1619
+ north = band >= 2;
1620
+ column = UPS_COLUMNS[band].indexOf(match[3]);
1621
+ row = UPS_ROWS[Number(north)].indexOf(match[4]);
1622
+ if (column < 0 || row < 0)
1623
+ throw new RangeError("Invalid UPS square");
1624
+ column += band % 2 ? 20 : north ? 13 : 8;
1625
+ row += north ? 13 : 8;
1626
+ }
1627
+ const resolution = 10 ** (5 - precision), center = options.center === false ? 0 : 0.5;
1628
+ const grid = {
1629
+ zone,
1630
+ north,
1631
+ easting: (column * 10 ** precision + Number(match[5].slice(0, precision) || 0) + center) * TILE / 10 ** precision,
1632
+ northing: (row * 10 ** precision + Number(match[5].slice(precision) || 0) + center) * TILE / 10 ** precision
1633
+ };
1634
+ return { ...grid, ...unprojectGrid(grid), precision, resolution };
1635
+ }
1636
+ function parseMGRSZone(text) {
1637
+ if (typeof text !== "string" || text.length > 128)
1638
+ throw new RangeError("Invalid MGRS zone");
1639
+ const m = /^(\d{1,2})?([C-HJ-NP-XABYZ])$/.exec(text.replace(/\s/g, "").toUpperCase());
1640
+ if (!m)
1641
+ throw new RangeError("Expected an MGRS grid-zone designation");
1642
+ const zone = m[1] ? Number(m[1]) : 0, band = m[2];
1643
+ if (m[1] ? zone < 1 || zone > 60 || !BANDS.includes(band) : !UPS_BANDS.includes(band))
1644
+ throw new RangeError("Invalid MGRS zone or band");
1645
+ return {
1646
+ zone,
1647
+ north: zone ? BANDS.indexOf(band) >= 10 : UPS_BANDS.indexOf(band) >= 2,
1648
+ band
1649
+ };
1650
+ }
1651
+ function formatMGRSZone(latitude, longitude, options = {}) {
1652
+ const cell = formatMGRS(latitude, longitude, 0, options);
1653
+ return cell.slice(0, cell.length - 2);
1654
+ }
1655
+
1656
+ // dist/local-reference-frame.js
1657
+ var import_matrix5 = require("@math.gl/core/matrix");
1658
+ var import_matrix6 = require("@math.gl/core/matrix");
1659
+
1660
+ // dist/ellipsoid.js
1661
+ var import_matrix3 = require("@math.gl/core/matrix");
1662
+ var import_matrix4 = require("@math.gl/core/matrix");
1663
+
1664
+ // dist/constants.js
1665
+ var WGS84_RADIUS_X = 6378137;
1666
+ var WGS84_RADIUS_Y = 6378137;
1667
+ var WGS84_RADIUS_Z = 6356752314245179e-9;
1668
+ var WGS84_CONSTANTS = {
1669
+ radii: [WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z],
1670
+ radiiSquared: [
1671
+ WGS84_RADIUS_X * WGS84_RADIUS_X,
1672
+ WGS84_RADIUS_Y * WGS84_RADIUS_Y,
1673
+ WGS84_RADIUS_Z * WGS84_RADIUS_Z
1674
+ ],
1675
+ oneOverRadii: [1 / WGS84_RADIUS_X, 1 / WGS84_RADIUS_Y, 1 / WGS84_RADIUS_Z],
1676
+ oneOverRadiiSquared: [
1677
+ 1 / (WGS84_RADIUS_X * WGS84_RADIUS_X),
1678
+ 1 / (WGS84_RADIUS_Y * WGS84_RADIUS_Y),
1679
+ 1 / (WGS84_RADIUS_Z * WGS84_RADIUS_Z)
1680
+ ],
1681
+ maximumRadius: Math.max(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z),
1682
+ centerToleranceSquared: 0.1
1683
+ // EPSILON1;
1684
+ };
1685
+
1686
+ // dist/type-utils.js
1687
+ var import_matrix = require("@math.gl/core/matrix");
1688
+ function identity(x) {
1689
+ return x;
1690
+ }
1691
+ var scratchVector = new import_matrix.Vector3();
1692
+ function fromCartographic(cartographic, result = [], map = identity) {
1693
+ if ("longitude" in cartographic) {
1694
+ result[0] = map(cartographic.longitude);
1695
+ result[1] = map(cartographic.latitude);
1696
+ result[2] = cartographic.height;
1697
+ } else if ("x" in cartographic) {
1698
+ result[0] = map(cartographic.x);
1699
+ result[1] = map(cartographic.y);
1700
+ result[2] = cartographic.z;
1701
+ } else {
1702
+ result[0] = map(cartographic[0]);
1703
+ result[1] = map(cartographic[1]);
1704
+ result[2] = cartographic[2];
1705
+ }
1706
+ return result;
1707
+ }
1708
+ function fromCartographicToRadians(cartographic, vector = []) {
1709
+ return fromCartographic(cartographic, vector, import_matrix.config._cartographicRadians ? identity : import_matrix.toRadians);
1710
+ }
1711
+ function toCartographicFromRadiansComponents(longitude, latitude, height, cartographic) {
1712
+ const map = import_matrix.config._cartographicRadians ? identity : import_matrix.toDegrees;
1713
+ const mappedLongitude = map(longitude), mappedLatitude = map(latitude);
1714
+ if ("longitude" in cartographic) {
1715
+ cartographic.longitude = mappedLongitude;
1716
+ cartographic.latitude = mappedLatitude;
1717
+ cartographic.height = height;
1718
+ } else if ("x" in cartographic) {
1719
+ cartographic.x = mappedLongitude;
1720
+ cartographic.y = mappedLatitude;
1721
+ cartographic.z = height;
1722
+ } else {
1723
+ cartographic[0] = mappedLongitude;
1724
+ cartographic[1] = mappedLatitude;
1725
+ cartographic[2] = height;
1726
+ }
1727
+ return cartographic;
1728
+ }
1729
+
1730
+ // dist/ellipsoid-helpers/scale-to-geodetic-surface.js
1731
+ var import_matrix2 = require("@math.gl/core/matrix");
1732
+
1733
+ // dist/ellipsoid-helpers/exact-nearest-surface.js
1734
+ function exactNearestSurface(x, y, z, a, b, c, result) {
1735
+ const values = [a, b, c, Math.abs(x), Math.abs(y), Math.abs(z)];
1736
+ const parts = values.map((value) => {
1737
+ const bits = value.toString(2);
1738
+ const dot2 = bits.indexOf(".");
1739
+ return {
1740
+ integer: BigInt("0b" + bits.replace(".", "")),
1741
+ exponent: dot2 < 0 ? 0 : dot2 + 1 - bits.length
1742
+ };
1743
+ });
1744
+ const exponent = Math.min(...parts.filter((p) => p.integer !== 0n).map((p) => p.exponent));
1745
+ const integers = parts.map((p) => p.integer << BigInt(p.exponent - exponent));
1746
+ const squares = integers.slice(0, 3).map((v) => v * v);
1747
+ const minimum = squares.reduce((p, v) => p < v ? p : v);
1748
+ const offsets = squares.map((v) => v - minimum);
1749
+ const products = squares.map((_, i) => integers[i] * integers[i + 3]);
1750
+ let precision = 64;
1751
+ if (!products.some((u3, i) => offsets[i] === 0n && u3 !== 0n)) {
1752
+ let numerator = -1n, denominator = 1n;
1753
+ for (let i = 0; i < 3; i++) {
1754
+ if (offsets[i] === 0n)
1755
+ continue;
1756
+ const d2 = offsets[i] * offsets[i];
1757
+ numerator = numerator * d2 + products[i] * products[i] * denominator;
1758
+ denominator *= d2;
1759
+ }
1760
+ if (numerator < 0n)
1761
+ return false;
1762
+ if (numerator === 0n) {
1763
+ return commit(0n, 1n);
1764
+ }
1765
+ const positive = offsets.filter((d2) => d2 > 0n);
1766
+ const least = positive.reduce((p, v) => p < v ? p : v);
1767
+ precision = Math.max(64, (2n * (denominator + numerator)).toString(2).length - (numerator * least).toString(2).length + 128);
1768
+ }
1769
+ const unit = 1n << BigInt(precision);
1770
+ const d = offsets.map((v) => v * unit);
1771
+ const u = products.map((v) => v * unit);
1772
+ const u2 = u.map((v) => v * v);
1773
+ let lower = 0n, upper = u.reduce((sum, v) => sum + v, 0n);
1774
+ if (upper === 0n)
1775
+ return false;
1776
+ for (let iteration = 0; iteration < 4096; iteration++) {
1777
+ const t = lower + upper >> 1n;
1778
+ if (t === lower)
1779
+ return false;
1780
+ const dx = d[0] + t, dy = d[1] + t, dz = d[2] + t;
1781
+ const xx = dx * dx, yy = dy * dy, zz = dz * dz;
1782
+ const sign = u2[0] * yy * zz + u2[1] * xx * zz + u2[2] * xx * yy - xx * yy * zz;
1783
+ if (sign === 0n)
1784
+ return commit(t, unit);
1785
+ if (sign > 0n)
1786
+ lower = t;
1787
+ else
1788
+ upper = t;
1789
+ if (lower > 0n && upper - lower <= lower >> 60n)
1790
+ return commit(lower + upper >> 1n, unit);
1791
+ }
1792
+ return false;
1793
+ function commit(t, unit2) {
1794
+ const output = squares.map((r2, i) => {
1795
+ const denominator = offsets[i] * unit2 + t;
1796
+ return denominator === 0n ? 0 : ratio(r2 * integers[i + 3] * unit2, denominator, exponent);
1797
+ });
1798
+ if (!output.every(Number.isFinite))
1799
+ return false;
1800
+ const qx = Math.sign(x) * output[0], qy = Math.sign(y) * output[1], qz = Math.sign(z) * output[2];
1801
+ result.x = qx;
1802
+ result.y = qy;
1803
+ result.z = qz;
1804
+ return true;
1805
+ }
1806
+ }
1807
+ function ratio(n, d, exponent) {
1808
+ if (n === 0n)
1809
+ return 0;
1810
+ const shift = 52 - (n.toString(2).length - d.toString(2).length);
1811
+ const numerator = shift >= 0 ? n << BigInt(shift) : n;
1812
+ const denominator = shift >= 0 ? d : d << BigInt(-shift);
1813
+ let quotient = numerator / denominator;
1814
+ const remainder = numerator % denominator;
1815
+ if (2n * remainder > denominator || 2n * remainder === denominator && quotient & 1n)
1816
+ quotient++;
1817
+ const power = exponent - shift;
1818
+ const first = Math.max(-1022, Math.min(1023, power));
1819
+ return Number(quotient) * 2 ** first * 2 ** (power - first);
1820
+ }
1821
+
1822
+ // dist/ellipsoid-helpers/nearest-surface.js
1823
+ function nearestSurface(x, y, z, a, b, c, result) {
1824
+ const minimum = Math.min(a, b, c);
1825
+ const minimumSquared = minimum * minimum;
1826
+ const aa = a * a, bb = b * b, cc = c * c;
1827
+ if (!(minimum > 0) || !(minimumSquared > 0) || !Number.isFinite(Math.max(aa, bb, cc)))
1828
+ return false;
1829
+ const minimumError = productError(minimum, minimum, minimumSquared);
1830
+ const dx = aa - minimumSquared, dy = bb - minimumSquared, dz = cc - minimumSquared;
1831
+ const ex = sumError(aa, -minimumSquared, dx) + productError(a, a, aa) - minimumError;
1832
+ const ey = sumError(bb, -minimumSquared, dy) + productError(b, b, bb) - minimumError;
1833
+ const ez = sumError(cc, -minimumSquared, dz) + productError(c, c, cc) - minimumError;
1834
+ const ux = a * Math.abs(x), uy = b * Math.abs(y), uz = c * Math.abs(z);
1835
+ if (minimumSquared < 2 ** -1022 || x !== 0 && ux < 2 ** -1022 || y !== 0 && uy < 2 ** -1022 || z !== 0 && uz < 2 ** -1022)
1836
+ return exactNearestSurface(x, y, z, a, b, c, result);
1837
+ const fx = productError(a, Math.abs(x), ux);
1838
+ const fy = productError(b, Math.abs(y), uy);
1839
+ const fz = productError(c, Math.abs(z), uz);
1840
+ const limit = Math.hypot(dx === 0 ? ux === 0 ? 0 : Infinity : ux / (dx + ex), dy === 0 ? uy === 0 ? 0 : Infinity : uy / (dy + ey), dz === 0 ? uz === 0 ? 0 : Infinity : uz / (dz + ez));
1841
+ if (limit <= 1 + 64 * Number.EPSILON)
1842
+ return exactNearestSurface(x, y, z, a, b, c, result);
1843
+ if ((x !== 0 ? 1 : 0) + (y !== 0 ? 1 : 0) + (z !== 0 ? 1 : 0) === 1) {
1844
+ result.x = x === 0 ? x : Math.sign(x) * a;
1845
+ result.y = y === 0 ? y : Math.sign(y) * b;
1846
+ result.z = z === 0 ? z : Math.sign(z) * c;
1847
+ return true;
1848
+ }
1849
+ let lower = Math.hypot(dx === 0 ? ux : 0, dy === 0 ? uy : 0, dz === 0 ? uz : 0);
1850
+ let upper = Math.hypot(ux, uy, uz);
1851
+ if (!(upper > 0) || !Number.isFinite(upper))
1852
+ return exactNearestSurface(x, y, z, a, b, c, result);
1853
+ let t = lower > 0 ? lower : upper;
1854
+ for (let iteration = 0; iteration < 512; iteration++) {
1855
+ const hx = dx + t, hy = dy + t, hz = dz + t;
1856
+ const lx = sumError(dx, t, hx) + ex;
1857
+ const ly = sumError(dy, t, hy) + ey;
1858
+ const lz = sumError(dz, t, hz) + ez;
1859
+ const vx = ux / hx, vy = uy / hy, vz = uz / hz;
1860
+ let term, rest;
1861
+ if (vx >= vy && vx >= vz) {
1862
+ term = offset(ux, fx, dx, ex, t, hx) * (vx + 1);
1863
+ rest = (vy * (1 - ly / hy)) ** 2 + (vz * (1 - lz / hz)) ** 2;
1864
+ } else if (vy >= vz) {
1865
+ term = offset(uy, fy, dy, ey, t, hy) * (vy + 1);
1866
+ rest = (vx * (1 - lx / hx)) ** 2 + (vz * (1 - lz / hz)) ** 2;
1867
+ } else {
1868
+ term = offset(uz, fz, dz, ez, t, hz) * (vz + 1);
1869
+ rest = (vx * (1 - lx / hx)) ** 2 + (vy * (1 - ly / hy)) ** 2;
1870
+ }
1871
+ const derivative = -2 * (vx * vx / hx + vy * vy / hy + vz * vz / hz);
1872
+ const roundoff = 4 * Number.EPSILON * (Math.abs(term) + rest);
1873
+ const residual = term + rest;
1874
+ if (!Number.isFinite(residual))
1875
+ return exactNearestSurface(x, y, z, a, b, c, result);
1876
+ if (Math.abs(residual) <= 4 * Number.EPSILON * (Math.abs(term) + rest) || upper - lower <= 4 * Number.EPSILON * t) {
1877
+ const uncertainty = roundoff / Math.abs(derivative);
1878
+ if (!Number.isFinite(derivative) || !(Math.abs(derivative) > 0) || uncertainty > 2e-13 * t)
1879
+ return exactNearestSurface(x, y, z, a, b, c, result);
1880
+ const qx = Math.sign(x) * a * (vx * (1 - lx / hx));
1881
+ const qy = Math.sign(y) * b * (vy * (1 - ly / hy));
1882
+ const qz = Math.sign(z) * c * (vz * (1 - lz / hz));
1883
+ const displacement = 2 * uncertainty * Math.max(Math.abs(qx / hx), Math.abs(qy / hy), Math.abs(qz / hz));
1884
+ if (!Number.isFinite(displacement) || displacement > 2e-13 * Math.max(a, b, c))
1885
+ return exactNearestSurface(x, y, z, a, b, c, result);
1886
+ if (!Number.isFinite(qx) || !Number.isFinite(qy) || !Number.isFinite(qz))
1887
+ return exactNearestSurface(x, y, z, a, b, c, result);
1888
+ result.x = qx;
1889
+ result.y = qy;
1890
+ result.z = qz;
1891
+ return true;
1892
+ }
1893
+ if (residual > 0)
1894
+ lower = t;
1895
+ else
1896
+ upper = t;
1897
+ const candidate = t - residual / derivative;
1898
+ const next = candidate > lower && candidate < upper ? candidate : lower + (upper - lower) / 2;
1899
+ if (next === t)
1900
+ return exactNearestSurface(x, y, z, a, b, c, result);
1901
+ t = next;
1902
+ }
1903
+ return exactNearestSurface(x, y, z, a, b, c, result);
1904
+ }
1905
+ function offset(u, error, d, dError, t, denominator) {
1906
+ const difference = u - d;
1907
+ const correction = sumError(u, -d, difference) + error - dError;
1908
+ const base = difference + correction;
1909
+ const low = sumError(difference, correction, base);
1910
+ const shifted = base - t;
1911
+ return (shifted + (sumError(base, -t, shifted) + low)) / denominator;
1912
+ }
1913
+ function sumError(x, y, sum) {
1914
+ const part = sum - x;
1915
+ return x - (sum - part) + (y - part);
1916
+ }
1917
+ function productError(x, y, product) {
1918
+ const sx = 134217729 * x, sy = 134217729 * y;
1919
+ if (!Number.isFinite(sx) || !Number.isFinite(sy))
1920
+ return 0;
1921
+ const hx = sx - (sx - x), hy = sy - (sy - y);
1922
+ const lx = x - hx, ly = y - hy;
1923
+ return hx * hy - product + hx * ly + lx * hy + lx * ly;
1924
+ }
1925
+
1926
+ // dist/ellipsoid-helpers/scale-to-geodetic-surface.js
1927
+ var surface = { x: 0, y: 0, z: 0 };
1928
+ function scaleToGeodeticSurface(cartesian, ellipsoid, result = []) {
1929
+ const object = cartesian;
1930
+ const x = "x" in cartesian ? object.x : cartesian[0];
1931
+ const y = "x" in cartesian ? object.y : cartesian[1];
1932
+ const z = "x" in cartesian ? object.z : cartesian[2];
1933
+ if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z))
1934
+ return void 0;
1935
+ if (!Number.isFinite(x * x + y * y + z * z))
1936
+ return void 0;
1937
+ const { radii } = ellipsoid;
1938
+ if (!nearestSurface(x, y, z, radii.x, radii.y, radii.z, surface))
1939
+ return void 0;
1940
+ return writeResult(result, surface.x, surface.y, surface.z);
1941
+ }
1942
+ function writeResult(result, x, y, z) {
1943
+ if ((0, import_matrix2.isArray)(result)) {
1944
+ result[0] = x;
1945
+ result[1] = y;
1946
+ result[2] = z;
1947
+ } else {
1948
+ const point = result;
1949
+ point.x = x;
1950
+ point.y = y;
1951
+ point.z = z;
1952
+ }
1953
+ return result;
1954
+ }
1955
+
1956
+ // dist/ellipsoid.js
1957
+ var spheroidScratch = { x: 0, y: 0, z: 0 };
1958
+ var scratchVector2 = new import_matrix3.Vector3();
1959
+ var scratchNormal = new import_matrix3.Vector3();
1960
+ var scratchPosition = new import_matrix3.Vector3();
1961
+ var scratchCartesian = new import_matrix3.Vector3();
1962
+ var Ellipsoid = class _Ellipsoid {
1963
+ /** Construct from two-axis geometry, including normalized projection ellipsoids.
1964
+ * The equatorial X/Y radii are equal; no CRS or datum information is inferred.
1965
+ */
1966
+ static fromSpheroid(parameters) {
1967
+ const { semiMajorAxis, semiMinorAxis } = parameters;
1968
+ validateSpheroid(semiMajorAxis, semiMinorAxis);
1969
+ return new _Ellipsoid(semiMajorAxis, semiMajorAxis, semiMinorAxis);
1970
+ }
1971
+ constructor(x = 0, y = 0, z = 0) {
1972
+ this.centerToleranceSquared = import_matrix3._MathUtils.EPSILON1;
1973
+ (0, import_matrix3.assert)(Number.isFinite(x) && x >= 0);
1974
+ (0, import_matrix3.assert)(Number.isFinite(y) && y >= 0);
1975
+ (0, import_matrix3.assert)(Number.isFinite(z) && z >= 0);
1976
+ this.radii = new import_matrix3.Vector3(x, y, z);
1977
+ this.radiiSquared = new import_matrix3.Vector3(x * x, y * y, z * z);
1978
+ this.radiiToTheFourth = new import_matrix3.Vector3(x * x * x * x, y * y * y * y, z * z * z * z);
1979
+ this.oneOverRadii = new import_matrix3.Vector3(x === 0 ? 0 : 1 / x, y === 0 ? 0 : 1 / y, z === 0 ? 0 : 1 / z);
1980
+ this.oneOverRadiiSquared = new import_matrix3.Vector3(x === 0 ? 0 : 1 / (x * x), y === 0 ? 0 : 1 / (y * y), z === 0 ? 0 : 1 / (z * z));
1981
+ this.minimumRadius = Math.min(x, y, z);
1982
+ this.maximumRadius = Math.max(x, y, z);
1983
+ if (z !== 0) {
1984
+ this.squaredXOverSquaredZ = (x / z) ** 2;
1985
+ }
1986
+ if (x === y && z > 0 && z <= x && Number.isFinite(this.radiiSquared.x) && this.radiiSquared.z > 0)
1987
+ this.spheroidGeometry = Object.freeze({
1988
+ semiMajorAxis: x,
1989
+ semiMinorAxis: z,
1990
+ eccentricitySquared: 1 - (z / x) ** 2
1991
+ });
1992
+ Object.freeze(this.radii);
1993
+ Object.freeze(this.radiiSquared);
1994
+ Object.freeze(this.radiiToTheFourth);
1995
+ Object.freeze(this.oneOverRadii);
1996
+ Object.freeze(this.oneOverRadiiSquared);
1997
+ Object.freeze(this);
1998
+ }
1999
+ /** Return an owned geometry snapshot for a sphere or oblate spheroid.
2000
+ * Triaxial, prolate and degenerate ellipsoids cannot be represented by this contract.
2001
+ * Call during setup, outside coordinate loops.
2002
+ */
2003
+ toSpheroid() {
2004
+ const { x, y, z } = this.radii;
2005
+ if (x !== y)
2006
+ throw new Error("Spheroid requires equal X/Y radii");
2007
+ validateSpheroid(x, z);
2008
+ return Object.freeze({ semiMajorAxis: x, semiMinorAxis: z });
2009
+ }
2010
+ /** Compares this Ellipsoid against the provided Ellipsoid componentwise */
2011
+ equals(right) {
2012
+ return this === right || Boolean(right && this.radii.equals(right.radii));
2013
+ }
2014
+ /** Creates a string representing this Ellipsoid in the format '[radii.x, radii.y, radii.z]'. */
2015
+ toString() {
2016
+ return this.radii.toString();
2017
+ }
2018
+ cartographicToCartesian(cartographic, result = [0, 0, 0]) {
2019
+ const llh = fromCartographicToRadians(cartographic, scratchCartesian);
2020
+ const longitude = llh[0], latitude = llh[1], height = llh[2];
2021
+ if (!Number.isFinite(longitude) || !Number.isFinite(latitude) || !Number.isFinite(height) || !(this.minimumRadius > 0) || !Number.isFinite(this.maximumRadius * this.maximumRadius))
2022
+ return void 0;
2023
+ if (this.spheroidGeometry && (import_matrix3.config._cartographicRadians || Math.abs(latitude) <= Math.PI / 4)) {
2024
+ spheroidScratch.x = longitude;
2025
+ spheroidScratch.y = latitude;
2026
+ spheroidScratch.z = height;
2027
+ if (!(0, import_matrix4.spheroidToCartesian)(spheroidScratch, this.spheroidGeometry))
2028
+ return void 0;
2029
+ return writeResult(result, spheroidScratch.x, spheroidScratch.y, spheroidScratch.z);
2030
+ }
2031
+ const normal = scratchNormal;
2032
+ this.geodeticSurfaceNormalCartographic(cartographic, normal);
2033
+ const nx = normal.x, ny = normal.y, nz = normal.z;
2034
+ const rx = this.radii.x, ry = this.radii.y, rz = this.radii.z;
2035
+ const gamma = Math.hypot(rx * nx, ry * ny, rz * nz);
2036
+ const x = rx * (rx * nx / gamma) + height * nx;
2037
+ const y = ry * (ry * ny / gamma) + height * ny;
2038
+ const z = rz * (rz * nz / gamma) + height * nz;
2039
+ if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z))
2040
+ return void 0;
2041
+ return writeResult(result, x, y, z);
2042
+ }
2043
+ cartesianToCartographic(cartesian, result = [0, 0, 0]) {
2044
+ const object = cartesian;
2045
+ const x = "x" in cartesian ? object.x : cartesian[0];
2046
+ const y = "x" in cartesian ? object.y : cartesian[1];
2047
+ const z = "x" in cartesian ? object.z : cartesian[2];
2048
+ if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z))
2049
+ return void 0;
2050
+ if (this.spheroidGeometry && Number.isFinite(x * x + y * y + z * z) && Number.isFinite(this.oneOverRadiiSquared.x) && Number.isFinite(this.oneOverRadiiSquared.z)) {
2051
+ spheroidScratch.x = x;
2052
+ spheroidScratch.y = y;
2053
+ spheroidScratch.z = z;
2054
+ const shape = this.spheroidGeometry;
2055
+ const nearBoundary = z === 0 && shape.semiMinorAxis < shape.semiMajorAxis && Math.abs(Math.hypot(x, y) - shape.semiMajorAxis * shape.eccentricitySquared) <= 64 * Number.EPSILON * shape.semiMajorAxis;
2056
+ if (!nearBoundary && (0, import_matrix4.cartesianToSpheroid)(spheroidScratch, shape)) {
2057
+ const longitude2 = x === 0 && y === 0 ? Math.atan2(y, x) : spheroidScratch.x;
2058
+ return toCartographicFromRadiansComponents(longitude2, spheroidScratch.y, spheroidScratch.z, result);
2059
+ }
2060
+ }
2061
+ if (!(this.minimumRadius > 0) || !Number.isFinite(this.maximumRadius * this.maximumRadius) || !Number.isFinite(1 / (this.minimumRadius * this.minimumRadius)))
2062
+ return void 0;
2063
+ scratchCartesian.set(x, y, z);
2064
+ const point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition);
2065
+ if (!point) {
2066
+ return void 0;
2067
+ }
2068
+ const gx = point[0] * this.oneOverRadiiSquared.x;
2069
+ const gy = point[1] * this.oneOverRadiiSquared.y;
2070
+ const gz = point[2] * this.oneOverRadiiSquared.z;
2071
+ const length = Math.hypot(gx, gy, gz);
2072
+ if (!(length > 0) || !Number.isFinite(length))
2073
+ return void 0;
2074
+ const nx = gx / length, ny = gy / length, nz = gz / length;
2075
+ const longitude = Math.atan2(ny, nx);
2076
+ const latitude = Math.atan2(nz, Math.hypot(nx, ny));
2077
+ const height = (x - point[0]) * nx + (y - point[1]) * ny + (z - point[2]) * nz;
2078
+ return toCartographicFromRadiansComponents(longitude, latitude, height, result);
2079
+ }
2080
+ geocentricSurfaceNormal(cartesian, result = [0, 0, 0]) {
2081
+ fromCartographic(cartesian, scratchVector2);
2082
+ const point = scratchVector2;
2083
+ return normalResult(point.x, point.y, point.z, result);
2084
+ }
2085
+ geodeticSurfaceNormalCartographic(cartographic, result = [0, 0, 0]) {
2086
+ const point = fromCartographic(cartographic, scratchCartesian);
2087
+ const longitude = import_matrix3.config._cartographicRadians ? point[0] : point[0] * Math.PI / 180;
2088
+ const latitude = import_matrix3.config._cartographicRadians ? point[1] : point[1] * Math.PI / 180;
2089
+ const polarDegrees = !import_matrix3.config._cartographicRadians && Math.abs(point[1]) > 45;
2090
+ const complement = (90 - Math.abs(point[1])) * Math.PI / 180;
2091
+ const cosLatitude = polarDegrees ? Math.sin(complement) : Math.abs(latitude) === Math.PI / 2 ? 0 : Math.cos(latitude);
2092
+ const sinLatitude = polarDegrees ? Math.sign(point[1]) * Math.cos(complement) : Math.sin(latitude);
2093
+ return normalResult(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), sinLatitude, result);
2094
+ }
2095
+ geodeticSurfaceNormal(cartesian, result = [0, 0, 0]) {
2096
+ if (!(this.minimumRadius > 0))
2097
+ return void 0;
2098
+ fromCartographic(cartesian, scratchVector2);
2099
+ const point = scratchVector2;
2100
+ const scale2 = Math.max(Math.abs(point.x), Math.abs(point.y), Math.abs(point.z));
2101
+ if (!(scale2 > 0) || !Number.isFinite(scale2))
2102
+ return void 0;
2103
+ const nx = point.x / scale2 * (this.minimumRadius / this.radii.x) ** 2;
2104
+ const ny = point.y / scale2 * (this.minimumRadius / this.radii.y) ** 2;
2105
+ const nz = point.z / scale2 * (this.minimumRadius / this.radii.z) ** 2;
2106
+ if ((point.x === 0 || Math.abs(nx) >= 2 ** -1022) && (point.y === 0 || Math.abs(ny) >= 2 ** -1022) && (point.z === 0 || Math.abs(nz) >= 2 ** -1022))
2107
+ return normalResult(nx, ny, nz, result);
2108
+ const ex = point.x === 0 ? 0 : Math.min(1023, Math.floor(Math.log2(Math.abs(point.x))));
2109
+ const ey = point.y === 0 ? 0 : Math.min(1023, Math.floor(Math.log2(Math.abs(point.y))));
2110
+ const ez = point.z === 0 ? 0 : Math.min(1023, Math.floor(Math.log2(Math.abs(point.z))));
2111
+ const ax = Math.min(1023, Math.floor(Math.log2(this.radii.x)));
2112
+ const ay = Math.min(1023, Math.floor(Math.log2(this.radii.y)));
2113
+ const az = Math.min(1023, Math.floor(Math.log2(this.radii.z)));
2114
+ const common = Math.max(point.x === 0 ? -Infinity : ex - 2 * ax, point.y === 0 ? -Infinity : ey - 2 * ay, point.z === 0 ? -Infinity : ez - 2 * az);
2115
+ return normalResult(point.x === 0 ? point.x : point.x / 2 ** ex / (this.radii.x / 2 ** ax) ** 2 * 2 ** (ex - 2 * ax - common), point.y === 0 ? point.y : point.y / 2 ** ey / (this.radii.y / 2 ** ay) ** 2 * 2 ** (ey - 2 * ay - common), point.z === 0 ? point.z : point.z / 2 ** ez / (this.radii.z / 2 ** az) ** 2 * 2 ** (ez - 2 * az - common), result);
2116
+ }
2117
+ /** Scales the provided Cartesian position along the geodetic surface normal
2118
+ * so that it is on the surface of this ellipsoid. If the position is
2119
+ * at the center of the ellipsoid, this function returns undefined. */
2120
+ scaleToGeodeticSurface(cartesian, result) {
2121
+ return scaleToGeodeticSurface(cartesian, this, result);
2122
+ }
2123
+ /** Scales the provided Cartesian position along the geocentric surface normal
2124
+ * so that it is on the surface of this ellipsoid. */
2125
+ scaleToGeocentricSurface(cartesian, result = [0, 0, 0]) {
2126
+ fromCartographic(cartesian, scratchPosition);
2127
+ const point = scratchPosition;
2128
+ const scale2 = Math.max(Math.abs(point.x), Math.abs(point.y), Math.abs(point.z));
2129
+ if (!(this.minimumRadius > 0) || !(scale2 > 0) || !Number.isFinite(scale2))
2130
+ return void 0;
2131
+ const squared = point.x * point.x * this.oneOverRadiiSquared.x + point.y * point.y * this.oneOverRadiiSquared.y + point.z * point.z * this.oneOverRadiiSquared.z;
2132
+ if (squared >= 2 ** -1022 && Number.isFinite(squared) && scale2 * scale2 >= 2 ** -1022 && Number.isFinite(scale2 * scale2)) {
2133
+ const beta = 1 / Math.sqrt(squared);
2134
+ return writeResult(result, point.x * beta, point.y * beta, point.z * beta);
2135
+ }
2136
+ const x = point.x / scale2, y = point.y / scale2, z = point.z / scale2;
2137
+ const norm = Math.hypot(x / this.radii.x, y / this.radii.y, z / this.radii.z);
2138
+ if (!(norm > 0) || !Number.isFinite(norm))
2139
+ return void 0;
2140
+ return writeResult(result, x / norm, y / norm, z / norm);
2141
+ }
2142
+ /** Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying
2143
+ * its components by the result of `Ellipsoid#oneOverRadii` */
2144
+ transformPositionToScaledSpace(position, result = [0, 0, 0]) {
2145
+ fromCartographic(position, scratchPosition);
2146
+ const point = scratchPosition.scale(this.oneOverRadii);
2147
+ return writeResult(result, point.x, point.y, point.z);
2148
+ }
2149
+ /** Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying
2150
+ * its components by the result of `Ellipsoid#radii`. */
2151
+ transformPositionFromScaledSpace(position, result = [0, 0, 0]) {
2152
+ fromCartographic(position, scratchPosition);
2153
+ const point = scratchPosition.scale(this.radii);
2154
+ return writeResult(result, point.x, point.y, point.z);
2155
+ }
2156
+ /** Computes a point which is the intersection of the surface normal with the z-axis. */
2157
+ getSurfaceNormalIntersectionWithZAxis(position, buffer = 0, result = [0, 0, 0]) {
2158
+ (0, import_matrix3.assert)(this.radii.x === this.radii.y && this.minimumRadius > 0);
2159
+ fromCartographic(position, scratchPosition);
2160
+ if (!Number.isFinite(scratchPosition.x) || !Number.isFinite(scratchPosition.y) || !Number.isFinite(scratchPosition.z) || !Number.isFinite(buffer))
2161
+ return void 0;
2162
+ const z = scratchPosition.z * (1 - this.squaredXOverSquaredZ);
2163
+ if (!Number.isFinite(z))
2164
+ return void 0;
2165
+ if (Math.abs(z) >= this.radii.z - buffer) {
2166
+ return void 0;
2167
+ }
2168
+ return writeResult(result, 0, 0, z);
2169
+ }
2170
+ };
2171
+ Ellipsoid.WGS84 = new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z);
2172
+ function validateSpheroid(a, b) {
2173
+ if (!Number.isFinite(a) || !Number.isFinite(b) || a <= 0 || b <= 0 || b > a)
2174
+ throw new Error("Spheroid requires finite positive axes with semiMinorAxis <= semiMajorAxis");
2175
+ }
2176
+ function normalResult(x, y, z, result) {
2177
+ const scale2 = Math.max(Math.abs(x), Math.abs(y), Math.abs(z));
2178
+ if (!(scale2 > 0) || !Number.isFinite(scale2))
2179
+ return void 0;
2180
+ const nx = x / scale2, ny = y / scale2, nz = z / scale2;
2181
+ const length = Math.hypot(nx, ny, nz);
2182
+ return writeResult(result, nx / length, ny / length, nz / length);
2183
+ }
2184
+
2185
+ // dist/local-reference-frame.js
2186
+ var LocalReferenceFrame = class {
2187
+ constructor(origin, options = {}) {
2188
+ finiteCoordinate(origin);
2189
+ const ellipsoid = options.ellipsoid || Ellipsoid.WGS84;
2190
+ const { x: a, y, z: b } = ellipsoid.radii;
2191
+ if (!(a > 0 && a === y && b > 0 && b <= a && Number.isFinite(a))) {
2192
+ throw new RangeError("LocalReferenceFrame requires a positive sphere or oblate spheroid");
2193
+ }
2194
+ const llh = ellipsoid.cartesianToCartographic(origin);
2195
+ if (!llh)
2196
+ throw new RangeError("Origin has no unique geodetic frame");
2197
+ const basis = (0, import_matrix6.createLocalFrameBasis)();
2198
+ const radians = import_matrix5.config._cartographicRadians ? 1 : Math.PI / 180;
2199
+ if (!(0, import_matrix6.eastNorthUpBasis)(llh[0] * radians, llh[1] * radians, basis))
2200
+ throw new RangeError("Cannot resolve local geodetic basis");
2201
+ const axes = options.axes || ["east", "north", "up"];
2202
+ const matrix = [];
2203
+ if (!(0, import_matrix6.localFrameToMatrix)(basis, { x: origin[0], y: origin[1], z: origin[2] }, ...axes, matrix)) {
2204
+ throw new RangeError("Expected three right-handed geographic axes");
2205
+ }
2206
+ this.matrix = Object.freeze(matrix);
2207
+ this.up = Object.freeze([basis.upX, basis.upY, basis.upZ]);
2208
+ }
2209
+ /** Independent copies: callers cannot mutate the cached frame. */
2210
+ get localToFixedMatrix() {
2211
+ return new import_matrix5.Matrix4(this.matrix);
2212
+ }
2213
+ get fixedToLocalMatrix() {
2214
+ return new import_matrix5.Matrix4(this.matrix).invert();
2215
+ }
2216
+ localToFixedPoint(point, result = new import_matrix5.Vector3()) {
2217
+ return this.transform(point, result, false, true);
2218
+ }
2219
+ fixedToLocalPoint(point, result = new import_matrix5.Vector3()) {
2220
+ return this.transform(point, result, true, true);
2221
+ }
2222
+ localToFixedVector(vector, result = new import_matrix5.Vector3()) {
2223
+ return this.transform(vector, result, false, false);
2224
+ }
2225
+ fixedToLocalVector(vector, result = new import_matrix5.Vector3()) {
2226
+ return this.transform(vector, result, true, false);
2227
+ }
2228
+ /** Packed XYZ points. Exact in-place operation is supported; other overlap is rejected.
2229
+ * All validation and representability checks finish before writing caller storage.
2230
+ */
2231
+ localToFixedPointsFlat(input, result) {
2232
+ return this.transformFlat(input, result, false, true);
2233
+ }
2234
+ fixedToLocalPointsFlat(input, result) {
2235
+ return this.transformFlat(input, result, true, true);
2236
+ }
2237
+ localToFixedVectorsFlat(input, result) {
2238
+ return this.transformFlat(input, result, false, false);
2239
+ }
2240
+ fixedToLocalVectorsFlat(input, result) {
2241
+ return this.transformFlat(input, result, true, false);
2242
+ }
2243
+ /** Model-to-fixed affine pose, with unit scale. Angles are radians. */
2244
+ headingPitchRollToFixedFrame(attitude, result = new import_matrix5.Matrix4()) {
2245
+ const { heading, pitch, roll } = attitude;
2246
+ if (![heading, pitch, roll].every(Number.isFinite))
2247
+ throw new RangeError("Nonfinite attitude");
2248
+ return result.copy(this.matrix).rotateZ(-heading).rotateY(-pitch).rotateX(roll);
2249
+ }
2250
+ headingPitchRollQuaternion(attitude, result = new import_matrix5.Quaternion()) {
2251
+ const m = this.headingPitchRollToFixedFrame(attitude);
2252
+ return result.fromMatrix3([m[0], m[1], m[2], m[4], m[5], m[6], m[8], m[9], m[10]]).normalize();
2253
+ }
2254
+ /** Extract attitude from a rigid model-to-fixed pose. Translation is ignored.
2255
+ * Pitch is canonicalized to [-pi/2, pi/2]. At gimbal lock, roll is zero.
2256
+ */
2257
+ fixedFrameToHeadingPitchRoll(pose) {
2258
+ validateRigidPose(pose);
2259
+ const local = new import_matrix5.Matrix4();
2260
+ const m = this.matrix;
2261
+ for (let column = 0; column < 3; column++) {
2262
+ for (let row = 0; row < 3; row++) {
2263
+ local[column * 4 + row] = m[row * 4] * pose[column * 4] + m[row * 4 + 1] * pose[column * 4 + 1] + m[row * 4 + 2] * pose[column * 4 + 2];
2264
+ }
2265
+ }
2266
+ const pitchY = Math.atan2(-local[2], Math.hypot(local[0], local[1]));
2267
+ const locked = Math.hypot(local[0], local[1]) < 1e-12;
2268
+ const roll = locked ? 0 : Math.atan2(local[6], local[10]);
2269
+ const yaw = locked ? Math.atan2(-local[4], local[5]) : Math.atan2(local[1], local[0]);
2270
+ return { heading: -yaw, pitch: -pitchY, roll };
2271
+ }
2272
+ /** Fixed-space velocity defines model +X. +Z is as close as possible to geodetic up.
2273
+ * Returns undefined without writing result for zero or nearly vertical velocity.
2274
+ * Stateless: callers own temporal continuity across these singularities.
2275
+ */
2276
+ velocityQuaternion(velocity, result = new import_matrix5.Quaternion()) {
2277
+ finiteCoordinate(velocity);
2278
+ const scale2 = Math.max(Math.abs(velocity[0]), Math.abs(velocity[1]), Math.abs(velocity[2]));
2279
+ if (scale2 === 0)
2280
+ return void 0;
2281
+ const x = new import_matrix5.Vector3(velocity[0] / scale2, velocity[1] / scale2, velocity[2] / scale2);
2282
+ x.scale(1 / Math.hypot(x[0], x[1], x[2]));
2283
+ const y = new import_matrix5.Vector3(this.up).cross(x);
2284
+ if (y.len() < 1e-12)
2285
+ return void 0;
2286
+ y.normalize();
2287
+ const z = new import_matrix5.Vector3(x).cross(y).normalize();
2288
+ return result.fromMatrix3([...x, ...y, ...z]).normalize();
2289
+ }
2290
+ transformFlat(input, result, inverse4, position) {
2291
+ if (!Number.isSafeInteger(input.length) || input.length % 3 || result && (!(result instanceof Float64Array) || result.length !== input.length))
2292
+ throw new RangeError("Expected packed XYZ and matching Float64 output");
2293
+ if (result && input !== result && ArrayBuffer.isView(input) && input.buffer === result.buffer && input.byteOffset < result.byteOffset + result.byteLength && result.byteOffset < input.byteOffset + input.byteLength)
2294
+ throw new RangeError("Packed frame buffers overlap");
2295
+ let bounded = !position || Math.max(Math.abs(this.matrix[12]), Math.abs(this.matrix[13]), Math.abs(this.matrix[14])) <= Number.MAX_VALUE / 8;
2296
+ for (let i = 0; i < input.length; i++) {
2297
+ if (!Number.isFinite(input[i]))
2298
+ throw new RangeError("Expected finite packed coordinates");
2299
+ bounded && (bounded = Math.abs(input[i]) <= Number.MAX_VALUE / 8);
2300
+ }
2301
+ const scratch = bounded ? void 0 : new import_matrix5.Vector3();
2302
+ if (scratch)
2303
+ for (let i = 0; i < input.length; i += 3)
2304
+ this.transform(scratch.set(input[i], input[i + 1], input[i + 2]), scratch, inverse4, position);
2305
+ const output = result || new Float64Array(input.length), [xx, xy, xz, , yx, yy, yz, , zx, zy, zz, , ox, oy, oz] = this.matrix;
2306
+ for (let i = 0; i < input.length; i += 3) {
2307
+ const x = input[i] - (inverse4 && position ? ox : 0), y = input[i + 1] - (inverse4 && position ? oy : 0), z = input[i + 2] - (inverse4 && position ? oz : 0);
2308
+ if (scratch) {
2309
+ this.transform(scratch.set(input[i], input[i + 1], input[i + 2]), scratch, inverse4, position);
2310
+ output.set(scratch, i);
2311
+ } else {
2312
+ output[i] = inverse4 ? xx * x + xy * y + xz * z : xx * x + yx * y + zx * z + (position ? ox : 0);
2313
+ output[i + 1] = inverse4 ? yx * x + yy * y + yz * z : xy * x + yy * y + zy * z + (position ? oy : 0);
2314
+ output[i + 2] = inverse4 ? zx * x + zy * y + zz * z : xz * x + yz * y + zz * z + (position ? oz : 0);
2315
+ }
2316
+ }
2317
+ return output;
2318
+ }
2319
+ transform(point, result, inverse4, position) {
2320
+ finiteCoordinate(point);
2321
+ const m = this.matrix;
2322
+ const x = point[0] - (inverse4 && position ? m[12] : 0);
2323
+ const y = point[1] - (inverse4 && position ? m[13] : 0);
2324
+ const z = point[2] - (inverse4 && position ? m[14] : 0);
2325
+ let ox = inverse4 ? m[0] * x + m[1] * y + m[2] * z : m[0] * x + m[4] * y + m[8] * z + (position ? m[12] : 0);
2326
+ let oy = inverse4 ? m[4] * x + m[5] * y + m[6] * z : m[1] * x + m[5] * y + m[9] * z + (position ? m[13] : 0);
2327
+ let oz = inverse4 ? m[8] * x + m[9] * y + m[10] * z : m[2] * x + m[6] * y + m[10] * z + (position ? m[14] : 0);
2328
+ if (!Number.isFinite(ox) || !Number.isFinite(oy) || !Number.isFinite(oz)) {
2329
+ const scale2 = Math.max(Math.abs(point[0]), Math.abs(point[1]), Math.abs(point[2]), position ? Math.abs(m[12]) : 0, position ? Math.abs(m[13]) : 0, position ? Math.abs(m[14]) : 0);
2330
+ const sx = point[0] / scale2 - (inverse4 && position ? m[12] / scale2 : 0);
2331
+ const sy = point[1] / scale2 - (inverse4 && position ? m[13] / scale2 : 0);
2332
+ const sz = point[2] / scale2 - (inverse4 && position ? m[14] / scale2 : 0);
2333
+ ox = (inverse4 ? m[0] * sx + m[1] * sy + m[2] * sz : m[0] * sx + m[4] * sy + m[8] * sz + (position ? m[12] / scale2 : 0)) * scale2;
2334
+ oy = (inverse4 ? m[4] * sx + m[5] * sy + m[6] * sz : m[1] * sx + m[5] * sy + m[9] * sz + (position ? m[13] / scale2 : 0)) * scale2;
2335
+ oz = (inverse4 ? m[8] * sx + m[9] * sy + m[10] * sz : m[2] * sx + m[6] * sy + m[10] * sz + (position ? m[14] / scale2 : 0)) * scale2;
2336
+ }
2337
+ if (!Number.isFinite(ox) || !Number.isFinite(oy) || !Number.isFinite(oz))
2338
+ throw new RangeError("Frame transformation overflow");
2339
+ return result.set(ox, oy, oz);
2340
+ }
2341
+ };
2342
+ function finiteCoordinate(point) {
2343
+ if (point.length !== 3 || !Number.isFinite(point[0]) || !Number.isFinite(point[1]) || !Number.isFinite(point[2])) {
2344
+ throw new RangeError("Expected three finite coordinates");
2345
+ }
2346
+ }
2347
+ function validateRigidPose(pose) {
2348
+ if (pose.length !== 16 || !Array.from(pose).every(Number.isFinite) || pose[3] !== 0 || pose[7] !== 0 || pose[11] !== 0 || pose[15] !== 1) {
2349
+ throw new RangeError("Expected a finite affine pose");
2350
+ }
2351
+ const x = new import_matrix5.Vector3(pose[0], pose[1], pose[2]);
2352
+ const y = new import_matrix5.Vector3(pose[4], pose[5], pose[6]);
2353
+ const z = new import_matrix5.Vector3(pose[8], pose[9], pose[10]);
2354
+ for (const axis of [x, y, z]) {
2355
+ if (Math.abs(Math.hypot(axis[0], axis[1], axis[2]) - 1) > 1e-6) {
2356
+ throw new RangeError("Pose rotation must be orthonormal and right-handed");
2357
+ }
2358
+ }
2359
+ const errors = [
2360
+ Math.abs(x.len() - 1),
2361
+ Math.abs(y.len() - 1),
2362
+ Math.abs(z.len() - 1),
2363
+ Math.abs(x.dot(y)),
2364
+ Math.abs(x.dot(z)),
2365
+ Math.abs(y.dot(z)),
2366
+ Math.abs(new import_matrix5.Vector3(x).cross(y).dot(z) - 1)
2367
+ ];
2368
+ if (!errors.every(Number.isFinite) || Math.max(...errors) > 1e-6) {
2369
+ throw new RangeError("Pose rotation must be orthonormal and right-handed");
2370
+ }
2371
+ }
2372
+
2373
+ // dist/ellipsoid-transforms.js
2374
+ var import_matrix9 = require("@math.gl/core/matrix");
2375
+
2376
+ // dist/ellipsoid-helpers/ellipsoid-transform.js
2377
+ var import_matrix7 = require("@math.gl/core/matrix");
2378
+ var import_matrix8 = require("@math.gl/core/matrix");
2379
+ var EPSILON14 = 1e-14;
2380
+ var scratchOrigin = new import_matrix7.Vector3();
2381
+ var scratchBasis = (0, import_matrix8.createLocalFrameBasis)();
2382
+ var VECTOR_PRODUCT_LOCAL_FRAME = {
2383
+ up: {
2384
+ south: "east",
2385
+ north: "west",
2386
+ west: "south",
2387
+ east: "north"
2388
+ },
2389
+ down: {
2390
+ south: "west",
2391
+ north: "east",
2392
+ west: "north",
2393
+ east: "south"
2394
+ },
2395
+ south: {
2396
+ up: "west",
2397
+ down: "east",
2398
+ west: "down",
2399
+ east: "up"
2400
+ },
2401
+ north: {
2402
+ up: "east",
2403
+ down: "west",
2404
+ west: "up",
2405
+ east: "down"
2406
+ },
2407
+ west: {
2408
+ up: "north",
2409
+ down: "south",
2410
+ north: "down",
2411
+ south: "up"
2412
+ },
2413
+ east: {
2414
+ up: "south",
2415
+ down: "north",
2416
+ north: "up",
2417
+ south: "down"
2418
+ }
2419
+ };
2420
+ var degeneratePositionLocalFrame = {
2421
+ north: [-1, 0, 0],
2422
+ east: [0, 1, 0],
2423
+ up: [0, 0, 1],
2424
+ south: [1, 0, 0],
2425
+ west: [0, -1, 0],
2426
+ down: [0, 0, -1]
2427
+ };
2428
+ var scratchAxisVectors = {
2429
+ east: new import_matrix7.Vector3(),
2430
+ north: new import_matrix7.Vector3(),
2431
+ up: new import_matrix7.Vector3(),
2432
+ west: new import_matrix7.Vector3(),
2433
+ south: new import_matrix7.Vector3(),
2434
+ down: new import_matrix7.Vector3()
2435
+ };
2436
+ var scratchVector1 = new import_matrix7.Vector3();
2437
+ var scratchVector22 = new import_matrix7.Vector3();
2438
+ var scratchVector3 = new import_matrix7.Vector3();
2439
+ function localFrameToFixedFrame(ellipsoid, firstAxis, secondAxis, thirdAxis, cartesianOrigin, result) {
2440
+ const thirdAxisInferred = VECTOR_PRODUCT_LOCAL_FRAME[firstAxis] && VECTOR_PRODUCT_LOCAL_FRAME[firstAxis][secondAxis];
2441
+ (0, import_matrix7.assert)(thirdAxisInferred && (!thirdAxis || thirdAxis === thirdAxisInferred));
2442
+ let firstAxisVector;
2443
+ let secondAxisVector;
2444
+ let thirdAxisVector;
2445
+ const origin = scratchOrigin.copy(cartesianOrigin);
2446
+ if (!Number.isFinite(origin.x) || !Number.isFinite(origin.y) || !Number.isFinite(origin.z) || !Array.isArray(result) && result.length < 16)
2447
+ throw new Error("Unsupported local frame");
2448
+ const poleTolerance = EPSILON14 * Math.min(1, ellipsoid.maximumRadius);
2449
+ const atPole = Math.abs(origin.x) <= poleTolerance && Math.abs(origin.y) <= poleTolerance;
2450
+ const radii = ellipsoid.radii;
2451
+ if (radii.x === radii.y && radii.x > 0 && radii.z > 0 && radii.z <= radii.x && (!atPole || origin.z !== 0)) {
2452
+ const { east, up } = scratchAxisVectors;
2453
+ if (atPole) {
2454
+ east.set(0, 1, 0);
2455
+ up.set(0, 0, Math.sign(origin.z));
2456
+ } else {
2457
+ const scale2 = Math.max(Math.abs(origin.x), Math.abs(origin.y));
2458
+ east.set(-origin.y / scale2, origin.x / scale2, 0).normalize();
2459
+ ellipsoid.geodeticSurfaceNormal(origin, up);
2460
+ }
2461
+ if (!(0, import_matrix8.eastNorthUpBasisFromDirections)(east, up, scratchBasis) || !(0, import_matrix8.localFrameToMatrix)(scratchBasis, origin, firstAxis, secondAxis, thirdAxis, result))
2462
+ throw new Error("Unsupported local frame");
2463
+ return result;
2464
+ }
2465
+ if (atPole) {
2466
+ const sign = Math.sign(origin.z);
2467
+ firstAxisVector = scratchVector1.fromArray(degeneratePositionLocalFrame[firstAxis]);
2468
+ if (firstAxis !== "east" && firstAxis !== "west") {
2469
+ firstAxisVector.scale(sign);
2470
+ }
2471
+ secondAxisVector = scratchVector22.fromArray(degeneratePositionLocalFrame[secondAxis]);
2472
+ if (secondAxis !== "east" && secondAxis !== "west") {
2473
+ secondAxisVector.scale(sign);
2474
+ }
2475
+ thirdAxisVector = scratchVector3.fromArray(degeneratePositionLocalFrame[thirdAxis]);
2476
+ if (thirdAxis !== "east" && thirdAxis !== "west") {
2477
+ thirdAxisVector.scale(sign);
2478
+ }
2479
+ } else {
2480
+ const { up, east, north } = scratchAxisVectors;
2481
+ const scale2 = Math.max(Math.abs(origin.x), Math.abs(origin.y));
2482
+ east.set(-origin.y / scale2, origin.x / scale2, 0).normalize();
2483
+ ellipsoid.geodeticSurfaceNormal(origin, up);
2484
+ north.copy(up).cross(east);
2485
+ const { down, west, south } = scratchAxisVectors;
2486
+ down.copy(up).scale(-1);
2487
+ west.copy(east).scale(-1);
2488
+ south.copy(north).scale(-1);
2489
+ firstAxisVector = scratchAxisVectors[firstAxis];
2490
+ secondAxisVector = scratchAxisVectors[secondAxis];
2491
+ thirdAxisVector = scratchAxisVectors[thirdAxis];
2492
+ }
2493
+ const ax = firstAxisVector.x, ay = firstAxisVector.y, az = firstAxisVector.z;
2494
+ const bx = secondAxisVector.x, by = secondAxisVector.y, bz = secondAxisVector.z;
2495
+ const cx = thirdAxisVector.x, cy = thirdAxisVector.y, cz = thirdAxisVector.z;
2496
+ const x = origin.x, y = origin.y, z = origin.z;
2497
+ result[0] = ax;
2498
+ result[1] = ay;
2499
+ result[2] = az;
2500
+ result[3] = 0;
2501
+ result[4] = bx;
2502
+ result[5] = by;
2503
+ result[6] = bz;
2504
+ result[7] = 0;
2505
+ result[8] = cx;
2506
+ result[9] = cy;
2507
+ result[10] = cz;
2508
+ result[11] = 0;
2509
+ result[12] = x;
2510
+ result[13] = y;
2511
+ result[14] = z;
2512
+ result[15] = 1;
2513
+ return result;
2514
+ }
2515
+
2516
+ // dist/ellipsoid-transforms.js
2517
+ function eastNorthUpToFixedFrame(ellipsoid, origin, result = new import_matrix9.Matrix4()) {
2518
+ return localFrameToFixedFrame(ellipsoid, "east", "north", "up", origin, result);
2519
+ }
2520
+ function localFrameToFixedFrame2(ellipsoid, firstAxis, secondAxis, thirdAxis, origin, result = new import_matrix9.Matrix4()) {
2521
+ return localFrameToFixedFrame(ellipsoid, firstAxis, secondAxis, thirdAxis, origin, result);
2522
+ }
2523
+ //# sourceMappingURL=coordinates.cjs.map