@math.gl/core 5.0.0-alpha.2 → 5.0.0-alpha.20

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 (272) hide show
  1. package/APACHE-2.0-LICENSE.txt +55 -0
  2. package/ARROW-NOTICE.txt +18 -0
  3. package/LICENSE +149 -40
  4. package/PROJ4-LICENSE.md +29 -0
  5. package/README.md +14 -0
  6. package/THIRD-PARTY-NOTICES.md +16 -0
  7. package/dist/classes/base/math-array.d.ts +1 -1
  8. package/dist/classes/base/math-array.d.ts.map +1 -1
  9. package/dist/classes/base/math-array.js +1 -1
  10. package/dist/classes/base/math-array.js.map +1 -1
  11. package/dist/classes/base/matrix.d.ts +1 -1
  12. package/dist/classes/base/matrix.d.ts.map +1 -1
  13. package/dist/classes/base/matrix.js +2 -2
  14. package/dist/classes/base/matrix.js.map +1 -1
  15. package/dist/classes/base/vector.d.ts +1 -1
  16. package/dist/classes/base/vector.d.ts.map +1 -1
  17. package/dist/classes/base/vector.js +2 -2
  18. package/dist/classes/base/vector.js.map +1 -1
  19. package/dist/classes/euler-types.js +1 -1
  20. package/dist/classes/euler-types.js.map +1 -1
  21. package/dist/classes/euler.d.ts +1 -1
  22. package/dist/classes/euler.d.ts.map +1 -1
  23. package/dist/classes/euler.js +4 -2
  24. package/dist/classes/euler.js.map +1 -1
  25. package/dist/classes/matrix3.d.ts +1 -1
  26. package/dist/classes/matrix3.d.ts.map +1 -1
  27. package/dist/classes/matrix3.js +2 -2
  28. package/dist/classes/matrix3.js.map +1 -1
  29. package/dist/classes/matrix4.d.ts +1 -1
  30. package/dist/classes/matrix4.d.ts.map +1 -1
  31. package/dist/classes/matrix4.js +2 -2
  32. package/dist/classes/matrix4.js.map +1 -1
  33. package/dist/classes/pose.d.ts +1 -1
  34. package/dist/classes/pose.d.ts.map +1 -1
  35. package/dist/classes/pose.js +2 -2
  36. package/dist/classes/pose.js.map +1 -1
  37. package/dist/classes/quaternion.d.ts +1 -1
  38. package/dist/classes/quaternion.d.ts.map +1 -1
  39. package/dist/classes/quaternion.js +2 -2
  40. package/dist/classes/quaternion.js.map +1 -1
  41. package/dist/classes/spherical-coordinates.js +2 -2
  42. package/dist/classes/spherical-coordinates.js.map +1 -1
  43. package/dist/classes/vector2.d.ts +1 -1
  44. package/dist/classes/vector2.d.ts.map +1 -1
  45. package/dist/classes/vector2.js +2 -2
  46. package/dist/classes/vector2.js.map +1 -1
  47. package/dist/classes/vector3.d.ts +1 -1
  48. package/dist/classes/vector3.d.ts.map +1 -1
  49. package/dist/classes/vector3.js +2 -2
  50. package/dist/classes/vector3.js.map +1 -1
  51. package/dist/classes/vector4.d.ts +1 -1
  52. package/dist/classes/vector4.d.ts.map +1 -1
  53. package/dist/classes/vector4.js +2 -2
  54. package/dist/classes/vector4.js.map +1 -1
  55. package/dist/expressions/expression-eval.d.ts +98 -0
  56. package/dist/expressions/expression-eval.d.ts.map +1 -0
  57. package/dist/expressions/expression-eval.js +302 -0
  58. package/dist/expressions/expression-eval.js.map +1 -0
  59. package/dist/expressions/function-libraries.d.ts +60 -0
  60. package/dist/expressions/function-libraries.d.ts.map +1 -0
  61. package/dist/expressions/function-libraries.js +69 -0
  62. package/dist/expressions/function-libraries.js.map +1 -0
  63. package/dist/expressions/function-registry.d.ts +93 -0
  64. package/dist/expressions/function-registry.d.ts.map +1 -0
  65. package/dist/expressions/function-registry.js +139 -0
  66. package/dist/expressions/function-registry.js.map +1 -0
  67. package/dist/expressions/get.d.ts +9 -0
  68. package/dist/expressions/get.d.ts.map +1 -0
  69. package/dist/expressions/get.js +32 -0
  70. package/dist/expressions/get.js.map +1 -0
  71. package/dist/expressions/index.cjs +1491 -0
  72. package/dist/expressions/index.cjs.map +6 -0
  73. package/dist/expressions/index.d.ts +7 -0
  74. package/dist/expressions/index.d.ts.map +1 -0
  75. package/dist/expressions/index.js +8 -0
  76. package/dist/expressions/index.js.map +1 -0
  77. package/dist/expressions/parse-expression-string.d.ts +21 -0
  78. package/dist/expressions/parse-expression-string.d.ts.map +1 -0
  79. package/dist/expressions/parse-expression-string.js +61 -0
  80. package/dist/expressions/parse-expression-string.js.map +1 -0
  81. package/dist/expressions/vendor/jsep/runtime.d.ts +3 -0
  82. package/dist/expressions/vendor/jsep/runtime.d.ts.map +1 -0
  83. package/dist/expressions/vendor/jsep/runtime.js +972 -0
  84. package/dist/expressions/vendor/jsep/runtime.js.map +1 -0
  85. package/dist/expressions/vendor/jsep/types.d.ts +141 -0
  86. package/dist/expressions/vendor/jsep/types.d.ts.map +1 -0
  87. package/dist/expressions/vendor/jsep/types.js +4 -0
  88. package/dist/expressions/vendor/jsep/types.js.map +1 -0
  89. package/dist/gl-matrix/common.d.ts +1 -1
  90. package/dist/gl-matrix/common.d.ts.map +1 -1
  91. package/dist/gl-matrix/common.js +5 -0
  92. package/dist/gl-matrix/common.js.map +1 -1
  93. package/dist/gl-matrix/mat3.d.ts.map +1 -1
  94. package/dist/gl-matrix/mat3.js +5 -0
  95. package/dist/gl-matrix/mat3.js.map +1 -1
  96. package/dist/gl-matrix/mat4.d.ts.map +1 -1
  97. package/dist/gl-matrix/mat4.js +5 -0
  98. package/dist/gl-matrix/mat4.js.map +1 -1
  99. package/dist/gl-matrix/quat.d.ts.map +1 -1
  100. package/dist/gl-matrix/quat.js +5 -0
  101. package/dist/gl-matrix/quat.js.map +1 -1
  102. package/dist/gl-matrix/vec2.d.ts +1 -1
  103. package/dist/gl-matrix/vec2.d.ts.map +1 -1
  104. package/dist/gl-matrix/vec2.js +5 -0
  105. package/dist/gl-matrix/vec2.js.map +1 -1
  106. package/dist/gl-matrix/vec3.d.ts.map +1 -1
  107. package/dist/gl-matrix/vec3.js +5 -0
  108. package/dist/gl-matrix/vec3.js.map +1 -1
  109. package/dist/gl-matrix/vec4.d.ts.map +1 -1
  110. package/dist/gl-matrix/vec4.js +5 -0
  111. package/dist/gl-matrix/vec4.js.map +1 -1
  112. package/dist/gl-matrix/wip/index.d.ts.map +1 -1
  113. package/dist/gl-matrix/wip/index.js +3 -1
  114. package/dist/gl-matrix/wip/index.js.map +1 -1
  115. package/dist/gl-matrix/wip/mat2.d.ts.map +1 -1
  116. package/dist/gl-matrix/wip/mat2.js +3 -1
  117. package/dist/gl-matrix/wip/mat2.js.map +1 -1
  118. package/dist/gl-matrix/wip/mat2d.d.ts.map +1 -1
  119. package/dist/gl-matrix/wip/mat2d.js +3 -1
  120. package/dist/gl-matrix/wip/mat2d.js.map +1 -1
  121. package/dist/gl-matrix/wip/quat2.d.ts.map +1 -1
  122. package/dist/gl-matrix/wip/quat2.js +3 -1
  123. package/dist/gl-matrix/wip/quat2.js.map +1 -1
  124. package/dist/index.cjs.map +1 -1
  125. package/dist/index.d.ts +3 -2
  126. package/dist/index.d.ts.map +1 -1
  127. package/dist/index.js +1 -1
  128. package/dist/index.js.map +1 -1
  129. package/dist/lib/assert.js +1 -1
  130. package/dist/lib/assert.js.map +1 -1
  131. package/dist/lib/common.d.ts +1 -1
  132. package/dist/lib/common.d.ts.map +1 -1
  133. package/dist/lib/common.js +1 -1
  134. package/dist/lib/common.js.map +1 -1
  135. package/dist/lib/gl-matrix-extras.d.ts +1 -1
  136. package/dist/lib/gl-matrix-extras.d.ts.map +1 -1
  137. package/dist/lib/gl-matrix-extras.js +1 -1
  138. package/dist/lib/gl-matrix-extras.js.map +1 -1
  139. package/dist/lib/math-utils.d.ts.map +1 -1
  140. package/dist/lib/math-utils.js +2 -1
  141. package/dist/lib/math-utils.js.map +1 -1
  142. package/dist/lib/validators.d.ts +1 -1
  143. package/dist/lib/validators.d.ts.map +1 -1
  144. package/dist/lib/validators.js +1 -1
  145. package/dist/lib/validators.js.map +1 -1
  146. package/dist/local-frame.cjs +139 -0
  147. package/dist/local-frame.cjs.map +6 -0
  148. package/dist/local-frame.d.ts +39 -0
  149. package/dist/local-frame.d.ts.map +1 -0
  150. package/dist/local-frame.js +157 -0
  151. package/dist/local-frame.js.map +1 -0
  152. package/dist/mat3.cjs.map +1 -1
  153. package/dist/mat3.js +1 -1
  154. package/dist/mat3.js.map +1 -1
  155. package/dist/mat4.cjs.map +1 -1
  156. package/dist/mat4.js +1 -1
  157. package/dist/mat4.js.map +1 -1
  158. package/dist/quat.cjs.map +1 -1
  159. package/dist/quat.js +1 -1
  160. package/dist/quat.js.map +1 -1
  161. package/dist/spheroid.cjs +147 -0
  162. package/dist/spheroid.cjs.map +6 -0
  163. package/dist/spheroid.d.ts +21 -0
  164. package/dist/spheroid.d.ts.map +1 -0
  165. package/dist/spheroid.js +175 -0
  166. package/dist/spheroid.js.map +1 -0
  167. package/dist/types/array-types.d.ts +98 -0
  168. package/dist/types/array-types.d.ts.map +1 -0
  169. package/dist/types/array-types.js +6 -0
  170. package/dist/types/array-types.js.map +1 -0
  171. package/dist/types/bigint.d.ts +21 -0
  172. package/dist/types/bigint.d.ts.map +1 -0
  173. package/dist/types/bigint.js +65 -0
  174. package/dist/types/bigint.js.map +1 -0
  175. package/dist/types/bounds-types.d.ts +11 -0
  176. package/dist/types/bounds-types.d.ts.map +1 -0
  177. package/dist/types/bounds-types.js +17 -0
  178. package/dist/types/bounds-types.js.map +1 -0
  179. package/dist/types/float16.d.ts +32 -0
  180. package/dist/types/float16.d.ts.map +1 -0
  181. package/dist/types/float16.js +41 -0
  182. package/dist/types/float16.js.map +1 -0
  183. package/dist/types/index.d.ts +6 -0
  184. package/dist/types/index.d.ts.map +1 -0
  185. package/dist/types/index.js +6 -0
  186. package/dist/types/index.js.map +1 -0
  187. package/dist/types/is-array.d.ts +22 -0
  188. package/dist/types/is-array.d.ts.map +1 -0
  189. package/dist/types/is-array.js +36 -0
  190. package/dist/types/is-array.js.map +1 -0
  191. package/dist/types/spheroid.d.ts +8 -0
  192. package/dist/types/spheroid.d.ts.map +1 -0
  193. package/dist/types/spheroid.js +5 -0
  194. package/dist/types/spheroid.js.map +1 -0
  195. package/dist/types/typed-array-brand.d.ts +2 -0
  196. package/dist/types/typed-array-brand.d.ts.map +1 -0
  197. package/dist/types/typed-array-brand.js +10 -0
  198. package/dist/types/typed-array-brand.js.map +1 -0
  199. package/dist/types.cjs +67 -0
  200. package/dist/types.cjs.map +6 -0
  201. package/dist/types.d.ts +2 -0
  202. package/dist/types.d.ts.map +1 -0
  203. package/dist/types.js +5 -0
  204. package/dist/types.js.map +1 -0
  205. package/dist/vec2.cjs.map +1 -1
  206. package/dist/vec2.js +1 -1
  207. package/dist/vec2.js.map +1 -1
  208. package/dist/vec3.cjs.map +1 -1
  209. package/dist/vec3.js +1 -1
  210. package/dist/vec3.js.map +1 -1
  211. package/dist/vec4.cjs.map +1 -1
  212. package/dist/vec4.js +1 -1
  213. package/dist/vec4.js.map +1 -1
  214. package/package.json +28 -6
  215. package/src/classes/base/math-array.ts +2 -2
  216. package/src/classes/base/matrix.ts +3 -3
  217. package/src/classes/base/vector.ts +3 -3
  218. package/src/classes/euler-types.ts +1 -1
  219. package/src/classes/euler.ts +5 -3
  220. package/src/classes/matrix3.ts +3 -3
  221. package/src/classes/matrix4.ts +3 -3
  222. package/src/classes/pose.ts +3 -3
  223. package/src/classes/quaternion.ts +3 -3
  224. package/src/classes/spherical-coordinates.ts +2 -2
  225. package/src/classes/vector2.ts +3 -3
  226. package/src/classes/vector3.ts +3 -3
  227. package/src/classes/vector4.ts +3 -3
  228. package/src/expressions/expression-eval.ts +435 -0
  229. package/src/expressions/function-libraries.ts +123 -0
  230. package/src/expressions/function-registry.ts +171 -0
  231. package/src/expressions/get.ts +37 -0
  232. package/src/expressions/index.ts +22 -0
  233. package/src/expressions/parse-expression-string.ts +80 -0
  234. package/src/expressions/vendor/jsep/LICENSE.txt +23 -0
  235. package/src/expressions/vendor/jsep/README.md +22 -0
  236. package/src/expressions/vendor/jsep/runtime.ts +949 -0
  237. package/src/expressions/vendor/jsep/types.ts +179 -0
  238. package/src/gl-matrix/common.js +5 -0
  239. package/src/gl-matrix/mat3.ts +5 -0
  240. package/src/gl-matrix/mat4.ts +5 -0
  241. package/src/gl-matrix/quat.ts +5 -0
  242. package/src/gl-matrix/vec2.ts +6 -1
  243. package/src/gl-matrix/vec3.ts +5 -0
  244. package/src/gl-matrix/vec4.ts +5 -0
  245. package/src/gl-matrix/wip/index.js +3 -1
  246. package/src/gl-matrix/wip/mat2.js +3 -1
  247. package/src/gl-matrix/wip/mat2d.js +3 -1
  248. package/src/gl-matrix/wip/quat2.ts +3 -1
  249. package/src/index.ts +5 -3
  250. package/src/lib/assert.ts +1 -1
  251. package/src/lib/common.ts +2 -2
  252. package/src/lib/gl-matrix-extras.ts +2 -2
  253. package/src/lib/gl-matrix.d.ts +1 -1
  254. package/src/lib/math-utils.ts +2 -1
  255. package/src/lib/validators.ts +2 -2
  256. package/src/local-frame.ts +253 -0
  257. package/src/mat3.ts +1 -1
  258. package/src/mat4.ts +1 -1
  259. package/src/quat.ts +1 -1
  260. package/src/spheroid.ts +230 -0
  261. package/src/types/array-types.ts +148 -0
  262. package/src/types/bigint.ts +74 -0
  263. package/src/types/bounds-types.ts +29 -0
  264. package/src/types/float16.ts +47 -0
  265. package/src/types/index.ts +45 -0
  266. package/src/types/is-array.ts +41 -0
  267. package/src/types/spheroid.ts +11 -0
  268. package/src/types/typed-array-brand.ts +14 -0
  269. package/src/types.ts +5 -0
  270. package/src/vec2.ts +1 -1
  271. package/src/vec3.ts +1 -1
  272. package/src/vec4.ts +1 -1
@@ -0,0 +1,230 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: 2014 Mike Adair, Richard Greenwood, Didier Richard, Stephen Irons, Olivier Terral and Calvin Metcalf (proj4js)
4
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
5
+ // SPDX-FileComment: Forward geocentric equations and Hannover inverse moved/adapted from math.gl projection's proj4js 2.22.0 datumUtils.js port. See ../PROJ4-LICENSE.md. Safeguarded compensated nearest-footpoint inverse, thin-exterior/pole fixes and numeric output commit are original math.gl code, qualified with independent mathematics and offline GeographicLib 2.7 (Charles Karney, MIT).
6
+
7
+ /** Numeric leaf: angles in radians, distances in axis units; no CRS, global config or scratch. */
8
+ import type {SpheroidParameters} from './types';
9
+ export type SpheroidGeometry = SpheroidParameters & {readonly eccentricitySquared: number};
10
+ export type SpheroidPoint = {x: number; y: number; z: number};
11
+
12
+ const EPSILON = Number.EPSILON;
13
+
14
+ /** Caller supplies validated positive finite axes and eccentricity. No latitude wrapping. */
15
+ export function spheroidToCartesian(
16
+ point: SpheroidPoint,
17
+ geometry: SpheroidGeometry,
18
+ result: SpheroidPoint = point
19
+ ): boolean {
20
+ const longitude = point.x,
21
+ latitude = point.y,
22
+ height = point.z;
23
+ const {semiMajorAxis: a, semiMinorAxis: b, eccentricitySquared: es} = geometry;
24
+ const sin = Math.sin(latitude),
25
+ cos = Math.abs(latitude) === Math.PI / 2 ? 0 : Math.cos(latitude);
26
+ // Use the axis ratio for very flat shapes: 1 - es*sin² loses polar precision.
27
+ const ratio = b / a;
28
+ const radius = es < 0.9 ? a / Math.sqrt(1 - es * sin * sin) : a / Math.hypot(cos, ratio * sin);
29
+ const x = (radius + height) * cos * Math.cos(longitude);
30
+ const y = (radius + height) * cos * Math.sin(longitude);
31
+ const z = (radius * (es < 0.9 ? 1 - es : ratio * ratio) + height) * sin;
32
+ return commit(result, x, y, z);
33
+ }
34
+
35
+ /**
36
+ * Bounded inverse. Sphere is analytic; ordinary spheroids use the retained Hannover
37
+ * iteration on exterior points. Interiors and thin-shape exteriors share a safeguarded nearest-footpoint solve.
38
+ * Equatorial interiors below the evolute cusp have two nearest normals: reject.
39
+ * false leaves output untouched, including the center and unresolved binary64 cases.
40
+ * Only exact poles canonicalize longitude; adapters may retain other conventions.
41
+ */
42
+ export function cartesianToSpheroid(
43
+ point: SpheroidPoint,
44
+ geometry: SpheroidGeometry,
45
+ result: SpheroidPoint = point
46
+ ): boolean {
47
+ const x = point.x,
48
+ y = point.y,
49
+ z = point.z;
50
+ const {semiMajorAxis: a, semiMinorAxis: b, eccentricitySquared: es} = geometry;
51
+ const longitude = Math.atan2(y, x);
52
+ const p = Math.hypot(x, y),
53
+ rr = Math.hypot(x, y, z);
54
+ if (!(rr > 0) || !Number.isFinite(rr)) return false;
55
+ if (es === 0) return commit(result, p === 0 ? 0 : longitude, Math.atan2(z, p), rr - a);
56
+ if (p === 0) return commit(result, 0, (Math.sign(z) * Math.PI) / 2, Math.abs(z) - b);
57
+ const horizontal = p / a,
58
+ vertical = z / b;
59
+ if (horizontal * horizontal + vertical * vertical < 1 - 16 * EPSILON)
60
+ return interiorInverse(x, y, z, p, a, b, result);
61
+ if (es >= 0.9) return interiorInverse(x, y, z, p, a, b, result);
62
+ const ct = z / rr,
63
+ st = p / rr;
64
+ let rx = 1 / Math.sqrt(1 - es * (2 - es) * st * st);
65
+ let cos = st * (1 - es) * rx,
66
+ sin = ct * rx;
67
+ for (let i = 0; i < 30; i++) {
68
+ const rn = a / Math.sqrt(1 - es * sin * sin);
69
+ const height = p * cos + z * sin - rn * (1 - es * sin * sin);
70
+ const rk = (es * rn) / (rn + height);
71
+ rx = 1 / Math.sqrt(1 - rk * (2 - rk) * st * st);
72
+ const nextCos = st * (1 - rk) * rx,
73
+ nextSin = ct * rx;
74
+ if (Math.abs(nextSin * cos - nextCos * sin) <= 1e-12) {
75
+ if (!Number.isFinite(height)) break;
76
+ return commit(result, longitude, Math.atan2(nextSin, Math.abs(nextCos)), height);
77
+ }
78
+ cos = nextCos;
79
+ sin = nextSin;
80
+ }
81
+ return interiorInverse(x, y, z, p, a, b, result);
82
+ }
83
+
84
+ /** Original nearest-normal solve in t = (lambda + b²)/a², avoiding interior cancellation and thin-exterior residual loss.
85
+ * The positive interval selects the globally nearest branch, rather than a stationary normal.
86
+ */
87
+ function interiorInverse(
88
+ x: number,
89
+ y: number,
90
+ z: number,
91
+ p: number,
92
+ a: number,
93
+ b: number,
94
+ result: SpheroidPoint
95
+ ): boolean {
96
+ const longitude = Math.atan2(y, x);
97
+ const ratio = b / a,
98
+ ratio2 = ratio * ratio;
99
+ const horizontal = p / a,
100
+ vertical = z / a,
101
+ delta = 1 - ratio2;
102
+ if (!(ratio2 > 0) || ratio > 1) return false;
103
+ const aa = a * a,
104
+ bb = b * b;
105
+ const ratioError =
106
+ Number.isFinite(aa) && aa > 0
107
+ ? (bb -
108
+ ratio2 * aa +
109
+ productError(b, b, bb) -
110
+ ratio2 * productError(a, a, aa) -
111
+ productError(ratio2, aa, ratio2 * aa)) /
112
+ aa
113
+ : 0;
114
+ const pp = p * p,
115
+ xx = x * x,
116
+ yy = y * y,
117
+ sum = xx + yy;
118
+ const radiusError =
119
+ Number.isFinite(pp) && pp > 0
120
+ ? (sum -
121
+ pp +
122
+ sumError(xx, yy, sum) +
123
+ productError(x, x, xx) +
124
+ productError(y, y, yy) -
125
+ productError(p, p, pp)) /
126
+ (2 * p)
127
+ : 0;
128
+ const shift = a * ratio2,
129
+ distance = p - a,
130
+ base = distance + shift;
131
+ const correction =
132
+ radiusError +
133
+ sumError(p, -a, distance) +
134
+ sumError(distance, shift, base) +
135
+ productError(a, ratio2, shift) +
136
+ a * ratioError;
137
+ if (z === 0) {
138
+ // A rounded hypot can equal the cusp for points just inside it. Include
139
+ // the radius/axis corrections before selecting a unique equatorial normal.
140
+ if (base + correction < 0) return false;
141
+ return commit(result, longitude, 0, distance);
142
+ }
143
+ const weighted = Math.abs(vertical) * ratio;
144
+ let lower = 0,
145
+ upper = ratio2 + Math.hypot(horizontal, vertical * ratio);
146
+ if (!Number.isFinite(upper)) return false;
147
+ // A lower bound near the short-axis singularity prevents thousands of bisections
148
+ // for deep, nearly equatorial interiors. No subtraction of lambda and -b².
149
+ let t = Math.max(weighted, horizontal - delta);
150
+ if (!(t > lower && t < upper)) t = upper / 2;
151
+ // Below the cusp, a vanishing polar input can make t subnormal. The
152
+ // limiting vertical footpoint remains well conditioned. Use it only when
153
+ // its bound t <= abs(z)*ratio/(a*v) is negligible relative to the cusp gap.
154
+ const gap = -(base + correction) / a;
155
+ const limiting = Math.sqrt(gap * (horizontal + delta)) / delta;
156
+ let latitude: number | undefined =
157
+ gap > 0 && (Math.abs(z) / limiting / a) * ratio <= EPSILON * gap
158
+ ? Math.atan2((Math.sign(z) * limiting) / ratio, horizontal / delta)
159
+ : undefined;
160
+ for (let i = 0; i < 1024 && latitude === undefined; i++) {
161
+ const equatorial = delta + t;
162
+ const u = horizontal / equatorial,
163
+ // Divide by t first: both z/a and a*t can lose precision in the
164
+ // subnormal range although the near-cusp latitude is representable.
165
+ verticalAt = z / t / a,
166
+ v = verticalAt * ratio;
167
+ const at = a * t,
168
+ difference = base - at;
169
+ const offset =
170
+ (difference + (sumError(base, -at, difference) + correction - productError(a, t, at))) /
171
+ (a * equatorial);
172
+ const term = offset * (u + 1);
173
+ const residual = term + v * v;
174
+ if (!Number.isFinite(residual)) return false;
175
+ if (residual > 0) lower = t;
176
+ else upper = t;
177
+ const derivative = -2 * ((u * u) / equatorial + (v * v) / t);
178
+ const next = t - residual / derivative;
179
+ const candidate = next > lower && next < upper ? next : lower + (upper - lower) / 2;
180
+ if (
181
+ Math.abs(residual) <= 4 * EPSILON * (Math.abs(term) + v * v) ||
182
+ upper - lower <= 4 * EPSILON * t
183
+ ) {
184
+ latitude = Math.atan2(verticalAt, u);
185
+ break;
186
+ }
187
+ t = candidate;
188
+ }
189
+ return latitude !== undefined && commitNormal(result, longitude, latitude, p, z, a, ratio);
190
+ }
191
+
192
+ /** Error-free transforms on the finite squared-axis domain used by geometry adapters. */
193
+ function sumError(x: number, y: number, sum: number): number {
194
+ const part = sum - x;
195
+ return x - (sum - part) + (y - part);
196
+ }
197
+ function productError(x: number, y: number, product: number): number {
198
+ const sx = 134217729 * x,
199
+ sy = 134217729 * y;
200
+ if (!Number.isFinite(sx) || !Number.isFinite(sy)) return 0;
201
+ const hx = sx - (sx - x),
202
+ hy = sy - (sy - y),
203
+ lx = x - hx,
204
+ ly = y - hy;
205
+ return hx * hy - product + hx * ly + lx * hy + lx * ly;
206
+ }
207
+
208
+ /** Shared signed distance along the solved surface normal. */
209
+ function commitNormal(
210
+ result: SpheroidPoint,
211
+ longitude: number,
212
+ latitude: number,
213
+ p: number,
214
+ z: number,
215
+ a: number,
216
+ ratio: number
217
+ ): boolean {
218
+ const sin = Math.sin(latitude),
219
+ cos = Math.cos(latitude);
220
+ return commit(result, longitude, latitude, p * cos + z * sin - a * Math.hypot(cos, ratio * sin));
221
+ }
222
+
223
+ /** Values are captured before invoking application setters; recursive writes are safe. */
224
+ function commit(result: SpheroidPoint, x: number, y: number, z: number): boolean {
225
+ if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z)) return false;
226
+ result.x = x;
227
+ result.y = y;
228
+ result.z = z;
229
+ return true;
230
+ }
@@ -0,0 +1,148 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ // Float16Array is declared in a separate TypeScript library. Preserve this reference so
6
+ // published declarations remain self-contained without changing the target or emitting runtime code.
7
+ // eslint-disable-next-line spaced-comment
8
+ /// <reference lib="es2025.float16" preserve="true" />
9
+
10
+ /**
11
+ * Type covering all non-big JavaScript typed arrays, including `Float16Array`.
12
+ *
13
+ * @remarks Including `Float16Array` does not guarantee that `globalThis.Float16Array` exists.
14
+ */
15
+ export type TypedArray =
16
+ | Int8Array
17
+ | Uint8Array
18
+ | Uint8ClampedArray
19
+ | Int16Array
20
+ | Uint16Array
21
+ | Int32Array
22
+ | Uint32Array
23
+ | Float16Array
24
+ | Float32Array
25
+ | Float64Array;
26
+
27
+ /**
28
+ * Type covering constructors for all non-big JavaScript typed arrays, including
29
+ * `Float16ArrayConstructor`.
30
+ *
31
+ * @remarks Including `Float16ArrayConstructor` does not install `globalThis.Float16Array`.
32
+ */
33
+ export type TypedArrayConstructor =
34
+ | Int8ArrayConstructor
35
+ | Uint8ArrayConstructor
36
+ | Uint8ClampedArrayConstructor
37
+ | Int16ArrayConstructor
38
+ | Uint16ArrayConstructor
39
+ | Int32ArrayConstructor
40
+ | Uint32ArrayConstructor
41
+ | Float16ArrayConstructor
42
+ | Float32ArrayConstructor
43
+ | Float64ArrayConstructor;
44
+
45
+ /**
46
+ * Type covering all big typed arrays
47
+ */
48
+ export type BigTypedArray = BigInt64Array | BigUint64Array;
49
+
50
+ /**
51
+ * Type covering constructors for all big typed arrays
52
+ */
53
+ export type BigTypedArrayConstructor = BigInt64ArrayConstructor | BigUint64ArrayConstructor;
54
+
55
+ /**
56
+ * Type for classic arrays consisting of numbers
57
+ * @note Included for completeness / orthogonality, prefer `number[]` in actual use
58
+ */
59
+ export type NumberArray = number[];
60
+
61
+ /** Array with exactly 1 number */
62
+ export type NumberArray1 = [number];
63
+
64
+ /** Array with exactly 2 numbers */
65
+ export type NumberArray2 = [number, number];
66
+
67
+ /** Array with exactly 3 numbers */
68
+ export type NumberArray3 = [number, number, number];
69
+
70
+ /** Array with exactly 4 numbers */
71
+ export type NumberArray4 = [number, number, number, number];
72
+
73
+ /** Array with exactly 6 numbers */
74
+ export type NumberArray6 = [number, number, number, number, number, number];
75
+
76
+ /** Array with exactly 8 numbers */
77
+ export type NumberArray8 = [number, number, number, number, number, number, number, number];
78
+
79
+ /** Array with exactly 9 numbers */
80
+ export type NumberArray9 = [number, number, number, number, number, number, number, number, number];
81
+
82
+ /** Array with exactly 12 numbers */
83
+ export type NumberArray12 = [
84
+ number,
85
+ number,
86
+ number,
87
+ number,
88
+ number,
89
+ number,
90
+ number,
91
+ number,
92
+ number,
93
+ number,
94
+ number,
95
+ number
96
+ ];
97
+
98
+ /** Array with exactly 16 numbers */
99
+ export type NumberArray16 = [
100
+ number,
101
+ number,
102
+ number,
103
+ number,
104
+ number,
105
+ number,
106
+ number,
107
+ number,
108
+ number,
109
+ number,
110
+ number,
111
+ number,
112
+ number,
113
+ number,
114
+ number,
115
+ number
116
+ ];
117
+
118
+ /**
119
+ * Type covering classic arrays consisting of numbers as well as typed arrays
120
+ */
121
+ export type NumericArray = TypedArray | number[];
122
+
123
+ /** Array with exactly 1 number, or a typed array */
124
+ export type NumericArray1 = NumberArray1 | TypedArray;
125
+
126
+ /** Array with exactly 2 numbers, or a typed array */
127
+ export type NumericArray2 = NumberArray2 | TypedArray;
128
+
129
+ /** Array with exactly 3 numbers, or a typed array */
130
+ export type NumericArray3 = NumberArray3 | TypedArray;
131
+
132
+ /** Array with exactly 4 numbers, or a typed array */
133
+ export type NumericArray4 = NumberArray4 | TypedArray;
134
+
135
+ /** Array with exactly 6 numbers, or a typed array */
136
+ export type NumericArray6 = NumberArray6 | TypedArray;
137
+
138
+ /** Array with exactly 8 numbers, or a typed array */
139
+ export type NumericArray8 = NumberArray8 | TypedArray;
140
+
141
+ /** Array with exactly 9 numbers, or a typed array */
142
+ export type NumericArray9 = NumberArray9 | TypedArray;
143
+
144
+ /** Array with exactly 12 numbers, or a typed array */
145
+ export type NumericArray12 = NumberArray12 | TypedArray;
146
+
147
+ /** Array with exactly 16 numbers, or a typed array */
148
+ export type NumericArray16 = NumberArray16 | TypedArray;
@@ -0,0 +1,74 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT AND Apache-2.0
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+ // SPDX-FileCopyrightText: Copyright 2016-2019 The Apache Software Foundation
5
+ // SPDX-FileComment: BigInt availability/fallback structure adapted from Apache Arrow JS util/compat.ts; compared with apache-arrow-4.0.0. See ../../ARROW-NOTICE.txt and ../../APACHE-2.0-LICENSE.txt. Modified to separate availability flags, share errors and narrow exports.
6
+
7
+ // Licensed to the Apache Software Foundation (ASF) under one
8
+ // or more contributor license agreements. See the NOTICE file
9
+ // distributed with this work for additional information
10
+ // regarding copyright ownership. The ASF licenses this file
11
+ // to you under the Apache License, Version 2.0 (the
12
+ // "License"); you may not use this file except in compliance
13
+ // with the License. You may obtain a copy of the License at
14
+ //
15
+ // http://www.apache.org/licenses/LICENSE-2.0
16
+ //
17
+ // Unless required by applicable law or agreed to in writing,
18
+ // software distributed under the License is distributed on an
19
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
+ // KIND, either express or implied. See the License for the
21
+ // specific language governing permissions and limitations
22
+ // under the License.
23
+
24
+ // BigInt compatibility layer
25
+ // Source comparison: https://github.com/apache/arrow/blob/apache-arrow-4.0.0/js/src/util/compat.ts
26
+ // Requires tsconfig.json: target=esnext or (lib: esnext.bigint)
27
+ // Requires eslint: env: {es2020: true}
28
+
29
+ const ERR_BIGINT_UNAVAILABLE = 'BigInt is not available in this environment';
30
+
31
+ function BigIntUnavailable() {
32
+ throw new Error(ERR_BIGINT_UNAVAILABLE);
33
+ }
34
+ BigIntUnavailable.asIntN = () => {
35
+ throw new Error(ERR_BIGINT_UNAVAILABLE);
36
+ };
37
+ BigIntUnavailable.asUintN = () => {
38
+ throw new Error(ERR_BIGINT_UNAVAILABLE);
39
+ };
40
+
41
+ class BigInt64ArrayUnavailable {
42
+ static get BYTES_PER_ELEMENT() {
43
+ return 8;
44
+ }
45
+ static of() {
46
+ throw new Error(ERR_BIGINT_UNAVAILABLE);
47
+ }
48
+ static from() {
49
+ throw new Error(ERR_BIGINT_UNAVAILABLE);
50
+ }
51
+ constructor() {
52
+ throw new Error(ERR_BIGINT_UNAVAILABLE);
53
+ }
54
+ }
55
+
56
+ export const BigIntAvailable = typeof BigInt !== 'undefined';
57
+ export const BigInt64ArrayAvailable = typeof BigInt64Array !== 'undefined';
58
+ export const BigUint64ArrayAvailable = typeof BigUint64Array !== 'undefined';
59
+
60
+ const BigIntCtor = (() => {
61
+ return BigIntAvailable ? BigInt : BigIntUnavailable;
62
+ })();
63
+
64
+ const BigInt64ArrayCtor = (() => {
65
+ return BigInt64ArrayAvailable ? BigInt64Array : BigInt64ArrayUnavailable;
66
+ })();
67
+
68
+ const BigUint64ArrayCtor = (() => {
69
+ return BigUint64ArrayAvailable ? BigUint64Array : BigInt64ArrayUnavailable;
70
+ })();
71
+
72
+ export {BigIntCtor as BigInt};
73
+ export {BigInt64ArrayCtor as BigInt64Array};
74
+ export {BigUint64ArrayCtor as BigUint64Array};
@@ -0,0 +1,29 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ /** 2 dimensional bounds [[minX, minY], [maxX, maxY]] */
6
+ export type Bounds2D = [[number, number], [number, number]];
7
+
8
+ /** 3 dimensional bounds [[minX, minY, minZ], [maxX, maxY, maxZ]] */
9
+ export type Bounds3D = [[number, number, number], [number, number, number]];
10
+
11
+ /** 2 or 3 dimensional bounds [[minX, minY], [maxX, maxY]] or [[minX, minY, minZ], [maxX, maxY, maxZ]] */
12
+ export type Bounds =
13
+ | [[number, number], [number, number]]
14
+ | [[number, number, number], [number, number, number]];
15
+
16
+ /** Checks if a `Bounds` is a `Bounds2D` */
17
+ export function isBounds2D(bounds: Bounds): bounds is Bounds2D {
18
+ return bounds.length === 2 && bounds[0].length === 2 && bounds[1].length === 2;
19
+ }
20
+
21
+ /** Accepts 2D and 3D bounds and returns a 2D bound, truncating 3D dimension if necessary */
22
+ export function getBounds2D(bounds: Bounds): Bounds2D {
23
+ return isBounds2D(bounds)
24
+ ? bounds
25
+ : [
26
+ [bounds[0][0], bounds[0][1]],
27
+ [bounds[1][0], bounds[1][1]]
28
+ ];
29
+ }
@@ -0,0 +1,47 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import type {TypedArrayConstructor} from './array-types';
6
+ import {getTypedArrayName} from './typed-array-brand';
7
+
8
+ /**
9
+ * Checks for native Float16Array values, including arrays from other realms.
10
+ * Does not identify Uint16Array binary16 storage as a decoded Float16Array.
11
+ * Does not require a Float16Array constructor in the current realm.
12
+ */
13
+ export function isFloat16Array(value: unknown): value is Float16Array {
14
+ return getTypedArrayName(value) === 'Float16Array';
15
+ }
16
+
17
+ /**
18
+ * The native `Float16Array` constructor exposed by the current JavaScript runtime.
19
+ *
20
+ * @remarks This is `undefined` when the runtime does not provide `Float16Array`. The value is
21
+ * captured when this module is evaluated, so a polyfill must be installed before importing
22
+ * `@math.gl/core/types`.
23
+ */
24
+ export const NativeFloat16ArrayConstructor: TypedArrayConstructor | undefined =
25
+ globalThis.Float16Array;
26
+
27
+ /**
28
+ * Returns the typed array constructor used for half-precision storage.
29
+ *
30
+ * @returns The native `Float16Array` constructor when available, otherwise `Uint16Array`.
31
+ * @remarks The `Uint16Array` fallback stores encoded IEEE 754 binary16 bit patterns. Unlike a
32
+ * native `Float16Array`, it does not encode numeric assignments or decode values when read.
33
+ */
34
+ export function getFloat16ArrayConstructor(): TypedArrayConstructor {
35
+ return NativeFloat16ArrayConstructor ?? Uint16Array;
36
+ }
37
+
38
+ /**
39
+ * Checks whether a value is the native `Float16Array` constructor for the current runtime.
40
+ *
41
+ * @param value The value to test.
42
+ * @returns `true` when `value` matches `NativeFloat16ArrayConstructor`. Returns `false` for the
43
+ * `Uint16Array` fallback.
44
+ */
45
+ export function isFloat16ArrayConstructor(value: unknown): boolean {
46
+ return Boolean(NativeFloat16ArrayConstructor && value === NativeFloat16ArrayConstructor);
47
+ }
@@ -0,0 +1,45 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ export type {
6
+ // typed arrays
7
+ TypedArray,
8
+ TypedArrayConstructor,
9
+ BigTypedArray,
10
+ BigTypedArrayConstructor,
11
+ // numeric arrays (sized number arrays)
12
+ NumberArray,
13
+ NumberArray1,
14
+ NumberArray2,
15
+ NumberArray3,
16
+ NumberArray4,
17
+ NumberArray6,
18
+ NumberArray8,
19
+ NumberArray9,
20
+ NumberArray12,
21
+ NumberArray16,
22
+ // numeric arrays (sized number arrays or typed arrays)
23
+ NumericArray,
24
+ NumericArray1,
25
+ NumericArray2,
26
+ NumericArray3,
27
+ NumericArray4,
28
+ NumericArray6,
29
+ NumericArray8,
30
+ NumericArray9,
31
+ NumericArray12,
32
+ NumericArray16
33
+ } from './array-types';
34
+
35
+ export {isTypedArray, isUint16Array, isNumberArray, isNumericArray} from './is-array';
36
+ export {
37
+ NativeFloat16ArrayConstructor,
38
+ getFloat16ArrayConstructor,
39
+ isFloat16ArrayConstructor,
40
+ isFloat16Array
41
+ } from './float16';
42
+
43
+ export type {Bounds, Bounds2D, Bounds3D} from './bounds-types';
44
+
45
+ export type {SpheroidParameters} from './spheroid';
@@ -0,0 +1,41 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import {TypedArray, NumericArray, NumberArray} from './array-types';
6
+ import {getTypedArrayName} from './typed-array-brand';
7
+
8
+ /** Checks for unsigned 16-bit samples, including typed arrays from other realms. */
9
+ export function isUint16Array(value: unknown): value is Uint16Array {
10
+ return getTypedArrayName(value) === 'Uint16Array';
11
+ }
12
+
13
+ /**
14
+ * Check is an array is a typed array
15
+ * @param value value to be tested
16
+ * @returns input with type narrowed to TypedArray, or null
17
+ */
18
+ export function isTypedArray(value: unknown): value is TypedArray {
19
+ return ArrayBuffer.isView(value) && !(value instanceof DataView);
20
+ }
21
+
22
+ /**
23
+ * Check is an array is an array of numbers)
24
+ * @param value value to be tested
25
+ * @returns input with type narrowed to NumberArray, or null
26
+ */
27
+ export function isNumberArray(value: unknown): value is NumberArray {
28
+ if (Array.isArray(value)) {
29
+ return value.length === 0 || typeof value[0] === 'number';
30
+ }
31
+ return false;
32
+ }
33
+
34
+ /**
35
+ * Check is an array is a numeric array (typed array or array of numbers)
36
+ * @param value value to be tested
37
+ * @returns input with type narrowed to NumericArray, or null
38
+ */
39
+ export function isNumericArray(value: unknown): value is NumericArray {
40
+ return isTypedArray(value) || isNumberArray(value);
41
+ }
@@ -0,0 +1,11 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ /** Geometry of a sphere or oblate spheroid, in metres. No datum, axes or epoch metadata.
6
+ * Both axes must be finite and positive, with semiMinorAxis <= semiMajorAxis.
7
+ */
8
+ export type SpheroidParameters = {
9
+ readonly semiMajorAxis: number;
10
+ readonly semiMinorAxis: number;
11
+ };
@@ -0,0 +1,14 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ // Use the intrinsic getter so constructor and Symbol.toStringTag overrides cannot
6
+ // disguise a typed array's element type. It also works for arrays from other realms.
7
+ const typedArrayTagGetter = Object.getOwnPropertyDescriptor(
8
+ Object.getPrototypeOf(Uint8Array.prototype),
9
+ Symbol.toStringTag
10
+ )!.get!;
11
+
12
+ export function getTypedArrayName(value: unknown): string | undefined {
13
+ return ArrayBuffer.isView(value) ? typedArrayTagGetter.call(value) : undefined;
14
+ }
package/src/types.ts ADDED
@@ -0,0 +1,5 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ export * from './types/index';
package/src/vec2.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // math.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  export * from './gl-matrix/vec2';
package/src/vec3.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // math.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  export * from './gl-matrix/vec3';
package/src/vec4.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // math.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
4
 
5
5
  export * from './gl-matrix/vec4';