@math.gl/core 3.5.3 → 3.6.0-alpha.1

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 (192) hide show
  1. package/dist/classes/base/math-array.d.ts +36 -0
  2. package/dist/classes/base/math-array.d.ts.map +1 -0
  3. package/dist/classes/base/math-array.js +214 -0
  4. package/dist/classes/base/matrix.d.ts +12 -0
  5. package/dist/classes/base/matrix.d.ts.map +1 -0
  6. package/dist/classes/base/matrix.js +69 -0
  7. package/dist/classes/base/vector.d.ts +32 -0
  8. package/dist/classes/base/vector.d.ts.map +1 -0
  9. package/dist/classes/base/vector.js +133 -0
  10. package/dist/classes/euler.d.ts +73 -0
  11. package/dist/classes/euler.d.ts.map +1 -0
  12. package/dist/classes/euler.js +505 -0
  13. package/dist/classes/matrix3.d.ts +43 -0
  14. package/dist/classes/matrix3.d.ts.map +1 -0
  15. package/dist/classes/matrix3.js +192 -0
  16. package/dist/classes/matrix4.d.ts +102 -0
  17. package/dist/classes/matrix4.d.ts.map +1 -0
  18. package/dist/classes/matrix4.js +457 -0
  19. package/dist/classes/pose.d.ts +37 -0
  20. package/dist/classes/pose.d.ts.map +1 -0
  21. package/dist/classes/pose.js +126 -0
  22. package/dist/classes/quaternion.d.ts +42 -0
  23. package/dist/classes/quaternion.d.ts.map +1 -0
  24. package/dist/classes/quaternion.js +266 -0
  25. package/dist/classes/spherical-coordinates.d.ts +40 -0
  26. package/dist/classes/spherical-coordinates.d.ts.map +1 -0
  27. package/dist/classes/spherical-coordinates.js +142 -0
  28. package/dist/classes/vector2.d.ts +19 -0
  29. package/dist/classes/vector2.d.ts.map +1 -0
  30. package/dist/classes/vector2.js +105 -0
  31. package/dist/classes/vector3.d.ts +41 -0
  32. package/dist/classes/vector3.d.ts.map +1 -0
  33. package/dist/classes/vector3.js +147 -0
  34. package/dist/classes/vector4.d.ts +23 -0
  35. package/dist/classes/vector4.d.ts.map +1 -0
  36. package/dist/classes/vector4.js +126 -0
  37. package/dist/es5/classes/base/math-array.d.js +46 -0
  38. package/dist/es5/classes/base/math-array.d.js.map +1 -0
  39. package/dist/es5/classes/base/math-array.js +178 -251
  40. package/dist/es5/classes/base/math-array.js.map +1 -1
  41. package/dist/es5/classes/base/matrix.d.js +15 -0
  42. package/dist/es5/classes/base/matrix.d.js.map +1 -0
  43. package/dist/es5/classes/base/matrix.js +54 -88
  44. package/dist/es5/classes/base/matrix.js.map +1 -1
  45. package/dist/es5/classes/base/vector.d.js +24 -0
  46. package/dist/es5/classes/base/vector.d.js.map +1 -0
  47. package/dist/es5/classes/base/vector.js +121 -179
  48. package/dist/es5/classes/base/vector.js.map +1 -1
  49. package/dist/es5/classes/euler.d.js +45 -0
  50. package/dist/es5/classes/euler.d.js.map +1 -0
  51. package/dist/es5/classes/euler.js +468 -549
  52. package/dist/es5/classes/euler.js.map +1 -1
  53. package/dist/es5/classes/matrix3.d.js +25 -0
  54. package/dist/es5/classes/matrix3.d.js.map +1 -0
  55. package/dist/es5/classes/matrix3.js +157 -206
  56. package/dist/es5/classes/matrix3.js.map +1 -1
  57. package/dist/es5/classes/matrix4.d.js +25 -0
  58. package/dist/es5/classes/matrix4.d.js.map +1 -0
  59. package/dist/es5/classes/matrix4.js +410 -500
  60. package/dist/es5/classes/matrix4.js.map +1 -1
  61. package/dist/es5/classes/pose.d.js +25 -0
  62. package/dist/es5/classes/pose.d.js.map +1 -0
  63. package/dist/es5/classes/pose.js +101 -125
  64. package/dist/es5/classes/pose.js.map +1 -1
  65. package/dist/es5/classes/quaternion.d.js +27 -0
  66. package/dist/es5/classes/quaternion.d.js.map +1 -0
  67. package/dist/es5/classes/quaternion.js +213 -277
  68. package/dist/es5/classes/quaternion.js.map +1 -1
  69. package/dist/es5/classes/spherical-coordinates.d.js +27 -0
  70. package/dist/es5/classes/spherical-coordinates.d.js.map +1 -0
  71. package/dist/es5/classes/spherical-coordinates.js +125 -166
  72. package/dist/es5/classes/spherical-coordinates.js.map +1 -1
  73. package/dist/es5/classes/vector2.d.js +18 -0
  74. package/dist/es5/classes/vector2.d.js.map +1 -0
  75. package/dist/es5/classes/vector2.js +76 -118
  76. package/dist/es5/classes/vector2.js.map +1 -1
  77. package/dist/es5/classes/vector3.d.js +24 -0
  78. package/dist/es5/classes/vector3.d.js.map +1 -0
  79. package/dist/es5/classes/vector3.js +120 -167
  80. package/dist/es5/classes/vector3.js.map +1 -1
  81. package/dist/es5/classes/vector4.d.js +25 -0
  82. package/dist/es5/classes/vector4.d.js.map +1 -0
  83. package/dist/es5/classes/vector4.js +95 -137
  84. package/dist/es5/classes/vector4.js.map +1 -1
  85. package/dist/es5/docs/README.md +0 -0
  86. package/dist/es5/index.js +105 -123
  87. package/dist/es5/index.js.map +1 -1
  88. package/dist/es5/lib/assert.js.map +1 -1
  89. package/dist/es5/lib/common.js +55 -84
  90. package/dist/es5/lib/common.js.map +1 -1
  91. package/dist/es5/lib/gl-matrix-extras.js +14 -14
  92. package/dist/es5/lib/gl-matrix-extras.js.map +1 -1
  93. package/dist/es5/lib/math-utils.js.map +1 -1
  94. package/dist/es5/lib/validators.js +3 -5
  95. package/dist/es5/lib/validators.js.map +1 -1
  96. package/dist/esm/classes/base/math-array.d.js +36 -0
  97. package/dist/esm/classes/base/math-array.d.js.map +1 -0
  98. package/dist/esm/classes/base/matrix.d.js +3 -0
  99. package/dist/esm/classes/base/matrix.d.js.map +1 -0
  100. package/dist/esm/classes/base/vector.d.js +13 -0
  101. package/dist/esm/classes/base/vector.d.js.map +1 -0
  102. package/dist/esm/classes/euler.d.js +55 -0
  103. package/dist/esm/classes/euler.d.js.map +1 -0
  104. package/dist/esm/classes/euler.js +1 -1
  105. package/dist/esm/classes/euler.js.map +1 -1
  106. package/dist/esm/classes/matrix3.d.js +15 -0
  107. package/dist/esm/classes/matrix3.d.js.map +1 -0
  108. package/dist/esm/classes/matrix4.d.js +15 -0
  109. package/dist/esm/classes/matrix4.d.js.map +1 -0
  110. package/dist/esm/classes/pose.d.js +18 -0
  111. package/dist/esm/classes/pose.d.js.map +1 -0
  112. package/dist/esm/classes/quaternion.d.js +19 -0
  113. package/dist/esm/classes/quaternion.d.js.map +1 -0
  114. package/dist/esm/classes/spherical-coordinates.d.js +22 -0
  115. package/dist/esm/classes/spherical-coordinates.d.js.map +1 -0
  116. package/dist/esm/classes/vector2.d.js +6 -0
  117. package/dist/esm/classes/vector2.d.js.map +1 -0
  118. package/dist/esm/classes/vector3.d.js +13 -0
  119. package/dist/esm/classes/vector3.d.js.map +1 -0
  120. package/dist/esm/classes/vector4.d.js +15 -0
  121. package/dist/esm/classes/vector4.d.js.map +1 -0
  122. package/dist/esm/docs/README.md +0 -0
  123. package/dist/esm/index.js +2 -13
  124. package/dist/esm/index.js.map +1 -1
  125. package/dist/esm/lib/assert.js.map +1 -1
  126. package/dist/esm/lib/common.js +34 -37
  127. package/dist/esm/lib/common.js.map +1 -1
  128. package/dist/esm/lib/gl-matrix-extras.js.map +1 -1
  129. package/dist/esm/lib/math-utils.js.map +1 -1
  130. package/dist/esm/lib/validators.js.map +1 -1
  131. package/dist/index.d.ts +17 -0
  132. package/dist/index.d.ts.map +1 -0
  133. package/dist/index.js +24 -0
  134. package/dist/lib/assert.d.ts +2 -0
  135. package/dist/lib/assert.d.ts.map +1 -0
  136. package/dist/lib/assert.js +5 -0
  137. package/dist/lib/common.d.ts +90 -0
  138. package/dist/lib/common.d.ts.map +1 -0
  139. package/dist/lib/common.js +223 -0
  140. package/dist/lib/gl-matrix-extras.d.ts +6 -0
  141. package/dist/lib/gl-matrix-extras.d.ts.map +1 -0
  142. package/dist/lib/gl-matrix-extras.js +50 -0
  143. package/dist/lib/math-utils.d.ts +28 -0
  144. package/dist/lib/math-utils.d.ts.map +1 -0
  145. package/dist/lib/math-utils.js +28 -0
  146. package/dist/lib/validators.d.ts +5 -0
  147. package/dist/lib/validators.d.ts.map +1 -0
  148. package/dist/lib/validators.js +52 -0
  149. package/package.json +5 -4
  150. package/src/classes/base/math-array.d.ts +0 -1
  151. package/src/classes/euler.js +1 -1
  152. package/src/docs/README.md +0 -0
  153. package/{dist/esm/index.d.ts → src/index.ts} +32 -34
  154. package/src/lib/{assert.js → assert.ts} +1 -1
  155. package/src/lib/common.ts +283 -0
  156. package/src/lib/{gl-matrix-extras.js → gl-matrix-extras.ts} +0 -0
  157. package/src/lib/{math-utils.js → math-utils.ts} +0 -0
  158. package/src/lib/{validators.js → validators.ts} +0 -0
  159. package/dist/es5/addons/polygon.d.ts +0 -17
  160. package/dist/es5/classes/base/math-array.d.ts +0 -56
  161. package/dist/es5/classes/base/matrix.d.ts +0 -15
  162. package/dist/es5/classes/base/vector.d.ts +0 -45
  163. package/dist/es5/classes/euler.d.ts +0 -92
  164. package/dist/es5/classes/matrix3.d.ts +0 -91
  165. package/dist/es5/classes/matrix4.d.ts +0 -161
  166. package/dist/es5/classes/pose.d.ts +0 -92
  167. package/dist/es5/classes/quaternion.d.ts +0 -107
  168. package/dist/es5/classes/spherical-coordinates.d.ts +0 -87
  169. package/dist/es5/classes/vector2.d.ts +0 -65
  170. package/dist/es5/classes/vector3.d.ts +0 -65
  171. package/dist/es5/classes/vector4.d.ts +0 -34
  172. package/dist/es5/index.d.ts +0 -54
  173. package/dist/es5/lib/common.d.ts +0 -80
  174. package/dist/esm/addons/polygon.d.ts +0 -17
  175. package/dist/esm/classes/base/math-array.d.ts +0 -56
  176. package/dist/esm/classes/base/matrix.d.ts +0 -15
  177. package/dist/esm/classes/base/vector.d.ts +0 -45
  178. package/dist/esm/classes/euler.d.ts +0 -92
  179. package/dist/esm/classes/matrix3.d.ts +0 -91
  180. package/dist/esm/classes/matrix4.d.ts +0 -161
  181. package/dist/esm/classes/pose.d.ts +0 -92
  182. package/dist/esm/classes/quaternion.d.ts +0 -107
  183. package/dist/esm/classes/spherical-coordinates.d.ts +0 -87
  184. package/dist/esm/classes/vector2.d.ts +0 -65
  185. package/dist/esm/classes/vector3.d.ts +0 -65
  186. package/dist/esm/classes/vector4.d.ts +0 -34
  187. package/dist/esm/lib/common.d.ts +0 -80
  188. package/src/addons/polygon.d.ts +0 -17
  189. package/src/index.d.ts +0 -54
  190. package/src/index.js +0 -86
  191. package/src/lib/common.d.ts +0 -80
  192. package/src/lib/common.js +0 -222
@@ -0,0 +1,266 @@
1
+ // Copyright (c) 2017 Uber Technologies, Inc.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in
11
+ // all copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ // THE SOFTWARE.
20
+ import MathArray from './base/math-array';
21
+ import { checkNumber, checkVector } from '../lib/validators';
22
+ import assert from '../lib/assert';
23
+ // @ts-ignore: error TS2307: Cannot find module 'gl-matrix/...'.
24
+ import * as quat from 'gl-matrix/quat';
25
+ // @ts-ignore: error TS2307: Cannot find module 'gl-matrix/...'.
26
+ import * as vec4 from 'gl-matrix/vec4';
27
+ const IDENTITY_QUATERNION = [0, 0, 0, 1];
28
+ export default class Quaternion extends MathArray {
29
+ constructor(x = 0, y = 0, z = 0, w = 1) {
30
+ // PERF NOTE: initialize elements as double precision numbers
31
+ super(-0, -0, -0, -0);
32
+ // eslint-disable-next-line prefer-rest-params
33
+ if (Array.isArray(x) && arguments.length === 1) {
34
+ this.copy(x);
35
+ }
36
+ else {
37
+ this.set(x, y, z, w);
38
+ }
39
+ }
40
+ copy(array) {
41
+ this[0] = array[0];
42
+ this[1] = array[1];
43
+ this[2] = array[2];
44
+ this[3] = array[3];
45
+ return this.check();
46
+ }
47
+ set(x, y, z, w) {
48
+ this[0] = x;
49
+ this[1] = y;
50
+ this[2] = z;
51
+ this[3] = w;
52
+ return this.check();
53
+ }
54
+ // Creates a quaternion from the given 3x3 rotation matrix.
55
+ // NOTE: The resultant quaternion is not normalized, so you should
56
+ // be sure to renormalize the quaternion yourself where necessary.
57
+ fromMatrix3(m) {
58
+ quat.fromMat3(this, m);
59
+ return this.check();
60
+ }
61
+ // Set a quat to the identity quaternion
62
+ identity() {
63
+ quat.identity(this);
64
+ return this.check();
65
+ }
66
+ fromAxisRotation(axis, rad) {
67
+ quat.setAxisAngle(this, axis, rad);
68
+ return this.check();
69
+ }
70
+ // Set the components of a quat to the given values
71
+ // set(i, j, k, l) {
72
+ // quat.set(this, i, j, k, l);
73
+ // return this.check();
74
+ // }
75
+ // Sets a quat from the given angle and rotation axis, then returns it.
76
+ setAxisAngle(axis, rad) {
77
+ return this.fromAxisRotation(axis, rad);
78
+ }
79
+ // Getters/setters
80
+ /* eslint-disable no-multi-spaces, brace-style, no-return-assign */
81
+ get ELEMENTS() {
82
+ return 4;
83
+ }
84
+ get x() {
85
+ return this[0];
86
+ }
87
+ set x(value) {
88
+ this[0] = checkNumber(value);
89
+ }
90
+ get y() {
91
+ return this[1];
92
+ }
93
+ set y(value) {
94
+ this[1] = checkNumber(value);
95
+ }
96
+ get z() {
97
+ return this[2];
98
+ }
99
+ set z(value) {
100
+ this[2] = checkNumber(value);
101
+ }
102
+ get w() {
103
+ return this[3];
104
+ }
105
+ set w(value) {
106
+ this[3] = checkNumber(value);
107
+ }
108
+ /* eslint-enable no-multi-spaces, brace-style, no-return-assign */
109
+ // Calculates the length of a quat
110
+ len() {
111
+ return quat.length(this);
112
+ }
113
+ // Calculates the squared length of a quat
114
+ lengthSquared() {
115
+ return quat.squaredLength(this);
116
+ }
117
+ // Calculates the dot product of two quat's
118
+ // @return {Number}
119
+ dot(a, b) {
120
+ if (b !== undefined) {
121
+ throw new Error('Quaternion.dot only takes one argument');
122
+ }
123
+ return quat.dot(this, a);
124
+ }
125
+ // Gets the rotation axis and angle for a given quaternion.
126
+ // If a quaternion is created with setAxisAngle, this method will
127
+ // return the same values as providied in the original parameter
128
+ // list OR functionally equivalent values.
129
+ // Example: The quaternion formed by axis [0, 0, 1] and angle -90
130
+ // is the same as the quaternion formed by [0, 0, 1] and 270.
131
+ // This method favors the latter.
132
+ // @return {{[x,y,z], Number}}
133
+ // getAxisAngle() {
134
+ // const axis = [];
135
+ // const angle = quat.getAxisAngle(axis, this);
136
+ // return {axis, angle};
137
+ // }
138
+ // MODIFIERS
139
+ // Sets a quaternion to represent the shortest rotation from one vector
140
+ // to another. Both vectors are assumed to be unit length.
141
+ rotationTo(vectorA, vectorB) {
142
+ quat.rotationTo(this, vectorA, vectorB);
143
+ return this.check();
144
+ }
145
+ // Sets the specified quaternion with values corresponding to the given axes.
146
+ // Each axis is a vec3 and is expected to be unit length and perpendicular
147
+ // to all other specified axes.
148
+ // setAxes() {
149
+ // Number
150
+ // }
151
+ // Performs a spherical linear interpolation with two control points
152
+ // sqlerp() {
153
+ // Number;
154
+ // }
155
+ // Adds two quat's
156
+ add(a, b) {
157
+ if (b !== undefined) {
158
+ throw new Error('Quaternion.add only takes one argument');
159
+ }
160
+ quat.add(this, this, a);
161
+ return this.check();
162
+ }
163
+ // Calculates the W component of a quat from the X, Y, and Z components.
164
+ // Any existing W component will be ignored.
165
+ calculateW() {
166
+ quat.calculateW(this, this);
167
+ return this.check();
168
+ }
169
+ // Calculates the conjugate of a quat If the quaternion is normalized,
170
+ // this function is faster than quat.inverse and produces the same result.
171
+ conjugate() {
172
+ quat.conjugate(this, this);
173
+ return this.check();
174
+ }
175
+ // Calculates the inverse of a quat
176
+ invert() {
177
+ quat.invert(this, this);
178
+ return this.check();
179
+ }
180
+ // Performs a linear interpolation between two quat's
181
+ lerp(a, b, t) {
182
+ quat.lerp(this, a, b, t);
183
+ return this.check();
184
+ }
185
+ // Multiplies two quat's
186
+ multiplyRight(a, b) {
187
+ assert(!b); // Quaternion.multiply only takes one argument
188
+ quat.multiply(this, this, a);
189
+ return this.check();
190
+ }
191
+ multiplyLeft(a, b) {
192
+ assert(!b); // Quaternion.multiply only takes one argument
193
+ quat.multiply(this, a, this);
194
+ return this.check();
195
+ }
196
+ // Normalize a quat
197
+ normalize() {
198
+ // Handle 0 case
199
+ const length = this.len();
200
+ const l = length > 0 ? 1 / length : 0;
201
+ this[0] = this[0] * l;
202
+ this[1] = this[1] * l;
203
+ this[2] = this[2] * l;
204
+ this[3] = this[3] * l;
205
+ // Set to [0, 0, 0, 1] if length is 0
206
+ if (length === 0) {
207
+ this[3] = 1;
208
+ }
209
+ return this.check();
210
+ }
211
+ // Rotates a quaternion by the given angle about the X axis
212
+ rotateX(rad) {
213
+ quat.rotateX(this, this, rad);
214
+ return this.check();
215
+ }
216
+ // Rotates a quaternion by the given angle about the Y axis
217
+ rotateY(rad) {
218
+ quat.rotateY(this, this, rad);
219
+ return this.check();
220
+ }
221
+ // Rotates a quaternion by the given angle about the Z axis
222
+ rotateZ(rad) {
223
+ quat.rotateZ(this, this, rad);
224
+ return this.check();
225
+ }
226
+ // Scales a quat by a scalar number
227
+ scale(b) {
228
+ quat.scale(this, this, b);
229
+ return this.check();
230
+ }
231
+ // Performs a spherical linear interpolation between two quat
232
+ slerp(start, target, ratio) {
233
+ // eslint-disable-next-line prefer-rest-params
234
+ switch (arguments.length) {
235
+ case 1: // Deprecated signature ({start, target, ratio})
236
+ // eslint-disable-next-line prefer-rest-params
237
+ ({ start = IDENTITY_QUATERNION, target, ratio } = arguments[0]);
238
+ break;
239
+ case 2: // THREE.js compatibility signature (target, ration)
240
+ // eslint-disable-next-line prefer-rest-params
241
+ [target, ratio] = arguments;
242
+ start = this; // eslint-disable-line
243
+ break;
244
+ default: // Default signature: (start, target, ratio)
245
+ }
246
+ quat.slerp(this, start, target, ratio);
247
+ return this.check();
248
+ }
249
+ transformVector4(vector, result = vector) {
250
+ vec4.transformQuat(result, vector, this);
251
+ return checkVector(result, 4);
252
+ }
253
+ // THREE.js Math API compatibility
254
+ lengthSq() {
255
+ return this.lengthSquared();
256
+ }
257
+ setFromAxisAngle(axis, rad) {
258
+ return this.setAxisAngle(axis, rad);
259
+ }
260
+ premultiply(a, b) {
261
+ return this.multiplyLeft(a, b);
262
+ }
263
+ multiply(a, b) {
264
+ return this.multiplyRight(a, b);
265
+ }
266
+ }
@@ -0,0 +1,40 @@
1
+ export default class SphericalCoordinates {
2
+ constructor({ phi, theta, radius, bearing, pitch, altitude, radiusScale }?: {
3
+ phi?: number;
4
+ theta?: number;
5
+ radius?: number;
6
+ bearing?: any;
7
+ pitch?: any;
8
+ altitude?: any;
9
+ radiusScale?: number;
10
+ });
11
+ phi: number;
12
+ theta: number;
13
+ radius: any;
14
+ radiusScale: number;
15
+ set bearing(arg: number);
16
+ get bearing(): number;
17
+ set pitch(arg: number);
18
+ get pitch(): number;
19
+ toString(): string;
20
+ formatString({ printTypes }: {
21
+ printTypes?: boolean;
22
+ }): string;
23
+ equals(other: any): boolean;
24
+ exactEquals(other: any): boolean;
25
+ get longitude(): number;
26
+ get latitude(): number;
27
+ get lng(): number;
28
+ get lat(): number;
29
+ get z(): number;
30
+ set(radius: any, phi: any, theta: any): SphericalCoordinates;
31
+ clone(): SphericalCoordinates;
32
+ copy(other: any): SphericalCoordinates;
33
+ fromLngLatZ([lng, lat, z]: [any, any, any]): void;
34
+ fromVector3(v: any): SphericalCoordinates;
35
+ toVector3(): Vector3;
36
+ makeSafe(): SphericalCoordinates;
37
+ check(): SphericalCoordinates;
38
+ }
39
+ import Vector3 from "./vector3";
40
+ //# sourceMappingURL=spherical-coordinates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spherical-coordinates.d.ts","sourceRoot":"","sources":["../../src/classes/spherical-coordinates.js"],"names":[],"mappings":"AAkCA;IAGE;;;;;;;;OAsBC;IAbC,YAAc;IACd,cAAkB;IAElB,YAAqC;IACrC,oBAAmC;IAsCrC,yBAEC;IALD,sBAEC;IAOD,uBAEC;IALD,oBAEC;IAhCD,mBAEC;IAED;;eAIC;IAED,4BAMC;IAED,iCAEC;IAqBD,wBAEC;IACD,uBAEC;IACD,kBAEC;IACD,kBAEC;IACD,gBAEC;IAGD,6DAKC;IAED,8BAEC;IAED,uCAKC;IAED,kDAIC;IAED,0CAOC;IAED,qBAIC;IAGD,iCAGC;IAED,8BAMC;CACF"}
@@ -0,0 +1,142 @@
1
+ // Copyright (c) 2017 Uber Technologies, Inc.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in
11
+ // all copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ // THE SOFTWARE.
20
+ // Adaptation of THREE.js Spherical class, under MIT license
21
+ import { formatValue, equals, config } from '../lib/common';
22
+ import { degrees, radians, clamp } from '../lib/common';
23
+ import Vector3 from './vector3';
24
+ // @ts-ignore: error TS2307: Cannot find module 'gl-matrix/...'.
25
+ import * as vec3 from 'gl-matrix/vec3';
26
+ // TODO - import epsilon
27
+ const EPSILON = 0.000001;
28
+ const EARTH_RADIUS_METERS = 6.371e6;
29
+ // Todo [rho, theta, phi] ?
30
+ export default class SphericalCoordinates {
31
+ // @ts-ignore TS2740: Type '{}' is missing the following properties from type
32
+ // eslint-disable-next-line complexity
33
+ constructor({ phi = 0, theta = 0, radius = 1, bearing = undefined, pitch = undefined, altitude = undefined, radiusScale = EARTH_RADIUS_METERS } = {}) {
34
+ this.phi = phi;
35
+ this.theta = theta;
36
+ // TODO - silently accepts illegal 0
37
+ this.radius = radius || altitude || 1; // radial distance from center
38
+ this.radiusScale = radiusScale || 1; // Used by lngLatZ
39
+ if (bearing !== undefined) {
40
+ this.bearing = bearing; // up / down towards top and bottom pole
41
+ }
42
+ if (pitch !== undefined) {
43
+ this.pitch = pitch; // around the equator of the sphere
44
+ }
45
+ this.check();
46
+ }
47
+ toString() {
48
+ return this.formatString(config);
49
+ }
50
+ formatString({ printTypes = false }) {
51
+ const f = formatValue;
52
+ return `${printTypes ? 'Spherical' : ''}\
53
+ [rho:${f(this.radius)},theta:${f(this.theta)},phi:${f(this.phi)}]`;
54
+ }
55
+ equals(other) {
56
+ return (equals(this.radius, other.radius) &&
57
+ equals(this.theta, other.theta) &&
58
+ equals(this.phi, other.phi));
59
+ }
60
+ exactEquals(other) {
61
+ return this.radius === other.radius && this.theta === other.theta && this.phi === other.phi;
62
+ }
63
+ /* eslint-disable brace-style */
64
+ // Cartographic (bearing 0 north, pitch 0 look from above)
65
+ get bearing() {
66
+ return 180 - degrees(this.phi);
67
+ }
68
+ set bearing(v) {
69
+ this.phi = Math.PI - radians(v);
70
+ }
71
+ get pitch() {
72
+ return degrees(this.theta);
73
+ }
74
+ set pitch(v) {
75
+ this.theta = radians(v);
76
+ }
77
+ // get pitch() { return 90 - degrees(this.phi); }
78
+ // set pitch(v) { this.phi = radians(v) + Math.PI / 2; }
79
+ // get altitude() { return this.radius - 1; } // relative altitude
80
+ // lnglatZ coordinates
81
+ get longitude() {
82
+ return degrees(this.phi);
83
+ }
84
+ get latitude() {
85
+ return degrees(this.theta);
86
+ }
87
+ get lng() {
88
+ return degrees(this.phi);
89
+ }
90
+ get lat() {
91
+ return degrees(this.theta);
92
+ }
93
+ get z() {
94
+ return (this.radius - 1) * this.radiusScale;
95
+ }
96
+ /* eslint-enable brace-style */
97
+ set(radius, phi, theta) {
98
+ this.radius = radius;
99
+ this.phi = phi;
100
+ this.theta = theta;
101
+ return this.check();
102
+ }
103
+ clone() {
104
+ return new SphericalCoordinates().copy(this);
105
+ }
106
+ copy(other) {
107
+ this.radius = other.radius;
108
+ this.phi = other.phi;
109
+ this.theta = other.theta;
110
+ return this.check();
111
+ }
112
+ fromLngLatZ([lng, lat, z]) {
113
+ this.radius = 1 + z / this.radiusScale;
114
+ this.phi = radians(lat);
115
+ this.theta = radians(lng);
116
+ }
117
+ fromVector3(v) {
118
+ this.radius = vec3.length(v);
119
+ if (this.radius > 0) {
120
+ this.theta = Math.atan2(v[0], v[1]); // equator angle around y-up axis
121
+ this.phi = Math.acos(clamp(v[2] / this.radius, -1, 1)); // polar angle
122
+ }
123
+ return this.check();
124
+ }
125
+ toVector3() {
126
+ return new Vector3(0, 0, this.radius)
127
+ .rotateX({ radians: this.theta })
128
+ .rotateZ({ radians: this.phi });
129
+ }
130
+ // restrict phi to be betwee EPS and PI-EPS
131
+ makeSafe() {
132
+ this.phi = Math.max(EPSILON, Math.min(Math.PI - EPSILON, this.phi));
133
+ return this;
134
+ }
135
+ check() {
136
+ // this.makeSafe();
137
+ if (!Number.isFinite(this.phi) || !Number.isFinite(this.theta) || !(this.radius > 0)) {
138
+ throw new Error('SphericalCoordinates: some fields set to invalid numbers');
139
+ }
140
+ return this;
141
+ }
142
+ }
@@ -0,0 +1,19 @@
1
+ export default class Vector2 extends Vector<any> {
2
+ constructor(x?: number, y?: number, ...args: any[]);
3
+ 0: number;
4
+ 1: number;
5
+ set(x: any, y: any): any;
6
+ copy(array: any): any;
7
+ fromObject(object: any): any;
8
+ toObject(object: any): any;
9
+ horizontalAngle(): number;
10
+ verticalAngle(): number;
11
+ transform(matrix4: any): any;
12
+ transformAsPoint(matrix4: any): any;
13
+ transformAsVector(matrix4: any): any;
14
+ transformByMatrix3(matrix3: any): any;
15
+ transformByMatrix2x3(matrix2x3: any): any;
16
+ transformByMatrix2(matrix2: any): any;
17
+ }
18
+ import Vector from "./base/vector";
19
+ //# sourceMappingURL=vector2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vector2.d.ts","sourceRoot":"","sources":["../../src/classes/vector2.js"],"names":[],"mappings":"AA6BA;IAEE,oDAaC;IAHG,UAAW;IACX,UAAW;IAIf,yBAIC;IAED,sBAIC;IAED,6BAQC;IAED,2BAIC;IASD,0BAEC;IAED,wBAEC;IAID,6BAEC;IAGD,oCAGC;IAGD,qCAGC;IAED,sCAGC;IAED,0CAGC;IAED,sCAGC;CACF"}
@@ -0,0 +1,105 @@
1
+ // Copyright (c) 2017 Uber Technologies, Inc.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in
11
+ // all copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ // THE SOFTWARE.
20
+ import Vector from './base/vector';
21
+ import { config, isArray } from '../lib/common';
22
+ import { checkNumber } from '../lib/validators';
23
+ // @ts-ignore: error TS2307: Cannot find module 'gl-matrix/...'.
24
+ import * as vec2 from 'gl-matrix/vec2';
25
+ // eslint-disable-next-line camelcase
26
+ import { vec2_transformMat4AsVector } from '../lib/gl-matrix-extras';
27
+ export default class Vector2 extends Vector {
28
+ // Creates a new, empty vec2
29
+ constructor(x = 0, y = 0) {
30
+ // PERF NOTE: initialize elements as double precision numbers
31
+ super(2); // -0, -0);
32
+ if (isArray(x) && arguments.length === 1) {
33
+ this.copy(x);
34
+ }
35
+ else {
36
+ if (config.debug) {
37
+ checkNumber(x);
38
+ checkNumber(y);
39
+ }
40
+ this[0] = x;
41
+ this[1] = y;
42
+ }
43
+ }
44
+ set(x, y) {
45
+ this[0] = x;
46
+ this[1] = y;
47
+ return this.check();
48
+ }
49
+ copy(array) {
50
+ this[0] = array[0];
51
+ this[1] = array[1];
52
+ return this.check();
53
+ }
54
+ fromObject(object) {
55
+ if (config.debug) {
56
+ checkNumber(object.x);
57
+ checkNumber(object.y);
58
+ }
59
+ this[0] = object.x;
60
+ this[1] = object.y;
61
+ return this.check();
62
+ }
63
+ toObject(object) {
64
+ object.x = this[0];
65
+ object.y = this[1];
66
+ return object;
67
+ }
68
+ // Getters/setters
69
+ get ELEMENTS() {
70
+ return 2;
71
+ }
72
+ // x,y inherited from Vector
73
+ horizontalAngle() {
74
+ return Math.atan2(this.y, this.x);
75
+ }
76
+ verticalAngle() {
77
+ return Math.atan2(this.x, this.y);
78
+ }
79
+ // Transforms
80
+ transform(matrix4) {
81
+ return this.transformAsPoint(matrix4);
82
+ }
83
+ // transforms as point (4th component is implicitly 1)
84
+ transformAsPoint(matrix4) {
85
+ vec2.transformMat4(this, this, matrix4);
86
+ return this.check();
87
+ }
88
+ // transforms as vector (4th component is implicitly 0, ignores translation. slightly faster)
89
+ transformAsVector(matrix4) {
90
+ vec2_transformMat4AsVector(this, this, matrix4);
91
+ return this.check();
92
+ }
93
+ transformByMatrix3(matrix3) {
94
+ vec2.transformMat3(this, this, matrix3);
95
+ return this.check();
96
+ }
97
+ transformByMatrix2x3(matrix2x3) {
98
+ vec2.transformMat2d(this, this, matrix2x3);
99
+ return this.check();
100
+ }
101
+ transformByMatrix2(matrix2) {
102
+ vec2.transformMat2(this, this, matrix2);
103
+ return this.check();
104
+ }
105
+ }
@@ -0,0 +1,41 @@
1
+ export default class Vector3 extends Vector<any> {
2
+ static get ZERO(): any;
3
+ /**
4
+ * @class
5
+ * @param {Number | [Number, Number, Number]} x
6
+ * @param {Number} y - rotation around X (latitude)
7
+ * @param {Number} z - rotation around X (latitude)
8
+ */
9
+ constructor(x?: number | [number, number, number], y?: number, z?: number, ...args: any[]);
10
+ 0: number | [number, number, number];
11
+ 1: number;
12
+ 2: number;
13
+ set(x: any, y: any, z: any): any;
14
+ copy(array: any): any;
15
+ fromObject(object: any): any;
16
+ toObject(object: any): any;
17
+ set z(arg: number);
18
+ get z(): number;
19
+ angle(vector: any): any;
20
+ cross(vector: any): any;
21
+ rotateX({ radians, origin }: {
22
+ radians: any;
23
+ origin?: number[];
24
+ }): any;
25
+ rotateY({ radians, origin }: {
26
+ radians: any;
27
+ origin?: number[];
28
+ }): any;
29
+ rotateZ({ radians, origin }: {
30
+ radians: any;
31
+ origin?: number[];
32
+ }): any;
33
+ transform(matrix4: any): any;
34
+ transformAsPoint(matrix4: any): any;
35
+ transformAsVector(matrix4: any): any;
36
+ transformByMatrix3(matrix3: any): any;
37
+ transformByMatrix2(matrix2: any): any;
38
+ transformByQuaternion(quaternion: any): any;
39
+ }
40
+ import Vector from "./base/vector";
41
+ //# sourceMappingURL=vector3.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vector3.d.ts","sourceRoot":"","sources":["../../src/classes/vector3.js"],"names":[],"mappings":"AAgCA;IACE,uBAEC;IAED;;;;;OAKG;IACH,gBAJW,SAAS,wBAAwB,0CAqB3C;IAJG,qCAAW;IACX,UAAW;IACX,UAAW;IAIf,iCAKC;IAED,sBAKC;IAED,6BAUC;IAED,2BAKC;IAaD,mBAEC;IALD,gBAEC;IAMD,wBAEC;IAID,wBAGC;IAED;;;YAGC;IAED;;;YAGC;IAED;;;YAGC;IAKD,6BAEC;IAGD,oCAGC;IAGD,qCAGC;IAED,sCAGC;IAED,sCAGC;IAED,4CAGC;CACF"}