@math.gl/core 3.5.6 → 3.6.0-alpha.2
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.
- package/dist/classes/base/math-array.d.ts +66 -0
- package/dist/classes/base/math-array.d.ts.map +1 -0
- package/dist/classes/base/math-array.js +216 -0
- package/dist/classes/base/matrix.d.ts +14 -0
- package/dist/classes/base/matrix.d.ts.map +1 -0
- package/dist/classes/base/matrix.js +61 -0
- package/dist/classes/base/vector.d.ts +44 -0
- package/dist/classes/base/vector.d.ts.map +1 -0
- package/dist/classes/base/vector.js +126 -0
- package/dist/classes/euler.d.ts +77 -0
- package/dist/classes/euler.d.ts.map +1 -0
- package/dist/classes/euler.js +485 -0
- package/dist/classes/matrix3.d.ts +60 -0
- package/dist/classes/matrix3.d.ts.map +1 -0
- package/dist/classes/matrix3.js +201 -0
- package/dist/classes/matrix4.d.ts +226 -0
- package/dist/classes/matrix4.d.ts.map +1 -0
- package/dist/classes/matrix4.js +538 -0
- package/dist/classes/pose.d.ts +40 -0
- package/dist/classes/pose.d.ts.map +1 -0
- package/dist/classes/pose.js +109 -0
- package/dist/classes/quaternion.d.ts +63 -0
- package/dist/classes/quaternion.d.ts.map +1 -0
- package/dist/classes/quaternion.js +262 -0
- package/dist/classes/spherical-coordinates.d.ts +60 -0
- package/dist/classes/spherical-coordinates.d.ts.map +1 -0
- package/dist/classes/spherical-coordinates.js +148 -0
- package/dist/classes/vector2.d.ts +55 -0
- package/dist/classes/vector2.d.ts.map +1 -0
- package/dist/classes/vector2.js +111 -0
- package/dist/classes/vector3.d.ts +56 -0
- package/dist/classes/vector3.d.ts.map +1 -0
- package/dist/classes/vector3.js +133 -0
- package/dist/classes/vector4.d.ts +41 -0
- package/dist/classes/vector4.d.ts.map +1 -0
- package/dist/classes/vector4.js +114 -0
- package/dist/es5/classes/base/math-array.js +57 -61
- package/dist/es5/classes/base/math-array.js.map +1 -1
- package/dist/es5/classes/base/matrix.js +0 -14
- package/dist/es5/classes/base/matrix.js.map +1 -1
- package/dist/es5/classes/base/vector.js +0 -12
- package/dist/es5/classes/base/vector.js.map +1 -1
- package/dist/es5/classes/euler.js +63 -49
- package/dist/es5/classes/euler.js.map +1 -1
- package/dist/es5/classes/matrix3.js +60 -33
- package/dist/es5/classes/matrix3.js.map +1 -1
- package/dist/es5/classes/matrix4.js +167 -164
- package/dist/es5/classes/matrix4.js.map +1 -1
- package/dist/es5/classes/pose.js +7 -6
- package/dist/es5/classes/pose.js.map +1 -1
- package/dist/es5/classes/quaternion.js +44 -36
- package/dist/es5/classes/quaternion.js.map +1 -1
- package/dist/es5/classes/spherical-coordinates.js +12 -8
- package/dist/es5/classes/spherical-coordinates.js.map +1 -1
- package/dist/es5/classes/vector2.js.map +1 -1
- package/dist/es5/classes/vector3.js +7 -2
- package/dist/es5/classes/vector3.js.map +1 -1
- package/dist/es5/classes/vector4.js +7 -2
- package/dist/es5/classes/vector4.js.map +1 -1
- package/dist/es5/docs/README.md +0 -0
- package/dist/es5/index.js +71 -89
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/assert.js.map +1 -1
- package/dist/es5/lib/common.js +40 -43
- package/dist/es5/lib/common.js.map +1 -1
- package/dist/es5/lib/gl-matrix-extras.js.map +1 -1
- package/dist/es5/lib/gl-matrix.d.js +2 -0
- package/dist/es5/lib/gl-matrix.d.js.map +1 -0
- package/dist/es5/lib/math-utils.js.map +1 -1
- package/dist/es5/lib/validators.js.map +1 -1
- package/dist/esm/classes/base/math-array.js +45 -47
- package/dist/esm/classes/base/math-array.js.map +1 -1
- package/dist/esm/classes/base/matrix.js +0 -11
- package/dist/esm/classes/base/matrix.js.map +1 -1
- package/dist/esm/classes/base/vector.js +0 -10
- package/dist/esm/classes/base/vector.js.map +1 -1
- package/dist/esm/classes/euler.js +61 -48
- package/dist/esm/classes/euler.js.map +1 -1
- package/dist/esm/classes/matrix3.js +55 -33
- package/dist/esm/classes/matrix3.js.map +1 -1
- package/dist/esm/classes/matrix4.js +156 -136
- package/dist/esm/classes/matrix4.js.map +1 -1
- package/dist/esm/classes/pose.js +8 -4
- package/dist/esm/classes/pose.js.map +1 -1
- package/dist/esm/classes/quaternion.js +37 -27
- package/dist/esm/classes/quaternion.js.map +1 -1
- package/dist/esm/classes/spherical-coordinates.js +15 -5
- package/dist/esm/classes/spherical-coordinates.js.map +1 -1
- package/dist/esm/classes/vector2.js.map +1 -1
- package/dist/esm/classes/vector3.js +7 -2
- package/dist/esm/classes/vector3.js.map +1 -1
- package/dist/esm/classes/vector4.js +7 -2
- package/dist/esm/classes/vector4.js.map +1 -1
- package/dist/esm/docs/README.md +0 -0
- package/dist/esm/index.js +2 -13
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/assert.js.map +1 -1
- package/dist/esm/lib/common.js +41 -44
- package/dist/esm/lib/common.js.map +1 -1
- package/dist/esm/lib/gl-matrix-extras.js.map +1 -1
- package/dist/esm/lib/gl-matrix.d.js +2 -0
- package/dist/esm/lib/gl-matrix.d.js.map +1 -0
- package/dist/esm/lib/math-utils.js.map +1 -1
- package/dist/esm/lib/validators.js.map +1 -1
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/lib/assert.d.ts +2 -0
- package/dist/lib/assert.d.ts.map +1 -0
- package/dist/lib/assert.js +5 -0
- package/dist/lib/common.d.ts +93 -0
- package/dist/lib/common.d.ts.map +1 -0
- package/dist/lib/common.js +210 -0
- package/dist/lib/gl-matrix-extras.d.ts +7 -0
- package/dist/lib/gl-matrix-extras.d.ts.map +1 -0
- package/dist/lib/gl-matrix-extras.js +49 -0
- package/dist/lib/math-utils.d.ts +28 -0
- package/dist/lib/math-utils.d.ts.map +1 -0
- package/dist/lib/math-utils.js +28 -0
- package/dist/lib/validators.d.ts +6 -0
- package/dist/lib/validators.d.ts.map +1 -0
- package/dist/lib/validators.js +33 -0
- package/package.json +5 -4
- package/src/classes/base/math-array.ts +265 -0
- package/src/classes/base/{matrix.js → matrix.ts} +15 -19
- package/src/classes/base/{vector.js → vector.ts} +47 -54
- package/src/classes/{euler.js → euler.ts} +121 -221
- package/src/classes/matrix3.ts +253 -0
- package/src/classes/matrix4.ts +668 -0
- package/src/classes/{pose.js → pose.ts} +52 -49
- package/src/classes/{quaternion.js → quaternion.ts} +107 -95
- package/src/classes/{spherical-coordinates.js → spherical-coordinates.ts} +84 -54
- package/src/classes/vector2.ts +127 -0
- package/src/classes/{vector3.js → vector3.ts} +43 -55
- package/src/classes/{vector4.js → vector4.ts} +44 -48
- package/src/docs/README.md +0 -0
- package/{dist/esm/index.d.ts → src/index.ts} +32 -34
- package/src/lib/{assert.js → assert.ts} +1 -1
- package/src/lib/common.ts +304 -0
- package/src/lib/{gl-matrix-extras.js → gl-matrix-extras.ts} +26 -5
- package/src/lib/gl-matrix.d.ts +266 -0
- package/src/lib/{math-utils.js → math-utils.ts} +0 -0
- package/src/lib/{validators.js → validators.ts} +10 -6
- package/dist/es5/addons/polygon.d.ts +0 -17
- package/dist/es5/classes/base/math-array.d.ts +0 -56
- package/dist/es5/classes/base/matrix.d.ts +0 -15
- package/dist/es5/classes/base/vector.d.ts +0 -45
- package/dist/es5/classes/euler.d.ts +0 -92
- package/dist/es5/classes/matrix3.d.ts +0 -91
- package/dist/es5/classes/matrix4.d.ts +0 -161
- package/dist/es5/classes/pose.d.ts +0 -92
- package/dist/es5/classes/quaternion.d.ts +0 -107
- package/dist/es5/classes/spherical-coordinates.d.ts +0 -87
- package/dist/es5/classes/vector2.d.ts +0 -65
- package/dist/es5/classes/vector3.d.ts +0 -65
- package/dist/es5/classes/vector4.d.ts +0 -34
- package/dist/es5/index.d.ts +0 -54
- package/dist/es5/lib/common.d.ts +0 -80
- package/dist/esm/addons/polygon.d.ts +0 -17
- package/dist/esm/classes/base/math-array.d.ts +0 -56
- package/dist/esm/classes/base/matrix.d.ts +0 -15
- package/dist/esm/classes/base/vector.d.ts +0 -45
- package/dist/esm/classes/euler.d.ts +0 -92
- package/dist/esm/classes/matrix3.d.ts +0 -91
- package/dist/esm/classes/matrix4.d.ts +0 -161
- package/dist/esm/classes/pose.d.ts +0 -92
- package/dist/esm/classes/quaternion.d.ts +0 -107
- package/dist/esm/classes/spherical-coordinates.d.ts +0 -87
- package/dist/esm/classes/vector2.d.ts +0 -65
- package/dist/esm/classes/vector3.d.ts +0 -65
- package/dist/esm/classes/vector4.d.ts +0 -34
- package/dist/esm/lib/common.d.ts +0 -80
- package/src/addons/polygon.d.ts +0 -17
- package/src/classes/base/math-array.d.ts +0 -56
- package/src/classes/base/math-array.js +0 -250
- package/src/classes/base/matrix.d.ts +0 -15
- package/src/classes/base/vector.d.ts +0 -45
- package/src/classes/euler.d.ts +0 -92
- package/src/classes/matrix3.d.ts +0 -91
- package/src/classes/matrix3.js +0 -225
- package/src/classes/matrix4.d.ts +0 -161
- package/src/classes/matrix4.js +0 -530
- package/src/classes/pose.d.ts +0 -92
- package/src/classes/quaternion.d.ts +0 -107
- package/src/classes/spherical-coordinates.d.ts +0 -87
- package/src/classes/vector2.d.ts +0 -65
- package/src/classes/vector2.js +0 -122
- package/src/classes/vector3.d.ts +0 -65
- package/src/classes/vector4.d.ts +0 -34
- package/src/index.d.ts +0 -54
- package/src/index.js +0 -86
- package/src/lib/common.d.ts +0 -80
- package/src/lib/common.js +0 -222
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import assert from './assert';
|
|
2
|
+
const RADIANS_TO_DEGREES = (1 / Math.PI) * 180;
|
|
3
|
+
const DEGREES_TO_RADIANS = (1 / 180) * Math.PI;
|
|
4
|
+
// TODO - remove
|
|
5
|
+
/* eslint-disable no-shadow */
|
|
6
|
+
export const config = {};
|
|
7
|
+
config.EPSILON = 1e-12;
|
|
8
|
+
config.debug = false;
|
|
9
|
+
config.precision = 4;
|
|
10
|
+
config.printTypes = false;
|
|
11
|
+
config.printDegrees = false;
|
|
12
|
+
config.printRowMajor = true;
|
|
13
|
+
export function configure(options = {}) {
|
|
14
|
+
// Only copy existing keys
|
|
15
|
+
for (const key in options) {
|
|
16
|
+
assert(key in config);
|
|
17
|
+
config[key] = options[key];
|
|
18
|
+
}
|
|
19
|
+
return config;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Formats a value into a string
|
|
23
|
+
* @param value
|
|
24
|
+
* @param param1
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
export function formatValue(value, { precision = config.precision || 4 } = {}) {
|
|
28
|
+
value = round(value);
|
|
29
|
+
// get rid of trailing zeros
|
|
30
|
+
return `${parseFloat(value.toPrecision(precision))}`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Check if value is an "array"
|
|
34
|
+
* Returns `true` if value is either an array or a typed array
|
|
35
|
+
*
|
|
36
|
+
* Note: returns `false` for `ArrayBuffer` and `DataView` instances
|
|
37
|
+
*/
|
|
38
|
+
export function isArray(value) {
|
|
39
|
+
return Array.isArray(value) || (ArrayBuffer.isView(value) && !(value instanceof DataView));
|
|
40
|
+
}
|
|
41
|
+
export function clone(array) {
|
|
42
|
+
return 'clone' in array ? array.clone() : array.slice();
|
|
43
|
+
}
|
|
44
|
+
export function toRadians(degrees) {
|
|
45
|
+
return radians(degrees);
|
|
46
|
+
}
|
|
47
|
+
export function toDegrees(radians) {
|
|
48
|
+
return degrees(radians);
|
|
49
|
+
}
|
|
50
|
+
export function radians(degrees, result) {
|
|
51
|
+
return map(degrees, (degrees) => degrees * DEGREES_TO_RADIANS, result);
|
|
52
|
+
}
|
|
53
|
+
export function degrees(radians, result) {
|
|
54
|
+
return map(radians, (radians) => radians * RADIANS_TO_DEGREES, result);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* "GLSL equivalent" of `Math.sin`: Works on single values and vectors
|
|
58
|
+
* @deprecated
|
|
59
|
+
*/
|
|
60
|
+
export function sin(radians, result) {
|
|
61
|
+
return map(radians, (angle) => Math.sin(angle), result);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* "GLSL equivalent" of `Math.cos`: Works on single values and vectors
|
|
65
|
+
* @deprecated
|
|
66
|
+
*/
|
|
67
|
+
export function cos(radians, result) {
|
|
68
|
+
return map(radians, (angle) => Math.cos(angle), result);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* "GLSL equivalent" of `Math.tan`: Works on single values and vectors
|
|
72
|
+
* @deprecated
|
|
73
|
+
*/
|
|
74
|
+
export function tan(radians, result) {
|
|
75
|
+
return map(radians, (angle) => Math.tan(angle), result);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* "GLSL equivalent" of `Math.asin`: Works on single values and vectors
|
|
79
|
+
* @deprecated
|
|
80
|
+
*/
|
|
81
|
+
export function asin(radians, result) {
|
|
82
|
+
return map(radians, (angle) => Math.asin(angle), result);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* "GLSL equivalent" of `Math.acos`: Works on single values and vectors
|
|
86
|
+
* @deprecated
|
|
87
|
+
*/
|
|
88
|
+
export function acos(radians, result) {
|
|
89
|
+
return map(radians, (angle) => Math.acos(angle), result);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* "GLSL equivalent" of `Math.atan`: Works on single values and vectors
|
|
93
|
+
* @deprecated
|
|
94
|
+
*/
|
|
95
|
+
export function atan(radians, result) {
|
|
96
|
+
return map(radians, (angle) => Math.atan(angle), result);
|
|
97
|
+
}
|
|
98
|
+
export function clamp(value, min, max) {
|
|
99
|
+
return map(value, (value) => Math.max(min, Math.min(max, value)));
|
|
100
|
+
}
|
|
101
|
+
export function lerp(a, b, t) {
|
|
102
|
+
if (isArray(a)) {
|
|
103
|
+
return a.map((ai, i) => lerp(ai, b[i], t));
|
|
104
|
+
}
|
|
105
|
+
return t * b + (1 - t) * a;
|
|
106
|
+
}
|
|
107
|
+
/* eslint-disable */
|
|
108
|
+
/**
|
|
109
|
+
* Compares any two math objects, using `equals` method if available.
|
|
110
|
+
* @param a
|
|
111
|
+
* @param b
|
|
112
|
+
* @param epsilon
|
|
113
|
+
* @returns
|
|
114
|
+
*/
|
|
115
|
+
export function equals(a, b, epsilon) {
|
|
116
|
+
const oldEpsilon = config.EPSILON;
|
|
117
|
+
if (epsilon) {
|
|
118
|
+
config.EPSILON = epsilon;
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
if (a === b) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
if (isArray(a) && isArray(b)) {
|
|
125
|
+
if (a.length !== b.length) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
for (let i = 0; i < a.length; ++i) {
|
|
129
|
+
// eslint-disable-next-line max-depth
|
|
130
|
+
if (!equals(a[i], b[i])) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
if (a && a.equals) {
|
|
137
|
+
return a.equals(b);
|
|
138
|
+
}
|
|
139
|
+
if (b && b.equals) {
|
|
140
|
+
return b.equals(a);
|
|
141
|
+
}
|
|
142
|
+
if (typeof a === 'number' && typeof b === 'number') {
|
|
143
|
+
return Math.abs(a - b) <= config.EPSILON * Math.max(1, Math.abs(a), Math.abs(b));
|
|
144
|
+
}
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
config.EPSILON = oldEpsilon;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
export function exactEquals(a, b) {
|
|
152
|
+
if (a === b) {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
if (a && typeof a === 'object' && b && typeof b === 'object') {
|
|
156
|
+
if (a.constructor !== b.constructor) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
if (a.exactEquals) {
|
|
160
|
+
return a.exactEquals(b);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (isArray(a) && isArray(b)) {
|
|
164
|
+
if (a.length !== b.length) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
for (let i = 0; i < a.length; ++i) {
|
|
168
|
+
if (!exactEquals(a[i], b[i])) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
/* eslint-enable */
|
|
177
|
+
export function withEpsilon(epsilon, func) {
|
|
178
|
+
const oldPrecision = config.EPSILON;
|
|
179
|
+
config.EPSILON = epsilon;
|
|
180
|
+
let value;
|
|
181
|
+
try {
|
|
182
|
+
value = func();
|
|
183
|
+
}
|
|
184
|
+
finally {
|
|
185
|
+
config.EPSILON = oldPrecision;
|
|
186
|
+
}
|
|
187
|
+
return value;
|
|
188
|
+
}
|
|
189
|
+
// HELPERS
|
|
190
|
+
function round(value) {
|
|
191
|
+
return Math.round(value / config.EPSILON) * config.EPSILON;
|
|
192
|
+
}
|
|
193
|
+
// If the array has a clone function, calls it, otherwise returns a copy
|
|
194
|
+
function duplicateArray(array) {
|
|
195
|
+
// @ts-expect-error We check for math.gl class methods
|
|
196
|
+
return array.clone ? array.clone() : new Array(array.length);
|
|
197
|
+
}
|
|
198
|
+
// If the argument value is an array, applies the func element wise,
|
|
199
|
+
// otherwise applies func to the argument value
|
|
200
|
+
function map(value, func, result) {
|
|
201
|
+
if (isArray(value)) {
|
|
202
|
+
const array = value;
|
|
203
|
+
result = result || duplicateArray(array);
|
|
204
|
+
for (let i = 0; i < result.length && i < array.length; ++i) {
|
|
205
|
+
result[i] = func(value[i], i, result);
|
|
206
|
+
}
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
return func(value);
|
|
210
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NumericArray } from '@math.gl/types';
|
|
2
|
+
export declare function vec2_transformMat4AsVector<T extends NumericArray>(out: T, a: Readonly<NumericArray>, m: Readonly<NumericArray>): T;
|
|
3
|
+
export declare function vec3_transformMat4AsVector<T extends NumericArray>(out: T, a: Readonly<NumericArray>, m: Readonly<NumericArray>): T;
|
|
4
|
+
export declare function vec3_transformMat2<T extends NumericArray>(out: T, a: Readonly<NumericArray>, m: Readonly<NumericArray>): T;
|
|
5
|
+
export declare function vec4_transformMat2<T extends NumericArray>(out: T, a: Readonly<NumericArray>, m: Readonly<NumericArray>): T;
|
|
6
|
+
export declare function vec4_transformMat3<T extends NumericArray>(out: T, a: Readonly<NumericArray>, m: Readonly<NumericArray>): T;
|
|
7
|
+
//# sourceMappingURL=gl-matrix-extras.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gl-matrix-extras.d.ts","sourceRoot":"","sources":["../../src/lib/gl-matrix-extras.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAG5C,wBAAgB,0BAA0B,CAAC,CAAC,SAAS,YAAY,EAC/D,GAAG,EAAE,CAAC,EACN,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,EACzB,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,GACxB,CAAC,CAOH;AAKD,wBAAgB,0BAA0B,CAAC,CAAC,SAAS,YAAY,EAC/D,GAAG,EAAE,CAAC,EACN,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,EACzB,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,GACxB,CAAC,CASH;AAED,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,YAAY,EACvD,GAAG,EAAE,CAAC,EACN,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,EACzB,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,GACxB,CAAC,CAOH;AAID,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,YAAY,EACvD,GAAG,EAAE,CAAC,EACN,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,EACzB,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,GACxB,CAAC,CAQH;AAED,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,YAAY,EACvD,GAAG,EAAE,CAAC,EACN,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,EACzB,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,GACxB,CAAC,CASH"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// vec2 additions
|
|
2
|
+
export function vec2_transformMat4AsVector(out, a, m) {
|
|
3
|
+
const x = a[0];
|
|
4
|
+
const y = a[1];
|
|
5
|
+
const w = m[3] * x + m[7] * y || 1.0;
|
|
6
|
+
out[0] = (m[0] * x + m[4] * y) / w;
|
|
7
|
+
out[1] = (m[1] * x + m[5] * y) / w;
|
|
8
|
+
return out;
|
|
9
|
+
}
|
|
10
|
+
// vec3 additions
|
|
11
|
+
// Transform as vector, only uses 3x3 minor matrix
|
|
12
|
+
export function vec3_transformMat4AsVector(out, a, m) {
|
|
13
|
+
const x = a[0];
|
|
14
|
+
const y = a[1];
|
|
15
|
+
const z = a[2];
|
|
16
|
+
const w = m[3] * x + m[7] * y + m[11] * z || 1.0;
|
|
17
|
+
out[0] = (m[0] * x + m[4] * y + m[8] * z) / w;
|
|
18
|
+
out[1] = (m[1] * x + m[5] * y + m[9] * z) / w;
|
|
19
|
+
out[2] = (m[2] * x + m[6] * y + m[10] * z) / w;
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
export function vec3_transformMat2(out, a, m) {
|
|
23
|
+
const x = a[0];
|
|
24
|
+
const y = a[1];
|
|
25
|
+
out[0] = m[0] * x + m[2] * y;
|
|
26
|
+
out[1] = m[1] * x + m[3] * y;
|
|
27
|
+
out[2] = a[2];
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
// vec4 additions
|
|
31
|
+
export function vec4_transformMat2(out, a, m) {
|
|
32
|
+
const x = a[0];
|
|
33
|
+
const y = a[1];
|
|
34
|
+
out[0] = m[0] * x + m[2] * y;
|
|
35
|
+
out[1] = m[1] * x + m[3] * y;
|
|
36
|
+
out[2] = a[2];
|
|
37
|
+
out[3] = a[3];
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
export function vec4_transformMat3(out, a, m) {
|
|
41
|
+
const x = a[0];
|
|
42
|
+
const y = a[1];
|
|
43
|
+
const z = a[2];
|
|
44
|
+
out[0] = m[0] * x + m[3] * y + m[6] * z;
|
|
45
|
+
out[1] = m[1] * x + m[4] * y + m[7] * z;
|
|
46
|
+
out[2] = m[2] * x + m[5] * y + m[8] * z;
|
|
47
|
+
out[3] = a[3];
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
EPSILON1: number;
|
|
3
|
+
EPSILON2: number;
|
|
4
|
+
EPSILON3: number;
|
|
5
|
+
EPSILON4: number;
|
|
6
|
+
EPSILON5: number;
|
|
7
|
+
EPSILON6: number;
|
|
8
|
+
EPSILON7: number;
|
|
9
|
+
EPSILON8: number;
|
|
10
|
+
EPSILON9: number;
|
|
11
|
+
EPSILON10: number;
|
|
12
|
+
EPSILON11: number;
|
|
13
|
+
EPSILON12: number;
|
|
14
|
+
EPSILON13: number;
|
|
15
|
+
EPSILON14: number;
|
|
16
|
+
EPSILON15: number;
|
|
17
|
+
EPSILON16: number;
|
|
18
|
+
EPSILON17: number;
|
|
19
|
+
EPSILON18: number;
|
|
20
|
+
EPSILON19: number;
|
|
21
|
+
EPSILON20: number;
|
|
22
|
+
PI_OVER_TWO: number;
|
|
23
|
+
PI_OVER_FOUR: number;
|
|
24
|
+
PI_OVER_SIX: number;
|
|
25
|
+
TWO_PI: number;
|
|
26
|
+
};
|
|
27
|
+
export default _default;
|
|
28
|
+
//# sourceMappingURL=math-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math-utils.d.ts","sourceRoot":"","sources":["../../src/lib/math-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,wBA2BE"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// NOTE: Added to make Cesium-derived test cases work
|
|
2
|
+
// TODO: Determine if/how to keep
|
|
3
|
+
export default {
|
|
4
|
+
EPSILON1: 1e-1,
|
|
5
|
+
EPSILON2: 1e-2,
|
|
6
|
+
EPSILON3: 1e-3,
|
|
7
|
+
EPSILON4: 1e-4,
|
|
8
|
+
EPSILON5: 1e-5,
|
|
9
|
+
EPSILON6: 1e-6,
|
|
10
|
+
EPSILON7: 1e-7,
|
|
11
|
+
EPSILON8: 1e-8,
|
|
12
|
+
EPSILON9: 1e-9,
|
|
13
|
+
EPSILON10: 1e-10,
|
|
14
|
+
EPSILON11: 1e-11,
|
|
15
|
+
EPSILON12: 1e-12,
|
|
16
|
+
EPSILON13: 1e-13,
|
|
17
|
+
EPSILON14: 1e-14,
|
|
18
|
+
EPSILON15: 1e-15,
|
|
19
|
+
EPSILON16: 1e-16,
|
|
20
|
+
EPSILON17: 1e-17,
|
|
21
|
+
EPSILON18: 1e-18,
|
|
22
|
+
EPSILON19: 1e-19,
|
|
23
|
+
EPSILON20: 1e-20,
|
|
24
|
+
PI_OVER_TWO: Math.PI / 2,
|
|
25
|
+
PI_OVER_FOUR: Math.PI / 4,
|
|
26
|
+
PI_OVER_SIX: Math.PI / 6,
|
|
27
|
+
TWO_PI: Math.PI * 2
|
|
28
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { NumberArray } from '@math.gl/types';
|
|
2
|
+
export declare function validateVector(v: NumberArray, length: number): boolean;
|
|
3
|
+
export declare function checkNumber(value: any): number;
|
|
4
|
+
export declare function checkVector<T extends NumberArray>(v: T, length: number, callerName?: string): T;
|
|
5
|
+
export declare function deprecated(method: string, version: string): void;
|
|
6
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/lib/validators.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAG3C,wBAAgB,cAAc,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAWtE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,GAAG,GAAG,MAAM,CAK9C;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,WAAW,EAC/C,CAAC,EAAE,CAAC,EACJ,MAAM,EAAE,MAAM,EACd,UAAU,GAAE,MAAW,GACtB,CAAC,CAKH;AAID,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAQhE"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { config } from './common';
|
|
2
|
+
export function validateVector(v, length) {
|
|
3
|
+
if (v.length !== length) {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
// Could be arguments "array" (v.every not availasble)
|
|
7
|
+
for (let i = 0; i < v.length; ++i) {
|
|
8
|
+
if (!Number.isFinite(v[i])) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
export function checkNumber(value) {
|
|
15
|
+
if (!Number.isFinite(value)) {
|
|
16
|
+
throw new Error(`Invalid number ${value}`);
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
export function checkVector(v, length, callerName = '') {
|
|
21
|
+
if (config.debug && !validateVector(v, length)) {
|
|
22
|
+
throw new Error(`math.gl: ${callerName} some fields set to invalid numbers'`);
|
|
23
|
+
}
|
|
24
|
+
return v;
|
|
25
|
+
}
|
|
26
|
+
const map = {};
|
|
27
|
+
export function deprecated(method, version) {
|
|
28
|
+
if (!map[method]) {
|
|
29
|
+
map[method] = true;
|
|
30
|
+
// eslint-disable-next-line
|
|
31
|
+
console.warn(`${method} has been removed in version ${version}, see upgrade guide for more information`);
|
|
32
|
+
}
|
|
33
|
+
}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "3.
|
|
8
|
+
"version": "3.6.0-alpha.2",
|
|
9
9
|
"keywords": [
|
|
10
10
|
"webgl",
|
|
11
11
|
"javascript",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"type": "git",
|
|
27
27
|
"url": "https://github.com/uber-web/math.gl.git"
|
|
28
28
|
},
|
|
29
|
-
"types": "src/index.
|
|
29
|
+
"types": "src/index.ts",
|
|
30
30
|
"main": "dist/es5/index.js",
|
|
31
31
|
"module": "dist/esm/index.js",
|
|
32
32
|
"files": [
|
|
@@ -38,7 +38,8 @@
|
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@babel/runtime": "^7.12.0",
|
|
41
|
-
"gl
|
|
41
|
+
"@math.gl/types": "3.6.0-alpha.2",
|
|
42
|
+
"gl-matrix": "^3.4.0"
|
|
42
43
|
},
|
|
43
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "ea7dc265c98b68af56218302d1d42b7d65f74ccb"
|
|
44
45
|
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
// math.gl, MIT License
|
|
2
|
+
import {NumericArray} from '@math.gl/types';
|
|
3
|
+
import {ConfigurationOptions, config, formatValue, equals, isArray} from '../../lib/common';
|
|
4
|
+
|
|
5
|
+
/** Base class for vectors and matrices */
|
|
6
|
+
export default abstract class MathArray extends Array<number> {
|
|
7
|
+
/** Number of elements (values) in this array */
|
|
8
|
+
abstract get ELEMENTS(): number;
|
|
9
|
+
|
|
10
|
+
abstract copy(vector: Readonly<NumericArray>): this;
|
|
11
|
+
|
|
12
|
+
abstract fromObject(object: object): this;
|
|
13
|
+
|
|
14
|
+
// Common methods
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Clone the current object
|
|
18
|
+
* @returns a new copy of this object
|
|
19
|
+
*/
|
|
20
|
+
clone(): this {
|
|
21
|
+
// @ts-expect-error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
|
|
22
|
+
return new this.constructor().copy(this); // eslint-disable-line
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
fromArray(array: Readonly<NumericArray>, offset: number = 0): this {
|
|
26
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
27
|
+
this[i] = array[i + offset];
|
|
28
|
+
}
|
|
29
|
+
return this.check();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
toArray<TypedArray>(targetArray: TypedArray, offset?: number): TypedArray;
|
|
33
|
+
toArray(targetArray?: number[], offset?: number): NumericArray;
|
|
34
|
+
|
|
35
|
+
toArray(targetArray: NumericArray = [], offset: number = 0): NumericArray {
|
|
36
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
37
|
+
targetArray[offset + i] = this[i];
|
|
38
|
+
}
|
|
39
|
+
return targetArray;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
from(arrayOrObject: Readonly<NumericArray> | object): this {
|
|
43
|
+
return Array.isArray(arrayOrObject) ? this.copy(arrayOrObject) : this.fromObject(arrayOrObject);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
to<T extends NumericArray | object>(arrayOrObject: T): T {
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
if (arrayOrObject === this) {
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
// @ts-expect-error TS2339: Property 'toObject' does not exist on type 'MathArray'.
|
|
52
|
+
return isArray(arrayOrObject) ? this.toArray(arrayOrObject) : this.toObject(arrayOrObject);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
toTarget(target: any): any {
|
|
56
|
+
return target ? this.to(target) : this;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** @deprecated */
|
|
60
|
+
toFloat32Array(): Float32Array {
|
|
61
|
+
return new Float32Array(this);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
toString(): string {
|
|
65
|
+
return this.formatString(config);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Formats string according to options */
|
|
69
|
+
formatString(opts: ConfigurationOptions): string {
|
|
70
|
+
let string = '';
|
|
71
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
72
|
+
string += (i > 0 ? ', ' : '') + formatValue(this[i], opts);
|
|
73
|
+
}
|
|
74
|
+
return `${opts.printTypes ? this.constructor.name : ''}[${string}]`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
equals(array: Readonly<NumericArray>): boolean {
|
|
78
|
+
if (!array || this.length !== array.length) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
82
|
+
if (!equals(this[i], array[i])) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
exactEquals(array: Readonly<NumericArray>): boolean {
|
|
90
|
+
if (!array || this.length !== array.length) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
94
|
+
if (this[i] !== array[i]) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Modifiers
|
|
102
|
+
|
|
103
|
+
/** Negates all values in this object */
|
|
104
|
+
negate(): this {
|
|
105
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
106
|
+
this[i] = -this[i];
|
|
107
|
+
}
|
|
108
|
+
return this.check();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Linearly interpolates between two values */
|
|
112
|
+
lerp(a: Readonly<NumericArray>, t: number): this;
|
|
113
|
+
lerp(a: Readonly<NumericArray>, b: Readonly<NumericArray>, t: number): this;
|
|
114
|
+
|
|
115
|
+
lerp(a: Readonly<NumericArray>, b: Readonly<NumericArray> | number, t?: number): this {
|
|
116
|
+
if (t === undefined) {
|
|
117
|
+
return this.lerp(this, a, b as number);
|
|
118
|
+
}
|
|
119
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
120
|
+
const ai = a[i];
|
|
121
|
+
this[i] = ai + t * (b[i] - ai);
|
|
122
|
+
}
|
|
123
|
+
return this.check();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Minimal */
|
|
127
|
+
min(vector: Readonly<NumericArray>): this {
|
|
128
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
129
|
+
this[i] = Math.min(vector[i], this[i]);
|
|
130
|
+
}
|
|
131
|
+
return this.check();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Maximal */
|
|
135
|
+
max(vector: Readonly<NumericArray>): this {
|
|
136
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
137
|
+
this[i] = Math.max(vector[i], this[i]);
|
|
138
|
+
}
|
|
139
|
+
return this.check();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
clamp(minVector: Readonly<NumericArray>, maxVector: Readonly<NumericArray>): this {
|
|
143
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
144
|
+
this[i] = Math.min(Math.max(this[i], minVector[i]), maxVector[i]);
|
|
145
|
+
}
|
|
146
|
+
return this.check();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
add(...vectors: Readonly<NumericArray>[]): this {
|
|
150
|
+
for (const vector of vectors) {
|
|
151
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
152
|
+
this[i] += vector[i];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return this.check();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
subtract(...vectors: Readonly<NumericArray>[]): this {
|
|
159
|
+
for (const vector of vectors) {
|
|
160
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
161
|
+
this[i] -= vector[i];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return this.check();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
scale(scale: number | Readonly<NumericArray>): this {
|
|
168
|
+
if (typeof scale === 'number') {
|
|
169
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
170
|
+
this[i] *= scale;
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
for (let i = 0; i < this.ELEMENTS && i < scale.length; ++i) {
|
|
174
|
+
this[i] *= scale[i];
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return this.check();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Multiplies all elements by `scale`
|
|
182
|
+
* Note: `Matrix4.multiplyByScalar` only scales its 3x3 "minor"
|
|
183
|
+
*/
|
|
184
|
+
multiplyByScalar(scalar: number): this {
|
|
185
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
186
|
+
this[i] *= scalar;
|
|
187
|
+
}
|
|
188
|
+
return this.check();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Debug checks
|
|
192
|
+
|
|
193
|
+
/** Throws an error if array length is incorrect or contains illegal values */
|
|
194
|
+
check(): this {
|
|
195
|
+
if (config.debug && !this.validate()) {
|
|
196
|
+
throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);
|
|
197
|
+
}
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Returns false if the array length is incorrect or contains illegal values */
|
|
202
|
+
validate(): boolean {
|
|
203
|
+
let valid = this.length === this.ELEMENTS;
|
|
204
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
205
|
+
valid = valid && Number.isFinite(this[i]);
|
|
206
|
+
}
|
|
207
|
+
return valid;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// three.js compatibility
|
|
211
|
+
|
|
212
|
+
/** @deprecated */
|
|
213
|
+
sub(a: Readonly<NumericArray>): this {
|
|
214
|
+
return this.subtract(a);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** @deprecated */
|
|
218
|
+
setScalar(a: number): this {
|
|
219
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
220
|
+
this[i] = a;
|
|
221
|
+
}
|
|
222
|
+
return this.check();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** @deprecated */
|
|
226
|
+
addScalar(a: number): this {
|
|
227
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
228
|
+
this[i] += a;
|
|
229
|
+
}
|
|
230
|
+
return this.check();
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** @deprecated */
|
|
234
|
+
subScalar(a: number): this {
|
|
235
|
+
return this.addScalar(-a);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** @deprecated */
|
|
239
|
+
multiplyScalar(scalar: number): this {
|
|
240
|
+
// Multiplies all elements
|
|
241
|
+
// `Matrix4.scale` only scales its 3x3 "minor"
|
|
242
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
243
|
+
this[i] *= scalar;
|
|
244
|
+
}
|
|
245
|
+
return this.check();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** @deprecated */
|
|
249
|
+
divideScalar(a: number): this {
|
|
250
|
+
return this.multiplyByScalar(1 / a);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** @deprecated */
|
|
254
|
+
clampScalar(min: number, max: number): this {
|
|
255
|
+
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
256
|
+
this[i] = Math.min(Math.max(this[i], min), max);
|
|
257
|
+
}
|
|
258
|
+
return this.check();
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** @deprecated */
|
|
262
|
+
get elements(): NumericArray {
|
|
263
|
+
return this;
|
|
264
|
+
}
|
|
265
|
+
}
|