@math.gl/core 5.0.0-alpha.11 → 5.0.0-alpha.13

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 (148) hide show
  1. package/LICENSE +7 -0
  2. package/PROJ4-LICENSE.md +29 -0
  3. package/README.md +5 -0
  4. package/dist/classes/base/math-array.js +1 -1
  5. package/dist/classes/base/math-array.js.map +1 -1
  6. package/dist/classes/base/matrix.js +2 -2
  7. package/dist/classes/base/matrix.js.map +1 -1
  8. package/dist/classes/base/vector.js +2 -2
  9. package/dist/classes/base/vector.js.map +1 -1
  10. package/dist/classes/euler-types.js +1 -1
  11. package/dist/classes/euler-types.js.map +1 -1
  12. package/dist/classes/euler.js +2 -2
  13. package/dist/classes/euler.js.map +1 -1
  14. package/dist/classes/matrix3.js +2 -2
  15. package/dist/classes/matrix3.js.map +1 -1
  16. package/dist/classes/matrix4.js +2 -2
  17. package/dist/classes/matrix4.js.map +1 -1
  18. package/dist/classes/pose.js +2 -2
  19. package/dist/classes/pose.js.map +1 -1
  20. package/dist/classes/quaternion.js +2 -2
  21. package/dist/classes/quaternion.js.map +1 -1
  22. package/dist/classes/spherical-coordinates.js +2 -2
  23. package/dist/classes/spherical-coordinates.js.map +1 -1
  24. package/dist/classes/vector2.js +2 -2
  25. package/dist/classes/vector2.js.map +1 -1
  26. package/dist/classes/vector3.js +2 -2
  27. package/dist/classes/vector3.js.map +1 -1
  28. package/dist/classes/vector4.js +2 -2
  29. package/dist/classes/vector4.js.map +1 -1
  30. package/dist/gl-matrix/common.d.ts.map +1 -1
  31. package/dist/gl-matrix/common.js +5 -0
  32. package/dist/gl-matrix/common.js.map +1 -1
  33. package/dist/gl-matrix/mat3.d.ts.map +1 -1
  34. package/dist/gl-matrix/mat3.js +5 -0
  35. package/dist/gl-matrix/mat3.js.map +1 -1
  36. package/dist/gl-matrix/mat4.d.ts.map +1 -1
  37. package/dist/gl-matrix/mat4.js +5 -0
  38. package/dist/gl-matrix/mat4.js.map +1 -1
  39. package/dist/gl-matrix/quat.d.ts.map +1 -1
  40. package/dist/gl-matrix/quat.js +5 -0
  41. package/dist/gl-matrix/quat.js.map +1 -1
  42. package/dist/gl-matrix/vec2.d.ts.map +1 -1
  43. package/dist/gl-matrix/vec2.js +5 -0
  44. package/dist/gl-matrix/vec2.js.map +1 -1
  45. package/dist/gl-matrix/vec3.d.ts.map +1 -1
  46. package/dist/gl-matrix/vec3.js +5 -0
  47. package/dist/gl-matrix/vec3.js.map +1 -1
  48. package/dist/gl-matrix/vec4.d.ts.map +1 -1
  49. package/dist/gl-matrix/vec4.js +5 -0
  50. package/dist/gl-matrix/vec4.js.map +1 -1
  51. package/dist/gl-matrix/wip/index.d.ts.map +1 -1
  52. package/dist/gl-matrix/wip/index.js +3 -1
  53. package/dist/gl-matrix/wip/index.js.map +1 -1
  54. package/dist/gl-matrix/wip/mat2.d.ts.map +1 -1
  55. package/dist/gl-matrix/wip/mat2.js +3 -1
  56. package/dist/gl-matrix/wip/mat2.js.map +1 -1
  57. package/dist/gl-matrix/wip/mat2d.d.ts.map +1 -1
  58. package/dist/gl-matrix/wip/mat2d.js +3 -1
  59. package/dist/gl-matrix/wip/mat2d.js.map +1 -1
  60. package/dist/gl-matrix/wip/quat2.d.ts.map +1 -1
  61. package/dist/gl-matrix/wip/quat2.js +3 -1
  62. package/dist/gl-matrix/wip/quat2.js.map +1 -1
  63. package/dist/index.cjs.map +1 -1
  64. package/dist/index.d.ts +1 -0
  65. package/dist/index.d.ts.map +1 -1
  66. package/dist/index.js +1 -1
  67. package/dist/index.js.map +1 -1
  68. package/dist/lib/assert.js +1 -1
  69. package/dist/lib/assert.js.map +1 -1
  70. package/dist/lib/common.js +1 -1
  71. package/dist/lib/common.js.map +1 -1
  72. package/dist/lib/gl-matrix-extras.js +1 -1
  73. package/dist/lib/gl-matrix-extras.js.map +1 -1
  74. package/dist/lib/math-utils.d.ts.map +1 -1
  75. package/dist/lib/math-utils.js +2 -1
  76. package/dist/lib/math-utils.js.map +1 -1
  77. package/dist/lib/validators.js +1 -1
  78. package/dist/lib/validators.js.map +1 -1
  79. package/dist/local-frame.cjs +139 -0
  80. package/dist/local-frame.cjs.map +6 -0
  81. package/dist/local-frame.d.ts +39 -0
  82. package/dist/local-frame.d.ts.map +1 -0
  83. package/dist/local-frame.js +157 -0
  84. package/dist/local-frame.js.map +1 -0
  85. package/dist/mat3.cjs.map +1 -1
  86. package/dist/mat3.js +1 -1
  87. package/dist/mat3.js.map +1 -1
  88. package/dist/mat4.cjs.map +1 -1
  89. package/dist/mat4.js +1 -1
  90. package/dist/mat4.js.map +1 -1
  91. package/dist/quat.cjs.map +1 -1
  92. package/dist/quat.js +1 -1
  93. package/dist/quat.js.map +1 -1
  94. package/dist/spheroid.cjs +170 -0
  95. package/dist/spheroid.cjs.map +6 -0
  96. package/dist/spheroid.d.ts +21 -0
  97. package/dist/spheroid.d.ts.map +1 -0
  98. package/dist/spheroid.js +186 -0
  99. package/dist/spheroid.js.map +1 -0
  100. package/dist/vec2.cjs.map +1 -1
  101. package/dist/vec2.js +1 -1
  102. package/dist/vec2.js.map +1 -1
  103. package/dist/vec3.cjs.map +1 -1
  104. package/dist/vec3.js +1 -1
  105. package/dist/vec3.js.map +1 -1
  106. package/dist/vec4.cjs.map +1 -1
  107. package/dist/vec4.js +1 -1
  108. package/dist/vec4.js.map +1 -1
  109. package/package.json +15 -4
  110. package/src/classes/base/math-array.ts +1 -1
  111. package/src/classes/base/matrix.ts +2 -2
  112. package/src/classes/base/vector.ts +2 -2
  113. package/src/classes/euler-types.ts +1 -1
  114. package/src/classes/euler.ts +2 -2
  115. package/src/classes/matrix3.ts +2 -2
  116. package/src/classes/matrix4.ts +2 -2
  117. package/src/classes/pose.ts +2 -2
  118. package/src/classes/quaternion.ts +2 -2
  119. package/src/classes/spherical-coordinates.ts +2 -2
  120. package/src/classes/vector2.ts +2 -2
  121. package/src/classes/vector3.ts +2 -2
  122. package/src/classes/vector4.ts +2 -2
  123. package/src/gl-matrix/common.js +5 -0
  124. package/src/gl-matrix/mat3.ts +5 -0
  125. package/src/gl-matrix/mat4.ts +5 -0
  126. package/src/gl-matrix/quat.ts +5 -0
  127. package/src/gl-matrix/vec2.ts +5 -0
  128. package/src/gl-matrix/vec3.ts +5 -0
  129. package/src/gl-matrix/vec4.ts +5 -0
  130. package/src/gl-matrix/wip/index.js +3 -1
  131. package/src/gl-matrix/wip/mat2.js +3 -1
  132. package/src/gl-matrix/wip/mat2d.js +3 -1
  133. package/src/gl-matrix/wip/quat2.ts +3 -1
  134. package/src/index.ts +3 -1
  135. package/src/lib/assert.ts +1 -1
  136. package/src/lib/common.ts +1 -1
  137. package/src/lib/gl-matrix-extras.ts +1 -1
  138. package/src/lib/gl-matrix.d.ts +1 -1
  139. package/src/lib/math-utils.ts +2 -1
  140. package/src/lib/validators.ts +1 -1
  141. package/src/local-frame.ts +253 -0
  142. package/src/mat3.ts +1 -1
  143. package/src/mat4.ts +1 -1
  144. package/src/quat.ts +1 -1
  145. package/src/spheroid.ts +253 -0
  146. package/src/vec2.ts +1 -1
  147. package/src/vec3.ts +1 -1
  148. package/src/vec4.ts +1 -1
@@ -1,3 +1,8 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+ // SPDX-FileCopyrightText: Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. (gl-matrix)
5
+ // SPDX-FileComment: Adapted from gl-matrix. See the repository LICENSE for upstream attribution and terms.
1
6
  // @eslint-disable
2
7
  // @ts-nocheck
3
8
 
@@ -1,3 +1,8 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+ // SPDX-FileCopyrightText: Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. (gl-matrix)
5
+ // SPDX-FileComment: Adapted from gl-matrix. See the repository LICENSE for upstream attribution and terms.
1
6
  // @eslint-disable
2
7
  // @ts-nocheck
3
8
 
@@ -1,3 +1,8 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+ // SPDX-FileCopyrightText: Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. (gl-matrix)
5
+ // SPDX-FileComment: Adapted from gl-matrix. See the repository LICENSE for upstream attribution and terms.
1
6
  // @eslint-disable
2
7
  // @ts-nocheck
3
8
 
@@ -1,3 +1,8 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+ // SPDX-FileCopyrightText: Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. (gl-matrix)
5
+ // SPDX-FileComment: Adapted from gl-matrix. See the repository LICENSE for upstream attribution and terms.
1
6
  // @eslint-disable
2
7
  // @ts-nocheck
3
8
 
@@ -1,6 +1,8 @@
1
1
  // math.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. (gl-matrix)
4
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
5
+ // SPDX-FileComment: Adapted from gl-matrix. See the repository LICENSE for upstream attribution and terms.
4
6
 
5
7
  // @eslint-disable
6
8
  // @ts-nocheck
@@ -1,6 +1,8 @@
1
1
  // math.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. (gl-matrix)
4
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
5
+ // SPDX-FileComment: Adapted from gl-matrix. See the repository LICENSE for upstream attribution and terms.
4
6
 
5
7
  // @ts-nocheck
6
8
  /* eslint-disable */
@@ -1,6 +1,8 @@
1
1
  // math.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. (gl-matrix)
4
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
5
+ // SPDX-FileComment: Adapted from gl-matrix. See the repository LICENSE for upstream attribution and terms.
4
6
 
5
7
  // @ts-nocheck
6
8
  /* eslint-disable */
@@ -1,6 +1,8 @@
1
1
  // math.gl
2
2
  // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
3
+ // SPDX-FileCopyrightText: Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV. (gl-matrix)
4
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
5
+ // SPDX-FileComment: Adapted from gl-matrix. See the repository LICENSE for upstream attribution and terms.
4
6
 
5
7
  // @ts-nocheck
6
8
  /* eslint-disable */
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
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
  // types
6
6
  export type {
@@ -68,3 +68,5 @@ export {
68
68
  lerp,
69
69
  withEpsilon
70
70
  } from './lib/common';
71
+
72
+ export type {SpheroidParameters} from '@math.gl/types';
package/src/lib/assert.ts CHANGED
@@ -1,6 +1,6 @@
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 function assert(condition: unknown, message?: string): void {
6
6
  if (!condition) {
package/src/lib/common.ts CHANGED
@@ -1,6 +1,6 @@
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
  /* eslint-disable no-shadow */ // radians and degrees are common variable names
6
6
 
@@ -1,6 +1,6 @@
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
  /* eslint-disable camelcase */
6
6
  import {NumericArray} from '@math.gl/types';
@@ -1,6 +1,6 @@
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
  // Float16Array is declared in a separate TypeScript library. This reference affects types only.
6
6
  // eslint-disable-next-line spaced-comment
@@ -1,6 +1,7 @@
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
+ // SPDX-FileComment: Original compatibility helpers for Cesium-derived tests.
4
5
 
5
6
  // NOTE: Added to make Cesium-derived test cases work
6
7
  // TODO: Determine if/how to keep
@@ -1,6 +1,6 @@
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
  import {NumericArray} from '@math.gl/types';
6
6
  import {config} from './common';
@@ -0,0 +1,253 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+ // SPDX-FileComment: Original factored ENU/NED basis, rotations and matrix commits. No CesiumJS or PROJ source is copied.
5
+ import type {NumericArray} from '@math.gl/types';
6
+
7
+ export type LocalFramePoint = {x: number; y: number; z: number};
8
+ export type LocalFrameAxis = 'east' | 'north' | 'up' | 'west' | 'south' | 'down';
9
+ /** East has zero Z. North is up × east; northZ is its horizontal radial factor. */
10
+ export type LocalFrameBasis = {
11
+ eastX: number;
12
+ eastY: number;
13
+ northZ: number;
14
+ upX: number;
15
+ upY: number;
16
+ upZ: number;
17
+ };
18
+
19
+ /** Setup-time scratch, initially the ENU basis at longitude/latitude zero. */
20
+ export function createLocalFrameBasis(): LocalFrameBasis {
21
+ return {eastX: 0, eastY: 1, northZ: 1, upX: 1, upY: 0, upZ: 0};
22
+ }
23
+
24
+ /** Angles in radians. Longitude is periodic; latitude must be within ±π/2. */
25
+ export function eastNorthUpBasis(
26
+ longitude: number,
27
+ latitude: number,
28
+ result: LocalFrameBasis
29
+ ): boolean {
30
+ if (!Number.isFinite(longitude) || !Number.isFinite(latitude) || Math.abs(latitude) > Math.PI / 2)
31
+ return false;
32
+ const sl = Math.sin(longitude),
33
+ cl = Math.cos(longitude);
34
+ const sp = Math.sin(latitude),
35
+ cp = Math.cos(latitude);
36
+ return commitBasis(result, -sl, cl, cp, cp * cl, cp * sl, sp);
37
+ }
38
+
39
+ /**
40
+ * Caller supplies finite unit east/up directions, east.z=0, mutually perpendicular,
41
+ * and an up direction whose horizontal component points radially outward.
42
+ * This form preserves supplied up components rather than inferring a geodetic footpoint.
43
+ * Finiteness is checked; orthonormality is a caller precondition, not certified here.
44
+ */
45
+ export function eastNorthUpBasisFromDirections(
46
+ east: LocalFramePoint,
47
+ up: LocalFramePoint,
48
+ result: LocalFrameBasis
49
+ ): boolean {
50
+ const ex = east.x,
51
+ ey = east.y,
52
+ ez = east.z;
53
+ const ux = up.x,
54
+ uy = up.y,
55
+ uz = up.z;
56
+ if (ez !== 0) return false;
57
+ return commitBasis(result, ex, ey, ux * ey - uy * ex, ux, uy, uz);
58
+ }
59
+
60
+ /** Rotate ENU offsets/velocities to fixed XYZ. Distances retain the input unit. */
61
+ export function localToFixed(
62
+ point: LocalFramePoint,
63
+ basis: LocalFrameBasis,
64
+ result: LocalFramePoint = point
65
+ ): boolean {
66
+ const sl = -basis.eastX,
67
+ cl = basis.eastY,
68
+ sp = basis.upZ,
69
+ cp = basis.northZ;
70
+ const east = point.x,
71
+ north = point.y,
72
+ up = point.z;
73
+ // Retain the factored rotation order used by deformation; no intermediate vector.
74
+ const radial = up * cp - north * sp;
75
+ return commitPoint(
76
+ result,
77
+ radial * cl - east * sl,
78
+ radial * sl + east * cl,
79
+ up * sp + north * cp
80
+ );
81
+ }
82
+
83
+ /** Transpose rotation, valid for the orthonormal ENU basis precondition. */
84
+ export function fixedToLocal(
85
+ point: LocalFramePoint,
86
+ basis: LocalFrameBasis,
87
+ result: LocalFramePoint = point
88
+ ): boolean {
89
+ const ex = basis.eastX,
90
+ ey = basis.eastY,
91
+ nz = basis.northZ;
92
+ const ux = basis.upX,
93
+ uy = basis.upY,
94
+ uz = basis.upZ;
95
+ const x = point.x,
96
+ y = point.y,
97
+ z = point.z;
98
+ return commitPoint(
99
+ result,
100
+ x * ex + y * ey,
101
+ -x * uz * ey + y * uz * ex + z * nz,
102
+ x * ux + y * uy + z * uz
103
+ );
104
+ }
105
+
106
+ /**
107
+ * Column-major affine matrix, with explicit signed local axes and fixed-space origin.
108
+ * Axis triples must be right handed (e.g. east/north/up or north/east/down).
109
+ * Translation uses the origin's distance unit. The basis itself has no origin.
110
+ * A failure leaves output unchanged; caller owns writable storage (a growable number array or a typed array of length ≥16).
111
+ */
112
+ export function localFrameToMatrix(
113
+ basis: LocalFrameBasis,
114
+ origin: LocalFramePoint,
115
+ firstAxis: LocalFrameAxis,
116
+ secondAxis: LocalFrameAxis,
117
+ thirdAxis: LocalFrameAxis,
118
+ result: NumericArray
119
+ ): boolean {
120
+ const first = axisCode(firstAxis),
121
+ second = axisCode(secondAxis),
122
+ third = axisCode(thirdAxis);
123
+ const a = Math.abs(first),
124
+ b = Math.abs(second),
125
+ c = Math.abs(third);
126
+ if (!a || !b || !c || a === b || a === c || b === c) return false;
127
+ const parity = (a % 3) + 1 === b ? 1 : -1;
128
+ if (
129
+ parity * Math.sign(first * second * third) !== 1 ||
130
+ (!Array.isArray(result) && result.length < 16)
131
+ )
132
+ return false;
133
+ const ex = basis.eastX,
134
+ ey = basis.eastY,
135
+ nz = basis.northZ;
136
+ const ux = basis.upX,
137
+ uy = basis.upY,
138
+ uz = basis.upZ;
139
+ const nx = -uz * ey,
140
+ ny = uz * ex;
141
+ const x = origin.x,
142
+ y = origin.y,
143
+ z = origin.z;
144
+ const ax = (a === 1 ? ex : a === 2 ? nx : ux) * Math.sign(first);
145
+ const ay = (a === 1 ? ey : a === 2 ? ny : uy) * Math.sign(first);
146
+ const az = (a === 1 ? 0 : a === 2 ? nz : uz) * Math.sign(first);
147
+ const bx = (b === 1 ? ex : b === 2 ? nx : ux) * Math.sign(second);
148
+ const by = (b === 1 ? ey : b === 2 ? ny : uy) * Math.sign(second);
149
+ const bz = (b === 1 ? 0 : b === 2 ? nz : uz) * Math.sign(second);
150
+ const cx = (c === 1 ? ex : c === 2 ? nx : ux) * Math.sign(third);
151
+ const cy = (c === 1 ? ey : c === 2 ? ny : uy) * Math.sign(third);
152
+ const cz = (c === 1 ? 0 : c === 2 ? nz : uz) * Math.sign(third);
153
+ if (
154
+ !Number.isFinite(ax) ||
155
+ !Number.isFinite(ay) ||
156
+ !Number.isFinite(az) ||
157
+ !Number.isFinite(bx) ||
158
+ !Number.isFinite(by) ||
159
+ !Number.isFinite(bz) ||
160
+ !Number.isFinite(cx) ||
161
+ !Number.isFinite(cy) ||
162
+ !Number.isFinite(cz) ||
163
+ !Number.isFinite(x) ||
164
+ !Number.isFinite(y) ||
165
+ !Number.isFinite(z)
166
+ )
167
+ return false;
168
+ if (
169
+ result instanceof Float32Array &&
170
+ (!Number.isFinite(Math.fround(ax)) ||
171
+ !Number.isFinite(Math.fround(ay)) ||
172
+ !Number.isFinite(Math.fround(az)) ||
173
+ !Number.isFinite(Math.fround(bx)) ||
174
+ !Number.isFinite(Math.fround(by)) ||
175
+ !Number.isFinite(Math.fround(bz)) ||
176
+ !Number.isFinite(Math.fround(cx)) ||
177
+ !Number.isFinite(Math.fround(cy)) ||
178
+ !Number.isFinite(Math.fround(cz)) ||
179
+ !Number.isFinite(Math.fround(x)) ||
180
+ !Number.isFinite(Math.fround(y)) ||
181
+ !Number.isFinite(Math.fround(z)))
182
+ )
183
+ return false;
184
+ // Snapshot every component before application setters can recursively change scratch.
185
+ result[0] = ax;
186
+ result[1] = ay;
187
+ result[2] = az;
188
+ result[3] = 0;
189
+ result[4] = bx;
190
+ result[5] = by;
191
+ result[6] = bz;
192
+ result[7] = 0;
193
+ result[8] = cx;
194
+ result[9] = cy;
195
+ result[10] = cz;
196
+ result[11] = 0;
197
+ result[12] = x;
198
+ result[13] = y;
199
+ result[14] = z;
200
+ result[15] = 1;
201
+ return true;
202
+ }
203
+ function axisCode(axis: LocalFrameAxis): number {
204
+ switch (axis) {
205
+ case 'east':
206
+ return 1;
207
+ case 'west':
208
+ return -1;
209
+ case 'north':
210
+ return 2;
211
+ case 'south':
212
+ return -2;
213
+ case 'up':
214
+ return 3;
215
+ case 'down':
216
+ return -3;
217
+ default:
218
+ return 0;
219
+ }
220
+ }
221
+ function commitBasis(
222
+ result: LocalFrameBasis,
223
+ ex: number,
224
+ ey: number,
225
+ nz: number,
226
+ ux: number,
227
+ uy: number,
228
+ uz: number
229
+ ): boolean {
230
+ if (
231
+ !Number.isFinite(ex) ||
232
+ !Number.isFinite(ey) ||
233
+ !Number.isFinite(nz) ||
234
+ !Number.isFinite(ux) ||
235
+ !Number.isFinite(uy) ||
236
+ !Number.isFinite(uz)
237
+ )
238
+ return false;
239
+ result.eastX = ex;
240
+ result.eastY = ey;
241
+ result.northZ = nz;
242
+ result.upX = ux;
243
+ result.upY = uy;
244
+ result.upZ = uz;
245
+ return true;
246
+ }
247
+ function commitPoint(result: LocalFramePoint, x: number, y: number, z: number): boolean {
248
+ if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z)) return false;
249
+ result.x = x;
250
+ result.y = y;
251
+ result.z = z;
252
+ return true;
253
+ }
package/src/mat3.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/mat3';
package/src/mat4.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/mat4';
package/src/quat.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/quat';
@@ -0,0 +1,253 @@
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 nearest-footpoint inverse and numeric output commit are original math.gl code.
6
+
7
+ /** Numeric leaf: angles in radians, distances in axis units; no CRS, global config or scratch. */
8
+ import type {SpheroidParameters} from '@math.gl/types';
9
+ export type SpheroidGeometry = SpheroidParameters & {readonly eccentricitySquared: number};
10
+ export type SpheroidPoint = {x: number; y: number; z: number};
11
+
12
+ /** Caller supplies validated positive finite axes and eccentricity. No latitude wrapping. */
13
+ export function spheroidToCartesian(
14
+ point: SpheroidPoint,
15
+ geometry: SpheroidGeometry,
16
+ result: SpheroidPoint = point
17
+ ): boolean {
18
+ const longitude = point.x,
19
+ latitude = point.y,
20
+ height = point.z;
21
+ const {semiMajorAxis: a, semiMinorAxis: b, eccentricitySquared: es} = geometry;
22
+ const sin = Math.sin(latitude),
23
+ cos = Math.cos(latitude);
24
+ // Use the axis ratio for very flat shapes: 1 - es*sin² loses polar precision.
25
+ const ratio = b / a;
26
+ const radius = es < 0.9 ? a / Math.sqrt(1 - es * sin * sin) : a / Math.hypot(cos, ratio * sin);
27
+ const x = (radius + height) * cos * Math.cos(longitude);
28
+ const y = (radius + height) * cos * Math.sin(longitude);
29
+ const z = (radius * (es < 0.9 ? 1 - es : ratio * ratio) + height) * sin;
30
+ return commit(result, x, y, z);
31
+ }
32
+
33
+ /**
34
+ * Bounded inverse. Sphere is analytic; ordinary spheroids use the retained Hannover
35
+ * iteration on exterior points. Interiors use a safeguarded nearest-footpoint solve.
36
+ * Equatorial interiors below the evolute cusp have two nearest normals: reject.
37
+ * false leaves output untouched, including the center and unresolved binary64 cases.
38
+ * Only exact poles canonicalize longitude; adapters may retain other conventions.
39
+ */
40
+ export function cartesianToSpheroid(
41
+ point: SpheroidPoint,
42
+ geometry: SpheroidGeometry,
43
+ result: SpheroidPoint = point
44
+ ): boolean {
45
+ const x = point.x,
46
+ y = point.y,
47
+ z = point.z;
48
+ const {semiMajorAxis: a, semiMinorAxis: b, eccentricitySquared: es} = geometry;
49
+ const p = Math.hypot(x, y),
50
+ rr = Math.hypot(x, y, z);
51
+ if (!(rr > 0) || !Number.isFinite(rr)) return false;
52
+ if (es === 0) return commit(result, p === 0 ? 0 : Math.atan2(y, x), Math.atan2(z, p), rr - a);
53
+ if (p === 0) return commit(result, 0, (Math.sign(z) * Math.PI) / 2, Math.abs(z) - b);
54
+ const horizontal = p / a,
55
+ vertical = z / b;
56
+ if (horizontal * horizontal + vertical * vertical < 1 - 16 * Number.EPSILON)
57
+ return interiorInverse(x, y, z, p, a, b, result);
58
+ if (es >= 0.9) return exteriorInverse(x, y, z, p, a, b, result);
59
+ const ct = z / rr,
60
+ st = p / rr;
61
+ let rx = 1 / Math.sqrt(1 - es * (2 - es) * st * st);
62
+ let cos = st * (1 - es) * rx,
63
+ sin = ct * rx;
64
+ for (let i = 0; i < 30; i++) {
65
+ const rn = a / Math.sqrt(1 - es * sin * sin);
66
+ const height = p * cos + z * sin - rn * (1 - es * sin * sin);
67
+ const rk = (es * rn) / (rn + height);
68
+ rx = 1 / Math.sqrt(1 - rk * (2 - rk) * st * st);
69
+ const nextCos = st * (1 - rk) * rx,
70
+ nextSin = ct * rx;
71
+ if (Math.abs(nextSin * cos - nextCos * sin) <= 1e-12) {
72
+ if (!Number.isFinite(height) || !Number.isFinite(nextSin) || !Number.isFinite(nextCos)) break;
73
+ return commit(result, Math.atan2(y, x), Math.atan2(nextSin, Math.abs(nextCos)), height);
74
+ }
75
+ cos = nextCos;
76
+ sin = nextSin;
77
+ }
78
+ return exteriorInverse(x, y, z, p, a, b, result);
79
+ }
80
+
81
+ /** Original nearest-normal solve in t = (lambda + b²)/a², avoiding interior cancellation.
82
+ * The positive interval selects the globally nearest branch, rather than a stationary normal.
83
+ */
84
+ function interiorInverse(
85
+ x: number,
86
+ y: number,
87
+ z: number,
88
+ p: number,
89
+ a: number,
90
+ b: number,
91
+ result: SpheroidPoint
92
+ ): boolean {
93
+ const ratio = b / a,
94
+ ratio2 = ratio * ratio;
95
+ const horizontal = p / a,
96
+ vertical = z / a,
97
+ delta = 1 - ratio2;
98
+ if (!(ratio2 > 0) || ratio > 1) return false;
99
+ if (z === 0) {
100
+ if (horizontal < delta) return false;
101
+ return commit(result, Math.atan2(y, x), 0, p - a);
102
+ }
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
+ base = p - a + shift;
130
+ const correction =
131
+ radiusError + sumError(p - a, shift, base) + productError(a, ratio2, shift) + a * ratioError;
132
+ const weighted = Math.abs(vertical) * ratio;
133
+ if (!(weighted > 0)) return false;
134
+ let lower = 0,
135
+ upper = ratio2;
136
+ // A lower bound near the short-axis singularity prevents thousands of bisections
137
+ // for deep, nearly equatorial interiors. No subtraction of lambda and -b².
138
+ let t = Math.max(weighted, horizontal - delta);
139
+ if (!(t > lower && t < upper)) t = upper / 2;
140
+ for (let i = 0; i < 128; i++) {
141
+ const equatorial = delta + t;
142
+ const u = horizontal / equatorial,
143
+ v = weighted / t;
144
+ const at = a * t,
145
+ difference = base - at;
146
+ const offset =
147
+ (difference + (sumError(base, -at, difference) + correction - productError(a, t, at))) /
148
+ (a * equatorial);
149
+ const term = offset * (u + 1);
150
+ const residual = term + v * v;
151
+ if (
152
+ Math.abs(residual) <= 4 * Number.EPSILON * (Math.abs(term) + v * v) ||
153
+ upper - lower <= 4 * Number.EPSILON * t
154
+ ) {
155
+ const latitude = Math.atan2(vertical / t, horizontal / equatorial);
156
+ const sin = Math.sin(latitude),
157
+ cos = Math.cos(latitude);
158
+ return commit(
159
+ result,
160
+ Math.atan2(y, x),
161
+ latitude,
162
+ p * cos + z * sin - a * Math.hypot(cos, ratio * sin)
163
+ );
164
+ }
165
+ if (residual > 0) lower = t;
166
+ else upper = t;
167
+ const derivative = -2 * ((u * u) / equatorial + (v * v) / t);
168
+ const next = t - residual / derivative;
169
+ const candidate =
170
+ Number.isFinite(next) && next > lower && next < upper ? next : lower + (upper - lower) / 2;
171
+ if (candidate === t) {
172
+ const latitude = Math.atan2(vertical / t, horizontal / equatorial);
173
+ return commit(
174
+ result,
175
+ Math.atan2(y, x),
176
+ latitude,
177
+ p * Math.cos(latitude) +
178
+ z * Math.sin(latitude) -
179
+ a * Math.hypot(Math.cos(latitude), ratio * Math.sin(latitude))
180
+ );
181
+ }
182
+ t = candidate;
183
+ }
184
+ return false;
185
+ }
186
+
187
+ /** Error-free transforms on the finite squared-axis domain used by geometry adapters. */
188
+ function sumError(x: number, y: number, sum: number): number {
189
+ const part = sum - x;
190
+ return x - (sum - part) + (y - part);
191
+ }
192
+ function productError(x: number, y: number, product: number): number {
193
+ const sx = 134217729 * x,
194
+ sy = 134217729 * y;
195
+ if (!Number.isFinite(sx) || !Number.isFinite(sy)) return 0;
196
+ const hx = sx - (sx - x),
197
+ hy = sy - (sy - y),
198
+ lx = x - hx,
199
+ ly = y - hy;
200
+ return hx * hy - product + hx * ly + lx * hy + lx * ly;
201
+ }
202
+
203
+ /** Original dimensionless Lagrange-multiplier solve, restricted to surface/exterior. */
204
+ function exteriorInverse(
205
+ x: number,
206
+ y: number,
207
+ z: number,
208
+ p: number,
209
+ a: number,
210
+ b: number,
211
+ result: SpheroidPoint
212
+ ): boolean {
213
+ const ratio = b / a,
214
+ ratio2 = ratio * ratio,
215
+ horizontal = p / a,
216
+ vertical = z / a;
217
+ const norm = Math.hypot(horizontal, z / b);
218
+ if (!Number.isFinite(norm) || norm < 1 - 8 * Number.EPSILON || !(ratio2 > 0)) return false;
219
+ let lower = 0,
220
+ upper = Math.hypot(horizontal, vertical * ratio);
221
+ if (!Number.isFinite(upper)) return false;
222
+ let multiplier = norm <= 1 + 8 * Number.EPSILON ? 0 : upper / 2;
223
+ for (let i = 0; i < 96; i++) {
224
+ const equatorial = 1 + multiplier,
225
+ polar = ratio2 + multiplier;
226
+ const u = horizontal / equatorial,
227
+ v = (vertical * ratio) / polar;
228
+ const length = Math.hypot(u, v);
229
+ const residual = length - 1;
230
+ if (Math.abs(residual) <= 4 * Number.EPSILON) {
231
+ const latitude = Math.atan2(vertical / polar, horizontal / equatorial);
232
+ const sin = Math.sin(latitude),
233
+ cos = Math.cos(latitude);
234
+ const height = p * cos + z * sin - a * Math.hypot(cos, ratio * sin);
235
+ return commit(result, Math.atan2(y, x), latitude, height);
236
+ }
237
+ if (residual > 0) lower = multiplier;
238
+ else upper = multiplier;
239
+ const derivative = -((u * u) / equatorial + (v * v) / polar) / length;
240
+ const next = multiplier - residual / derivative;
241
+ multiplier = Number.isFinite(next) && next > lower && next < upper ? next : (lower + upper) / 2;
242
+ }
243
+ return false;
244
+ }
245
+
246
+ /** Values are captured before invoking application setters; recursive writes are safe. */
247
+ function commit(result: SpheroidPoint, x: number, y: number, z: number): boolean {
248
+ if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(z)) return false;
249
+ result.x = x;
250
+ result.y = y;
251
+ result.z = z;
252
+ return true;
253
+ }