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

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 (188) hide show
  1. package/dist/classes/base/math-array.d.ts +61 -31
  2. package/dist/classes/base/math-array.d.ts.map +1 -1
  3. package/dist/classes/base/math-array.js +67 -65
  4. package/dist/classes/base/matrix.d.ts +12 -10
  5. package/dist/classes/base/matrix.d.ts.map +1 -1
  6. package/dist/classes/base/matrix.js +2 -10
  7. package/dist/classes/base/vector.d.ts +37 -25
  8. package/dist/classes/base/vector.d.ts.map +1 -1
  9. package/dist/classes/base/vector.js +17 -24
  10. package/dist/classes/euler.d.ts +59 -55
  11. package/dist/classes/euler.d.ts.map +1 -1
  12. package/dist/classes/euler.js +57 -77
  13. package/dist/classes/matrix3.d.ts +58 -41
  14. package/dist/classes/matrix3.d.ts.map +1 -1
  15. package/dist/classes/matrix3.js +68 -59
  16. package/dist/classes/matrix4.d.ts +214 -90
  17. package/dist/classes/matrix4.d.ts.map +1 -1
  18. package/dist/classes/matrix4.js +252 -171
  19. package/dist/classes/pose.d.ts +29 -26
  20. package/dist/classes/pose.d.ts.map +1 -1
  21. package/dist/classes/pose.js +6 -23
  22. package/dist/classes/quaternion.d.ts +61 -40
  23. package/dist/classes/quaternion.d.ts.map +1 -1
  24. package/dist/classes/quaternion.js +49 -53
  25. package/dist/classes/spherical-coordinates.d.ts +45 -25
  26. package/dist/classes/spherical-coordinates.d.ts.map +1 -1
  27. package/dist/classes/spherical-coordinates.js +30 -24
  28. package/dist/classes/vector2.d.ts +51 -15
  29. package/dist/classes/vector2.d.ts.map +1 -1
  30. package/dist/classes/vector2.js +29 -23
  31. package/dist/classes/vector3.d.ts +47 -32
  32. package/dist/classes/vector3.d.ts.map +1 -1
  33. package/dist/classes/vector3.js +16 -30
  34. package/dist/classes/vector4.d.ts +37 -19
  35. package/dist/classes/vector4.d.ts.map +1 -1
  36. package/dist/classes/vector4.js +12 -24
  37. package/dist/es5/classes/base/math-array.js +248 -179
  38. package/dist/es5/classes/base/math-array.js.map +1 -1
  39. package/dist/es5/classes/base/matrix.js +74 -54
  40. package/dist/es5/classes/base/matrix.js.map +1 -1
  41. package/dist/es5/classes/base/vector.js +167 -121
  42. package/dist/es5/classes/base/vector.js.map +1 -1
  43. package/dist/es5/classes/euler.js +575 -480
  44. package/dist/es5/classes/euler.js.map +1 -1
  45. package/dist/es5/classes/matrix3.js +234 -158
  46. package/dist/es5/classes/matrix3.js.map +1 -1
  47. package/dist/es5/classes/matrix4.js +510 -417
  48. package/dist/es5/classes/matrix4.js.map +1 -1
  49. package/dist/es5/classes/pose.js +126 -101
  50. package/dist/es5/classes/pose.js.map +1 -1
  51. package/dist/es5/classes/quaternion.js +285 -213
  52. package/dist/es5/classes/quaternion.js.map +1 -1
  53. package/dist/es5/classes/spherical-coordinates.js +170 -125
  54. package/dist/es5/classes/spherical-coordinates.js.map +1 -1
  55. package/dist/es5/classes/vector2.js +118 -76
  56. package/dist/es5/classes/vector2.js.map +1 -1
  57. package/dist/es5/classes/vector3.js +171 -119
  58. package/dist/es5/classes/vector3.js.map +1 -1
  59. package/dist/es5/classes/vector4.js +141 -94
  60. package/dist/es5/classes/vector4.js.map +1 -1
  61. package/dist/es5/index.js +34 -34
  62. package/dist/es5/lib/common.js +56 -30
  63. package/dist/es5/lib/common.js.map +1 -1
  64. package/dist/es5/lib/gl-matrix-extras.js +14 -14
  65. package/dist/es5/lib/gl-matrix-extras.js.map +1 -1
  66. package/dist/es5/lib/gl-matrix.d.js +2 -0
  67. package/dist/es5/lib/gl-matrix.d.js.map +1 -0
  68. package/dist/es5/lib/validators.js +5 -3
  69. package/dist/es5/lib/validators.js.map +1 -1
  70. package/dist/esm/classes/base/math-array.js +45 -47
  71. package/dist/esm/classes/base/math-array.js.map +1 -1
  72. package/dist/esm/classes/base/matrix.js +0 -11
  73. package/dist/esm/classes/base/matrix.js.map +1 -1
  74. package/dist/esm/classes/base/vector.js +0 -10
  75. package/dist/esm/classes/base/vector.js.map +1 -1
  76. package/dist/esm/classes/euler.js +61 -48
  77. package/dist/esm/classes/euler.js.map +1 -1
  78. package/dist/esm/classes/matrix3.js +55 -33
  79. package/dist/esm/classes/matrix3.js.map +1 -1
  80. package/dist/esm/classes/matrix4.js +156 -136
  81. package/dist/esm/classes/matrix4.js.map +1 -1
  82. package/dist/esm/classes/pose.js +8 -4
  83. package/dist/esm/classes/pose.js.map +1 -1
  84. package/dist/esm/classes/quaternion.js +37 -27
  85. package/dist/esm/classes/quaternion.js.map +1 -1
  86. package/dist/esm/classes/spherical-coordinates.js +15 -5
  87. package/dist/esm/classes/spherical-coordinates.js.map +1 -1
  88. package/dist/esm/classes/vector2.js.map +1 -1
  89. package/dist/esm/classes/vector3.js +7 -2
  90. package/dist/esm/classes/vector3.js.map +1 -1
  91. package/dist/esm/classes/vector4.js +7 -2
  92. package/dist/esm/classes/vector4.js.map +1 -1
  93. package/dist/esm/lib/common.js +8 -8
  94. package/dist/esm/lib/common.js.map +1 -1
  95. package/dist/esm/lib/gl-matrix-extras.js.map +1 -1
  96. package/dist/esm/lib/gl-matrix.d.js +2 -0
  97. package/dist/esm/lib/gl-matrix.d.js.map +1 -0
  98. package/dist/esm/lib/validators.js.map +1 -1
  99. package/dist/lib/common.d.ts +14 -11
  100. package/dist/lib/common.d.ts.map +1 -1
  101. package/dist/lib/common.js +10 -23
  102. package/dist/lib/gl-matrix-extras.d.ts +6 -5
  103. package/dist/lib/gl-matrix-extras.d.ts.map +1 -1
  104. package/dist/lib/gl-matrix-extras.js +0 -1
  105. package/dist/lib/validators.d.ts +5 -4
  106. package/dist/lib/validators.d.ts.map +1 -1
  107. package/dist/lib/validators.js +0 -19
  108. package/package.json +5 -5
  109. package/src/classes/base/math-array.ts +265 -0
  110. package/src/classes/base/{matrix.js → matrix.ts} +15 -19
  111. package/src/classes/base/{vector.js → vector.ts} +47 -54
  112. package/src/classes/{euler.js → euler.ts} +121 -221
  113. package/src/classes/matrix3.ts +253 -0
  114. package/src/classes/matrix4.ts +668 -0
  115. package/src/classes/{pose.js → pose.ts} +52 -49
  116. package/src/classes/{quaternion.js → quaternion.ts} +107 -95
  117. package/src/classes/{spherical-coordinates.js → spherical-coordinates.ts} +84 -54
  118. package/src/classes/vector2.ts +127 -0
  119. package/src/classes/{vector3.js → vector3.ts} +43 -55
  120. package/src/classes/{vector4.js → vector4.ts} +44 -48
  121. package/src/lib/common.ts +58 -37
  122. package/src/lib/gl-matrix-extras.ts +26 -5
  123. package/src/lib/gl-matrix.d.ts +266 -0
  124. package/src/lib/validators.ts +10 -6
  125. package/dist/es5/classes/base/math-array.d.js +0 -46
  126. package/dist/es5/classes/base/math-array.d.js.map +0 -1
  127. package/dist/es5/classes/base/matrix.d.js +0 -15
  128. package/dist/es5/classes/base/matrix.d.js.map +0 -1
  129. package/dist/es5/classes/base/vector.d.js +0 -24
  130. package/dist/es5/classes/base/vector.d.js.map +0 -1
  131. package/dist/es5/classes/euler.d.js +0 -45
  132. package/dist/es5/classes/euler.d.js.map +0 -1
  133. package/dist/es5/classes/matrix3.d.js +0 -25
  134. package/dist/es5/classes/matrix3.d.js.map +0 -1
  135. package/dist/es5/classes/matrix4.d.js +0 -25
  136. package/dist/es5/classes/matrix4.d.js.map +0 -1
  137. package/dist/es5/classes/pose.d.js +0 -25
  138. package/dist/es5/classes/pose.d.js.map +0 -1
  139. package/dist/es5/classes/quaternion.d.js +0 -27
  140. package/dist/es5/classes/quaternion.d.js.map +0 -1
  141. package/dist/es5/classes/spherical-coordinates.d.js +0 -27
  142. package/dist/es5/classes/spherical-coordinates.d.js.map +0 -1
  143. package/dist/es5/classes/vector2.d.js +0 -18
  144. package/dist/es5/classes/vector2.d.js.map +0 -1
  145. package/dist/es5/classes/vector3.d.js +0 -24
  146. package/dist/es5/classes/vector3.d.js.map +0 -1
  147. package/dist/es5/classes/vector4.d.js +0 -25
  148. package/dist/es5/classes/vector4.d.js.map +0 -1
  149. package/dist/esm/classes/base/math-array.d.js +0 -36
  150. package/dist/esm/classes/base/math-array.d.js.map +0 -1
  151. package/dist/esm/classes/base/matrix.d.js +0 -3
  152. package/dist/esm/classes/base/matrix.d.js.map +0 -1
  153. package/dist/esm/classes/base/vector.d.js +0 -13
  154. package/dist/esm/classes/base/vector.d.js.map +0 -1
  155. package/dist/esm/classes/euler.d.js +0 -55
  156. package/dist/esm/classes/euler.d.js.map +0 -1
  157. package/dist/esm/classes/matrix3.d.js +0 -15
  158. package/dist/esm/classes/matrix3.d.js.map +0 -1
  159. package/dist/esm/classes/matrix4.d.js +0 -15
  160. package/dist/esm/classes/matrix4.d.js.map +0 -1
  161. package/dist/esm/classes/pose.d.js +0 -18
  162. package/dist/esm/classes/pose.d.js.map +0 -1
  163. package/dist/esm/classes/quaternion.d.js +0 -19
  164. package/dist/esm/classes/quaternion.d.js.map +0 -1
  165. package/dist/esm/classes/spherical-coordinates.d.js +0 -22
  166. package/dist/esm/classes/spherical-coordinates.d.js.map +0 -1
  167. package/dist/esm/classes/vector2.d.js +0 -6
  168. package/dist/esm/classes/vector2.d.js.map +0 -1
  169. package/dist/esm/classes/vector3.d.js +0 -13
  170. package/dist/esm/classes/vector3.d.js.map +0 -1
  171. package/dist/esm/classes/vector4.d.js +0 -15
  172. package/dist/esm/classes/vector4.d.js.map +0 -1
  173. package/src/classes/base/math-array.d.ts +0 -55
  174. package/src/classes/base/math-array.js +0 -250
  175. package/src/classes/base/matrix.d.ts +0 -15
  176. package/src/classes/base/vector.d.ts +0 -45
  177. package/src/classes/euler.d.ts +0 -92
  178. package/src/classes/matrix3.d.ts +0 -91
  179. package/src/classes/matrix3.js +0 -225
  180. package/src/classes/matrix4.d.ts +0 -161
  181. package/src/classes/matrix4.js +0 -530
  182. package/src/classes/pose.d.ts +0 -92
  183. package/src/classes/quaternion.d.ts +0 -107
  184. package/src/classes/spherical-coordinates.d.ts +0 -87
  185. package/src/classes/vector2.d.ts +0 -65
  186. package/src/classes/vector2.js +0 -122
  187. package/src/classes/vector3.d.ts +0 -65
  188. package/src/classes/vector4.d.ts +0 -34
@@ -1,66 +1,44 @@
1
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 { checkVector, deprecated } from '../lib/validators';
2
+ // MIT License
21
3
  import Matrix from './base/matrix';
22
- // eslint-disable-next-line camelcase
4
+ import { checkVector } from '../lib/validators';
5
+ /* eslint-disable camelcase */
23
6
  import { vec2_transformMat4AsVector, vec3_transformMat4AsVector } from '../lib/gl-matrix-extras';
24
- // @ts-ignore: error TS2307: Cannot find module 'gl-matrix/...'.
25
7
  import * as mat4 from 'gl-matrix/mat4';
26
- // @ts-ignore: error TS2307: Cannot find module 'gl-matrix/...'.
27
8
  import * as vec2 from 'gl-matrix/vec2';
28
- // @ts-ignore: error TS2307: Cannot find module 'gl-matrix/...'.
29
9
  import * as vec3 from 'gl-matrix/vec3';
30
- // @ts-ignore: error TS2307: Cannot find module 'gl-matrix/...'.
31
10
  import * as vec4 from 'gl-matrix/vec4';
32
- const IDENTITY = Object.freeze([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
33
- const ZERO = Object.freeze([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
34
- const INDICES = Object.freeze({
35
- COL0ROW0: 0,
36
- COL0ROW1: 1,
37
- COL0ROW2: 2,
38
- COL0ROW3: 3,
39
- COL1ROW0: 4,
40
- COL1ROW1: 5,
41
- COL1ROW2: 6,
42
- COL1ROW3: 7,
43
- COL2ROW0: 8,
44
- COL2ROW1: 9,
45
- COL2ROW2: 10,
46
- COL2ROW3: 11,
47
- COL3ROW0: 12,
48
- COL3ROW1: 13,
49
- COL3ROW2: 14,
50
- COL3ROW3: 15
51
- });
52
- const constants = {};
11
+ var INDICES;
12
+ (function (INDICES) {
13
+ INDICES[INDICES["COL0ROW0"] = 0] = "COL0ROW0";
14
+ INDICES[INDICES["COL0ROW1"] = 1] = "COL0ROW1";
15
+ INDICES[INDICES["COL0ROW2"] = 2] = "COL0ROW2";
16
+ INDICES[INDICES["COL0ROW3"] = 3] = "COL0ROW3";
17
+ INDICES[INDICES["COL1ROW0"] = 4] = "COL1ROW0";
18
+ INDICES[INDICES["COL1ROW1"] = 5] = "COL1ROW1";
19
+ INDICES[INDICES["COL1ROW2"] = 6] = "COL1ROW2";
20
+ INDICES[INDICES["COL1ROW3"] = 7] = "COL1ROW3";
21
+ INDICES[INDICES["COL2ROW0"] = 8] = "COL2ROW0";
22
+ INDICES[INDICES["COL2ROW1"] = 9] = "COL2ROW1";
23
+ INDICES[INDICES["COL2ROW2"] = 10] = "COL2ROW2";
24
+ INDICES[INDICES["COL2ROW3"] = 11] = "COL2ROW3";
25
+ INDICES[INDICES["COL3ROW0"] = 12] = "COL3ROW0";
26
+ INDICES[INDICES["COL3ROW1"] = 13] = "COL3ROW1";
27
+ INDICES[INDICES["COL3ROW2"] = 14] = "COL3ROW2";
28
+ INDICES[INDICES["COL3ROW3"] = 15] = "COL3ROW3";
29
+ })(INDICES || (INDICES = {}));
30
+ const DEFAULT_FOVY = (45 * Math.PI) / 180;
31
+ const DEFAULT_ASPECT = 1;
32
+ const DEFAULT_NEAR = 0.1;
33
+ const DEFAULT_FAR = 500;
34
+ const IDENTITY_MATRIX = Object.freeze([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
35
+ /** 4x4 matrix */
53
36
  export default class Matrix4 extends Matrix {
54
37
  static get IDENTITY() {
55
- constants.IDENTITY = constants.IDENTITY || Object.freeze(new Matrix4(IDENTITY));
56
- return constants.IDENTITY;
38
+ return getIdentityMatrix();
57
39
  }
58
40
  static get ZERO() {
59
- constants.ZERO = constants.ZERO || Object.freeze(new Matrix4(ZERO));
60
- return constants.ZERO;
61
- }
62
- get INDICES() {
63
- return INDICES;
41
+ return getZeroMatrix();
64
42
  }
65
43
  get ELEMENTS() {
66
44
  return 16;
@@ -68,6 +46,9 @@ export default class Matrix4 extends Matrix {
68
46
  get RANK() {
69
47
  return 4;
70
48
  }
49
+ get INDICES() {
50
+ return INDICES;
51
+ }
71
52
  constructor(array) {
72
53
  // PERF NOTE: initialize elements as double precision numbers
73
54
  super(-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0);
@@ -158,100 +139,93 @@ export default class Matrix4 extends Matrix {
158
139
  return result;
159
140
  }
160
141
  // Constructors
142
+ /** Set to identity matrix */
161
143
  identity() {
162
- return this.copy(IDENTITY);
144
+ return this.copy(IDENTITY_MATRIX);
145
+ }
146
+ /**
147
+ *
148
+ * @param object
149
+ * @returns self
150
+ */
151
+ fromObject(object) {
152
+ return this.check();
163
153
  }
164
- // Calculates a 4x4 matrix from the given quaternion
165
- // q quat Quaternion to create matrix from
166
- fromQuaternion(q) {
167
- mat4.fromQuat(this, q);
154
+ /**
155
+ * Calculates a 4x4 matrix from the given quaternion
156
+ * @param quaternion Quaternion to create matrix from
157
+ * @returns self
158
+ */
159
+ fromQuaternion(quaternion) {
160
+ mat4.fromQuat(this, quaternion);
168
161
  return this.check();
169
162
  }
170
- // Generates a frustum matrix with the given bounds
171
- // left Number Left bound of the frustum
172
- // right Number Right bound of the frustum
173
- // bottom Number Bottom bound of the frustum
174
- // top Number Top bound of the frustum
175
- // near Number Near bound of the frustum
176
- // far Number Far bound of the frustum
177
- frustum({ left, right, bottom, top, near, far }) {
163
+ /**
164
+ * Generates a frustum matrix with the given bounds
165
+ * @param view.left - Left bound of the frustum
166
+ * @param view.right - Right bound of the frustum
167
+ * @param view.bottom - Bottom bound of the frustum
168
+ * @param view.top - Top bound of the frustum
169
+ * @param view.near - Near bound of the frustum
170
+ * @param view.far - Far bound of the frustum. Can be set to Infinity.
171
+ * @returns self
172
+ */
173
+ frustum(view) {
174
+ const { left, right, bottom, top, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
178
175
  if (far === Infinity) {
179
- Matrix4._computeInfinitePerspectiveOffCenter(this, left, right, bottom, top, near);
176
+ computeInfinitePerspectiveOffCenter(this, left, right, bottom, top, near);
180
177
  }
181
178
  else {
182
179
  mat4.frustum(this, left, right, bottom, top, near, far);
183
180
  }
184
181
  return this.check();
185
182
  }
186
- // eslint-disable-next-line max-params
187
- static _computeInfinitePerspectiveOffCenter(result, left, right, bottom, top, near) {
188
- const column0Row0 = (2.0 * near) / (right - left);
189
- const column1Row1 = (2.0 * near) / (top - bottom);
190
- const column2Row0 = (right + left) / (right - left);
191
- const column2Row1 = (top + bottom) / (top - bottom);
192
- const column2Row2 = -1.0;
193
- const column2Row3 = -1.0;
194
- const column3Row2 = -2.0 * near;
195
- result[0] = column0Row0;
196
- result[1] = 0.0;
197
- result[2] = 0.0;
198
- result[3] = 0.0;
199
- result[4] = 0.0;
200
- result[5] = column1Row1;
201
- result[6] = 0.0;
202
- result[7] = 0.0;
203
- result[8] = column2Row0;
204
- result[9] = column2Row1;
205
- result[10] = column2Row2;
206
- result[11] = column2Row3;
207
- result[12] = 0.0;
208
- result[13] = 0.0;
209
- result[14] = column3Row2;
210
- result[15] = 0.0;
211
- return result;
212
- }
213
- // Generates a look-at matrix with the given eye position, focal point,
214
- // and up axis
215
- // eye vec3 Position of the viewer
216
- // center vec3 Point the viewer is looking at
217
- // up vec3 vec3 pointing up
218
- lookAt(eye, center, up) {
219
- // Signature: lookAt({eye, center = [0, 0, 0], up = [0, 1, 0]}))
220
- if (arguments.length === 1) {
221
- ({ eye, center, up } = eye);
222
- }
223
- center = center || [0, 0, 0];
224
- up = up || [0, 1, 0];
183
+ /**
184
+ * Generates a look-at matrix with the given eye position, focal point,
185
+ * and up axis
186
+ * @param view.eye - (vector) Position of the viewer
187
+ * @param view.center - (vector) Point the viewer is looking at
188
+ * @param view.up - (vector) Up axis
189
+ * @returns self
190
+ */
191
+ lookAt(view) {
192
+ const { eye, center = [0, 0, 0], up = [0, 1, 0] } = view;
225
193
  mat4.lookAt(this, eye, center, up);
226
194
  return this.check();
227
195
  }
228
- // Generates a orthogonal projection matrix with the given bounds
229
- // from "traditional" view space parameters
230
- // left number Left bound of the frustum
231
- // right number Right bound of the frustum
232
- // bottom number Bottom bound of the frustum
233
- // top number Top bound of the frustum
234
- // near number Near bound of the frustum
235
- // far number Far bound of the frustum
236
- ortho({ left, right, bottom, top, near = 0.1, far = 500 }) {
196
+ /**
197
+ * Generates a orthogonal projection matrix with the given bounds
198
+ * from "traditional" view space parameters
199
+ * @param view.left - Left bound of the frustum
200
+ * @param view.right number Right bound of the frustum
201
+ * @param view.bottom - Bottom bound of the frustum
202
+ * @param view.top number Top bound of the frustum
203
+ * @param view.near - Near bound of the frustum
204
+ * @param view.far number Far bound of the frustum
205
+ * @returns self
206
+ */
207
+ ortho(view) {
208
+ const { left, right, bottom, top, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
237
209
  mat4.ortho(this, left, right, bottom, top, near, far);
238
210
  return this.check();
239
211
  }
240
- // Generates an orthogonal projection matrix with the same parameters
241
- // as a perspective matrix (plus focalDistance)
242
- // fovy number Vertical field of view in radians
243
- // aspect number Aspect ratio. typically viewport width/height
244
- // focalDistance distance in the view frustum used for extent calculations
245
- // near number Near bound of the frustum
246
- // far number Far bound of the frustum
247
- orthographic({ fovy = (45 * Math.PI) / 180, aspect = 1, focalDistance = 1, near = 0.1, far = 500 }) {
248
- if (fovy > Math.PI * 2) {
249
- throw Error('radians');
250
- }
212
+ /**
213
+ * Generates an orthogonal projection matrix with the same parameters
214
+ * as a perspective matrix (plus focalDistance)
215
+ * @param view.fovy Vertical field of view in radians
216
+ * @param view.aspect Aspect ratio. Typically viewport width / viewport height
217
+ * @param view.focalDistance Distance in the view frustum used for extent calculations
218
+ * @param view.near Near bound of the frustum
219
+ * @param view.far Far bound of the frustum
220
+ * @returns self
221
+ */
222
+ orthographic(view) {
223
+ const { fovy = DEFAULT_FOVY, aspect = DEFAULT_ASPECT, focalDistance = 1, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
224
+ checkRadians(fovy);
251
225
  const halfY = fovy / 2;
252
226
  const top = focalDistance * Math.tan(halfY); // focus_plane is the distance from the camera
253
227
  const right = top * aspect;
254
- return new Matrix4().ortho({
228
+ return this.ortho({
255
229
  left: -right,
256
230
  right,
257
231
  bottom: -top,
@@ -260,17 +234,17 @@ export default class Matrix4 extends Matrix {
260
234
  far
261
235
  });
262
236
  }
263
- // Generates a perspective projection matrix with the given bounds
264
- // fovy number Vertical field of view in radians
265
- // aspect number Aspect ratio. typically viewport width/height
266
- // near number Near bound of the frustum
267
- // far number Far bound of the frustum
268
- perspective({ fovy = undefined, fov = (45 * Math.PI) / 180, // DEPRECATED
269
- aspect = 1, near = 0.1, far = 500 } = {}) {
270
- fovy = fovy || fov;
271
- if (fovy > Math.PI * 2) {
272
- throw Error('radians');
273
- }
237
+ /**
238
+ * Generates a perspective projection matrix with the given bounds
239
+ * @param view.fovy Vertical field of view in radians
240
+ * @param view.aspect Aspect ratio. typically viewport width/height
241
+ * @param view.near Near bound of the frustum
242
+ * @param view.far Far bound of the frustum
243
+ * @returns self
244
+ */
245
+ perspective(view) {
246
+ const { fovy = (45 * Math.PI) / 180, aspect = 1, near = 0.1, far = 500 } = view;
247
+ checkRadians(fovy);
274
248
  mat4.perspective(this, fovy, aspect, near, far);
275
249
  return this.check();
276
250
  }
@@ -278,8 +252,12 @@ export default class Matrix4 extends Matrix {
278
252
  determinant() {
279
253
  return mat4.determinant(this);
280
254
  }
281
- // Extracts the non-uniform scale assuming the matrix is an affine transformation.
282
- // The scales are the "lengths" of the column vectors in the upper-left 3x3 matrix.
255
+ /**
256
+ * Extracts the non-uniform scale assuming the matrix is an affine transformation.
257
+ * The scales are the "lengths" of the column vectors in the upper-left 3x3 matrix.
258
+ * @param result
259
+ * @returns self
260
+ */
283
261
  getScale(result = [-0, -0, -0]) {
284
262
  // explicit is faster than hypot...
285
263
  result[0] = Math.sqrt(this[0] * this[0] + this[1] * this[1] + this[2] * this[2]);
@@ -290,16 +268,27 @@ export default class Matrix4 extends Matrix {
290
268
  // result[2] = Math.hypot(this[8], this[9], this[10]);
291
269
  return result;
292
270
  }
293
- // Gets the translation portion, assuming the matrix is a affine transformation matrix.
271
+ /**
272
+ * Gets the translation portion, assuming the matrix is a affine transformation matrix.
273
+ * @param result
274
+ * @returns self
275
+ */
294
276
  getTranslation(result = [-0, -0, -0]) {
295
277
  result[0] = this[12];
296
278
  result[1] = this[13];
297
279
  result[2] = this[14];
298
280
  return result;
299
281
  }
300
- // Gets upper left 3x3 pure rotation matrix (non-scaling), assume affine transformation matrix
301
- getRotation(result = [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0], scaleResult = null) {
302
- const scale = this.getScale(scaleResult || [-0, -0, -0]);
282
+ /**
283
+ * Gets upper left 3x3 pure rotation matrix (non-scaling), assume affine transformation matrix
284
+ * @param result
285
+ * @param scaleResult
286
+ * @returns self
287
+ */
288
+ getRotation(result, scaleResult) {
289
+ result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
290
+ scaleResult = scaleResult || [-0, -0, -0];
291
+ const scale = this.getScale(scaleResult);
303
292
  const inverseScale0 = 1 / scale[0];
304
293
  const inverseScale1 = 1 / scale[1];
305
294
  const inverseScale2 = 1 / scale[2];
@@ -321,8 +310,16 @@ export default class Matrix4 extends Matrix {
321
310
  result[15] = 1;
322
311
  return result;
323
312
  }
324
- getRotationMatrix3(result = [-0, -0, -0, -0, -0, -0, -0, -0, -0], scaleResult = null) {
325
- const scale = this.getScale(scaleResult || [-0, -0, -0]);
313
+ /**
314
+ *
315
+ * @param result
316
+ * @param scaleResult
317
+ * @returns self
318
+ */
319
+ getRotationMatrix3(result, scaleResult) {
320
+ result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0];
321
+ scaleResult = scaleResult || [-0, -0, -0];
322
+ const scale = this.getScale(scaleResult);
326
323
  const inverseScale0 = 1 / scale[0];
327
324
  const inverseScale1 = 1 / scale[1];
328
325
  const inverseScale2 = 1 / scale[2];
@@ -367,34 +364,59 @@ export default class Matrix4 extends Matrix {
367
364
  // mat4.rotate(this, this, radians, [0, 1, 0]);
368
365
  return this.check();
369
366
  }
370
- // Rotates a matrix by the given angle around the Z axis.
367
+ /**
368
+ * Rotates a matrix by the given angle around the Z axis.
369
+ * @param radians
370
+ * @returns self
371
+ */
371
372
  rotateZ(radians) {
372
373
  mat4.rotateZ(this, this, radians);
373
374
  // mat4.rotate(this, this, radians, [0, 0, 1]);
374
375
  return this.check();
375
376
  }
376
- rotateXYZ([rx, ry, rz]) {
377
- return this.rotateX(rx).rotateY(ry).rotateZ(rz);
378
- }
377
+ /**
378
+ *
379
+ * @param param0
380
+ * @returns self
381
+ */
382
+ rotateXYZ(angleXYZ) {
383
+ return this.rotateX(angleXYZ[0]).rotateY(angleXYZ[1]).rotateZ(angleXYZ[2]);
384
+ }
385
+ /**
386
+ *
387
+ * @param radians
388
+ * @param axis
389
+ * @returns self
390
+ */
379
391
  rotateAxis(radians, axis) {
380
392
  mat4.rotate(this, this, radians, axis);
381
393
  return this.check();
382
394
  }
395
+ /**
396
+ *
397
+ * @param factor
398
+ * @returns self
399
+ */
383
400
  scale(factor) {
384
- if (Array.isArray(factor)) {
385
- mat4.scale(this, this, factor);
386
- }
387
- else {
388
- mat4.scale(this, this, [factor, factor, factor]);
389
- }
401
+ mat4.scale(this, this, Array.isArray(factor) ? factor : [factor, factor, factor]);
390
402
  return this.check();
391
403
  }
392
- translate(vec) {
393
- mat4.translate(this, this, vec);
404
+ /**
405
+ *
406
+ * @param vec
407
+ * @returns self
408
+ */
409
+ translate(vector) {
410
+ mat4.translate(this, this, vector);
394
411
  return this.check();
395
412
  }
396
413
  // Transforms
397
- // Transforms any 2, 3 or 4 element vector. 2 and 3 elements are treated as points
414
+ /**
415
+ * Transforms any 2, 3 or 4 element vector. 2 and 3 elements are treated as points
416
+ * @param vector
417
+ * @param result
418
+ * @returns self
419
+ */
398
420
  transform(vector, result) {
399
421
  if (vector.length === 4) {
400
422
  result = vec4.transformMat4(result || [-0, -0, -0, -0], vector, this);
@@ -403,7 +425,12 @@ export default class Matrix4 extends Matrix {
403
425
  }
404
426
  return this.transformAsPoint(vector, result);
405
427
  }
406
- // Transforms any 2 or 3 element array as point (w implicitly 1)
428
+ /**
429
+ * Transforms any 2 or 3 element array as point (w implicitly 1)
430
+ * @param vector
431
+ * @param result
432
+ * @returns self
433
+ */
407
434
  transformAsPoint(vector, result) {
408
435
  const { length } = vector;
409
436
  switch (length) {
@@ -419,7 +446,12 @@ export default class Matrix4 extends Matrix {
419
446
  checkVector(result, vector.length);
420
447
  return result;
421
448
  }
422
- // Transforms any 2 or 3 element array as vector (w implicitly 0)
449
+ /**
450
+ * Transforms any 2 or 3 element array as vector (w implicitly 0)
451
+ * @param vector
452
+ * @param result
453
+ * @returns self
454
+ */
423
455
  transformAsVector(vector, result) {
424
456
  switch (vector.length) {
425
457
  case 2:
@@ -434,24 +466,73 @@ export default class Matrix4 extends Matrix {
434
466
  checkVector(result, vector.length);
435
467
  return result;
436
468
  }
437
- // three.js math API compatibility
438
- makeRotationX(radians) {
439
- return this.identity().rotateX(radians);
440
- }
441
- makeTranslation(x, y, z) {
442
- return this.identity().translate([x, y, z]);
443
- }
444
- // DEPRECATED in 3.0
469
+ /** @deprecated */
445
470
  transformPoint(vector, result) {
446
- deprecated('Matrix4.transformPoint', '3.0');
447
471
  return this.transformAsPoint(vector, result);
448
472
  }
473
+ /** @deprecated */
449
474
  transformVector(vector, result) {
450
- deprecated('Matrix4.transformVector', '3.0');
451
475
  return this.transformAsPoint(vector, result);
452
476
  }
477
+ /** @deprecated */
453
478
  transformDirection(vector, result) {
454
- deprecated('Matrix4.transformDirection', '3.0');
455
479
  return this.transformAsVector(vector, result);
456
480
  }
481
+ // three.js math API compatibility
482
+ makeRotationX(radians) {
483
+ return this.identity().rotateX(radians);
484
+ }
485
+ makeTranslation(x, y, z) {
486
+ return this.identity().translate([x, y, z]);
487
+ }
488
+ }
489
+ // TODO initializing static members directly is an option, but make sure no tree-shaking issues
490
+ let ZERO;
491
+ let IDENTITY;
492
+ function getZeroMatrix() {
493
+ if (!ZERO) {
494
+ ZERO = new Matrix4([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
495
+ Object.freeze(ZERO);
496
+ }
497
+ return ZERO;
498
+ }
499
+ function getIdentityMatrix() {
500
+ if (!IDENTITY) {
501
+ IDENTITY = new Matrix4();
502
+ Object.freeze(IDENTITY);
503
+ }
504
+ return IDENTITY;
505
+ }
506
+ // HELPER FUNCTIONS
507
+ function checkRadians(possiblyDegrees) {
508
+ if (possiblyDegrees > Math.PI * 2) {
509
+ throw Error('expected radians');
510
+ }
511
+ }
512
+ // eslint-disable-next-line max-params
513
+ function computeInfinitePerspectiveOffCenter(result, left, right, bottom, top, near) {
514
+ const column0Row0 = (2 * near) / (right - left);
515
+ const column1Row1 = (2 * near) / (top - bottom);
516
+ const column2Row0 = (right + left) / (right - left);
517
+ const column2Row1 = (top + bottom) / (top - bottom);
518
+ const column2Row2 = -1;
519
+ const column2Row3 = -1;
520
+ const column3Row2 = -2 * near;
521
+ result[0] = column0Row0;
522
+ result[1] = 0;
523
+ result[2] = 0;
524
+ result[3] = 0;
525
+ result[4] = 0;
526
+ result[5] = column1Row1;
527
+ result[6] = 0;
528
+ result[7] = 0;
529
+ result[8] = column2Row0;
530
+ result[9] = column2Row1;
531
+ result[10] = column2Row2;
532
+ result[11] = column2Row3;
533
+ result[12] = 0;
534
+ result[13] = 0;
535
+ result[14] = column3Row2;
536
+ result[15] = 0;
537
+ return result;
457
538
  }
@@ -1,37 +1,40 @@
1
+ import Matrix4 from './matrix4';
2
+ import Vector3 from './vector3';
3
+ import Euler from './euler';
4
+ import { NumericArray } from '@math.gl/types';
5
+ declare type PoseOptions = {
6
+ position?: Readonly<NumericArray>;
7
+ orientation?: Readonly<NumericArray>;
8
+ x?: number;
9
+ y?: number;
10
+ z?: number;
11
+ roll?: number;
12
+ pitch?: number;
13
+ yaw?: number;
14
+ };
1
15
  export default class Pose {
2
- constructor({ x, y, z, roll, pitch, yaw, position, orientation }?: {
3
- x?: number;
4
- y?: number;
5
- z?: number;
6
- roll?: number;
7
- pitch?: number;
8
- yaw?: number;
9
- position?: any;
10
- orientation?: any;
11
- });
12
- position: Vector3;
13
- orientation: Euler;
14
- set x(arg: number);
16
+ readonly position: Vector3;
17
+ readonly orientation: Euler;
18
+ constructor({ x, y, z, roll, pitch, yaw, position, orientation }?: PoseOptions);
15
19
  get x(): number;
16
- set y(arg: number);
20
+ set x(value: number);
17
21
  get y(): number;
18
- set z(arg: number);
22
+ set y(value: number);
19
23
  get z(): number;
20
- set roll(arg: number);
24
+ set z(value: number);
21
25
  get roll(): number;
22
- set pitch(arg: number);
26
+ set roll(value: number);
23
27
  get pitch(): number;
24
- set yaw(arg: number);
28
+ set pitch(value: number);
25
29
  get yaw(): number;
30
+ set yaw(value: number);
26
31
  getPosition(): Vector3;
27
32
  getOrientation(): Euler;
28
- equals(pose: any): boolean;
29
- exactEquals(pose: any): boolean;
30
- getTransformationMatrix(): any;
31
- getTransformationMatrixFromPose(pose: any): Matrix4;
32
- getTransformationMatrixToPose(pose: any): Matrix4;
33
+ equals(pose: Pose): boolean;
34
+ exactEquals(pose: Pose): boolean;
35
+ getTransformationMatrix(): Matrix4;
36
+ getTransformationMatrixFromPose(pose: Pose): Matrix4;
37
+ getTransformationMatrixToPose(pose: Pose): Matrix4;
33
38
  }
34
- import Vector3 from "./vector3";
35
- import Euler from "./euler";
36
- import Matrix4 from "./matrix4";
39
+ export {};
37
40
  //# sourceMappingURL=pose.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pose.d.ts","sourceRoot":"","sources":["../../src/classes/pose.js"],"names":[],"mappings":"AAuBA;IAEE;;;;;;;;;OAoBC;IATG,kBAAqC;IAKrC,mBAAyD;IAS7D,mBAEC;IALD,gBAEC;IAOD,mBAEC;IALD,gBAEC;IAOD,mBAEC;IALD,gBAEC;IAOD,sBAEC;IALD,mBAEC;IAOD,uBAEC;IALD,oBAEC;IAOD,qBAEC;IALD,kBAEC;IAKD,uBAEC;IAED,wBAEC;IAED,2BAKC;IAED,gCAOC;IAED,+BAiCC;IAED,oDAIC;IAED,kDAIC;CACF"}
1
+ {"version":3,"file":"pose.d.ts","sourceRoot":"","sources":["../../src/classes/pose.ts"],"names":[],"mappings":"AAEA,OAAO,OAAO,MAAM,WAAW,CAAC;AAChC,OAAO,OAAO,MAAM,WAAW,CAAC;AAChC,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C,aAAK,WAAW,GAAG;IACjB,QAAQ,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAClC,WAAW,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACrC,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,IAAI;IACvB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC;gBAEhB,EACV,CAAK,EACL,CAAK,EACL,CAAK,EACL,IAAQ,EACR,KAAS,EACT,GAAO,EACP,QAAQ,EACR,WAAW,EACZ,GAAE,WAAgB;IAcnB,IAAI,CAAC,IAAI,MAAM,CAEd;IAED,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,EAElB;IAED,IAAI,CAAC,IAAI,MAAM,CAEd;IAED,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,EAElB;IAED,IAAI,CAAC,IAAI,MAAM,CAEd;IAED,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,EAElB;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,EAErB;IAED,IAAI,KAAK,IAAI,MAAM,CAElB;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,EAEtB;IAED,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED,IAAI,GAAG,CAAC,KAAK,EAAE,MAAM,EAEpB;IAED,WAAW,IAAI,OAAO;IAItB,cAAc,IAAI,KAAK;IAIvB,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAO3B,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAShC,uBAAuB,IAAI,OAAO;IA8BlC,+BAA+B,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAMpD,6BAA6B,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;CAKnD"}