@math.gl/core 3.6.0-alpha.8 → 3.6.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.
@@ -1,114 +0,0 @@
1
- // Copyright (c) 2017 Uber Technologies, Inc.
2
- // MIT License
3
- import Vector from './base/vector';
4
- import { config, isArray } from '../lib/common';
5
- import { checkNumber } from '../lib/validators';
6
- import * as vec4 from 'gl-matrix/vec3';
7
- /* eslint-disable camelcase */
8
- import { vec4_transformMat2, vec4_transformMat3 } from '../lib/gl-matrix-extras';
9
- let ZERO;
10
- /**
11
- * Four-element vector class.
12
- * Subclass of Array<number>
13
- */
14
- export default class Vector4 extends Vector {
15
- static get ZERO() {
16
- if (!ZERO) {
17
- ZERO = new Vector4(0, 0, 0, 0);
18
- Object.freeze(ZERO);
19
- }
20
- return ZERO;
21
- }
22
- constructor(x = 0, y = 0, z = 0, w = 0) {
23
- // PERF NOTE: initialize elements as double precision numbers
24
- super(-0, -0, -0, -0);
25
- if (isArray(x) && arguments.length === 1) {
26
- this.copy(x);
27
- }
28
- else {
29
- // this.set(x, y, z, w);
30
- if (config.debug) {
31
- checkNumber(x);
32
- checkNumber(y);
33
- checkNumber(z);
34
- checkNumber(w);
35
- }
36
- this[0] = x;
37
- this[1] = y;
38
- this[2] = z;
39
- this[3] = w;
40
- }
41
- }
42
- set(x, y, z, w) {
43
- this[0] = x;
44
- this[1] = y;
45
- this[2] = z;
46
- this[3] = w;
47
- return this.check();
48
- }
49
- copy(array) {
50
- this[0] = array[0];
51
- this[1] = array[1];
52
- this[2] = array[2];
53
- this[3] = array[3];
54
- return this.check();
55
- }
56
- fromObject(object) {
57
- if (config.debug) {
58
- checkNumber(object.x);
59
- checkNumber(object.y);
60
- checkNumber(object.z);
61
- checkNumber(object.w);
62
- }
63
- this[0] = object.x;
64
- this[1] = object.y;
65
- this[2] = object.z;
66
- this[3] = object.w;
67
- return this;
68
- }
69
- toObject(object) {
70
- object.x = this[0];
71
- object.y = this[1];
72
- object.z = this[2];
73
- object.w = this[3];
74
- return object;
75
- }
76
- // Getters/setters
77
- /* eslint-disable no-multi-spaces, brace-style, no-return-assign */
78
- get ELEMENTS() {
79
- return 4;
80
- }
81
- get z() {
82
- return this[2];
83
- }
84
- set z(value) {
85
- this[2] = checkNumber(value);
86
- }
87
- get w() {
88
- return this[3];
89
- }
90
- set w(value) {
91
- this[3] = checkNumber(value);
92
- }
93
- transform(matrix4) {
94
- vec4.transformMat4(this, this, matrix4);
95
- return this.check();
96
- }
97
- transformByMatrix3(matrix3) {
98
- vec4_transformMat3(this, this, matrix3);
99
- return this.check();
100
- }
101
- transformByMatrix2(matrix2) {
102
- vec4_transformMat2(this, this, matrix2);
103
- return this.check();
104
- }
105
- transformByQuaternion(quaternion) {
106
- vec4.transformQuat(this, this, quaternion);
107
- return this.check();
108
- }
109
- // three.js compatibility
110
- applyMatrix4(m) {
111
- m.transform(this, this);
112
- return this;
113
- }
114
- }
package/dist/index.js DELETED
@@ -1,24 +0,0 @@
1
- // luma.gl, MIT license
2
- // classes
3
- export { default as Vector2 } from './classes/vector2';
4
- export { default as Vector3 } from './classes/vector3';
5
- export { default as Vector4 } from './classes/vector4';
6
- export { default as Matrix3 } from './classes/matrix3';
7
- export { default as Matrix4 } from './classes/matrix4';
8
- export { default as Quaternion } from './classes/quaternion';
9
- // experimental
10
- export { default as SphericalCoordinates } from './classes/spherical-coordinates';
11
- export { default as Pose } from './classes/pose';
12
- export { default as Euler } from './classes/euler';
13
- export { default as _MathUtils } from './lib/math-utils';
14
- // lib
15
- export { default as assert } from './lib/assert';
16
- export {
17
- // math.gl global utility methods
18
- config, configure, formatValue, isArray, clone, equals, exactEquals, toRadians, toDegrees,
19
- // math.gl "GLSL"-style functions
20
- radians, degrees, sin, cos, tan, asin, acos, atan, clamp, lerp, withEpsilon } from './lib/common';
21
- // DEPRECATED
22
- export { default as _SphericalCoordinates } from './classes/spherical-coordinates';
23
- export { default as _Pose } from './classes/pose';
24
- export { default as _Euler } from './classes/euler';
@@ -1,5 +0,0 @@
1
- export default function assert(condition, message) {
2
- if (!condition) {
3
- throw new Error(`math.gl assertion ${message}`);
4
- }
5
- }
@@ -1,210 +0,0 @@
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
- export const config = {
6
- EPSILON: 1e-12,
7
- debug: false,
8
- precision: 4,
9
- printTypes: false,
10
- printDegrees: false,
11
- printRowMajor: true
12
- };
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 } = {}) {
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
- }
@@ -1,49 +0,0 @@
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
- }
@@ -1,28 +0,0 @@
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
- };
@@ -1,33 +0,0 @@
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
- }