@math.gl/core 3.5.6 → 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 (189) 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/matrix3.d.js +15 -0
  105. package/dist/esm/classes/matrix3.d.js.map +1 -0
  106. package/dist/esm/classes/matrix4.d.js +15 -0
  107. package/dist/esm/classes/matrix4.d.js.map +1 -0
  108. package/dist/esm/classes/pose.d.js +18 -0
  109. package/dist/esm/classes/pose.d.js.map +1 -0
  110. package/dist/esm/classes/quaternion.d.js +19 -0
  111. package/dist/esm/classes/quaternion.d.js.map +1 -0
  112. package/dist/esm/classes/spherical-coordinates.d.js +22 -0
  113. package/dist/esm/classes/spherical-coordinates.d.js.map +1 -0
  114. package/dist/esm/classes/vector2.d.js +6 -0
  115. package/dist/esm/classes/vector2.d.js.map +1 -0
  116. package/dist/esm/classes/vector3.d.js +13 -0
  117. package/dist/esm/classes/vector3.d.js.map +1 -0
  118. package/dist/esm/classes/vector4.d.js +15 -0
  119. package/dist/esm/classes/vector4.d.js.map +1 -0
  120. package/dist/esm/docs/README.md +0 -0
  121. package/dist/esm/index.js +2 -13
  122. package/dist/esm/index.js.map +1 -1
  123. package/dist/esm/lib/assert.js.map +1 -1
  124. package/dist/esm/lib/common.js +34 -37
  125. package/dist/esm/lib/common.js.map +1 -1
  126. package/dist/esm/lib/gl-matrix-extras.js.map +1 -1
  127. package/dist/esm/lib/math-utils.js.map +1 -1
  128. package/dist/esm/lib/validators.js.map +1 -1
  129. package/dist/index.d.ts +17 -0
  130. package/dist/index.d.ts.map +1 -0
  131. package/dist/index.js +24 -0
  132. package/dist/lib/assert.d.ts +2 -0
  133. package/dist/lib/assert.d.ts.map +1 -0
  134. package/dist/lib/assert.js +5 -0
  135. package/dist/lib/common.d.ts +90 -0
  136. package/dist/lib/common.d.ts.map +1 -0
  137. package/dist/lib/common.js +223 -0
  138. package/dist/lib/gl-matrix-extras.d.ts +6 -0
  139. package/dist/lib/gl-matrix-extras.d.ts.map +1 -0
  140. package/dist/lib/gl-matrix-extras.js +50 -0
  141. package/dist/lib/math-utils.d.ts +28 -0
  142. package/dist/lib/math-utils.d.ts.map +1 -0
  143. package/dist/lib/math-utils.js +28 -0
  144. package/dist/lib/validators.d.ts +5 -0
  145. package/dist/lib/validators.d.ts.map +1 -0
  146. package/dist/lib/validators.js +52 -0
  147. package/package.json +4 -3
  148. package/src/classes/base/math-array.d.ts +0 -1
  149. package/src/docs/README.md +0 -0
  150. package/{dist/esm/index.d.ts → src/index.ts} +32 -34
  151. package/src/lib/{assert.js → assert.ts} +1 -1
  152. package/src/lib/common.ts +283 -0
  153. package/src/lib/{gl-matrix-extras.js → gl-matrix-extras.ts} +0 -0
  154. package/src/lib/{math-utils.js → math-utils.ts} +0 -0
  155. package/src/lib/{validators.js → validators.ts} +0 -0
  156. package/dist/es5/addons/polygon.d.ts +0 -17
  157. package/dist/es5/classes/base/math-array.d.ts +0 -56
  158. package/dist/es5/classes/base/matrix.d.ts +0 -15
  159. package/dist/es5/classes/base/vector.d.ts +0 -45
  160. package/dist/es5/classes/euler.d.ts +0 -92
  161. package/dist/es5/classes/matrix3.d.ts +0 -91
  162. package/dist/es5/classes/matrix4.d.ts +0 -161
  163. package/dist/es5/classes/pose.d.ts +0 -92
  164. package/dist/es5/classes/quaternion.d.ts +0 -107
  165. package/dist/es5/classes/spherical-coordinates.d.ts +0 -87
  166. package/dist/es5/classes/vector2.d.ts +0 -65
  167. package/dist/es5/classes/vector3.d.ts +0 -65
  168. package/dist/es5/classes/vector4.d.ts +0 -34
  169. package/dist/es5/index.d.ts +0 -54
  170. package/dist/es5/lib/common.d.ts +0 -80
  171. package/dist/esm/addons/polygon.d.ts +0 -17
  172. package/dist/esm/classes/base/math-array.d.ts +0 -56
  173. package/dist/esm/classes/base/matrix.d.ts +0 -15
  174. package/dist/esm/classes/base/vector.d.ts +0 -45
  175. package/dist/esm/classes/euler.d.ts +0 -92
  176. package/dist/esm/classes/matrix3.d.ts +0 -91
  177. package/dist/esm/classes/matrix4.d.ts +0 -161
  178. package/dist/esm/classes/pose.d.ts +0 -92
  179. package/dist/esm/classes/quaternion.d.ts +0 -107
  180. package/dist/esm/classes/spherical-coordinates.d.ts +0 -87
  181. package/dist/esm/classes/vector2.d.ts +0 -65
  182. package/dist/esm/classes/vector3.d.ts +0 -65
  183. package/dist/esm/classes/vector4.d.ts +0 -34
  184. package/dist/esm/lib/common.d.ts +0 -80
  185. package/src/addons/polygon.d.ts +0 -17
  186. package/src/index.d.ts +0 -54
  187. package/src/index.js +0 -86
  188. package/src/lib/common.d.ts +0 -80
  189. package/src/lib/common.js +0 -222
@@ -0,0 +1,457 @@
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';
21
+ import Matrix from './base/matrix';
22
+ // eslint-disable-next-line camelcase
23
+ import { vec2_transformMat4AsVector, vec3_transformMat4AsVector } from '../lib/gl-matrix-extras';
24
+ // @ts-ignore: error TS2307: Cannot find module 'gl-matrix/...'.
25
+ import * as mat4 from 'gl-matrix/mat4';
26
+ // @ts-ignore: error TS2307: Cannot find module 'gl-matrix/...'.
27
+ import * as vec2 from 'gl-matrix/vec2';
28
+ // @ts-ignore: error TS2307: Cannot find module 'gl-matrix/...'.
29
+ import * as vec3 from 'gl-matrix/vec3';
30
+ // @ts-ignore: error TS2307: Cannot find module 'gl-matrix/...'.
31
+ 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 = {};
53
+ export default class Matrix4 extends Matrix {
54
+ static get IDENTITY() {
55
+ constants.IDENTITY = constants.IDENTITY || Object.freeze(new Matrix4(IDENTITY));
56
+ return constants.IDENTITY;
57
+ }
58
+ static get ZERO() {
59
+ constants.ZERO = constants.ZERO || Object.freeze(new Matrix4(ZERO));
60
+ return constants.ZERO;
61
+ }
62
+ get INDICES() {
63
+ return INDICES;
64
+ }
65
+ get ELEMENTS() {
66
+ return 16;
67
+ }
68
+ get RANK() {
69
+ return 4;
70
+ }
71
+ constructor(array) {
72
+ // PERF NOTE: initialize elements as double precision numbers
73
+ super(-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0);
74
+ if (arguments.length === 1 && Array.isArray(array)) {
75
+ this.copy(array);
76
+ }
77
+ else {
78
+ this.identity();
79
+ }
80
+ }
81
+ copy(array) {
82
+ this[0] = array[0];
83
+ this[1] = array[1];
84
+ this[2] = array[2];
85
+ this[3] = array[3];
86
+ this[4] = array[4];
87
+ this[5] = array[5];
88
+ this[6] = array[6];
89
+ this[7] = array[7];
90
+ this[8] = array[8];
91
+ this[9] = array[9];
92
+ this[10] = array[10];
93
+ this[11] = array[11];
94
+ this[12] = array[12];
95
+ this[13] = array[13];
96
+ this[14] = array[14];
97
+ this[15] = array[15];
98
+ return this.check();
99
+ }
100
+ // eslint-disable-next-line max-params
101
+ set(m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33) {
102
+ this[0] = m00;
103
+ this[1] = m10;
104
+ this[2] = m20;
105
+ this[3] = m30;
106
+ this[4] = m01;
107
+ this[5] = m11;
108
+ this[6] = m21;
109
+ this[7] = m31;
110
+ this[8] = m02;
111
+ this[9] = m12;
112
+ this[10] = m22;
113
+ this[11] = m32;
114
+ this[12] = m03;
115
+ this[13] = m13;
116
+ this[14] = m23;
117
+ this[15] = m33;
118
+ return this.check();
119
+ }
120
+ // accepts row major order, stores as column major
121
+ // eslint-disable-next-line max-params
122
+ setRowMajor(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
123
+ this[0] = m00;
124
+ this[1] = m10;
125
+ this[2] = m20;
126
+ this[3] = m30;
127
+ this[4] = m01;
128
+ this[5] = m11;
129
+ this[6] = m21;
130
+ this[7] = m31;
131
+ this[8] = m02;
132
+ this[9] = m12;
133
+ this[10] = m22;
134
+ this[11] = m32;
135
+ this[12] = m03;
136
+ this[13] = m13;
137
+ this[14] = m23;
138
+ this[15] = m33;
139
+ return this.check();
140
+ }
141
+ toRowMajor(result) {
142
+ result[0] = this[0];
143
+ result[1] = this[4];
144
+ result[2] = this[8];
145
+ result[3] = this[12];
146
+ result[4] = this[1];
147
+ result[5] = this[5];
148
+ result[6] = this[9];
149
+ result[7] = this[13];
150
+ result[8] = this[2];
151
+ result[9] = this[6];
152
+ result[10] = this[10];
153
+ result[11] = this[14];
154
+ result[12] = this[3];
155
+ result[13] = this[7];
156
+ result[14] = this[11];
157
+ result[15] = this[15];
158
+ return result;
159
+ }
160
+ // Constructors
161
+ identity() {
162
+ return this.copy(IDENTITY);
163
+ }
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);
168
+ return this.check();
169
+ }
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 }) {
178
+ if (far === Infinity) {
179
+ Matrix4._computeInfinitePerspectiveOffCenter(this, left, right, bottom, top, near);
180
+ }
181
+ else {
182
+ mat4.frustum(this, left, right, bottom, top, near, far);
183
+ }
184
+ return this.check();
185
+ }
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];
225
+ mat4.lookAt(this, eye, center, up);
226
+ return this.check();
227
+ }
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 }) {
237
+ mat4.ortho(this, left, right, bottom, top, near, far);
238
+ return this.check();
239
+ }
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
+ }
251
+ const halfY = fovy / 2;
252
+ const top = focalDistance * Math.tan(halfY); // focus_plane is the distance from the camera
253
+ const right = top * aspect;
254
+ return new Matrix4().ortho({
255
+ left: -right,
256
+ right,
257
+ bottom: -top,
258
+ top,
259
+ near,
260
+ far
261
+ });
262
+ }
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
+ }
274
+ mat4.perspective(this, fovy, aspect, near, far);
275
+ return this.check();
276
+ }
277
+ // Accessors
278
+ determinant() {
279
+ return mat4.determinant(this);
280
+ }
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.
283
+ getScale(result = [-0, -0, -0]) {
284
+ // explicit is faster than hypot...
285
+ result[0] = Math.sqrt(this[0] * this[0] + this[1] * this[1] + this[2] * this[2]);
286
+ result[1] = Math.sqrt(this[4] * this[4] + this[5] * this[5] + this[6] * this[6]);
287
+ result[2] = Math.sqrt(this[8] * this[8] + this[9] * this[9] + this[10] * this[10]);
288
+ // result[0] = Math.hypot(this[0], this[1], this[2]);
289
+ // result[1] = Math.hypot(this[4], this[5], this[6]);
290
+ // result[2] = Math.hypot(this[8], this[9], this[10]);
291
+ return result;
292
+ }
293
+ // Gets the translation portion, assuming the matrix is a affine transformation matrix.
294
+ getTranslation(result = [-0, -0, -0]) {
295
+ result[0] = this[12];
296
+ result[1] = this[13];
297
+ result[2] = this[14];
298
+ return result;
299
+ }
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]);
303
+ const inverseScale0 = 1 / scale[0];
304
+ const inverseScale1 = 1 / scale[1];
305
+ const inverseScale2 = 1 / scale[2];
306
+ result[0] = this[0] * inverseScale0;
307
+ result[1] = this[1] * inverseScale1;
308
+ result[2] = this[2] * inverseScale2;
309
+ result[3] = 0;
310
+ result[4] = this[4] * inverseScale0;
311
+ result[5] = this[5] * inverseScale1;
312
+ result[6] = this[6] * inverseScale2;
313
+ result[7] = 0;
314
+ result[8] = this[8] * inverseScale0;
315
+ result[9] = this[9] * inverseScale1;
316
+ result[10] = this[10] * inverseScale2;
317
+ result[11] = 0;
318
+ result[12] = 0;
319
+ result[13] = 0;
320
+ result[14] = 0;
321
+ result[15] = 1;
322
+ return result;
323
+ }
324
+ getRotationMatrix3(result = [-0, -0, -0, -0, -0, -0, -0, -0, -0], scaleResult = null) {
325
+ const scale = this.getScale(scaleResult || [-0, -0, -0]);
326
+ const inverseScale0 = 1 / scale[0];
327
+ const inverseScale1 = 1 / scale[1];
328
+ const inverseScale2 = 1 / scale[2];
329
+ result[0] = this[0] * inverseScale0;
330
+ result[1] = this[1] * inverseScale1;
331
+ result[2] = this[2] * inverseScale2;
332
+ result[3] = this[4] * inverseScale0;
333
+ result[4] = this[5] * inverseScale1;
334
+ result[5] = this[6] * inverseScale2;
335
+ result[6] = this[8] * inverseScale0;
336
+ result[7] = this[9] * inverseScale1;
337
+ result[8] = this[10] * inverseScale2;
338
+ return result;
339
+ }
340
+ // Modifiers
341
+ transpose() {
342
+ mat4.transpose(this, this);
343
+ return this.check();
344
+ }
345
+ invert() {
346
+ mat4.invert(this, this);
347
+ return this.check();
348
+ }
349
+ // Operations
350
+ multiplyLeft(a) {
351
+ mat4.multiply(this, a, this);
352
+ return this.check();
353
+ }
354
+ multiplyRight(a) {
355
+ mat4.multiply(this, this, a);
356
+ return this.check();
357
+ }
358
+ // Rotates a matrix by the given angle around the X axis
359
+ rotateX(radians) {
360
+ mat4.rotateX(this, this, radians);
361
+ // mat4.rotate(this, this, radians, [1, 0, 0]);
362
+ return this.check();
363
+ }
364
+ // Rotates a matrix by the given angle around the Y axis.
365
+ rotateY(radians) {
366
+ mat4.rotateY(this, this, radians);
367
+ // mat4.rotate(this, this, radians, [0, 1, 0]);
368
+ return this.check();
369
+ }
370
+ // Rotates a matrix by the given angle around the Z axis.
371
+ rotateZ(radians) {
372
+ mat4.rotateZ(this, this, radians);
373
+ // mat4.rotate(this, this, radians, [0, 0, 1]);
374
+ return this.check();
375
+ }
376
+ rotateXYZ([rx, ry, rz]) {
377
+ return this.rotateX(rx).rotateY(ry).rotateZ(rz);
378
+ }
379
+ rotateAxis(radians, axis) {
380
+ mat4.rotate(this, this, radians, axis);
381
+ return this.check();
382
+ }
383
+ 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
+ }
390
+ return this.check();
391
+ }
392
+ translate(vec) {
393
+ mat4.translate(this, this, vec);
394
+ return this.check();
395
+ }
396
+ // Transforms
397
+ // Transforms any 2, 3 or 4 element vector. 2 and 3 elements are treated as points
398
+ transform(vector, result) {
399
+ if (vector.length === 4) {
400
+ result = vec4.transformMat4(result || [-0, -0, -0, -0], vector, this);
401
+ checkVector(result, 4);
402
+ return result;
403
+ }
404
+ return this.transformAsPoint(vector, result);
405
+ }
406
+ // Transforms any 2 or 3 element array as point (w implicitly 1)
407
+ transformAsPoint(vector, result) {
408
+ const { length } = vector;
409
+ switch (length) {
410
+ case 2:
411
+ result = vec2.transformMat4(result || [-0, -0], vector, this);
412
+ break;
413
+ case 3:
414
+ result = vec3.transformMat4(result || [-0, -0, -0], vector, this);
415
+ break;
416
+ default:
417
+ throw new Error('Illegal vector');
418
+ }
419
+ checkVector(result, vector.length);
420
+ return result;
421
+ }
422
+ // Transforms any 2 or 3 element array as vector (w implicitly 0)
423
+ transformAsVector(vector, result) {
424
+ switch (vector.length) {
425
+ case 2:
426
+ result = vec2_transformMat4AsVector(result || [-0, -0], vector, this);
427
+ break;
428
+ case 3:
429
+ result = vec3_transformMat4AsVector(result || [-0, -0, -0], vector, this);
430
+ break;
431
+ default:
432
+ throw new Error('Illegal vector');
433
+ }
434
+ checkVector(result, vector.length);
435
+ return result;
436
+ }
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
445
+ transformPoint(vector, result) {
446
+ deprecated('Matrix4.transformPoint', '3.0');
447
+ return this.transformAsPoint(vector, result);
448
+ }
449
+ transformVector(vector, result) {
450
+ deprecated('Matrix4.transformVector', '3.0');
451
+ return this.transformAsPoint(vector, result);
452
+ }
453
+ transformDirection(vector, result) {
454
+ deprecated('Matrix4.transformDirection', '3.0');
455
+ return this.transformAsVector(vector, result);
456
+ }
457
+ }
@@ -0,0 +1,37 @@
1
+ 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);
15
+ get x(): number;
16
+ set y(arg: number);
17
+ get y(): number;
18
+ set z(arg: number);
19
+ get z(): number;
20
+ set roll(arg: number);
21
+ get roll(): number;
22
+ set pitch(arg: number);
23
+ get pitch(): number;
24
+ set yaw(arg: number);
25
+ get yaw(): number;
26
+ getPosition(): Vector3;
27
+ 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
+ }
34
+ import Vector3 from "./vector3";
35
+ import Euler from "./euler";
36
+ import Matrix4 from "./matrix4";
37
+ //# sourceMappingURL=pose.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,126 @@
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 Matrix4 from './matrix4';
21
+ import Vector3 from './vector3';
22
+ import Euler from './euler';
23
+ export default class Pose {
24
+ // @ts-ignore TS2740: Type '{}' is missing the following properties from type
25
+ constructor({ x = 0, y = 0, z = 0, roll = 0, pitch = 0, yaw = 0, position = undefined, orientation = undefined } = {}) {
26
+ if (Array.isArray(position) && position.length === 3) {
27
+ this.position = new Vector3(position);
28
+ }
29
+ else {
30
+ this.position = new Vector3(x, y, z);
31
+ }
32
+ if (Array.isArray(orientation) && orientation.length === 4) {
33
+ this.orientation = new Euler(orientation, orientation[3]);
34
+ }
35
+ else {
36
+ this.orientation = new Euler(roll, pitch, yaw, Euler.RollPitchYaw);
37
+ }
38
+ }
39
+ get x() {
40
+ return this.position.x;
41
+ }
42
+ set x(value) {
43
+ this.position.x = value;
44
+ }
45
+ get y() {
46
+ return this.position.y;
47
+ }
48
+ set y(value) {
49
+ this.position.y = value;
50
+ }
51
+ get z() {
52
+ return this.position.z;
53
+ }
54
+ set z(value) {
55
+ this.position.z = value;
56
+ }
57
+ get roll() {
58
+ return this.orientation.roll;
59
+ }
60
+ set roll(value) {
61
+ this.orientation.roll = value;
62
+ }
63
+ get pitch() {
64
+ return this.orientation.pitch;
65
+ }
66
+ set pitch(value) {
67
+ this.orientation.pitch = value;
68
+ }
69
+ get yaw() {
70
+ return this.orientation.yaw;
71
+ }
72
+ set yaw(value) {
73
+ this.orientation.yaw = value;
74
+ }
75
+ getPosition() {
76
+ return this.position;
77
+ }
78
+ getOrientation() {
79
+ return this.orientation;
80
+ }
81
+ equals(pose) {
82
+ if (!pose) {
83
+ return false;
84
+ }
85
+ return this.position.equals(pose.position) && this.orientation.equals(pose.orientation);
86
+ }
87
+ exactEquals(pose) {
88
+ if (!pose) {
89
+ return false;
90
+ }
91
+ return (this.position.exactEquals(pose.position) && this.orientation.exactEquals(pose.orientation));
92
+ }
93
+ getTransformationMatrix() {
94
+ // setup precomputations for the sin/cos of the angles
95
+ const sr = Math.sin(this.roll);
96
+ const sp = Math.sin(this.pitch);
97
+ const sw = Math.sin(this.yaw);
98
+ const cr = Math.cos(this.roll);
99
+ const cp = Math.cos(this.pitch);
100
+ const cw = Math.cos(this.yaw);
101
+ const matrix = new Matrix4().setRowMajor(cw * cp, // 0,0
102
+ -sw * cr + cw * sp * sr, // 0,1
103
+ sw * sr + cw * sp * cr, // 0,2
104
+ this.x, // 0,3
105
+ sw * cp, // 1,0
106
+ cw * cr + sw * sp * sr, // 1,1
107
+ -cw * sr + sw * sp * cr, // 1,2
108
+ this.y, // 1,3
109
+ -sp, // 2,0
110
+ cp * sr, // 2,1
111
+ cp * cr, // 2,2
112
+ this.z, // 2,3
113
+ 0, 0, 0, 1);
114
+ return matrix;
115
+ }
116
+ getTransformationMatrixFromPose(pose) {
117
+ return new Matrix4()
118
+ .multiplyRight(this.getTransformationMatrix())
119
+ .multiplyRight(pose.getTransformationMatrix().invert());
120
+ }
121
+ getTransformationMatrixToPose(pose) {
122
+ return new Matrix4()
123
+ .multiplyRight(pose.getTransformationMatrix())
124
+ .multiplyRight(this.getTransformationMatrix().invert());
125
+ }
126
+ }
@@ -0,0 +1,42 @@
1
+ export default class Quaternion extends MathArray<any> {
2
+ constructor(x?: number, y?: number, z?: number, w?: number, ...args: any[]);
3
+ copy(array: any): any;
4
+ 0: any;
5
+ 1: any;
6
+ 2: any;
7
+ 3: any;
8
+ set(x: any, y: any, z: any, w: any): any;
9
+ fromMatrix3(m: any): any;
10
+ identity(): any;
11
+ fromAxisRotation(axis: any, rad: any): any;
12
+ setAxisAngle(axis: any, rad: any): any;
13
+ set x(arg: any);
14
+ get x(): any;
15
+ set y(arg: any);
16
+ get y(): any;
17
+ set z(arg: any);
18
+ get z(): any;
19
+ set w(arg: any);
20
+ get w(): any;
21
+ len(): any;
22
+ lengthSquared(): any;
23
+ dot(a: any, b: any): any;
24
+ rotationTo(vectorA: any, vectorB: any): any;
25
+ calculateW(): any;
26
+ conjugate(): any;
27
+ invert(): any;
28
+ multiplyRight(a: any, b: any): any;
29
+ multiplyLeft(a: any, b: any): any;
30
+ normalize(): any;
31
+ rotateX(rad: any): any;
32
+ rotateY(rad: any): any;
33
+ rotateZ(rad: any): any;
34
+ slerp(start: any, target: any, ratio: any, ...args: any[]): any;
35
+ transformVector4(vector: any, result?: any): any;
36
+ lengthSq(): any;
37
+ setFromAxisAngle(axis: any, rad: any): any;
38
+ premultiply(a: any, b: any): any;
39
+ multiply(a: any, b: any): any;
40
+ }
41
+ import MathArray from "./base/math-array";
42
+ //# sourceMappingURL=quaternion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quaternion.d.ts","sourceRoot":"","sources":["../../src/classes/quaternion.js"],"names":[],"mappings":"AA+BA;IACE,4EASC;IAED,sBAMC;IALC,OAAkB;IAClB,OAAkB;IAClB,OAAkB;IAClB,OAAkB;IAIpB,yCAMC;IAKD,yBAGC;IAGD,gBAGC;IAED,2CAGC;IASD,uCAEC;IAYD,gBAEC;IAND,aAEC;IAUD,gBAEC;IAND,aAEC;IAUD,gBAEC;IAND,aAEC;IAUD,gBAEC;IAND,aAEC;IASD,WAEC;IAGD,qBAEC;IAID,yBAKC;IAoBD,4CAGC;IAyBD,kBAGC;IAID,iBAGC;IAGD,cAGC;IASD,mCAIC;IAED,kCAIC;IAGD,iBAaC;IAGD,uBAGC;IAGD,uBAGC;IAGD,uBAGC;IASD,gEAgBC;IAED,iDAGC;IAGD,gBAEC;IAED,2CAEC;IAED,iCAEC;IAED,8BAEC;CACF"}