-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathutils.js
56 lines (49 loc) · 1.17 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
export default class Utils {
static atan2(x, y) {
let a = Math.atan2(x, y);
if (a < 0) {
a += 2 * Math.PI;
}
return a;
}
static cloneVars(vars) {
return Object.assign({}, vars);
}
static range(start, end) {
if (end === undefined) {
return [...Array(start).keys()];
}
return Array.from({ length: end - start }, (_, i) => i + start);
}
static pick(obj, keys) {
const newObj = {};
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
newObj[key] = obj[key] || 0;
}
return newObj;
}
static omit(obj, keys) {
const newObj = Object.assign({}, obj);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
delete newObj[key];
}
return newObj;
}
static setWasm(wasmGlobals, obj, keys) {
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
// eslint-disable-next-line no-param-reassign
wasmGlobals[key].value = obj[key];
}
}
static pickWasm(wasmGlobals, keys) {
const newObj = {};
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
newObj[key] = wasmGlobals[key].value;
}
return newObj;
}
}