ziko 0.51.1 → 0.52.0
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/ziko.cjs +1638 -1456
- package/dist/ziko.js +853 -810
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +853 -810
- package/package.json +1 -1
- package/src/{__helpers__ → helpers}/register/index.js +1 -1
- package/src/hooks/use-ipc.js +1 -3
- package/src/math/adapted/index.js +7 -0
- package/src/math/complex/index.js +5 -2
- package/src/math/functions/helper.js +68 -17
- package/src/math/functions/index.js +3 -2
- package/src/math/functions/primitives/index.js +176 -0
- package/src/math/mapfun/index.js +19 -0
- package/src/math/utils/index.js +1 -1
- package/src/math/utils/mapfun.js +30 -30
- package/src/ui/constructors/UIElement.js +9 -9
- package/src/ui/constructors/UIElementCore.js +2 -2
- package/types/math/adapted/index.d.ts +4 -0
- package/types/math/complex/index.d.ts +1 -1
- package/types/math/mapfun/index.d.ts +87 -0
- /package/src/{__helpers__ → helpers}/checkers/index.js +0 -0
- /package/src/{__helpers__ → helpers}/index.js +0 -0
- /package/src/{__helpers__ → helpers}/register/register-to-class.js +0 -0
- /package/src/{__helpers__ → helpers}/register/register-to-instance.js +0 -0
package/dist/ziko.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/*
|
|
3
3
|
Project: ziko.js
|
|
4
4
|
Author: Zakaria Elalaoui
|
|
5
|
-
Date :
|
|
5
|
+
Date : Fri Dec 05 2025 11:33:57 GMT+0100 (UTC+01:00)
|
|
6
6
|
Git-Repo : https://github.com/zakarialaoui10/ziko.js
|
|
7
7
|
Git-Wiki : https://github.com/zakarialaoui10/ziko.js/wiki
|
|
8
8
|
Released under MIT License
|
|
@@ -13,87 +13,340 @@
|
|
|
13
13
|
const { PI: PI$2, E } = Math;
|
|
14
14
|
const EPSILON=Number.EPSILON;
|
|
15
15
|
|
|
16
|
-
const {PI: PI$1, cos: cos$3, sin: sin$3, tan: tan$1,
|
|
16
|
+
const {PI: PI$1, cos: cos$3, sin: sin$3, tan: tan$1, atan: atan$1, cosh: cosh$2, sinh: sinh$2, tanh: tanh$1, acosh: acosh$1, asinh: asinh$1, atanh: atanh$1, log: log$1} = Math;
|
|
17
17
|
let Fixed={
|
|
18
|
-
cos:
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
cos : x=> {
|
|
19
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
20
|
+
cos$3(x.a)*cosh$2(x.b),
|
|
21
|
+
-(sin$3(x.a)*sinh$2(x.b))
|
|
22
|
+
);
|
|
23
|
+
return cos$3(x)
|
|
24
|
+
},
|
|
25
|
+
sin : x=>{
|
|
26
|
+
if(x?.isComplex) return new x.constructor(
|
|
27
|
+
sin$3(x.a)*cosh$2(x.b),
|
|
28
|
+
cos$3(x.a)*sinh$2(x.b)
|
|
29
|
+
);
|
|
30
|
+
return sin$3(x)
|
|
31
|
+
},
|
|
32
|
+
tan : x=>{
|
|
33
|
+
if(x?.isComplex){
|
|
34
|
+
const DEN = cos$3(2*x.a)+cosh$2(2*x.b);
|
|
35
|
+
return new x.constructor(
|
|
36
|
+
sin$3(2*x.a)/DEN,
|
|
37
|
+
sinh$2(2*x.b)/DEN
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return tan$1(x)
|
|
41
|
+
},
|
|
21
42
|
sinc: x => sin$3(PI$1*x)/(PI$1*x),
|
|
22
43
|
sec: x => 1/cos$3(x),
|
|
23
44
|
csc: x => 1/sin$3(x),
|
|
24
45
|
cot: x => 1/tan$1(x),
|
|
25
|
-
acos:
|
|
26
|
-
|
|
27
|
-
|
|
46
|
+
acos: x=>{
|
|
47
|
+
if(x?.isComplex) return
|
|
48
|
+
return sin$3(x)
|
|
49
|
+
},
|
|
50
|
+
asin: x=>{
|
|
51
|
+
if(x?.isComplex) return
|
|
52
|
+
return sin$3(x)
|
|
53
|
+
},
|
|
54
|
+
atan: x=>{
|
|
55
|
+
if(x?.isComplex) return
|
|
56
|
+
return sin$3(x)
|
|
57
|
+
},
|
|
28
58
|
acot: x => PI$1/2-atan$1(x),
|
|
29
|
-
cosh:
|
|
30
|
-
|
|
31
|
-
|
|
59
|
+
cosh: x=>{
|
|
60
|
+
if(x?.isComplex) return new x.constructor(
|
|
61
|
+
cosh$2(x.a)*cos$3(x.b),
|
|
62
|
+
sinh$2(x.a)*sin$3(x.b)
|
|
63
|
+
);
|
|
64
|
+
return cosh$2(x)
|
|
65
|
+
},
|
|
66
|
+
sinh: x=>{
|
|
67
|
+
if(x?.isComplex) return new x.constructor(
|
|
68
|
+
sinh$2(x.a)*cos$3(x.b),
|
|
69
|
+
cosh$2(x.a)*sin$3(x.b)
|
|
70
|
+
);
|
|
71
|
+
return sinh$2(x)
|
|
72
|
+
},
|
|
73
|
+
tanh: x=>{
|
|
74
|
+
if(x?.isComplex){
|
|
75
|
+
const DEN=cosh$2(2*a)+cos$3(2*b);
|
|
76
|
+
return new x.constructor(
|
|
77
|
+
sinh$2(2*a)/DEN,
|
|
78
|
+
sin$3(2*b)/DEN
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
return tanh$1(x)
|
|
82
|
+
},
|
|
32
83
|
coth: n => (1/2*log$1((1+n)/(1-n))),
|
|
33
84
|
acosh: acosh$1,
|
|
34
85
|
asinh: asinh$1,
|
|
35
86
|
atanh: atanh$1,
|
|
36
87
|
};
|
|
37
88
|
|
|
38
|
-
Fixed = new Proxy(Fixed, {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
})
|
|
89
|
+
// Fixed = new Proxy(Fixed, {
|
|
90
|
+
// get(target, prop) {
|
|
91
|
+
// if(prop in target){
|
|
92
|
+
// return x => + target[prop](x).toFixed(15);
|
|
93
|
+
// }
|
|
94
|
+
// return undefined;
|
|
95
|
+
// }
|
|
96
|
+
// })
|
|
46
97
|
|
|
47
|
-
// To generalise
|
|
48
|
-
|
|
49
98
|
const mapfun$1=(fun,...X)=>{
|
|
50
99
|
const Y=X.map(x=>{
|
|
51
|
-
if(
|
|
52
|
-
|
|
100
|
+
if(
|
|
101
|
+
x===null||
|
|
102
|
+
["number","string","boolean","bigint","undefined"].includes(typeof x)||
|
|
103
|
+
x?.__mapfun__
|
|
104
|
+
) return fun(x)
|
|
53
105
|
if(x instanceof Array) return x.map(n=>mapfun$1(fun,n));
|
|
54
106
|
if(ArrayBuffer.isView(x)) return x.map(n=>fun(n));
|
|
55
107
|
if(x instanceof Set) return new Set(mapfun$1(fun,...[...x]));
|
|
56
108
|
if(x instanceof Map) return new Map([...x].map(n=>[n[0],mapfun$1(fun,n[1])]));
|
|
57
|
-
if(x
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
109
|
+
if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, mapfun$1(x.arr.flat(1)))
|
|
110
|
+
// if(x.isComplex?.()){
|
|
111
|
+
// const [a,b,z,phi]=[x.a,x.b,x.z,x.phi];
|
|
112
|
+
// switch(fun){
|
|
113
|
+
// // Moved to Fixed to avoid Circular Dep
|
|
114
|
+
// // case Math.log: return new x.constructor(ln(z),phi); // Done
|
|
115
|
+
// // case Math.exp: return new x.constructor(e(a)*cos(b),e(a)*sin(b)); // Done
|
|
116
|
+
// // case Math.abs: return z; // Done
|
|
117
|
+
// // case Math.sqrt: return new x.constructor(sqrt(z)*cos(phi/2),sqrt(z)*sin(phi/2)); // Done
|
|
118
|
+
// // case Fixed.cos: return new x.constructor(cos(a)*cosh(b),-(sin(a)*sinh(b)));
|
|
119
|
+
// // case Fixed.sin: return new x.constructor(sin(a)*cosh(b),cos(a)*sinh(b));
|
|
120
|
+
// // case Fixed.tan:{
|
|
121
|
+
// // const DEN = cos(2*a)+cosh(2*b);
|
|
122
|
+
// // return new x.constructor(sin(2*a)/DEN,sinh(2*b)/DEN);
|
|
123
|
+
// // }
|
|
124
|
+
// // case Fixed.cosh:return new x.constructor(cosh(a)*cos(b),sinh(a)*sin(b));
|
|
125
|
+
// // case Fixed.sinh:return new x.constructor(sinh(a)*cos(b),cosh(a)*sin(b));
|
|
126
|
+
// // case Fixed.tanh:{
|
|
127
|
+
// // const DEN=cosh(2*a)+cos(2*b);
|
|
128
|
+
// // return new x.constructor(sinh(2*a)/DEN,sin(2*b)/DEN)
|
|
129
|
+
// // }
|
|
130
|
+
// default : return fun(x)
|
|
131
|
+
// }
|
|
132
|
+
// }
|
|
82
133
|
else if(x instanceof Object){
|
|
83
134
|
return Object.fromEntries(Object.entries(x).map(n=>n=[n[0],mapfun$1(fun,n[1])]))
|
|
135
|
+
// return fun(Object) || Object.fromEntries(Object.entries(x).map(n=>n=[n[0],mapfun(fun,n[1])]))
|
|
84
136
|
}
|
|
85
137
|
});
|
|
86
|
-
return Y.length==1?Y[0]:Y;
|
|
138
|
+
return Y.length==1? Y[0]: Y;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// Mixed calcul
|
|
142
|
+
const sum=(...x)=>{
|
|
143
|
+
if(x.every(n=>typeof n==="number")){
|
|
144
|
+
let s = x[0];
|
|
145
|
+
for (let i = 1; i < x.length; i++) s += x[i];
|
|
146
|
+
return s;
|
|
147
|
+
}
|
|
148
|
+
const Y=[];
|
|
149
|
+
for(let i=0;i<x.length;i++){
|
|
150
|
+
if(x[i] instanceof Array)Y.push(sum(...x[i]));
|
|
151
|
+
else if(x[i] instanceof Object){
|
|
152
|
+
Y.push(sum(...Object.values(x[i])));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return Y.length===1?Y[0]:Y;
|
|
156
|
+
};
|
|
157
|
+
const prod=(...x)=>{
|
|
158
|
+
if(x.every(n=>typeof n==="number")){
|
|
159
|
+
let p = x[0];
|
|
160
|
+
for (let i = 1; i < x.length; i++) p *= x[i];
|
|
161
|
+
return p;
|
|
162
|
+
}
|
|
163
|
+
const Y=[];
|
|
164
|
+
for(let i=0;i<x.length;i++){
|
|
165
|
+
if(x[i] instanceof Array)Y.push(prod(...x[i]));
|
|
166
|
+
else if(x[i] instanceof Object){
|
|
167
|
+
Y.push(prod(...Object.values(x[i])));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return Y.length===1?Y[0]:Y;
|
|
171
|
+
};
|
|
172
|
+
const min=(...num)=>{
|
|
173
|
+
if(num.every(n=>typeof n==="number"))return Math.min(...num);
|
|
174
|
+
const Y=[];
|
|
175
|
+
for(let i=0;i<num.length;i++){
|
|
176
|
+
if(num[i] instanceof Array)Y.push(min(...num[i]));
|
|
177
|
+
else if(num[i] instanceof Object){
|
|
178
|
+
Y.push(
|
|
179
|
+
Object.fromEntries(
|
|
180
|
+
[Object.entries(num[i]).sort((a,b)=>a[1]-b[1])[0]]
|
|
181
|
+
)
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return Y.length===1?Y[0]:Y;
|
|
186
|
+
};
|
|
187
|
+
const max=(...num)=>{
|
|
188
|
+
if(num.every(n=>typeof n==="number"))return Math.max(...num);
|
|
189
|
+
const Y=[];
|
|
190
|
+
for(let i=0;i<num.length;i++){
|
|
191
|
+
if(num[i] instanceof Array)Y.push(min(...num[i]));
|
|
192
|
+
else if(num[i] instanceof Object){
|
|
193
|
+
Y.push(
|
|
194
|
+
Object.fromEntries(
|
|
195
|
+
[Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
|
|
196
|
+
)
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return Y.length===1?Y[0]:Y;
|
|
201
|
+
};
|
|
202
|
+
const accum=(...num)=>{
|
|
203
|
+
if(num.every(n=>typeof n==="number")){
|
|
204
|
+
let acc = num.reduce((x, y) => [...x, x[x.length - 1] + y], [0]);
|
|
205
|
+
acc.shift();
|
|
206
|
+
return acc;
|
|
207
|
+
}
|
|
208
|
+
const Y=[];
|
|
209
|
+
for(let i=0;i<num.length;i++){
|
|
210
|
+
if(num[i] instanceof Array)Y.push(accum(...num[i]));
|
|
211
|
+
else if(num[i] instanceof Object){
|
|
212
|
+
Y.push(null
|
|
213
|
+
// Object.fromEntries(
|
|
214
|
+
// [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
|
|
215
|
+
// )
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return Y.length===1?Y[0]:Y;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
//moy
|
|
223
|
+
//med
|
|
224
|
+
//variance
|
|
225
|
+
//std
|
|
226
|
+
//mode
|
|
227
|
+
//acccum
|
|
228
|
+
//min2max
|
|
229
|
+
//max2min
|
|
230
|
+
//percentile
|
|
231
|
+
|
|
232
|
+
const abs=(...x)=>mapfun$1(Math.abs,...x);
|
|
233
|
+
const sqrt$2=(...x)=>mapfun$1(Math.sqrt,...x);
|
|
234
|
+
const pow$1=(x,n)=>{
|
|
235
|
+
if(typeof x === "number"){
|
|
236
|
+
if(typeof n === "number")return Math.pow(x,n);
|
|
237
|
+
else if(n?.isComplex?.())return n.constructor.fromExpo(x**n.a,n.b*ln(x))
|
|
238
|
+
else return mapfun$1(a=>pow$1(x,a),...n);
|
|
239
|
+
}
|
|
240
|
+
else if(x.isComplex?.()){
|
|
241
|
+
if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
|
|
242
|
+
else if(n.isComplex?.())return x.constructor.fromExpo(
|
|
243
|
+
x.z**n.a*e(-x.phi*n.b),
|
|
244
|
+
ln(x.z)*n.b+n.a*x.phi
|
|
245
|
+
)
|
|
246
|
+
else return mapfun$1(a=>pow$1(x,a),...n);
|
|
247
|
+
}
|
|
248
|
+
else if(x instanceof Array){
|
|
249
|
+
if(typeof n === "number") return mapfun$1(a=>pow$1(a,n),...x);
|
|
250
|
+
else if(n instanceof Array){
|
|
251
|
+
const Y=[];
|
|
252
|
+
for(let i=0;i<x.length;i++){
|
|
253
|
+
Y.push(mapfun$1(a=>pow$1(x[i],a),...n));
|
|
254
|
+
}
|
|
255
|
+
return Y;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
const sqrtn=(x,n)=>{
|
|
260
|
+
if(typeof x === "number"){
|
|
261
|
+
if(typeof n === "number")return Math.pow(x,1/n);
|
|
262
|
+
else return mapfun$1(a=>sqrtn(x,a),...n);
|
|
263
|
+
}
|
|
264
|
+
else if(x.isComplex?.()){
|
|
265
|
+
if(typeof n === "number")return x.constructor.fromExpo(sqrtn(x.z,n),x.phi/n);
|
|
266
|
+
else return mapfun$1(a=>sqrtn(x,a),...n);
|
|
267
|
+
}
|
|
268
|
+
else if(x instanceof Array){
|
|
269
|
+
if(typeof n === "number") return mapfun$1(a=>sqrtn(a,n),...x);
|
|
270
|
+
else if(n instanceof Array){
|
|
271
|
+
const Y=[];
|
|
272
|
+
for(let i=0;i<x.length;i++){
|
|
273
|
+
Y.push(mapfun$1(a=>sqrtn(x[i],a),...n));
|
|
274
|
+
}
|
|
275
|
+
return Y;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
const e=(...x) => mapfun$1(Math.exp,...x);
|
|
280
|
+
const ln=(...x) => mapfun$1(Math.log,...x);
|
|
281
|
+
const cos$2=(...x) => mapfun$1(Fixed.cos,...x);
|
|
282
|
+
const sin$2=(...x) => mapfun$1(Fixed.sin,...x);
|
|
283
|
+
const tan=(...x) => mapfun$1(Fixed.tan,...x);
|
|
284
|
+
const sec=(...x) => mapfun$1(Fixed.sec,...x);
|
|
285
|
+
const sinc=(...x) => mapfun$1(Fixed.sinc,...x);
|
|
286
|
+
const csc=(...x) => mapfun$1(Fixed.csc,...x);
|
|
287
|
+
const cot=(...x) => mapfun$1(Fixed.cot,...x);
|
|
288
|
+
const acos$1=(...x) => mapfun$1(Fixed.acos,...x);
|
|
289
|
+
const asin=(...x) => mapfun$1(Fixed.asin,...x);
|
|
290
|
+
const atan=(...x) => mapfun$1(Fixed.atan,...x);
|
|
291
|
+
const acot=(...x) => mapfun$1(Fixed.acot,...x);
|
|
292
|
+
const cosh$1=(...x) => mapfun$1(Fixed.cosh,...x);
|
|
293
|
+
const sinh$1=(...x) => mapfun$1(Fixed.sinh,...x);
|
|
294
|
+
const tanh=(...x) => mapfun$1(Fixed.tanh,...x);
|
|
295
|
+
const coth=(...x) => mapfun$1(Fixed.coth,...x);
|
|
296
|
+
const acosh=(...x) => mapfun$1(Fixed.acosh,...x);
|
|
297
|
+
const asinh=(...x) => mapfun$1(Fixed.asinh,...x);
|
|
298
|
+
const atanh=(...x) => mapfun$1(Fixed.atanh,...x);
|
|
299
|
+
const ceil=(...x) => mapfun$1(Math.ceil,...x);
|
|
300
|
+
const floor=(...x) => mapfun$1(Math.floor,...x);
|
|
301
|
+
const round=(...x) => mapfun$1(Math.round,...x);
|
|
302
|
+
const atan2=(x,y,rad=true)=>{
|
|
303
|
+
if(typeof x === "number"){
|
|
304
|
+
if(typeof y === "number")return rad?Math.atan2(x,y):Math.atan2(x,y)*180/Math.PI;
|
|
305
|
+
else return mapfun$1(a=>atan2(x,a,rad),...y);
|
|
306
|
+
}
|
|
307
|
+
// else if(x.isComplex?.()){
|
|
308
|
+
// if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
|
|
309
|
+
// else return mapfun(a=>pow(x,a),...n);
|
|
310
|
+
// }
|
|
311
|
+
else if(x instanceof Array){
|
|
312
|
+
if(typeof y === "number") return mapfun$1(a=>atan2(a,y,rad),...x);
|
|
313
|
+
else if(y instanceof Array){
|
|
314
|
+
const Y=[];
|
|
315
|
+
for(let i=0;i<x.length;i++){
|
|
316
|
+
Y.push(mapfun$1(a=>pow$1(x[i],a),...y));
|
|
317
|
+
}
|
|
318
|
+
return Y;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
const fact=(...x)=>mapfun$1(n=> {
|
|
323
|
+
let i,
|
|
324
|
+
y = 1;
|
|
325
|
+
if (n == 0) y = 1;
|
|
326
|
+
else if (n > 0) for (i = 1; i <= n; i++) y *= i;
|
|
327
|
+
else y = NaN;
|
|
328
|
+
return y;
|
|
329
|
+
},...x);
|
|
330
|
+
const sign=(...x)=>mapfun$1(Math.sign,...x);
|
|
331
|
+
|
|
332
|
+
const sig=(...x)=>mapfun$1(n=>1/(1+e(-n)),...x);
|
|
333
|
+
|
|
334
|
+
const hypot=(...x)=>{
|
|
335
|
+
if(x.every(n=>typeof n === "number"))return Math.hypot(...x);
|
|
336
|
+
if(x.every(n=>n instanceof Array))return mapfun$1(
|
|
337
|
+
Math.hypot,
|
|
338
|
+
...x
|
|
339
|
+
)
|
|
87
340
|
};
|
|
88
341
|
|
|
89
342
|
const _add=(a,b)=>{
|
|
90
343
|
if(typeof(a)==="number"){
|
|
91
344
|
if (typeof b == "number") return a + b;
|
|
92
|
-
else if (b
|
|
93
|
-
else if (b
|
|
345
|
+
else if (b.isComplex?.())return new b.constructor(a + b.a, b.b);
|
|
346
|
+
else if (b.isMatrix?.()) return b.constructor.nums(b.rows, b.cols, a).add(b);
|
|
94
347
|
else if (b instanceof Array)return b.map(n=>add(n,a));
|
|
95
348
|
}
|
|
96
|
-
else if(a
|
|
349
|
+
else if(a.isComplex?.()||a.isMatrix?.()){
|
|
97
350
|
if(b instanceof Array)return b.map(n=>a.clone.add(n));
|
|
98
351
|
return a.clone.add(b);
|
|
99
352
|
}
|
|
@@ -109,11 +362,11 @@ const _add=(a,b)=>{
|
|
|
109
362
|
const _sub=(a,b)=>{
|
|
110
363
|
if(typeof(a)==="number"){
|
|
111
364
|
if (typeof b == "number") return a - b;
|
|
112
|
-
else if (b
|
|
113
|
-
else if (b
|
|
365
|
+
else if (b.isComplex?.())return new b.constructor(a - b.a, -b.b);
|
|
366
|
+
else if (b.isMatrix?.()) return b.constructor.nums(b.rows, b.cols, a).sub(b);
|
|
114
367
|
else if (b instanceof Array)return b.map(n=>sub(n,a));
|
|
115
368
|
}
|
|
116
|
-
else if(a
|
|
369
|
+
else if(a.isComplex?.()||a.isMatrix?.()){
|
|
117
370
|
if(b instanceof Array)return b.map(n=>a.clone.sub(n));
|
|
118
371
|
return a.clone.sub(b);
|
|
119
372
|
}
|
|
@@ -131,11 +384,11 @@ const _sub=(a,b)=>{
|
|
|
131
384
|
const _mul=(a,b)=>{
|
|
132
385
|
if(typeof(a)==="number"){
|
|
133
386
|
if (typeof b == "number") return a * b;
|
|
134
|
-
else if (b
|
|
135
|
-
else if (b
|
|
387
|
+
else if (b.isComplex?.())return new b.constructor(a * b.a,a * b.b);
|
|
388
|
+
else if (b.isMatrix?.()) return b.constructor.nums(b.rows, b.cols, a).mul(b);
|
|
136
389
|
else if (b instanceof Array)return b.map(n=>mul(a,n));
|
|
137
390
|
}
|
|
138
|
-
else if(a
|
|
391
|
+
else if(a.isComplex?.()||a.isMatrix?.()){
|
|
139
392
|
if(b instanceof Array)return b.map(n=>a.clone.mul(n));
|
|
140
393
|
return a.clone.mul(b);
|
|
141
394
|
}
|
|
@@ -153,11 +406,11 @@ const _mul=(a,b)=>{
|
|
|
153
406
|
const _div=(a,b)=>{
|
|
154
407
|
if(typeof(a)==="number"){
|
|
155
408
|
if (typeof b == "number") return a / b;
|
|
156
|
-
else if (b
|
|
157
|
-
else if (b
|
|
409
|
+
else if (b.isComplex?.())return new b.constructor(a / b.a,a / b.b);
|
|
410
|
+
else if (b.isMatrix?.()) return b.constructor.nums(b.rows, b.cols, a).div(b);
|
|
158
411
|
else if (b instanceof Array)return b.map(n=>div(a,n));
|
|
159
412
|
}
|
|
160
|
-
else if(a
|
|
413
|
+
else if(a.isComplex?.()||a.isMatrix?.()){
|
|
161
414
|
if(b instanceof Array)return b.map(n=>a.clone.div(n));
|
|
162
415
|
return a.clone.div(b);
|
|
163
416
|
}
|
|
@@ -175,11 +428,11 @@ const _div=(a,b)=>{
|
|
|
175
428
|
const _modulo=(a,b)=>{
|
|
176
429
|
if(typeof(a)==="number"){
|
|
177
430
|
if (typeof b == "number") return a % b;
|
|
178
|
-
else if (b
|
|
179
|
-
else if (b
|
|
431
|
+
else if (b.isComplex?.())return new b.constructor(a % b.a,a % b.b);
|
|
432
|
+
else if (b.isMatrix?.()) return b.constructor.nums(b.rows, b.cols, a).modulo(b);
|
|
180
433
|
else if (b instanceof Array)return b.map(n=>div(a,n));
|
|
181
434
|
}
|
|
182
|
-
else if(a
|
|
435
|
+
else if(a.isComplex?.()||a.isMatrix?.()){
|
|
183
436
|
if(b instanceof Array)return b.map(n=>a.clone.div(n));
|
|
184
437
|
return a.clone.div(b);
|
|
185
438
|
}
|
|
@@ -221,8 +474,8 @@ const ones=(n)=>new Array(n).fill(1);
|
|
|
221
474
|
const nums=(num,n)=>new Array(n).fill(num);
|
|
222
475
|
const norm=(value, min, max)=>{
|
|
223
476
|
if (typeof value === "number") return min !== max ? (value - min) / (max - min) : 0;
|
|
224
|
-
else if (value
|
|
225
|
-
else if (value
|
|
477
|
+
else if (value.isMatrix?.()) return new value.constructor(value.rows, value.cols, norm(value.arr.flat(1), min, max));
|
|
478
|
+
else if (value.isComplex?.()) return new value.constructor(norm(value.a, min, max), norm(value.b, min, max));
|
|
226
479
|
else if (value instanceof Array) {
|
|
227
480
|
if (value.every((n) => typeof (n === "number"))) {
|
|
228
481
|
return value.map((n) => norm(n, min, max));
|
|
@@ -236,8 +489,8 @@ const norm=(value, min, max)=>{
|
|
|
236
489
|
};
|
|
237
490
|
const lerp=(value, min, max)=>{
|
|
238
491
|
if (typeof value === "number") return (max - min) * value + min;
|
|
239
|
-
else if (value
|
|
240
|
-
else if (value
|
|
492
|
+
else if (value.isMatrix?.()) return new value.constructor(value.rows, value.cols, lerp(value.arr.flat(1), min, max));
|
|
493
|
+
else if (value.isComplex?.()) return new value.constructor(lerp(value.a, min, max), lerp(value.b, min, max));
|
|
241
494
|
else if (value instanceof Array) {
|
|
242
495
|
if (value.every((n) => typeof (n === "number"))) {
|
|
243
496
|
return value.map((n) => lerp(n, min, max));
|
|
@@ -249,17 +502,17 @@ const lerp=(value, min, max)=>{
|
|
|
249
502
|
}
|
|
250
503
|
}
|
|
251
504
|
};
|
|
252
|
-
const map$1=(
|
|
253
|
-
if (typeof
|
|
254
|
-
else if (
|
|
255
|
-
else if (
|
|
256
|
-
else if (
|
|
257
|
-
if (
|
|
258
|
-
return
|
|
505
|
+
const map$1=(x, a, b, c, d)=>{
|
|
506
|
+
if (typeof x === "number") return lerp(norm(x, a, b), c, d);
|
|
507
|
+
else if (x.isMatrix?.()) return new x.constructor(x.rows, x.cols, map$1(x.arr.flat(1), a, b, c, d));
|
|
508
|
+
else if (x.isComplex?.()) return new x.constructor(map$1(x.a, b, c, d), map$1(x.b, a, b, c, d));
|
|
509
|
+
else if (x instanceof Array) {
|
|
510
|
+
if (x.every((n) => typeof (n === "number"))) {
|
|
511
|
+
return x.map((n) => map$1(n, a, b, c, d));
|
|
259
512
|
} else {
|
|
260
|
-
let y = new Array(
|
|
261
|
-
for (let i = 0; i <
|
|
262
|
-
y[i] = map$1(
|
|
513
|
+
let y = new Array(x.length);
|
|
514
|
+
for (let i = 0; i < x.length; i++) {
|
|
515
|
+
y[i] = map$1(x[i], a, b, c, d);
|
|
263
516
|
}
|
|
264
517
|
}
|
|
265
518
|
}
|
|
@@ -267,8 +520,8 @@ const map$1=(value, a, b, c, d)=>{
|
|
|
267
520
|
const clamp=(x, a , b)=>{
|
|
268
521
|
const [min_value,max_value]=[min(a,b),max(a,b)];
|
|
269
522
|
if (typeof x === "number") return min(max(x, min_value), max_value);
|
|
270
|
-
else if (x
|
|
271
|
-
else if (x
|
|
523
|
+
else if (x.isMatrix?.()) return new x.constructor(x.rows, x.cols, clamp(x.arr.flat(1), min_value, max_value));
|
|
524
|
+
else if (x.isComplex?.()) return new x.constructor(clamp(x.a, min_value, max_value), clamp(x.b, min_value, max_value));
|
|
272
525
|
else if (x instanceof Array) {
|
|
273
526
|
if (x.every((n) => typeof (n === "number"))) {
|
|
274
527
|
return x.map((n) => clamp(n, min_value, max_value));
|
|
@@ -303,14 +556,14 @@ const linspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
|
|
|
303
556
|
return Y
|
|
304
557
|
}
|
|
305
558
|
|
|
306
|
-
if([a,b].some(n=>n
|
|
307
|
-
const z1=
|
|
308
|
-
const z2=
|
|
559
|
+
if([a,b].some(n=>n.isComplex?.())){
|
|
560
|
+
const z1 = new n.constructor(a);
|
|
561
|
+
const z2 = new n.constructor(b);
|
|
309
562
|
n=n||Math.abs(z1.a-z2.a)+1;
|
|
310
563
|
const X=linspace(z1.a,z2.a,n,endpoint);
|
|
311
564
|
const Y=linspace(z1.b,z2.b,n,endpoint);
|
|
312
565
|
let Z=new Array(n).fill(null);
|
|
313
|
-
Z=Z.map((n,i)=>
|
|
566
|
+
Z=Z.map((n,i)=> new n.constructor(X[i],Y[i]));
|
|
314
567
|
return Z;
|
|
315
568
|
}
|
|
316
569
|
};
|
|
@@ -330,9 +583,9 @@ const geomspace=(a,b,n=abs(b-a)+1,endpoint=true)=>{
|
|
|
330
583
|
return a<b?Y:Y.reverse()
|
|
331
584
|
}
|
|
332
585
|
|
|
333
|
-
if([a,b].some(n=>n
|
|
334
|
-
const z1=
|
|
335
|
-
const z2=
|
|
586
|
+
if([a,b].some(n=>n.isComplex?.())){
|
|
587
|
+
const z1 = new n.constructor(a);
|
|
588
|
+
const z2 = new n.constructor(b);
|
|
336
589
|
n=n||Math.abs(z1.a-z2.a)+1;
|
|
337
590
|
let base;
|
|
338
591
|
endpoint ? base = sqrtn(z2.div(z1),n-1) : base = sqrtn(z2.div(z1),n) ;
|
|
@@ -359,109 +612,18 @@ const deg2rad = (...deg) => mapfun(x => x * Math.PI / 180, ...deg);
|
|
|
359
612
|
*/
|
|
360
613
|
const rad2deg = (...rad) => mapfun(x => x / Math.PI * 180, ...rad);
|
|
361
614
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
return Y.length===1?Y[0]:Y;
|
|
377
|
-
};
|
|
378
|
-
const prod=(...x)=>{
|
|
379
|
-
if(x.every(n=>typeof n==="number")){
|
|
380
|
-
let p = x[0];
|
|
381
|
-
for (let i = 1; i < x.length; i++) p *= x[i];
|
|
382
|
-
return p;
|
|
383
|
-
}
|
|
384
|
-
const Y=[];
|
|
385
|
-
for(let i=0;i<x.length;i++){
|
|
386
|
-
if(x[i] instanceof Array)Y.push(prod(...x[i]));
|
|
387
|
-
else if(x[i] instanceof Object){
|
|
388
|
-
Y.push(prod(...Object.values(x[i])));
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
return Y.length===1?Y[0]:Y;
|
|
392
|
-
};
|
|
393
|
-
const min=(...num)=>{
|
|
394
|
-
if(num.every(n=>typeof n==="number"))return Math.min(...num);
|
|
395
|
-
const Y=[];
|
|
396
|
-
for(let i=0;i<num.length;i++){
|
|
397
|
-
if(num[i] instanceof Array)Y.push(min(...num[i]));
|
|
398
|
-
else if(num[i] instanceof Object){
|
|
399
|
-
Y.push(
|
|
400
|
-
Object.fromEntries(
|
|
401
|
-
[Object.entries(num[i]).sort((a,b)=>a[1]-b[1])[0]]
|
|
402
|
-
)
|
|
403
|
-
);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
return Y.length===1?Y[0]:Y;
|
|
407
|
-
};
|
|
408
|
-
const max=(...num)=>{
|
|
409
|
-
if(num.every(n=>typeof n==="number"))return Math.max(...num);
|
|
410
|
-
const Y=[];
|
|
411
|
-
for(let i=0;i<num.length;i++){
|
|
412
|
-
if(num[i] instanceof Array)Y.push(min(...num[i]));
|
|
413
|
-
else if(num[i] instanceof Object){
|
|
414
|
-
Y.push(
|
|
415
|
-
Object.fromEntries(
|
|
416
|
-
[Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
|
|
417
|
-
)
|
|
418
|
-
);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
return Y.length===1?Y[0]:Y;
|
|
422
|
-
};
|
|
423
|
-
const accum=(...num)=>{
|
|
424
|
-
if(num.every(n=>typeof n==="number")){
|
|
425
|
-
let acc = num.reduce((x, y) => [...x, x[x.length - 1] + y], [0]);
|
|
426
|
-
acc.shift();
|
|
427
|
-
return acc;
|
|
428
|
-
}
|
|
429
|
-
const Y=[];
|
|
430
|
-
for(let i=0;i<num.length;i++){
|
|
431
|
-
if(num[i] instanceof Array)Y.push(accum(...num[i]));
|
|
432
|
-
else if(num[i] instanceof Object){
|
|
433
|
-
Y.push(null
|
|
434
|
-
// Object.fromEntries(
|
|
435
|
-
// [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
|
|
436
|
-
// )
|
|
437
|
-
);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
return Y.length===1?Y[0]:Y;
|
|
441
|
-
};
|
|
442
|
-
|
|
443
|
-
//moy
|
|
444
|
-
//med
|
|
445
|
-
//variance
|
|
446
|
-
//std
|
|
447
|
-
//mode
|
|
448
|
-
//acccum
|
|
449
|
-
//min2max
|
|
450
|
-
//max2min
|
|
451
|
-
//percentile
|
|
452
|
-
|
|
453
|
-
/** @module Math */
|
|
454
|
-
/**
|
|
455
|
-
* Checks if a value is within the specified range.
|
|
456
|
-
* @function
|
|
457
|
-
* @param {number} x - The value to check.
|
|
458
|
-
* @param {number} a - The start of the range.
|
|
459
|
-
* @param {number} b - The end of the range.
|
|
460
|
-
* @returns {boolean} Returns true if the value is within the range [a, b], otherwise false.
|
|
461
|
-
*/
|
|
462
|
-
const inRange = (x, a, b) => {
|
|
463
|
-
const [min, max] = [Math.min(a, b), Math.max(a, b)];
|
|
464
|
-
return x >= min && x <= max;
|
|
615
|
+
/** @module Math */
|
|
616
|
+
/**
|
|
617
|
+
* Checks if a value is within the specified range.
|
|
618
|
+
* @function
|
|
619
|
+
* @param {number} x - The value to check.
|
|
620
|
+
* @param {number} a - The start of the range.
|
|
621
|
+
* @param {number} b - The end of the range.
|
|
622
|
+
* @returns {boolean} Returns true if the value is within the range [a, b], otherwise false.
|
|
623
|
+
*/
|
|
624
|
+
const inRange = (x, a, b) => {
|
|
625
|
+
const [min, max] = [Math.min(a, b), Math.max(a, b)];
|
|
626
|
+
return x >= min && x <= max;
|
|
465
627
|
};
|
|
466
628
|
|
|
467
629
|
/**
|
|
@@ -554,394 +716,194 @@ const Utils={
|
|
|
554
716
|
isApproximatlyEqual
|
|
555
717
|
};
|
|
556
718
|
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
719
|
+
class Complex{
|
|
720
|
+
constructor(a = 0, b = 0) {
|
|
721
|
+
if(a instanceof Complex){
|
|
722
|
+
this.a=a.a;
|
|
723
|
+
this.b=a.b;
|
|
724
|
+
}
|
|
725
|
+
else if(typeof(a)==="object"){
|
|
726
|
+
if(("a" in a && "b" in a)){
|
|
727
|
+
this.a=a.a;
|
|
728
|
+
this.b=a.b;
|
|
729
|
+
}
|
|
730
|
+
else if(("a" in a && "z" in a)){
|
|
731
|
+
this.a=a.a;
|
|
732
|
+
this.b=sqrt$2((a.z**2)-(a.a**2));
|
|
733
|
+
}
|
|
734
|
+
else if(("a" in a && "phi" in a)){
|
|
735
|
+
this.a=a.a;
|
|
736
|
+
this.b=a.a*tan(a.phi);
|
|
737
|
+
}
|
|
738
|
+
else if(("b" in a && "z" in a)){
|
|
739
|
+
this.b=a.b;
|
|
740
|
+
this.a=sqrt$2((a.z**2)-(a.b**2));
|
|
741
|
+
}
|
|
742
|
+
else if(("b" in a && "phi" in a)){
|
|
743
|
+
this.b=b;
|
|
744
|
+
this.a=a.b/tan(a.phi);
|
|
745
|
+
}
|
|
746
|
+
else if(("z" in a && "phi" in a)){
|
|
747
|
+
this.a=a.z*cos$2(a.phi);
|
|
748
|
+
this.a=a.z*sin$2(a.phi);
|
|
565
749
|
}
|
|
566
750
|
}
|
|
567
|
-
|
|
751
|
+
else if(typeof(a)==="number"&&typeof(b)==="number"){
|
|
752
|
+
this.a = +a.toFixed(32);
|
|
753
|
+
this.b = +b.toFixed(32);
|
|
754
|
+
}
|
|
568
755
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
// const subSet = (...arr) => {
|
|
573
|
-
// let list = arange(0, 2 ** arr.length, 1);
|
|
574
|
-
// let bin = list.map((n) => n.toString(2).padStart(arr.length, '0')).map((n) => n.split("").map((n) => +n));
|
|
575
|
-
// let sub = bin.map((n) => n.map((m, i) => (m === 1 ? arr[i] : null))).map((n) => n.filter((x) => x !== null));
|
|
576
|
-
// return sub;
|
|
577
|
-
// };
|
|
578
|
-
const subSet = null;
|
|
579
|
-
|
|
580
|
-
const Base={
|
|
581
|
-
_mode:Number,
|
|
582
|
-
_map:function(func,number,toBase){
|
|
583
|
-
if (number instanceof Matrix)
|
|
584
|
-
return new Matrix(
|
|
585
|
-
number.rows,
|
|
586
|
-
number.cols,
|
|
587
|
-
number.arr.flat(1).map(n=>func(n,toBase))
|
|
588
|
-
);
|
|
589
|
-
else if (number instanceof Complex) return new Complex(func(number.a,toBase),func(number.b,toBase));
|
|
590
|
-
else if (number instanceof Array) return number.map((n) =>func(n,toBase));
|
|
591
|
-
},
|
|
592
|
-
dec2base(dec,base){
|
|
593
|
-
base<=10?this._mode=Number:this._mode=String;
|
|
594
|
-
//this._mode=String
|
|
595
|
-
if (typeof dec === "number") return this._mode((dec >>> 0).toString(base));
|
|
596
|
-
return this._map(this.dec2base,dec,base)
|
|
597
|
-
},
|
|
598
|
-
dec2bin(dec){
|
|
599
|
-
return this.dec2base(dec,2);
|
|
600
|
-
},
|
|
601
|
-
dec2oct(dec){
|
|
602
|
-
return this.dec2base(dec,8);
|
|
603
|
-
},
|
|
604
|
-
dec2hex(dec){
|
|
605
|
-
return this.dec2base(dec,16);
|
|
606
|
-
},
|
|
607
|
-
bin2base(bin, base) {
|
|
608
|
-
return this.dec2base(this.bin2dec(bin),base)
|
|
609
|
-
},
|
|
610
|
-
bin2dec(bin){
|
|
611
|
-
return this._mode("0b"+bin);
|
|
612
|
-
},
|
|
613
|
-
bin2oct(bin){
|
|
614
|
-
return this.bin2base(bin,8);
|
|
615
|
-
},
|
|
616
|
-
bin2hex(bin){
|
|
617
|
-
return this.bin2base(bin,16);
|
|
618
|
-
},
|
|
619
|
-
oct2dec(oct){
|
|
620
|
-
return this._mode("0o"+oct);
|
|
621
|
-
},
|
|
622
|
-
oct2bin(oct){
|
|
623
|
-
return this.dec2bin(this.oct2dec(oct))
|
|
624
|
-
},
|
|
625
|
-
oct2hex(oct){
|
|
626
|
-
return this.dec2hex(this.oct2dec(oct))
|
|
627
|
-
},
|
|
628
|
-
oct2base(oct, base) {
|
|
629
|
-
return this.dec2base(this.oct2dec(oct),base)
|
|
630
|
-
},
|
|
631
|
-
hex2dec(hex){
|
|
632
|
-
return this._mode("0x"+hex);
|
|
633
|
-
},
|
|
634
|
-
hex2bin(hex){
|
|
635
|
-
return this.dec2bin(this.hex2dec(hex))
|
|
636
|
-
},
|
|
637
|
-
hex2oct(hex){
|
|
638
|
-
return this.dec2oct(this.hex2dec(hex))
|
|
639
|
-
},
|
|
640
|
-
hex2base(hex, base) {
|
|
641
|
-
return this.dec2base(this.hex2dec(hex),base)
|
|
642
|
-
},
|
|
643
|
-
IEEE32toDec(Bin){
|
|
644
|
-
let IEEE32=Bin.split(" ").join("").padEnd(32,"0");
|
|
645
|
-
let s=IEEE32[0];
|
|
646
|
-
let e=2**(+("0b"+IEEE32.slice(1,9))-127);
|
|
647
|
-
let m=IEEE32.slice(9,32).split("").map(n=>+n);
|
|
648
|
-
let M=m.map((n,i)=>n*(2**(-i-1))).reduce((a,b)=>a+b,0);
|
|
649
|
-
let dec=(-1)**s*(1+M)*e;
|
|
650
|
-
return dec
|
|
651
|
-
},
|
|
652
|
-
IEEE64toDec(Bin){
|
|
653
|
-
let IEEE64=Bin.split(" ").join("").padEnd(64,"0");
|
|
654
|
-
let s=IEEE64[0];
|
|
655
|
-
let e=2**(+("0b"+IEEE64.slice(1,12))-1023);
|
|
656
|
-
let m=IEEE64.slice(13,64).split("").map(n=>+n);
|
|
657
|
-
let M=m.map((n,i)=>n*(2**(-i-1))).reduce((a,b)=>a+b,0);
|
|
658
|
-
let dec=(-1)**s*(1+M)*e;
|
|
659
|
-
return dec;
|
|
756
|
+
get __mapfun__(){
|
|
757
|
+
return true
|
|
660
758
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
const Logic$1={
|
|
664
|
-
_mode:Number,
|
|
665
|
-
_map:function(func,a,b){
|
|
666
|
-
if (a instanceof Matrix)
|
|
667
|
-
return new Matrix(
|
|
668
|
-
a.rows,
|
|
669
|
-
a.cols,
|
|
670
|
-
a.arr.flat(1).map((n) => func(n, b))
|
|
671
|
-
);
|
|
672
|
-
else if (a instanceof Complex) return new Complex(func(a.a, b), func(a.b, b));
|
|
673
|
-
else if (a instanceof Array) return a.map((n) => func(n, b));
|
|
674
|
-
},
|
|
675
|
-
not:function(input){
|
|
676
|
-
if(["number","boolean"].includes(typeof input)) return Logic$1._mode(!input);
|
|
677
|
-
else return this._map(this.not,input)
|
|
678
|
-
},
|
|
679
|
-
and:function(a, ...b){
|
|
680
|
-
if(["number","boolean"].includes(typeof a))return Logic$1._mode(b.reduce((n, m) => (n &= m), a));
|
|
681
|
-
else return this._map(this.and,a,b)
|
|
682
|
-
},
|
|
683
|
-
or:function(a, ...b) {
|
|
684
|
-
if(["number","boolean"].includes(typeof a)) return Logic$1._mode(b.reduce((n, m) => (n |= m), a));
|
|
685
|
-
else return this._map(this.or,a,b);
|
|
686
|
-
},
|
|
687
|
-
nand:function(a, ...b) {
|
|
688
|
-
return this.not(this.and(a, b));
|
|
689
|
-
},
|
|
690
|
-
nor:function(a, ...b) {
|
|
691
|
-
return this.not(this.or(a, b));
|
|
692
|
-
},
|
|
693
|
-
xor:function(a,...b){
|
|
694
|
-
let arr=[a,...b];
|
|
695
|
-
if(["number","boolean"].includes(typeof a))return this._mode(arr.reduce((length,cur)=>{
|
|
696
|
-
if(+cur===1)length+=1;
|
|
697
|
-
return length;
|
|
698
|
-
},0)===1);
|
|
699
|
-
else return this._map(this.xor,a,b);
|
|
700
|
-
},
|
|
701
|
-
xnor:function(a,...b){
|
|
702
|
-
return Logic$1.not(Logic$1.xor(a,b))
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
};
|
|
706
|
-
|
|
707
|
-
class Permutation {
|
|
708
|
-
static withDiscount(arr, l = arr.length) {
|
|
709
|
-
if (l === 1) return arr.map((n) => [n]);
|
|
710
|
-
const permutations = [];
|
|
711
|
-
let smallerPermutations;
|
|
712
|
-
smallerPermutations = this.withDiscount(arr, l - 1);
|
|
713
|
-
arr.forEach((currentOption) => {
|
|
714
|
-
smallerPermutations.forEach((smallerPermutation) => {
|
|
715
|
-
permutations.push([currentOption].concat(smallerPermutation));
|
|
716
|
-
});
|
|
717
|
-
});
|
|
718
|
-
return permutations;
|
|
719
|
-
}
|
|
720
|
-
static withoutDiscount(arr) {
|
|
721
|
-
const l = arr.length;
|
|
722
|
-
if (l === 1) return arr.map((n) => [n]);
|
|
723
|
-
const permutations = [];
|
|
724
|
-
const smallerPermutations = this.withoutDiscount(arr.slice(1));
|
|
725
|
-
const firstOption = arr[0];
|
|
726
|
-
for (let i = 0; i < smallerPermutations.length; i++) {
|
|
727
|
-
const smallerPermutation = smallerPermutations[i];
|
|
728
|
-
for (let j = 0; j <= smallerPermutation.length; j++) {
|
|
729
|
-
const permutationPrefix = smallerPermutation.slice(0, j);
|
|
730
|
-
const permutationSuffix = smallerPermutation.slice(j);
|
|
731
|
-
permutations.push(permutationPrefix.concat([firstOption], permutationSuffix));
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
return permutations;
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
class Combinaison {
|
|
739
|
-
static withDiscount(comboOptions, comboLength) {
|
|
740
|
-
if (comboLength === 1) {
|
|
741
|
-
return comboOptions.map((comboOption) => [comboOption]);
|
|
742
|
-
}
|
|
743
|
-
const combos = [];
|
|
744
|
-
comboOptions.forEach((currentOption, optionIndex) => {
|
|
745
|
-
const smallerCombos = this.withDiscount(comboOptions.slice(optionIndex), comboLength - 1);
|
|
746
|
-
smallerCombos.forEach((smallerCombo) => {
|
|
747
|
-
combos.push([currentOption].concat(smallerCombo));
|
|
748
|
-
});
|
|
749
|
-
});
|
|
750
|
-
return combos;
|
|
751
|
-
}
|
|
752
|
-
static withoutDiscount(comboOptions, comboLength) {
|
|
753
|
-
if (comboLength === 1) {
|
|
754
|
-
return comboOptions.map((comboOption) => [comboOption]);
|
|
755
|
-
}
|
|
756
|
-
const combos = [];
|
|
757
|
-
comboOptions.forEach((currentOption, optionIndex) => {
|
|
758
|
-
const smallerCombos = this.withoutDiscount(comboOptions.slice(optionIndex + 1), comboLength - 1);
|
|
759
|
-
smallerCombos.forEach((smallerCombo) => {
|
|
760
|
-
combos.push([currentOption].concat(smallerCombo));
|
|
761
|
-
});
|
|
762
|
-
});
|
|
763
|
-
|
|
764
|
-
return combos;
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
const combinaison=(comboOptions, comboLength, discount=false)=>Combinaison[discount?"withDiscount":"withoutDiscount"](comboOptions, comboLength);
|
|
768
|
-
|
|
769
|
-
class Random {
|
|
770
|
-
static float(a = 1, b) {
|
|
771
|
-
return b ? Math.random() * (b - a) + a : a * Math.random();
|
|
772
|
-
}
|
|
773
|
-
static int(a, b) {
|
|
774
|
-
return Math.floor(this.float(a, b));
|
|
775
|
-
}
|
|
776
|
-
static char(upperCase){
|
|
777
|
-
upperCase=upperCase??this.bool();
|
|
778
|
-
const Char=String.fromCharCode(this.int(97,120));
|
|
779
|
-
return upperCase?Char.toUpperCase():Char;
|
|
780
|
-
}
|
|
781
|
-
static bool(){
|
|
782
|
-
return [false,true][Math.floor(Math.random()*2)];
|
|
783
|
-
}
|
|
784
|
-
static string(length,upperCase){
|
|
785
|
-
return length instanceof Array?
|
|
786
|
-
new Array(this.int(...length)).fill(0).map(() => this.char(upperCase)).join(""):
|
|
787
|
-
new Array(length).fill(0).map(() => this.char(upperCase)).join("");
|
|
788
|
-
}
|
|
789
|
-
static bin() {
|
|
790
|
-
return this.int(2);
|
|
791
|
-
}
|
|
792
|
-
static oct() {
|
|
793
|
-
return this.int(8);
|
|
794
|
-
}
|
|
795
|
-
static dec() {
|
|
796
|
-
return this.int(8);
|
|
797
|
-
}
|
|
798
|
-
static hex() {
|
|
799
|
-
return this.int(16);
|
|
800
|
-
}
|
|
801
|
-
static choice(choices = [1, 2, 3], p = new Array(choices.length).fill(1 / choices.length)) {
|
|
802
|
-
let newchoice = new Array(100);
|
|
803
|
-
p=Utils.accum(...p).map(n=>n*100);
|
|
804
|
-
newchoice.fill(choices[0], 0, p[0]);
|
|
805
|
-
for (let i = 1; i < choices.length; i++) newchoice.fill(choices[i], p[i - 1], p[i]);
|
|
806
|
-
return newchoice[this.int(newchoice.length - 1)];
|
|
807
|
-
}
|
|
808
|
-
static shuffleArr(arr){
|
|
809
|
-
return arr.sort(()=>0.5-Math.random())
|
|
810
|
-
}
|
|
811
|
-
static shuffleMatrix(M){
|
|
812
|
-
const {rows,cols,arr}=M;
|
|
813
|
-
return matrix(rows,cols,arr.flat().sort(()=>0.5-Math.random()))
|
|
759
|
+
isComplex(){
|
|
760
|
+
return true
|
|
814
761
|
}
|
|
815
|
-
|
|
816
|
-
|
|
762
|
+
toString(){
|
|
763
|
+
let str = "";
|
|
764
|
+
if (this.a !== 0)
|
|
765
|
+
this.b >= 0
|
|
766
|
+
? (str = `${this.a}+${this.b}*i`)
|
|
767
|
+
: (str = `${this.a}-${Math.abs(this.b)}*i`);
|
|
768
|
+
else
|
|
769
|
+
this.b >= 0
|
|
770
|
+
? (str = `${this.b}*i`)
|
|
771
|
+
: (str = `-${Math.abs(this.b)}*i`);
|
|
772
|
+
return str;
|
|
817
773
|
}
|
|
818
|
-
|
|
819
|
-
|
|
774
|
+
|
|
775
|
+
get clone() {
|
|
776
|
+
return new Complex(this.a, this.b);
|
|
820
777
|
}
|
|
821
|
-
|
|
822
|
-
return
|
|
778
|
+
get z(){
|
|
779
|
+
return hypot(this.a,this.b);
|
|
823
780
|
}
|
|
824
|
-
|
|
825
|
-
return
|
|
781
|
+
get phi(){
|
|
782
|
+
return atan2(this.b , this.a);
|
|
826
783
|
}
|
|
827
|
-
static
|
|
828
|
-
return new
|
|
784
|
+
static Zero() {
|
|
785
|
+
return new Complex(0, 0);
|
|
829
786
|
}
|
|
830
|
-
|
|
831
|
-
return new
|
|
787
|
+
get conj() {
|
|
788
|
+
return new Complex(this.a, -this.b);
|
|
832
789
|
}
|
|
833
|
-
|
|
834
|
-
return new
|
|
790
|
+
get inv() {
|
|
791
|
+
return new Complex(this.a / (pow$1(this.a, 2) + pow$1(this.b, 2)), -this.b / (pow$1(this.a, 2) + pow$1(this.b, 2)));
|
|
835
792
|
}
|
|
836
|
-
|
|
837
|
-
|
|
793
|
+
add(...z) {
|
|
794
|
+
for (let i = 0; i < z.length; i++) {
|
|
795
|
+
if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
|
|
796
|
+
}
|
|
797
|
+
let re = z.map((n) => n.a);
|
|
798
|
+
let im = z.map((n) => n.b);
|
|
799
|
+
this.a+=+sum(...re).toFixed(15);
|
|
800
|
+
this.b+=+sum(...im).toFixed(15);
|
|
801
|
+
return this;
|
|
838
802
|
}
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
803
|
+
sub(...z) {
|
|
804
|
+
for (let i = 0; i < z.length; i++) {
|
|
805
|
+
if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
|
|
806
|
+
}
|
|
807
|
+
let re = z.map((n) => n.a);
|
|
808
|
+
let im = z.map((n) => n.b);
|
|
809
|
+
this.a-=+sum(...re).toFixed(15);
|
|
810
|
+
this.b-=+sum(...im).toFixed(15);
|
|
811
|
+
return this;
|
|
842
812
|
}
|
|
843
|
-
|
|
844
|
-
|
|
813
|
+
mul(...z){
|
|
814
|
+
for (let i = 0; i < z.length; i++) {
|
|
815
|
+
if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
|
|
816
|
+
}
|
|
817
|
+
let Z=+prod(this.z,...z.map(n=>n.z)).toFixed(15);
|
|
818
|
+
let phi=+sum(this.phi,...z.map(n=>n.phi)).toFixed(15);
|
|
819
|
+
this.a=+(Z*cos$2(phi).toFixed(15)).toFixed(14);
|
|
820
|
+
this.b=+(Z*sin$2(phi).toFixed(15)).toFixed(14);
|
|
821
|
+
return this;
|
|
845
822
|
}
|
|
846
|
-
|
|
847
|
-
|
|
823
|
+
div(...z) {
|
|
824
|
+
for (let i = 0; i < z.length; i++) {
|
|
825
|
+
if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
|
|
826
|
+
}
|
|
827
|
+
let Z=+(this.z/prod(...z.map(n=>n.z))).toFixed(15);
|
|
828
|
+
let phi=+(this.phi-sum(...z.map(n=>n.phi))).toFixed(15);
|
|
829
|
+
this.a=+(Z*cos$2(phi).toFixed(15)).toFixed(15);
|
|
830
|
+
this.b=+(Z*sin$2(phi).toFixed(15)).toFixed(15);
|
|
831
|
+
return this;
|
|
848
832
|
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
this.
|
|
853
|
-
this.
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
)
|
|
858
|
-
|
|
833
|
+
pow(n) {
|
|
834
|
+
if (floor(n) === n && n > 0) {
|
|
835
|
+
let z=+(this.z**n).toFixed(15);
|
|
836
|
+
let phi=+(this.phi*n).toFixed(15);
|
|
837
|
+
this.a=+(z*cos$2(phi).toFixed(15)).toFixed(15);
|
|
838
|
+
this.b=+(z*sin$2(phi).toFixed(15)).toFixed(15);
|
|
839
|
+
}
|
|
840
|
+
return this;
|
|
859
841
|
}
|
|
860
|
-
static
|
|
842
|
+
static fromExpo(z, phi) {
|
|
861
843
|
return new Complex(
|
|
862
|
-
|
|
863
|
-
|
|
844
|
+
+(z * cos$2(phi)).toFixed(13),
|
|
845
|
+
+(z * sin$2(phi)).toFixed(13)
|
|
864
846
|
);
|
|
865
847
|
}
|
|
866
|
-
|
|
867
|
-
return
|
|
848
|
+
get expo() {
|
|
849
|
+
return [this.z, this.phi];
|
|
868
850
|
}
|
|
869
|
-
static
|
|
870
|
-
return
|
|
851
|
+
static add(c,...z) {
|
|
852
|
+
return c.clone.add(...z);
|
|
871
853
|
}
|
|
872
|
-
static
|
|
873
|
-
return
|
|
854
|
+
static sub(c,...z) {
|
|
855
|
+
return c.clone.sub(...z);
|
|
874
856
|
}
|
|
875
|
-
static
|
|
876
|
-
return
|
|
857
|
+
static mul(c,...z) {
|
|
858
|
+
return c.clone.mul(...z);
|
|
877
859
|
}
|
|
878
|
-
static
|
|
879
|
-
return
|
|
860
|
+
static div(c,...z) {
|
|
861
|
+
return c.clone.div(...z);
|
|
880
862
|
}
|
|
881
|
-
static
|
|
882
|
-
return
|
|
863
|
+
static pow(z,n){
|
|
864
|
+
return z.clone.pow(n);
|
|
883
865
|
}
|
|
884
|
-
static
|
|
885
|
-
return
|
|
866
|
+
static xpowZ(x){
|
|
867
|
+
return complex((x**this.a)*cos$2(this.b*ln(x)),(x**this.a)*sin$2(this.b*ln(x)));
|
|
886
868
|
}
|
|
887
|
-
|
|
888
|
-
return
|
|
869
|
+
sqrtn(n=2){
|
|
870
|
+
return complex(sqrtn(this.z,n)*cos$2(this.phi/n),sqrtn(this.z,n)*sin$2(this.phi/n));
|
|
889
871
|
}
|
|
890
|
-
|
|
891
|
-
return
|
|
872
|
+
get sqrt(){
|
|
873
|
+
return this.sqrtn(2);
|
|
892
874
|
}
|
|
893
|
-
|
|
894
|
-
return
|
|
875
|
+
get log(){
|
|
876
|
+
return complex(this.z,this.phi);
|
|
895
877
|
}
|
|
896
|
-
|
|
897
|
-
return
|
|
878
|
+
get cos(){
|
|
879
|
+
return complex(cos$2(this.a)*cosh$1(this.b),sin$2(this.a)*sinh$1(this.b))
|
|
898
880
|
}
|
|
899
|
-
|
|
900
|
-
return
|
|
881
|
+
get sin(){
|
|
882
|
+
return complex(sin$2(this.a)*cosh$1(this.b),cos$2(this.a)*sinh$1(this.b))
|
|
901
883
|
}
|
|
902
|
-
|
|
903
|
-
|
|
884
|
+
get tan(){
|
|
885
|
+
const de=cos$2(this.a*2)+cosh$1(this.b*2);
|
|
886
|
+
return complex(sin$2(2*this.a)/de,sinh$1(2*this.b)/de);
|
|
904
887
|
}
|
|
905
|
-
|
|
906
|
-
|
|
888
|
+
}
|
|
889
|
+
const complex=(a,b)=>{
|
|
890
|
+
if((a instanceof Array||ArrayBuffer.isView(a)) && (b instanceof Array||ArrayBuffer.isView(a)))return a.map((n,i)=>complex(a[i],b[i]));
|
|
891
|
+
if(a.isMatrix?.() && b.isMatrix?.()){
|
|
892
|
+
if((a.shape[0]!==b.shape[0])||(a.shape[1]!==b.shape[1]))return Error(0)
|
|
893
|
+
const arr=a.arr.map((n,i)=>complex(a.arr[i],b.arr[i]));
|
|
894
|
+
return new a.constructor(a.rows,a.cols,...arr)
|
|
907
895
|
}
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
}
|
|
920
|
-
static matrixComplexInt(r,c,a,b){
|
|
921
|
-
return matrix(r,c,this.complexesInt(r*c,a,b))
|
|
922
|
-
}
|
|
923
|
-
static matrixComplexBin(r,c){
|
|
924
|
-
return matrix(r,c,this.complexesBin(r*c))
|
|
925
|
-
}
|
|
926
|
-
static matrixComplexOct(r,c){
|
|
927
|
-
return matrix(r,c,this.complexesBin(r*c))
|
|
928
|
-
}
|
|
929
|
-
static matrixComplexDec(r,c){
|
|
930
|
-
return matrix(r,c,this.complexesBin(r*c))
|
|
931
|
-
}
|
|
932
|
-
static matrixComplexHex(r,c){
|
|
933
|
-
return matrix(r,c,this.complexesBin(r*c))
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
const preload=(url)=>{
|
|
938
|
-
const xhr = new XMLHttpRequest();
|
|
939
|
-
xhr.open("GET", url, false);
|
|
940
|
-
xhr.send();
|
|
941
|
-
if (xhr.status === 200) {
|
|
942
|
-
return xhr.responseText;
|
|
943
|
-
} else {
|
|
944
|
-
throw new Error(`Failed to fetch data from ${url}. Status: ${xhr.status}`);
|
|
896
|
+
return new Complex(a,b)
|
|
897
|
+
};
|
|
898
|
+
|
|
899
|
+
const preload=(url)=>{
|
|
900
|
+
const xhr = new XMLHttpRequest();
|
|
901
|
+
xhr.open("GET", url, false);
|
|
902
|
+
xhr.send();
|
|
903
|
+
if (xhr.status === 200) {
|
|
904
|
+
return xhr.responseText;
|
|
905
|
+
} else {
|
|
906
|
+
throw new Error(`Failed to fetch data from ${url}. Status: ${xhr.status}`);
|
|
945
907
|
}
|
|
946
908
|
};
|
|
947
909
|
|
|
@@ -1086,6 +1048,35 @@ class UINode {
|
|
|
1086
1048
|
|
|
1087
1049
|
// globalThis.node = (node) => new UINode(node);
|
|
1088
1050
|
|
|
1051
|
+
function parseQueryParams$1(queryString) {
|
|
1052
|
+
const params = {};
|
|
1053
|
+
queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
|
|
1054
|
+
const [key, value] = match.split('=');
|
|
1055
|
+
params[key] = value;
|
|
1056
|
+
});
|
|
1057
|
+
return params;
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
function defineParamsGetter$1(target ){
|
|
1061
|
+
Object.defineProperties(target, {
|
|
1062
|
+
'QueryParams': {
|
|
1063
|
+
get: function() {
|
|
1064
|
+
return parseQueryParams$1(globalThis.location.search.substring(1));
|
|
1065
|
+
},
|
|
1066
|
+
configurable: false,
|
|
1067
|
+
enumerable: true
|
|
1068
|
+
},
|
|
1069
|
+
'HashParams': {
|
|
1070
|
+
get: function() {
|
|
1071
|
+
const hash = globalThis.location.hash.substring(1);
|
|
1072
|
+
return hash.split("#");
|
|
1073
|
+
},
|
|
1074
|
+
configurable: false,
|
|
1075
|
+
enumerable: true
|
|
1076
|
+
}
|
|
1077
|
+
});
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1089
1080
|
class UIStore extends Array {
|
|
1090
1081
|
constructor(...args) {
|
|
1091
1082
|
super(...args);
|
|
@@ -1119,202 +1110,6 @@ class UIStore extends Array {
|
|
|
1119
1110
|
// create the singleton
|
|
1120
1111
|
const __UI__ = new UIStore();
|
|
1121
1112
|
|
|
1122
|
-
// __init__global__()
|
|
1123
|
-
class UIElementCore extends UINode{
|
|
1124
|
-
constructor(){
|
|
1125
|
-
super();
|
|
1126
|
-
}
|
|
1127
|
-
init(element, name, type, render){
|
|
1128
|
-
this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
|
|
1129
|
-
if(typeof element === "string") {
|
|
1130
|
-
switch(type){
|
|
1131
|
-
case "html" : {
|
|
1132
|
-
element = globalThis?.document?.createElement(element);
|
|
1133
|
-
// console.log('1')
|
|
1134
|
-
} break;
|
|
1135
|
-
case "svg" : {
|
|
1136
|
-
element = globalThis?.document?.createElementNS("http://www.w3.org/2000/svg", element);
|
|
1137
|
-
// console.log('2')
|
|
1138
|
-
} break;
|
|
1139
|
-
default : throw Error("Not supported")
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
else this.target = element?.parentElement;
|
|
1143
|
-
Object.assign(this.cache, {
|
|
1144
|
-
name,
|
|
1145
|
-
isInteractive : false,
|
|
1146
|
-
parent:null,
|
|
1147
|
-
isBody:false,
|
|
1148
|
-
isRoot:false,
|
|
1149
|
-
isHidden: false,
|
|
1150
|
-
isFrozzen:false,
|
|
1151
|
-
legacyParent : null,
|
|
1152
|
-
attributes: {},
|
|
1153
|
-
filters: {},
|
|
1154
|
-
temp:{}
|
|
1155
|
-
});
|
|
1156
|
-
this.events = {
|
|
1157
|
-
ptr:null,
|
|
1158
|
-
mouse:null,
|
|
1159
|
-
wheel:null,
|
|
1160
|
-
key:null,
|
|
1161
|
-
drag:null,
|
|
1162
|
-
drop:null,
|
|
1163
|
-
click:null,
|
|
1164
|
-
clipboard:null,
|
|
1165
|
-
focus:null,
|
|
1166
|
-
swipe:null,
|
|
1167
|
-
custom:null,
|
|
1168
|
-
};
|
|
1169
|
-
this.observer={
|
|
1170
|
-
resize:null,
|
|
1171
|
-
intersection:null
|
|
1172
|
-
};
|
|
1173
|
-
if(element) Object.assign(this.cache,{element});
|
|
1174
|
-
// useDefaultStyle && this.style({
|
|
1175
|
-
// position: "relative",
|
|
1176
|
-
// boxSizing:"border-box",
|
|
1177
|
-
// margin:0,
|
|
1178
|
-
// padding:0,
|
|
1179
|
-
// width : "auto",
|
|
1180
|
-
// height : "auto"
|
|
1181
|
-
// });
|
|
1182
|
-
this.items = new UIStore();
|
|
1183
|
-
globalThis.__Ziko__.__UI__[this.cache.name]?globalThis.__Ziko__.__UI__[this.cache.name]?.push(this):globalThis.__Ziko__.__UI__[this.cache.name]=[this];
|
|
1184
|
-
element && render && this?.render?.();
|
|
1185
|
-
globalThis.__Ziko__.__UI__.push(this);
|
|
1186
|
-
}
|
|
1187
|
-
get element(){
|
|
1188
|
-
return this.cache.element;
|
|
1189
|
-
}
|
|
1190
|
-
[Symbol.iterator]() {
|
|
1191
|
-
return this.items[Symbol.iterator]();
|
|
1192
|
-
}
|
|
1193
|
-
maintain() {
|
|
1194
|
-
for (let i = 0; i < this.items.length; i++) {
|
|
1195
|
-
Object.defineProperty(this, i, {
|
|
1196
|
-
value: this.items[i],
|
|
1197
|
-
writable: true,
|
|
1198
|
-
configurable: true,
|
|
1199
|
-
enumerable: false
|
|
1200
|
-
});
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
isInteractive(){
|
|
1204
|
-
return this.cache.isInteractive;
|
|
1205
|
-
}
|
|
1206
|
-
isUIElement(){
|
|
1207
|
-
return true;
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
|
|
1211
|
-
function register_to_class(target, ...mixins){
|
|
1212
|
-
mixins.forEach(n => _register_to_class_(target, n));
|
|
1213
|
-
}
|
|
1214
|
-
function _register_to_class_(target, mixin) {
|
|
1215
|
-
const descriptors = Object.getOwnPropertyDescriptors(mixin);
|
|
1216
|
-
for (const key of Reflect.ownKeys(descriptors)) {
|
|
1217
|
-
const desc = descriptors[key];
|
|
1218
|
-
if ('get' in desc || 'set' in desc || typeof desc.value !== 'function') {
|
|
1219
|
-
Object.defineProperty(Object.getPrototypeOf(target), key, desc);
|
|
1220
|
-
} else if (typeof desc.value === 'function') {
|
|
1221
|
-
if (!Object.getPrototypeOf(target).hasOwnProperty(key)) {
|
|
1222
|
-
Object.defineProperty(Object.getPrototypeOf(target), key, desc);
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
// export function mount(target = this.target) {
|
|
1229
|
-
// if(this.isBody) return ;
|
|
1230
|
-
// if(target?.isUIElement)target=target.element;
|
|
1231
|
-
// this.target=target;
|
|
1232
|
-
// this.target?.appendChild(this.element);
|
|
1233
|
-
// return this;
|
|
1234
|
-
// }
|
|
1235
|
-
// export function unmount(){
|
|
1236
|
-
// if(this.cache.parent)this.cache.parent.remove(this);
|
|
1237
|
-
// else if(this.target?.children?.length && [...this.target?.children].includes(this.element)) this.target.removeChild(this.element);
|
|
1238
|
-
// return this;
|
|
1239
|
-
// }
|
|
1240
|
-
|
|
1241
|
-
// export function mountAfter(target = this.target, t = 1) {
|
|
1242
|
-
// setTimeout(() => this.mount(), t);
|
|
1243
|
-
// return this;
|
|
1244
|
-
// }
|
|
1245
|
-
// export function unmountAfter(t = 1) {
|
|
1246
|
-
// setTimeout(() => this.unmount(), t);
|
|
1247
|
-
// return this;
|
|
1248
|
-
// }
|
|
1249
|
-
|
|
1250
|
-
function mount(target = this.target, delay = 0) {
|
|
1251
|
-
if (delay > 0) {
|
|
1252
|
-
setTimeout(() => this.mount(target, 0), delay);
|
|
1253
|
-
return this;
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
if (this.isBody) return this;
|
|
1257
|
-
|
|
1258
|
-
if (target?.isUIElement) target = target.element;
|
|
1259
|
-
this.target = target;
|
|
1260
|
-
|
|
1261
|
-
this.target?.appendChild(this.element);
|
|
1262
|
-
return this;
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
function unmount(delay = 0) {
|
|
1266
|
-
if (delay > 0) {
|
|
1267
|
-
setTimeout(() => this.unmount(0), delay);
|
|
1268
|
-
return this;
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
if (this.cache.parent) {
|
|
1272
|
-
this.cache.parent.remove(this);
|
|
1273
|
-
} else if (
|
|
1274
|
-
this.target?.children?.length &&
|
|
1275
|
-
[...this.target.children].includes(this.element)
|
|
1276
|
-
) {
|
|
1277
|
-
this.target.removeChild(this.element);
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
return this;
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
var LifecycleMethods = /*#__PURE__*/Object.freeze({
|
|
1284
|
-
__proto__: null,
|
|
1285
|
-
mount: mount,
|
|
1286
|
-
unmount: unmount
|
|
1287
|
-
});
|
|
1288
|
-
|
|
1289
|
-
function parseQueryParams$1(queryString) {
|
|
1290
|
-
const params = {};
|
|
1291
|
-
queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
|
|
1292
|
-
const [key, value] = match.split('=');
|
|
1293
|
-
params[key] = value;
|
|
1294
|
-
});
|
|
1295
|
-
return params;
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
function defineParamsGetter$1(target ){
|
|
1299
|
-
Object.defineProperties(target, {
|
|
1300
|
-
'QueryParams': {
|
|
1301
|
-
get: function() {
|
|
1302
|
-
return parseQueryParams$1(globalThis.location.search.substring(1));
|
|
1303
|
-
},
|
|
1304
|
-
configurable: false,
|
|
1305
|
-
enumerable: true
|
|
1306
|
-
},
|
|
1307
|
-
'HashParams': {
|
|
1308
|
-
get: function() {
|
|
1309
|
-
const hash = globalThis.location.hash.substring(1);
|
|
1310
|
-
return hash.split("#");
|
|
1311
|
-
},
|
|
1312
|
-
configurable: false,
|
|
1313
|
-
enumerable: true
|
|
1314
|
-
}
|
|
1315
|
-
});
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
1113
|
const __Config__ = {
|
|
1319
1114
|
default:{
|
|
1320
1115
|
target:null,
|
|
@@ -1369,7 +1164,7 @@ class UseIPC {
|
|
|
1369
1164
|
this.#channel = new BroadcastChannel(name);
|
|
1370
1165
|
this.#eventData = new Map();
|
|
1371
1166
|
this.#handlers = new Map(); // Map<event, Array<{fn, rooms}>>
|
|
1372
|
-
this.#uuid = "ziko-channel:" +
|
|
1167
|
+
this.#uuid = "ziko-channel:" + (Math.random()*10e16); // To Be Replaced by UUID
|
|
1373
1168
|
this.#subscribers = new Set([this.#uuid]);
|
|
1374
1169
|
this.#currentRooms = new Set();
|
|
1375
1170
|
this.#channel.addEventListener("message", (e) => {
|
|
@@ -1568,19 +1363,186 @@ function __init__global__(){
|
|
|
1568
1363
|
}
|
|
1569
1364
|
}
|
|
1570
1365
|
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1366
|
+
__init__global__();
|
|
1367
|
+
class UIElementCore extends UINode{
|
|
1368
|
+
constructor(){
|
|
1369
|
+
super();
|
|
1370
|
+
}
|
|
1371
|
+
init(element, name, type, render){
|
|
1372
|
+
this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
|
|
1373
|
+
if(typeof element === "string") {
|
|
1374
|
+
switch(type){
|
|
1375
|
+
case "html" : {
|
|
1376
|
+
element = globalThis?.document?.createElement(element);
|
|
1377
|
+
// console.log('1')
|
|
1378
|
+
} break;
|
|
1379
|
+
case "svg" : {
|
|
1380
|
+
element = globalThis?.document?.createElementNS("http://www.w3.org/2000/svg", element);
|
|
1381
|
+
// console.log('2')
|
|
1382
|
+
} break;
|
|
1383
|
+
default : throw Error("Not supported")
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
else this.target = element?.parentElement;
|
|
1387
|
+
Object.assign(this.cache, {
|
|
1388
|
+
name,
|
|
1389
|
+
isInteractive : false,
|
|
1390
|
+
parent:null,
|
|
1391
|
+
isBody:false,
|
|
1392
|
+
isRoot:false,
|
|
1393
|
+
isHidden: false,
|
|
1394
|
+
isFrozzen:false,
|
|
1395
|
+
legacyParent : null,
|
|
1396
|
+
attributes: {},
|
|
1397
|
+
filters: {},
|
|
1398
|
+
temp:{}
|
|
1399
|
+
});
|
|
1400
|
+
this.events = {
|
|
1401
|
+
ptr:null,
|
|
1402
|
+
mouse:null,
|
|
1403
|
+
wheel:null,
|
|
1404
|
+
key:null,
|
|
1405
|
+
drag:null,
|
|
1406
|
+
drop:null,
|
|
1407
|
+
click:null,
|
|
1408
|
+
clipboard:null,
|
|
1409
|
+
focus:null,
|
|
1410
|
+
swipe:null,
|
|
1411
|
+
custom:null,
|
|
1412
|
+
};
|
|
1413
|
+
this.observer={
|
|
1414
|
+
resize:null,
|
|
1415
|
+
intersection:null
|
|
1416
|
+
};
|
|
1417
|
+
if(element) Object.assign(this.cache,{element});
|
|
1418
|
+
// useDefaultStyle && this.style({
|
|
1419
|
+
// position: "relative",
|
|
1420
|
+
// boxSizing:"border-box",
|
|
1421
|
+
// margin:0,
|
|
1422
|
+
// padding:0,
|
|
1423
|
+
// width : "auto",
|
|
1424
|
+
// height : "auto"
|
|
1425
|
+
// });
|
|
1426
|
+
this.items = new UIStore();
|
|
1427
|
+
globalThis.__Ziko__.__UI__[this.cache.name]?globalThis.__Ziko__.__UI__[this.cache.name]?.push(this):globalThis.__Ziko__.__UI__[this.cache.name]=[this];
|
|
1428
|
+
element && render && this?.render?.();
|
|
1429
|
+
globalThis.__Ziko__.__UI__.push(this);
|
|
1430
|
+
}
|
|
1431
|
+
get element(){
|
|
1432
|
+
return this.cache.element;
|
|
1433
|
+
}
|
|
1434
|
+
[Symbol.iterator]() {
|
|
1435
|
+
return this.items[Symbol.iterator]();
|
|
1436
|
+
}
|
|
1437
|
+
maintain() {
|
|
1438
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
1439
|
+
Object.defineProperty(this, i, {
|
|
1440
|
+
value: this.items[i],
|
|
1441
|
+
writable: true,
|
|
1442
|
+
configurable: true,
|
|
1443
|
+
enumerable: false
|
|
1444
|
+
});
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
isInteractive(){
|
|
1448
|
+
return this.cache.isInteractive;
|
|
1449
|
+
}
|
|
1450
|
+
isUIElement(){
|
|
1451
|
+
return true;
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
function register_to_class(target, ...mixins){
|
|
1456
|
+
mixins.forEach(n => _register_to_class_(target, n));
|
|
1457
|
+
}
|
|
1458
|
+
function _register_to_class_(target, mixin) {
|
|
1459
|
+
const descriptors = Object.getOwnPropertyDescriptors(mixin);
|
|
1460
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
1461
|
+
const desc = descriptors[key];
|
|
1462
|
+
if ('get' in desc || 'set' in desc || typeof desc.value !== 'function') {
|
|
1463
|
+
Object.defineProperty(Object.getPrototypeOf(target), key, desc);
|
|
1464
|
+
} else if (typeof desc.value === 'function') {
|
|
1465
|
+
if (!Object.getPrototypeOf(target).hasOwnProperty(key)) {
|
|
1466
|
+
Object.defineProperty(Object.getPrototypeOf(target), key, desc);
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
// export function mount(target = this.target) {
|
|
1473
|
+
// if(this.isBody) return ;
|
|
1474
|
+
// if(target?.isUIElement)target=target.element;
|
|
1475
|
+
// this.target=target;
|
|
1476
|
+
// this.target?.appendChild(this.element);
|
|
1477
|
+
// return this;
|
|
1478
|
+
// }
|
|
1479
|
+
// export function unmount(){
|
|
1480
|
+
// if(this.cache.parent)this.cache.parent.remove(this);
|
|
1481
|
+
// else if(this.target?.children?.length && [...this.target?.children].includes(this.element)) this.target.removeChild(this.element);
|
|
1482
|
+
// return this;
|
|
1483
|
+
// }
|
|
1484
|
+
|
|
1485
|
+
// export function mountAfter(target = this.target, t = 1) {
|
|
1486
|
+
// setTimeout(() => this.mount(), t);
|
|
1487
|
+
// return this;
|
|
1488
|
+
// }
|
|
1489
|
+
// export function unmountAfter(t = 1) {
|
|
1490
|
+
// setTimeout(() => this.unmount(), t);
|
|
1491
|
+
// return this;
|
|
1492
|
+
// }
|
|
1493
|
+
|
|
1494
|
+
function mount(target = this.target, delay = 0) {
|
|
1495
|
+
if (delay > 0) {
|
|
1496
|
+
setTimeout(() => this.mount(target, 0), delay);
|
|
1497
|
+
return this;
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
if (this.isBody) return this;
|
|
1501
|
+
|
|
1502
|
+
if (target?.isUIElement) target = target.element;
|
|
1503
|
+
this.target = target;
|
|
1504
|
+
|
|
1505
|
+
this.target?.appendChild(this.element);
|
|
1506
|
+
return this;
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
function unmount(delay = 0) {
|
|
1510
|
+
if (delay > 0) {
|
|
1511
|
+
setTimeout(() => this.unmount(0), delay);
|
|
1512
|
+
return this;
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
if (this.cache.parent) {
|
|
1516
|
+
this.cache.parent.remove(this);
|
|
1517
|
+
} else if (
|
|
1518
|
+
this.target?.children?.length &&
|
|
1519
|
+
[...this.target.children].includes(this.element)
|
|
1520
|
+
) {
|
|
1521
|
+
this.target.removeChild(this.element);
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
return this;
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
var LifecycleMethods = /*#__PURE__*/Object.freeze({
|
|
1528
|
+
__proto__: null,
|
|
1529
|
+
mount: mount,
|
|
1530
|
+
unmount: unmount
|
|
1531
|
+
});
|
|
1532
|
+
|
|
1533
|
+
if(!globalThis.__Ziko__) __init__global__();
|
|
1534
|
+
|
|
1535
|
+
function useState(initialValue) {
|
|
1536
|
+
|
|
1537
|
+
const {store, index} = __Ziko__.__State__;
|
|
1538
|
+
__Ziko__.__State__.register({
|
|
1539
|
+
value : initialValue,
|
|
1540
|
+
subscribers : new Set(),
|
|
1541
|
+
paused : false
|
|
1542
|
+
});
|
|
1543
|
+
|
|
1544
|
+
let current = store.get(index);
|
|
1545
|
+
|
|
1584
1546
|
function getValue() {
|
|
1585
1547
|
return {
|
|
1586
1548
|
value: current.value,
|
|
@@ -2022,38 +1984,137 @@ function key_details_setter(){
|
|
|
2022
1984
|
}
|
|
2023
1985
|
}
|
|
2024
1986
|
|
|
2025
|
-
function ptr_details_setter(){
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
1987
|
+
function ptr_details_setter() {
|
|
1988
|
+
const rect = this.targetElement.getBoundingClientRect();
|
|
1989
|
+
const e = this.event;
|
|
1990
|
+
let x = (e.clientX - rect.left) | 0;
|
|
1991
|
+
let y = (e.clientY - rect.top) | 0;
|
|
1992
|
+
|
|
1993
|
+
if(this.cache.useNormalisedCoordinates){
|
|
1994
|
+
const w = this.targetElement.clientWidth;
|
|
1995
|
+
const h = this.targetElement.clientHeight;
|
|
1996
|
+
x = +((x / w) * 2 - 1).toFixed(8);
|
|
1997
|
+
y = +((y / h) * -2 + 1).toFixed(8);
|
|
1998
|
+
}
|
|
1999
|
+
switch (this.currentEvent) {
|
|
2000
|
+
|
|
2001
|
+
case "pointerdown":
|
|
2002
|
+
this.dx = x;
|
|
2003
|
+
this.dy = y;
|
|
2030
2004
|
this.isDown = true;
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
this.
|
|
2005
|
+
break;
|
|
2006
|
+
|
|
2007
|
+
case "pointermove":
|
|
2008
|
+
this.mx = x;
|
|
2009
|
+
this.my = y;
|
|
2035
2010
|
this.isMoving = true;
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
this.
|
|
2011
|
+
break;
|
|
2012
|
+
|
|
2013
|
+
case "pointerup":
|
|
2014
|
+
this.ux = x;
|
|
2015
|
+
this.uy = y;
|
|
2040
2016
|
this.isDown = false;
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2017
|
+
this.isMoving = false;
|
|
2018
|
+
break;
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
function mouse_details_setter() {
|
|
2023
|
+
const rect = this.targetElement.getBoundingClientRect();
|
|
2024
|
+
const e = this.event;
|
|
2025
|
+
let x = (e.clientX - rect.left) | 0;
|
|
2026
|
+
let y = (e.clientY - rect.top) | 0;
|
|
2027
|
+
|
|
2028
|
+
if(this.cache.useNormalisedCoordinates){
|
|
2029
|
+
const w = this.targetElement.clientWidth;
|
|
2030
|
+
const h = this.targetElement.clientHeight;
|
|
2031
|
+
x = +((x / w) * 2 - 1).toFixed(8);
|
|
2032
|
+
y = +((y / h) * -2 + 1).toFixed(8);
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
switch (this.currentEvent) {
|
|
2036
|
+
|
|
2037
|
+
case "mousedown":
|
|
2038
|
+
this.dx = x;
|
|
2039
|
+
this.dy = y;
|
|
2040
|
+
this.isDown = true;
|
|
2041
|
+
break;
|
|
2042
|
+
|
|
2043
|
+
case "mousemove":
|
|
2044
|
+
this.mx = x;
|
|
2045
|
+
this.my = y;
|
|
2046
|
+
this.isMoving = true;
|
|
2047
|
+
break;
|
|
2048
|
+
|
|
2049
|
+
case "mouserup":
|
|
2050
|
+
this.ux = x;
|
|
2051
|
+
this.uy = y;
|
|
2052
|
+
this.isDown = false;
|
|
2053
|
+
this.isMoving = false;
|
|
2054
|
+
break;
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
|
|
2058
|
+
function touch_details_setter() {
|
|
2059
|
+
const e = this.event;
|
|
2060
|
+
const touch = e.touches?.[0] || e.changedTouches?.[0];
|
|
2061
|
+
|
|
2062
|
+
if (!touch) return; // should never happen but safe
|
|
2063
|
+
|
|
2064
|
+
const rect = this.targetElement.getBoundingClientRect();
|
|
2065
|
+
let x = touch.clientX - rect.left;
|
|
2066
|
+
let y = touch.clientY - rect.top;
|
|
2067
|
+
|
|
2068
|
+
if(this.cache.useNormalisedCoordinates){
|
|
2069
|
+
const w = this.targetElement.clientWidth;
|
|
2070
|
+
const h = this.targetElement.clientHeight;
|
|
2071
|
+
x = +((x / w) * 2 - 1).toFixed(8);
|
|
2072
|
+
y = +((y / h) * -2 + 1).toFixed(8);
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
switch (this.currentEvent) {
|
|
2076
|
+
case "touchstart":
|
|
2077
|
+
this.dx = x;
|
|
2078
|
+
this.dy = y;
|
|
2079
|
+
this.isDown = true;
|
|
2080
|
+
break;
|
|
2081
|
+
|
|
2082
|
+
case "touchmove":
|
|
2083
|
+
this.mx = x;
|
|
2084
|
+
this.my = y;
|
|
2085
|
+
this.isMoving = true;
|
|
2086
|
+
break;
|
|
2087
|
+
|
|
2088
|
+
case "touchend":
|
|
2089
|
+
this.ux = x;
|
|
2090
|
+
this.uy = y;
|
|
2091
|
+
this.isDown = false;
|
|
2092
|
+
break;
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
|
|
2096
|
+
class CoordinatesBasedEvent extends ZikoEvent{
|
|
2097
|
+
constructor(signature, target = null, Events = [], details_setter, customizer){
|
|
2098
|
+
super(signature, target, Events, details_setter, customizer);
|
|
2099
|
+
Object.assign(this.cache,{
|
|
2100
|
+
useNormalisedCoordinates : false
|
|
2101
|
+
});
|
|
2102
|
+
this.isDown = false;
|
|
2103
|
+
this.isMoving = false;
|
|
2104
|
+
this.dx = 0;
|
|
2105
|
+
this.dy = 0;
|
|
2106
|
+
this.mx = 0;
|
|
2107
|
+
this.my = 0;
|
|
2108
|
+
this.ux = 0;
|
|
2109
|
+
this.uy = 0;
|
|
2110
|
+
}
|
|
2111
|
+
get isDragging(){
|
|
2112
|
+
return this.isDown && this.isMoving
|
|
2113
|
+
}
|
|
2114
|
+
useNormalisedCoordinates(enable = true){
|
|
2115
|
+
this.cache.useNormalisedCoordinates = enable;
|
|
2116
|
+
return this;
|
|
2053
2117
|
}
|
|
2054
|
-
// if(this.currentEvent==="click") this.dx = 0
|
|
2055
|
-
// else this.dx = 1
|
|
2056
|
-
// console.log(this.currentEvent)
|
|
2057
2118
|
}
|
|
2058
2119
|
|
|
2059
2120
|
class ClickAwayEvent extends Event {
|
|
@@ -2284,25 +2345,25 @@ const bind_key_event = (target, customizer) => new ZikoEvent(
|
|
|
2284
2345
|
key_details_setter,
|
|
2285
2346
|
customizer
|
|
2286
2347
|
);
|
|
2287
|
-
const bind_mouse_event = (target, customizer) => new
|
|
2348
|
+
const bind_mouse_event = (target, customizer) => new CoordinatesBasedEvent(
|
|
2288
2349
|
'mouse',
|
|
2289
2350
|
target,
|
|
2290
2351
|
EventsMap.Mouse,
|
|
2291
|
-
|
|
2352
|
+
mouse_details_setter,
|
|
2292
2353
|
customizer
|
|
2293
2354
|
);
|
|
2294
|
-
const bind_pointer_event = (target, customizer) => new
|
|
2355
|
+
const bind_pointer_event = (target, customizer) => new CoordinatesBasedEvent(
|
|
2295
2356
|
'ptr',
|
|
2296
2357
|
target,
|
|
2297
2358
|
EventsMap.Ptr,
|
|
2298
2359
|
ptr_details_setter,
|
|
2299
2360
|
customizer
|
|
2300
2361
|
);
|
|
2301
|
-
const bind_touch_event = (target, customizer) => new
|
|
2362
|
+
const bind_touch_event = (target, customizer) => new CoordinatesBasedEvent(
|
|
2302
2363
|
'touch',
|
|
2303
2364
|
target,
|
|
2304
2365
|
EventsMap.Touch,
|
|
2305
|
-
|
|
2366
|
+
touch_details_setter,
|
|
2306
2367
|
customizer
|
|
2307
2368
|
);
|
|
2308
2369
|
const bind_wheel_event = (target, customizer) => new ZikoEvent(
|
|
@@ -2465,6 +2526,14 @@ var StyleMethods = /*#__PURE__*/Object.freeze({
|
|
|
2465
2526
|
style: style
|
|
2466
2527
|
});
|
|
2467
2528
|
|
|
2529
|
+
// import {
|
|
2530
|
+
// // useCustomEvent,
|
|
2531
|
+
// // useSwipeEvent,
|
|
2532
|
+
// // watchIntersection,
|
|
2533
|
+
// // watchSize,
|
|
2534
|
+
// // watchAttr,
|
|
2535
|
+
// // watchChildren
|
|
2536
|
+
// } from "../../--reactivity-deprecated/events/custom-event.js"
|
|
2468
2537
|
let UIElement$1 = class UIElement extends UIElementCore{
|
|
2469
2538
|
constructor({element, name ='', type='html', render = __Ziko__.__Config__.default.render}={}){
|
|
2470
2539
|
super();
|
|
@@ -3211,274 +3280,454 @@ function trimKeys(obj) {
|
|
|
3211
3280
|
}, Array.isArray(obj) ? [] : {});
|
|
3212
3281
|
}
|
|
3213
3282
|
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
arr = arguments[0];
|
|
3229
|
-
} else {
|
|
3230
|
-
for (i = 0; i < rows; i++) {
|
|
3231
|
-
arr.push([]);
|
|
3232
|
-
arr[i].push(new Array(cols));
|
|
3233
|
-
for (j = 0; j < cols; j++) {
|
|
3234
|
-
arr[i][j] = element[i * cols + j];
|
|
3235
|
-
if (element[i * cols + j] == undefined) arr[i][j] = 0;
|
|
3236
|
-
}
|
|
3237
|
-
}
|
|
3283
|
+
function matrix_inverse(M) {
|
|
3284
|
+
if(M.row !== M.cols) throw Error('is not a square matrix"')
|
|
3285
|
+
if (M.det === 0) throw Error("determinant should not equal 0");
|
|
3286
|
+
const { arr } = M;
|
|
3287
|
+
if (arr.length !== arr[0].length) return;
|
|
3288
|
+
var i = 0, ii = 0, j = 0, dim = arr.length, e = 0;
|
|
3289
|
+
var I = [], C = [];
|
|
3290
|
+
for (i = 0; i < dim; i += 1) {
|
|
3291
|
+
I[I.length] = [];
|
|
3292
|
+
C[C.length] = [];
|
|
3293
|
+
for (j = 0; j < dim; j += 1) {
|
|
3294
|
+
if (i == j) I[i][j] = 1;
|
|
3295
|
+
else I[i][j] = 0;
|
|
3296
|
+
C[i][j] = arr[i][j];
|
|
3238
3297
|
}
|
|
3239
|
-
this.rows = rows;
|
|
3240
|
-
this.cols = cols;
|
|
3241
|
-
this.arr = arr;
|
|
3242
3298
|
}
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3299
|
+
for (i = 0; i < dim; i += 1) {
|
|
3300
|
+
e = C[i][i];
|
|
3301
|
+
if (e == 0) {
|
|
3302
|
+
for (ii = i + 1; ii < dim; ii += 1) {
|
|
3303
|
+
if (C[ii][i] != 0) {
|
|
3304
|
+
for (j = 0; j < dim; j++) {
|
|
3305
|
+
e = C[i][j];
|
|
3306
|
+
C[i][j] = C[ii][j];
|
|
3307
|
+
C[ii][j] = e;
|
|
3308
|
+
e = I[i][j];
|
|
3309
|
+
I[i][j] = I[ii][j];
|
|
3310
|
+
I[ii][j] = e;
|
|
3311
|
+
}
|
|
3312
|
+
break;
|
|
3313
|
+
}
|
|
3314
|
+
}
|
|
3315
|
+
e = C[i][i];
|
|
3316
|
+
if (e == 0) return;
|
|
3317
|
+
}
|
|
3318
|
+
for (j = 0; j < dim; j++) {
|
|
3319
|
+
C[i][j] = C[i][j] / e;
|
|
3320
|
+
I[i][j] = I[i][j] / e;
|
|
3321
|
+
}
|
|
3322
|
+
for (ii = 0; ii < dim; ii++) {
|
|
3323
|
+
if (ii == i) {
|
|
3324
|
+
continue;
|
|
3325
|
+
}
|
|
3326
|
+
e = C[ii][i];
|
|
3327
|
+
for (j = 0; j < dim; j++) {
|
|
3328
|
+
C[ii][j] -= e * C[i][j];
|
|
3329
|
+
I[ii][j] -= e * I[i][j];
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3259
3332
|
}
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3333
|
+
return new M.constructor(I);
|
|
3334
|
+
}
|
|
3335
|
+
|
|
3336
|
+
function matrix_det(M) {
|
|
3337
|
+
if (!M.isSquare) return new Error("is not square matrix");
|
|
3338
|
+
if (M.rows == 1) return M.arr[0][0];
|
|
3339
|
+
function determinat(M) {
|
|
3340
|
+
if (M.length == 2) {
|
|
3341
|
+
if (M.flat(1).some((n) => n?.isMatrix?.())) {
|
|
3342
|
+
console.warn("Tensors are not completely supported yet ...");
|
|
3343
|
+
return;
|
|
3344
|
+
}
|
|
3345
|
+
return sub(mul(M[0][0],M[1][1]),mul(M[0][1],M[1][0]))
|
|
3346
|
+
}
|
|
3347
|
+
var answer = 0;
|
|
3348
|
+
for (var i = 0; i < M.length; i++) {
|
|
3349
|
+
//console.log(M[0][i]);
|
|
3350
|
+
/*answer = answer.add(
|
|
3351
|
+
pow(-1, i)
|
|
3352
|
+
.mul(M[0][i])
|
|
3353
|
+
.mul(determinat(deleteRowAndColumn(M, i)))
|
|
3354
|
+
);*/
|
|
3355
|
+
//const to_be_added=add(mul(pow(-1, i),mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
|
|
3356
|
+
const to_be_added=add(mul(pow$1(-1, i),mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
|
|
3357
|
+
answer=add(answer,to_be_added);
|
|
3358
|
+
}
|
|
3359
|
+
return answer;
|
|
3264
3360
|
}
|
|
3265
|
-
|
|
3266
|
-
|
|
3361
|
+
return determinat(M.arr);
|
|
3362
|
+
}
|
|
3363
|
+
function deleteRowAndColumn(M, index) {
|
|
3364
|
+
var temp = [];
|
|
3365
|
+
for (let i = 0; i < M.length; i++) temp.push(M[i].slice(0));
|
|
3366
|
+
temp.splice(0, 1);
|
|
3367
|
+
for (let i = 0; i < temp.length; i++) temp[i].splice(index, 1);
|
|
3368
|
+
return temp;
|
|
3369
|
+
}
|
|
3370
|
+
|
|
3371
|
+
function hstack(M1, M2){
|
|
3372
|
+
M1 = M1.clone();
|
|
3373
|
+
M2 = M2.clone();
|
|
3374
|
+
if (M1.rows !== M2.rows) return;
|
|
3375
|
+
let newArr = M1.arr;
|
|
3376
|
+
for (let i = 0; i < M1.rows; i++)
|
|
3377
|
+
for (let j = M1.cols; j < M1.cols + M2.cols; j++)
|
|
3378
|
+
newArr[i][j] = M2.arr[i][j - M1.cols];
|
|
3379
|
+
M1.cols += M2.cols;
|
|
3380
|
+
return new M1.constructor(M1.rows, M1.cols, newArr.flat(1));
|
|
3381
|
+
}
|
|
3382
|
+
|
|
3383
|
+
function vstack(M1, M2){
|
|
3384
|
+
M1 = M1.clone();
|
|
3385
|
+
M2 = M2.clone();
|
|
3386
|
+
if (M1.cols !== M2.cols) return;
|
|
3387
|
+
let newArr = M1.arr;
|
|
3388
|
+
for (let i = M1.rows; i < M1.rows + M2.rows; i++) {
|
|
3389
|
+
newArr[i] = [];
|
|
3390
|
+
for (let j = 0; j < M1.cols; j++) newArr[i][j] = M2.arr[i - M1.rows][j];
|
|
3391
|
+
}
|
|
3392
|
+
M1.rows += M2.rows;
|
|
3393
|
+
return new M1.constructor(M1.rows, M1.cols, newArr.flat(1));
|
|
3394
|
+
}
|
|
3395
|
+
|
|
3396
|
+
class Matrix{
|
|
3397
|
+
constructor(rows, cols, element = [] ) {
|
|
3398
|
+
if(rows instanceof Matrix){
|
|
3399
|
+
this.arr=rows.arr;
|
|
3400
|
+
this.rows=rows.rows;
|
|
3401
|
+
this.cols=rows.cols;
|
|
3402
|
+
}
|
|
3403
|
+
else {
|
|
3404
|
+
let arr = [], i, j;
|
|
3405
|
+
if (arguments[0] instanceof Array) {
|
|
3406
|
+
rows = arguments[0].length;
|
|
3407
|
+
cols = arguments[0][0].length;
|
|
3408
|
+
arr = arguments[0];
|
|
3409
|
+
} else {
|
|
3410
|
+
for (i = 0; i < rows; i++) {
|
|
3411
|
+
arr.push([]);
|
|
3412
|
+
arr[i].push(new Array(cols));
|
|
3413
|
+
for (j = 0; j < cols; j++) {
|
|
3414
|
+
arr[i][j] = element[i * cols + j];
|
|
3415
|
+
if (element[i * cols + j] == undefined) arr[i][j] = 0;
|
|
3416
|
+
}
|
|
3417
|
+
}
|
|
3418
|
+
}
|
|
3419
|
+
this.rows = rows;
|
|
3420
|
+
this.cols = cols;
|
|
3421
|
+
this.arr = arr;
|
|
3267
3422
|
}
|
|
3268
|
-
|
|
3269
|
-
return this.rows * this.cols;
|
|
3270
|
-
}
|
|
3271
|
-
get shape() {
|
|
3272
|
-
return [this.rows, this.cols];
|
|
3423
|
+
this.#maintain();
|
|
3273
3424
|
}
|
|
3274
|
-
|
|
3275
|
-
return
|
|
3425
|
+
isMatrix(){
|
|
3426
|
+
return true
|
|
3276
3427
|
}
|
|
3277
|
-
|
|
3278
|
-
return new Matrix(this.
|
|
3428
|
+
clone() {
|
|
3429
|
+
return new Matrix(this.rows, this.cols, this.arr.flat(1));
|
|
3279
3430
|
}
|
|
3280
3431
|
[Symbol.iterator]() {
|
|
3281
3432
|
return this.arr[Symbol.iterator]();
|
|
3282
3433
|
}
|
|
3283
3434
|
#maintain() {
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
}
|
|
3292
|
-
}
|
|
3293
|
-
get(row = 0, col = 0) {
|
|
3294
|
-
if (col == -1) return this.arr[row];
|
|
3295
|
-
else if (row == -1) return this.arr.map((n) => n[col]);
|
|
3296
|
-
else return this.arr[row][col];
|
|
3297
|
-
}
|
|
3298
|
-
set(row = 0, col = 0, value) {
|
|
3299
|
-
if (col == -1) return (this.arr[row] = value);
|
|
3300
|
-
else if (row == -1) {
|
|
3301
|
-
for (let i = 0; i < this.cols; i++) {
|
|
3302
|
-
this.arr[i][col] = value[i] || 0;
|
|
3303
|
-
}
|
|
3304
|
-
return this.arr;
|
|
3435
|
+
for (let i = 0; i < this.arr.length; i++) {
|
|
3436
|
+
Object.defineProperty(this, i, {
|
|
3437
|
+
value: this.arr[i],
|
|
3438
|
+
writable: true,
|
|
3439
|
+
configurable: true,
|
|
3440
|
+
enumerable: false
|
|
3441
|
+
});
|
|
3305
3442
|
}
|
|
3306
|
-
return (this.arr[row][col] = value);
|
|
3307
3443
|
}
|
|
3308
|
-
get
|
|
3309
|
-
return this.rows
|
|
3444
|
+
get size() {
|
|
3445
|
+
return this.rows * this.cols;
|
|
3446
|
+
}
|
|
3447
|
+
get shape() {
|
|
3448
|
+
return [this.rows, this.cols];
|
|
3310
3449
|
}
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
const T = this.T;
|
|
3314
|
-
const M = this.clone;
|
|
3315
|
-
return Matrix.sub(M, T).max == 0 && Matrix.sub(M, T).min == 0;
|
|
3450
|
+
toString(){
|
|
3451
|
+
return arr2str(this.arr);
|
|
3316
3452
|
}
|
|
3317
|
-
|
|
3318
|
-
if (
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3453
|
+
at(i = 0, j = undefined) {
|
|
3454
|
+
if (i < 0) i += this.rows;
|
|
3455
|
+
if (i < 0 || i >= this.rows) throw new Error('Row index out of bounds');
|
|
3456
|
+
if (j === undefined) return this.arr[i];
|
|
3457
|
+
if (j < 0) j += this.cols;
|
|
3458
|
+
if (j < 0 || j >= this.cols) throw new Error('Column index out of bounds');
|
|
3459
|
+
return this.arr[i][j];
|
|
3322
3460
|
}
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3461
|
+
slice(r0=0, c0=0, r1=this.rows-1, c1=this.cols-1) {
|
|
3462
|
+
let newRow = r1 - r0,
|
|
3463
|
+
newCol = c1 - c0;
|
|
3464
|
+
let newArr = new Array(newCol);
|
|
3465
|
+
for (let i = 0; i < newRow; i++) {
|
|
3466
|
+
newArr[i] = [];
|
|
3467
|
+
for (let j = 0; j < newCol; j++) newArr[i][j] = this.arr[i + r0][j + c0];
|
|
3468
|
+
}
|
|
3469
|
+
return new Matrix(newRow, newCol, newArr.flat(1));
|
|
3330
3470
|
}
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
return this.isDiag && (this.det == 1 || this.det == -1);
|
|
3471
|
+
static slice(m1,r0=0, c0=0, r1=this.rows-1, c1=this.cols-1) {
|
|
3472
|
+
return m1.slice(r0, c0, r1, c1);
|
|
3334
3473
|
}
|
|
3335
|
-
|
|
3336
|
-
if
|
|
3337
|
-
|
|
3338
|
-
const MM = Matrix.dot(M, M);
|
|
3339
|
-
return Matrix.sub(MM, M).max == 0 && Matrix.sub(MM, M).min == 0;
|
|
3474
|
+
reshape(newRows, newCols) {
|
|
3475
|
+
if(!(newRows * newCols === this.rows * this.cols)) throw Error('size not matched')
|
|
3476
|
+
return new Matrix(newRows, newCols, this.arr.flat(1));
|
|
3340
3477
|
}
|
|
3341
3478
|
get T() {
|
|
3342
3479
|
let transpose = [];
|
|
3343
3480
|
for (let i = 0; i < this.arr[0].length; i++) {
|
|
3344
3481
|
transpose[i] = [];
|
|
3345
|
-
for (let j = 0; j < this.arr.length; j++)
|
|
3482
|
+
for (let j = 0; j < this.arr.length; j++)
|
|
3346
3483
|
transpose[i][j] = this.arr[j][i];
|
|
3347
|
-
}
|
|
3348
3484
|
}
|
|
3349
3485
|
return new Matrix(this.cols, this.rows, transpose.flat(1));
|
|
3350
3486
|
}
|
|
3351
3487
|
get det() {
|
|
3352
|
-
|
|
3353
|
-
if (this.rows == 1) return this.arr[0][0];
|
|
3354
|
-
function determinat(M) {
|
|
3355
|
-
if (M.length == 2) {
|
|
3356
|
-
if (M.flat(1).some((n) => n instanceof Matrix)) {
|
|
3357
|
-
console.warn("Tensors are not completely supported yet ...");
|
|
3358
|
-
return;
|
|
3359
|
-
}
|
|
3360
|
-
return Utils.sub(Utils.mul(M[0][0],M[1][1]),Utils.mul(M[0][1],M[1][0]))
|
|
3361
|
-
}
|
|
3362
|
-
var answer = 0;
|
|
3363
|
-
for (var i = 0; i < M.length; i++) {
|
|
3364
|
-
//console.log(M[0][i]);
|
|
3365
|
-
/*answer = answer.add(
|
|
3366
|
-
pow(-1, i)
|
|
3367
|
-
.mul(M[0][i])
|
|
3368
|
-
.mul(determinat(deleteRowAndColumn(M, i)))
|
|
3369
|
-
);*/
|
|
3370
|
-
//const to_be_added=Utils.add(Utils.mul(pow(-1, i),Utils.mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
|
|
3371
|
-
const to_be_added=Utils.add(Utils.mul(pow$1(-1, i),Utils.mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
|
|
3372
|
-
answer=Utils.add(answer,to_be_added);
|
|
3373
|
-
}
|
|
3374
|
-
return answer;
|
|
3375
|
-
}
|
|
3376
|
-
function deleteRowAndColumn(M, index) {
|
|
3377
|
-
var temp = [];
|
|
3378
|
-
for (let i = 0; i < M.length; i++) temp.push(M[i].slice(0));
|
|
3379
|
-
temp.splice(0, 1);
|
|
3380
|
-
for (let i = 0; i < temp.length; i++) temp[i].splice(index, 1);
|
|
3381
|
-
return temp;
|
|
3382
|
-
}
|
|
3383
|
-
return determinat(this.arr);
|
|
3488
|
+
return matrix_det(this)
|
|
3384
3489
|
}
|
|
3385
3490
|
get inv() {
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3491
|
+
return matrix_inverse(this)
|
|
3492
|
+
}
|
|
3493
|
+
static eye(size) {
|
|
3494
|
+
let result = new Matrix(size, size);
|
|
3495
|
+
for (let i = 0; i < size; i++)
|
|
3496
|
+
for (let j = 0; j < size; j++) i === j ? (result.arr[i][j] = 1) : (result.arr[i][j] = 0);
|
|
3497
|
+
return result;
|
|
3390
3498
|
}
|
|
3391
3499
|
static zeros(rows, cols) {
|
|
3392
3500
|
let result = new Matrix(rows, cols);
|
|
3393
|
-
for (let i = 0; i < rows; i++)
|
|
3501
|
+
for (let i = 0; i < rows; i++)
|
|
3502
|
+
for (var j = 0; j < cols; j++) result.arr[i][j] = 0;
|
|
3394
3503
|
return result;
|
|
3395
3504
|
}
|
|
3396
3505
|
static ones(rows, cols) {
|
|
3397
3506
|
let result = new Matrix(rows, cols);
|
|
3398
|
-
for (let i = 0; i < rows; i++)
|
|
3507
|
+
for (let i = 0; i < rows; i++)
|
|
3508
|
+
for (let j = 0; j < cols; j++) result.arr[i][j] = 1;
|
|
3399
3509
|
return result;
|
|
3400
3510
|
}
|
|
3401
3511
|
static nums(rows, cols, number) {
|
|
3402
3512
|
let result = new Matrix(rows, cols);
|
|
3403
|
-
for (let i = 0; i < rows; i++)
|
|
3513
|
+
for (let i = 0; i < rows; i++)
|
|
3514
|
+
for (let j = 0; j < cols; j++) result.arr[i][j] = number;
|
|
3404
3515
|
return result;
|
|
3405
3516
|
}
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3517
|
+
hstack(...matrices) {
|
|
3518
|
+
const M=[this, ...matrices].reduce((a,b)=>hstack(a, b));
|
|
3519
|
+
Object.assign(this, M);
|
|
3520
|
+
this.#maintain();
|
|
3521
|
+
return this;
|
|
3522
|
+
}
|
|
3523
|
+
static hstack(matrix,...matrices) {
|
|
3524
|
+
return matrix.clone().hstack(...matrices);
|
|
3525
|
+
}
|
|
3526
|
+
vstack(...matrices){
|
|
3527
|
+
const M=[this, ...matrices].reduce((a,b)=>vstack(a, b));
|
|
3528
|
+
Object.assign(this, M);
|
|
3529
|
+
this.#maintain();
|
|
3530
|
+
return this;
|
|
3531
|
+
}
|
|
3532
|
+
static vstack(matrix,...matrices) {
|
|
3533
|
+
return matrix.clone().vstack(...matrices);
|
|
3534
|
+
}
|
|
3535
|
+
hqueue(...matrices){
|
|
3536
|
+
const M=[this, ...matrices].reverse().reduce((a,b)=>hstack(a, b));
|
|
3537
|
+
Object.assign(this, M);
|
|
3538
|
+
return this;
|
|
3539
|
+
}
|
|
3540
|
+
static hqueue(matrix,...matrices) {
|
|
3541
|
+
return matrix.clone().hqueue(...matrices);
|
|
3542
|
+
}
|
|
3543
|
+
vqueue(...matrices){
|
|
3544
|
+
const M=[this,...matrices].reverse().reduce((a, b)=>vstack(a, b));
|
|
3545
|
+
Object.assign(this, M);
|
|
3546
|
+
return this;
|
|
3547
|
+
}
|
|
3548
|
+
static vqueue(matrix,...matrices) {
|
|
3549
|
+
return matrix.clone().vqueue(...matrices);
|
|
3550
|
+
}
|
|
3551
|
+
shuffle(){
|
|
3552
|
+
this.arr = this.arr.sort(()=>0.5-Math.random());
|
|
3553
|
+
return this;
|
|
3554
|
+
}
|
|
3555
|
+
static shuffle(M){
|
|
3556
|
+
return M.clone().shuffle()
|
|
3557
|
+
}
|
|
3558
|
+
// get reel() {
|
|
3559
|
+
// return new Matrix(this.cols, this.rows, this.arr.flat(1).reel);
|
|
3560
|
+
// }
|
|
3561
|
+
// get imag() {
|
|
3562
|
+
// return new Matrix(this.cols, this.rows, this.arr.flat(1).imag);
|
|
3563
|
+
// }
|
|
3564
|
+
|
|
3565
|
+
// Checkers
|
|
3566
|
+
get isSquare() {
|
|
3567
|
+
return this.rows === this.cols;
|
|
3568
|
+
}
|
|
3569
|
+
get isSym() {
|
|
3570
|
+
if (!this.isSquare) return false;
|
|
3571
|
+
for (let i = 0; i < this.rows; i++) {
|
|
3572
|
+
for (let j = i + 1; j < this.cols; j++) {
|
|
3573
|
+
if (this.arr[i][j] !== this.arr[j][i]) return false;
|
|
3574
|
+
}
|
|
3575
|
+
}
|
|
3576
|
+
return true;
|
|
3577
|
+
}
|
|
3578
|
+
get isAntiSym() {
|
|
3579
|
+
if (!this.isSquare) return false;
|
|
3580
|
+
const n = this.rows;
|
|
3581
|
+
for (let i = 0; i < n; i++) {
|
|
3582
|
+
if (this.arr[i][i] !== 0) return false;
|
|
3583
|
+
for (let j = i + 1; j < n; j++) {
|
|
3584
|
+
if (this.arr[i][j] !== -this.arr[j][i]) return false;
|
|
3585
|
+
}
|
|
3586
|
+
}
|
|
3587
|
+
return true;
|
|
3588
|
+
}
|
|
3589
|
+
get isDiag() {
|
|
3590
|
+
if (!this.isSquare) return false;
|
|
3591
|
+
const n = this.rows;
|
|
3592
|
+
for (let i = 0; i < n; i++) {
|
|
3593
|
+
for (let j = i + 1; j < n; j++) {
|
|
3594
|
+
if (this.arr[i][j] !== 0 || this.arr[j][i] !== 0) return false;
|
|
3595
|
+
}
|
|
3596
|
+
}
|
|
3597
|
+
return true;
|
|
3598
|
+
}
|
|
3599
|
+
get isOrtho() {
|
|
3600
|
+
if (!this.isSquare) return false;
|
|
3601
|
+
return this.isDiag && (this.det == 1 || this.det == -1);
|
|
3602
|
+
}
|
|
3603
|
+
get isIdemp() {
|
|
3604
|
+
if (!this.isSquare) return false;
|
|
3605
|
+
const n = this.rows;
|
|
3606
|
+
const A = this.arr;
|
|
3607
|
+
// Compute A * A
|
|
3608
|
+
const MM = [];
|
|
3609
|
+
for (let i = 0; i < n; i++) {
|
|
3610
|
+
MM[i] = [];
|
|
3611
|
+
for (let j = 0; j < n; j++) {
|
|
3612
|
+
let sum = 0;
|
|
3613
|
+
for (let k = 0; k < n; k++) {
|
|
3614
|
+
sum += A[i][k] * A[k][j];
|
|
3424
3615
|
}
|
|
3425
|
-
|
|
3426
|
-
}
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
permutation:(rows,cols,arr)=>{
|
|
3433
|
-
//return new Matrix(rows, cols, Random.permutation(...arr))
|
|
3616
|
+
MM[i][j] = sum;
|
|
3617
|
+
}
|
|
3618
|
+
}
|
|
3619
|
+
// Check if A * A == A
|
|
3620
|
+
for (let i = 0; i < n; i++) {
|
|
3621
|
+
for (let j = 0; j < n; j++) {
|
|
3622
|
+
if (MM[i][j] !== A[i][j]) return false;
|
|
3434
3623
|
}
|
|
3435
3624
|
}
|
|
3625
|
+
return true;
|
|
3436
3626
|
}
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3627
|
+
|
|
3628
|
+
get isUpperTri() {
|
|
3629
|
+
if (!this.isSquare) return false;
|
|
3630
|
+
const n = this.rows;
|
|
3631
|
+
for (let i = 1; i < n; i++) {
|
|
3632
|
+
for (let j = 0; j < i; j++) {
|
|
3633
|
+
if (this.arr[i][j] !== 0) return false;
|
|
3634
|
+
}
|
|
3635
|
+
}
|
|
3636
|
+
return true;
|
|
3441
3637
|
}
|
|
3638
|
+
get isLowerTri() {
|
|
3639
|
+
if (!this.isSquare) return false;
|
|
3640
|
+
const n = this.rows;
|
|
3641
|
+
for (let i = 0; i < n - 1; i++) {
|
|
3642
|
+
for (let j = i + 1; j < n; j++) {
|
|
3643
|
+
if (this.arr[i][j] !== 0) return false;
|
|
3644
|
+
}
|
|
3645
|
+
}
|
|
3646
|
+
return true;
|
|
3647
|
+
}
|
|
3648
|
+
|
|
3649
|
+
// static get rand(){
|
|
3650
|
+
// return {
|
|
3651
|
+
// int:(rows, cols, a, b)=>{
|
|
3652
|
+
// let result = new Matrix(rows, cols);
|
|
3653
|
+
// for (let i = 0; i < rows; i++) for (let j = 0; j < cols; j++) result.arr[i][j] = Random.randInt(a, b);
|
|
3654
|
+
// return result;
|
|
3655
|
+
// },
|
|
3656
|
+
// bin:(rows,cols)=>{
|
|
3657
|
+
// let result = new Matrix(rows, cols);
|
|
3658
|
+
// for (let i = 0; i < rows; i++) {
|
|
3659
|
+
// for (let j = 0; j < cols; j++) result.arr[i][j] = Random.randBin;
|
|
3660
|
+
// }
|
|
3661
|
+
// return result;
|
|
3662
|
+
// },
|
|
3663
|
+
// hex:(rows,cols)=>{
|
|
3664
|
+
// let result = new Matrix(rows, cols);
|
|
3665
|
+
// for (let i = 0; i < rows; i++) {
|
|
3666
|
+
// for (let j = 0; j < cols; j++) result.arr[i][j] = Random.randHex;
|
|
3667
|
+
// }
|
|
3668
|
+
// return result;
|
|
3669
|
+
// },
|
|
3670
|
+
// choices:(rows, cols, choices, p)=>{
|
|
3671
|
+
// let result = new Matrix(rows, cols);
|
|
3672
|
+
// for (let i = 0; i < rows; i++) for (let j = 0; j < cols; j++) result.arr[i][j] = Random.choice(choices, p);
|
|
3673
|
+
// return result
|
|
3674
|
+
// },
|
|
3675
|
+
// permutation:(rows,cols,arr)=>{
|
|
3676
|
+
// //return new Matrix(rows, cols, Random.permutation(...arr))
|
|
3677
|
+
// }
|
|
3678
|
+
// }
|
|
3679
|
+
// }
|
|
3680
|
+
// static rands(rows, cols, a = 1, b) {
|
|
3681
|
+
// let result = new Matrix(rows, cols);
|
|
3682
|
+
// for (let i = 0; i < rows; i++) for (let j = 0; j < cols; j++) result.arr[i][j] = Random.rand(a, b);
|
|
3683
|
+
// return result;
|
|
3684
|
+
// }
|
|
3442
3685
|
map(Imin, Imax, Fmin, Fmax) {
|
|
3443
|
-
|
|
3686
|
+
this.arr = map$1(this.arr, Imin, Imax, Fmin, Fmax);
|
|
3687
|
+
return this;
|
|
3444
3688
|
}
|
|
3445
3689
|
lerp(min, max) {
|
|
3446
|
-
|
|
3690
|
+
this.arr = lerp(this.arr, min, max);
|
|
3691
|
+
return this;
|
|
3447
3692
|
}
|
|
3448
3693
|
norm(min, max) {
|
|
3449
|
-
|
|
3694
|
+
this.arr = norm(this.arr, min, max);
|
|
3695
|
+
return this;
|
|
3450
3696
|
}
|
|
3451
3697
|
clamp(min, max) {
|
|
3452
|
-
|
|
3698
|
+
this.arr = clamp(this.arr, min, max);
|
|
3699
|
+
return this;
|
|
3453
3700
|
}
|
|
3454
|
-
static map(
|
|
3455
|
-
return
|
|
3701
|
+
static map(M, Imin, Imax, Fmin, Fmax) {
|
|
3702
|
+
return M.clone().map(Imin, Imax, Fmin, Fmax)
|
|
3456
3703
|
}
|
|
3457
|
-
static lerp(
|
|
3458
|
-
return
|
|
3704
|
+
static lerp(M, min, max) {
|
|
3705
|
+
return M.clone().lerp(min, max)
|
|
3459
3706
|
}
|
|
3460
|
-
static norm(
|
|
3461
|
-
return
|
|
3707
|
+
static norm(M, min, max) {
|
|
3708
|
+
return M.clone().norm(min, max)
|
|
3462
3709
|
}
|
|
3463
|
-
static clamp(
|
|
3464
|
-
return
|
|
3710
|
+
static clamp(M, min, max) {
|
|
3711
|
+
return M.clone().clamp(min, max)
|
|
3465
3712
|
}
|
|
3466
3713
|
toPrecision(p) {
|
|
3467
|
-
for (let i = 0; i < this.cols; i++)
|
|
3714
|
+
for (let i = 0; i < this.cols; i++)
|
|
3715
|
+
for (let j = 0; j < this.rows; j++)
|
|
3716
|
+
this.arr[i][j] = +this.arr[i][j].toPrecision(p);
|
|
3468
3717
|
return this;
|
|
3469
3718
|
}
|
|
3470
|
-
get toBin() {
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
}
|
|
3474
|
-
get toOct() {
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
}
|
|
3478
|
-
get toHex() {
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
}
|
|
3719
|
+
// get toBin() {
|
|
3720
|
+
// let newArr = this.arr.flat(1).toBin;
|
|
3721
|
+
// return new Matrix(this.rows, this.cols, newArr);
|
|
3722
|
+
// }
|
|
3723
|
+
// get toOct() {
|
|
3724
|
+
// let newArr = this.arr.flat(1).toOct;
|
|
3725
|
+
// return new Matrix(this.rows, this.cols, newArr);
|
|
3726
|
+
// }
|
|
3727
|
+
// get toHex() {
|
|
3728
|
+
// let newArr = this.arr.flat(1).toHex;
|
|
3729
|
+
// return new Matrix(this.rows, this.cols, newArr);
|
|
3730
|
+
// }
|
|
3482
3731
|
/*get isOdd() {
|
|
3483
3732
|
let newArr = this.arr.flat(1).isOdd;
|
|
3484
3733
|
return new Matrix(this.rows, this.cols, newArr);
|
|
@@ -3518,136 +3767,77 @@ class Matrix{
|
|
|
3518
3767
|
count(n) {
|
|
3519
3768
|
return this.arr.flat(1).count(n);
|
|
3520
3769
|
}
|
|
3521
|
-
toBase(n) {
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
}
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
for (let i = 0; i < this.rows; i++) for (let j = this.cols; j < this.cols + matrix.cols; j++) newArr[i][j] = matrix.arr[i][j - this.cols];
|
|
3529
|
-
this.cols += matrix.cols;
|
|
3530
|
-
return new Matrix(this.rows, this.cols, newArr.flat(1));
|
|
3770
|
+
// toBase(n) {
|
|
3771
|
+
// let newArr = this.arr.flat(1).toBase(n);
|
|
3772
|
+
// return new Matrix(this.rows, this.cols, newArr);
|
|
3773
|
+
// }
|
|
3774
|
+
|
|
3775
|
+
splice(r0,c0,deleteCount,...items){
|
|
3776
|
+
|
|
3531
3777
|
}
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
Object.assign(this,M);
|
|
3535
|
-
return this;
|
|
3778
|
+
getRows(ri, rf = ri + 1) {
|
|
3779
|
+
return this.slice(ri, 0, rf, this.cols);
|
|
3536
3780
|
}
|
|
3537
|
-
|
|
3538
|
-
return
|
|
3781
|
+
getCols(ci, cf = ci + 1) {
|
|
3782
|
+
return this.slice(0, ci, this.rows, cf);
|
|
3539
3783
|
}
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
let newArr = this.arr;
|
|
3543
|
-
for (let i = this.rows; i < this.rows + matrix.rows; i++) {
|
|
3544
|
-
newArr[i] = [];
|
|
3545
|
-
for (let j = 0; j < this.cols; j++) newArr[i][j] = matrix.arr[i - this.rows][j];
|
|
3546
|
-
}
|
|
3547
|
-
this.rows += matrix.rows;
|
|
3548
|
-
return new Matrix(this.rows, this.cols, newArr.flat(1));
|
|
3784
|
+
static getRows(m, ri, rf = ri + 1) {
|
|
3785
|
+
return m.slice(ri, 0, rf, m.cols);
|
|
3549
3786
|
}
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
Object.assign(this,M);
|
|
3553
|
-
return this;
|
|
3787
|
+
static getCols(m, ci, cf = ci + 1) {
|
|
3788
|
+
return m.slice(0, ci, m.rows, cf);
|
|
3554
3789
|
}
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
return this;
|
|
3562
|
-
}
|
|
3563
|
-
vqueue(...matrices){
|
|
3564
|
-
const M=[this,...matrices].reverse().reduce((a,b)=>a.#vstack(b));
|
|
3565
|
-
Object.assign(this,M);
|
|
3566
|
-
return this;
|
|
3567
|
-
}
|
|
3568
|
-
static hqueue(matrix,...matrices) {
|
|
3569
|
-
return matrix.clone.hqueue(...matrices);
|
|
3570
|
-
}
|
|
3571
|
-
static vqueue(matrix,...matrices) {
|
|
3572
|
-
return matrix.clone.vqueue(...matrices);
|
|
3573
|
-
}
|
|
3574
|
-
slice(r0=0, c0=0, r1=this.rows-1, c1=this.cols-1) {
|
|
3575
|
-
let newRow = r1 - r0,
|
|
3576
|
-
newCol = c1 - c0;
|
|
3577
|
-
let newArr = new Array(newCol);
|
|
3578
|
-
for (let i = 0; i < newRow; i++) {
|
|
3579
|
-
newArr[i] = [];
|
|
3580
|
-
for (let j = 0; j < newCol; j++) newArr[i][j] = this.arr[i + r0][j + c0];
|
|
3581
|
-
}
|
|
3582
|
-
return new Matrix(newRow, newCol, newArr.flat(1));
|
|
3583
|
-
}
|
|
3584
|
-
static slice(m1,r0=0, c0=0, r1=this.rows-1, c1=this.cols-1) {
|
|
3585
|
-
return m1.slice(r0, c0, r1, c1);
|
|
3586
|
-
}
|
|
3587
|
-
splice(r0,c0,deleteCount,...items){
|
|
3588
|
-
|
|
3589
|
-
}
|
|
3590
|
-
getRows(ri, rf = ri + 1) {
|
|
3591
|
-
return this.slice(ri, 0, rf, this.cols);
|
|
3592
|
-
}
|
|
3593
|
-
getCols(ci, cf = ci + 1) {
|
|
3594
|
-
return this.slice(0, ci, this.rows, cf);
|
|
3595
|
-
}
|
|
3596
|
-
static getRows(m, ri, rf = ri + 1) {
|
|
3597
|
-
return m.slice(ri, 0, rf, m.cols);
|
|
3598
|
-
}
|
|
3599
|
-
static getCols(m, ci, cf = ci + 1) {
|
|
3600
|
-
return m.slice(0, ci, m.rows, cf);
|
|
3601
|
-
}
|
|
3602
|
-
add(...matr) {
|
|
3603
|
-
for (let k = 0; k < matr.length; k++) {
|
|
3604
|
-
if (typeof matr[k] == "number"||matr[k] instanceof Complex) matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
|
|
3605
|
-
for (let i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] = Utils.add(this.arr[i][j],matr[k].arr[i][j]);
|
|
3606
|
-
}
|
|
3607
|
-
return new Matrix(this.rows, this.cols, this.arr.flat(1));
|
|
3790
|
+
add(...matr) {
|
|
3791
|
+
for (let k = 0; k < matr.length; k++) {
|
|
3792
|
+
if (typeof matr[k] == "number"||matr[k] instanceof Complex) matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
|
|
3793
|
+
for (let i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] = add(this.arr[i][j],matr[k].arr[i][j]);
|
|
3794
|
+
}
|
|
3795
|
+
return new Matrix(this.rows, this.cols, this.arr.flat(1));
|
|
3608
3796
|
}
|
|
3609
3797
|
sub(...matr) {
|
|
3610
3798
|
for (let k = 0; k < matr.length; k++) {
|
|
3611
3799
|
if (typeof matr[k] == "number") matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
|
|
3612
|
-
for (let i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] =
|
|
3800
|
+
for (let i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] = sub(this.arr[i][j],matr[k].arr[i][j]);
|
|
3613
3801
|
}
|
|
3614
3802
|
return new Matrix(this.rows, this.cols, this.arr.flat(1));
|
|
3615
3803
|
}
|
|
3616
3804
|
static add(m1, ...m2) {
|
|
3617
|
-
return m1.clone.add(...m2);
|
|
3805
|
+
return m1.clone().add(...m2);
|
|
3618
3806
|
}
|
|
3619
3807
|
static sub(m1, ...m2) {
|
|
3620
|
-
return m1.clone.sub(...m2);
|
|
3808
|
+
return m1.clone().sub(...m2);
|
|
3621
3809
|
}
|
|
3622
3810
|
mul(...matr) {
|
|
3623
3811
|
for (let k = 0; k < matr.length; k++) {
|
|
3624
3812
|
if (typeof matr[k] == "number") matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
|
|
3625
|
-
for (var i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] =
|
|
3813
|
+
for (var i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] = mul(this.arr[i][j],matr[k].arr[i][j]);
|
|
3626
3814
|
}
|
|
3627
3815
|
return new Matrix(this.rows, this.cols, this.arr.flat(1));
|
|
3628
3816
|
}
|
|
3629
3817
|
div(...matr) {
|
|
3630
3818
|
for (let k = 0; k < matr.length; k++) {
|
|
3631
3819
|
if (typeof matr[k] == "number") matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
|
|
3632
|
-
for (let i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] =
|
|
3820
|
+
for (let i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] = div(this.arr[i][j],matr[k].arr[i][j]);
|
|
3633
3821
|
}
|
|
3634
3822
|
return new Matrix(this.rows, this.cols, this.arr.flat(1));
|
|
3635
3823
|
}
|
|
3636
3824
|
static div(m1, ...m2) {
|
|
3637
|
-
return m1.clone.div(...m2);
|
|
3825
|
+
return m1.clone().div(...m2);
|
|
3638
3826
|
}
|
|
3639
3827
|
static mul(m1, ...m2) {
|
|
3640
|
-
return m1.clone.mul(...m2);
|
|
3828
|
+
return m1.clone().mul(...m2);
|
|
3641
3829
|
}
|
|
3642
3830
|
modulo(...matr) {
|
|
3643
3831
|
for (let k = 0; k < matr.length; k++) {
|
|
3644
3832
|
if (typeof matr[k] == "number") matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
|
|
3645
|
-
for (let i = 0; i < this.rows; i++)
|
|
3833
|
+
for (let i = 0; i < this.rows; i++)
|
|
3834
|
+
for (var j = 0; j < this.cols; j++)
|
|
3835
|
+
this.arr[i][j]=modulo(this.arr[i][j],matr[k].arr[i][j]);
|
|
3646
3836
|
}
|
|
3647
3837
|
return new Matrix(this.rows, this.cols, this.arr.flat(1));
|
|
3648
3838
|
}
|
|
3649
3839
|
static modulo(m1, ...m2) {
|
|
3650
|
-
return m1.clone.modulo(...m2);
|
|
3840
|
+
return m1.clone().modulo(...m2);
|
|
3651
3841
|
}
|
|
3652
3842
|
dot(matrix) {
|
|
3653
3843
|
var res = [];
|
|
@@ -3656,9 +3846,9 @@ class Matrix{
|
|
|
3656
3846
|
for (var j = 0; j < matrix.arr[0].length; j++) {
|
|
3657
3847
|
res[i][j] = 0;
|
|
3658
3848
|
for (var k = 0; k < this.arr[0].length; k++) {
|
|
3659
|
-
res[i][j] =
|
|
3849
|
+
res[i][j] = add(
|
|
3660
3850
|
res[i][j],
|
|
3661
|
-
|
|
3851
|
+
mul(this.arr[i][k],matrix.arr[k][j])
|
|
3662
3852
|
);
|
|
3663
3853
|
}
|
|
3664
3854
|
}
|
|
@@ -3669,52 +3859,52 @@ class Matrix{
|
|
|
3669
3859
|
return matrix1.dot(matrix2);
|
|
3670
3860
|
}
|
|
3671
3861
|
pow(n) {
|
|
3672
|
-
let a = this.clone,
|
|
3673
|
-
p = this.clone;
|
|
3862
|
+
let a = this.clone(),
|
|
3863
|
+
p = this.clone();
|
|
3674
3864
|
for (let i = 0; i < n - 1; i++) p = p.dot(a);
|
|
3675
3865
|
return p;
|
|
3676
3866
|
}
|
|
3677
3867
|
static pow(m, n) {
|
|
3678
|
-
return m.clone.pow(n);
|
|
3868
|
+
return m.clone().pow(n);
|
|
3679
3869
|
}
|
|
3680
3870
|
get somme() {
|
|
3681
3871
|
let S = 0;
|
|
3682
3872
|
for (let i = 0; i < this.rows; i++) for (let j = 0; j < this.cols; j++) S += this.arr[i][j];
|
|
3683
3873
|
return S;
|
|
3684
3874
|
}
|
|
3685
|
-
get
|
|
3875
|
+
get hasComplex() {
|
|
3686
3876
|
return this.arr.flat(Infinity).some((n) => n instanceof Complex);
|
|
3687
3877
|
}
|
|
3688
3878
|
get min() {
|
|
3689
|
-
if (this.
|
|
3879
|
+
if (this.hasComplex) console.error("Complex numbers are not comparable");
|
|
3690
3880
|
let minRow = [];
|
|
3691
3881
|
for (let i = 0; i < this.rows; i++) minRow.push(min(...this.arr[i]));
|
|
3692
3882
|
return min(...minRow);
|
|
3693
3883
|
}
|
|
3694
3884
|
get max() {
|
|
3695
|
-
if (this.
|
|
3885
|
+
if (this.hasComplex) console.error("Complex numbers are not comparable");
|
|
3696
3886
|
let maxRow = [];
|
|
3697
3887
|
for (let i = 0; i < this.rows; i++) maxRow.push(max(...this.arr[i]));
|
|
3698
3888
|
return max(...maxRow);
|
|
3699
3889
|
}
|
|
3700
3890
|
get minRows() {
|
|
3701
|
-
if (this.
|
|
3891
|
+
if (this.hasComplex) console.error("Complex numbers are not comparable");
|
|
3702
3892
|
let minRow = [];
|
|
3703
3893
|
for (let i = 0; i < this.rows; i++) minRow.push(min(...this.arr[i]));
|
|
3704
3894
|
return minRow;
|
|
3705
3895
|
}
|
|
3706
3896
|
get maxRows() {
|
|
3707
|
-
if (this.
|
|
3897
|
+
if (this.hasComplex) console.error("Complex numbers are not comparable");
|
|
3708
3898
|
let maxRow = [];
|
|
3709
3899
|
for (let i = 0; i < this.rows; i++) maxRow.push(max(...this.arr[i]));
|
|
3710
3900
|
return maxRow;
|
|
3711
3901
|
}
|
|
3712
3902
|
get minCols() {
|
|
3713
|
-
if (this.
|
|
3903
|
+
if (this.hasComplex) console.error("Complex numbers are not comparable");
|
|
3714
3904
|
return this.T.minRows;
|
|
3715
3905
|
}
|
|
3716
3906
|
get maxCols() {
|
|
3717
|
-
if (this.
|
|
3907
|
+
if (this.hasComplex) console.error("Complex numbers are not comparable");
|
|
3718
3908
|
return this.T.maxRows;
|
|
3719
3909
|
}
|
|
3720
3910
|
static fromVector(v) {
|
|
@@ -3729,53 +3919,15 @@ class Matrix{
|
|
|
3729
3919
|
}
|
|
3730
3920
|
return arr;
|
|
3731
3921
|
}
|
|
3732
|
-
get print() {
|
|
3733
|
-
//"pretty print" the matrix
|
|
3734
|
-
let fstring = "[";
|
|
3735
|
-
for (let i = 0; i < this.arr.length; i++) {
|
|
3736
|
-
fstring += (i != 0 ? " " : "") + ` [${this.arr[i].map((n) => " " + n.toString() + " ")}],\n`;
|
|
3737
|
-
}
|
|
3738
|
-
console.log(fstring.substring(0, fstring.length - 2) + " ]");
|
|
3739
|
-
document.write(fstring.substring(0, fstring.length - 2) + " ]");
|
|
3740
|
-
}
|
|
3741
|
-
get table() {
|
|
3742
|
-
console.table(this.arr);
|
|
3743
|
-
}
|
|
3744
3922
|
get serialize() {
|
|
3745
3923
|
return JSON.stringify(this);
|
|
3746
3924
|
}
|
|
3747
3925
|
static deserialize(data) {
|
|
3748
|
-
if (typeof data == "string")
|
|
3749
|
-
data = JSON.parse(data);
|
|
3750
|
-
}
|
|
3926
|
+
if (typeof data == "string") data = JSON.parse(data);
|
|
3751
3927
|
let matrix = new Matrix(data.rows, data.cols);
|
|
3752
3928
|
matrix.arr = data.arr;
|
|
3753
3929
|
return matrix;
|
|
3754
3930
|
}
|
|
3755
|
-
|
|
3756
|
-
toTable() {
|
|
3757
|
-
var table = new DocumentFragment();
|
|
3758
|
-
var Tr = new Array(this.rows).fill(null).map(() => document?.createElement("tr"));
|
|
3759
|
-
var Td = this.arr.map((n) => n.map(() => document?.createElement("td")));
|
|
3760
|
-
for (let i = 0; i < Td.length; i++) {
|
|
3761
|
-
for (let j = 0; j < Td[0].length; j++) {
|
|
3762
|
-
Td[i][j].innerHTML = this.arr[i][j];
|
|
3763
|
-
Tr[i].appendChild(Td[i][j]);
|
|
3764
|
-
}
|
|
3765
|
-
}
|
|
3766
|
-
Tr.map((n) => table.appendChild(n));
|
|
3767
|
-
return table;
|
|
3768
|
-
}
|
|
3769
|
-
toGrid(element, style = {}) {
|
|
3770
|
-
let a = Grid();
|
|
3771
|
-
a.append(
|
|
3772
|
-
...this.map(element)
|
|
3773
|
-
.arr.flat(1)
|
|
3774
|
-
.map((n) => n.style(style))
|
|
3775
|
-
);
|
|
3776
|
-
a.Columns(this.cols);
|
|
3777
|
-
return a;
|
|
3778
|
-
}
|
|
3779
3931
|
sortTable(n=0,{type="num",order="asc"}={}) {
|
|
3780
3932
|
var obj=this.T.arr.map(n=>n.map((n,i)=>Object.assign({},{x:n,y:i})));
|
|
3781
3933
|
var newObj=this.T.arr.map(n=>n.map((n,i)=>Object.assign({},{x:n,y:i})));
|
|
@@ -3807,68 +3959,7 @@ class Matrix{
|
|
|
3807
3959
|
}
|
|
3808
3960
|
}
|
|
3809
3961
|
|
|
3810
|
-
|
|
3811
|
-
if (M.length !== M[0].length) {
|
|
3812
|
-
return;
|
|
3813
|
-
}
|
|
3814
|
-
var i = 0,
|
|
3815
|
-
ii = 0,
|
|
3816
|
-
j = 0,
|
|
3817
|
-
dim = M.length,
|
|
3818
|
-
e = 0;
|
|
3819
|
-
//t = 0;
|
|
3820
|
-
var I = [],
|
|
3821
|
-
C = [];
|
|
3822
|
-
for (i = 0; i < dim; i += 1) {
|
|
3823
|
-
I[I.length] = [];
|
|
3824
|
-
C[C.length] = [];
|
|
3825
|
-
for (j = 0; j < dim; j += 1) {
|
|
3826
|
-
if (i == j) {
|
|
3827
|
-
I[i][j] = 1;
|
|
3828
|
-
} else {
|
|
3829
|
-
I[i][j] = 0;
|
|
3830
|
-
}
|
|
3831
|
-
C[i][j] = M[i][j];
|
|
3832
|
-
}
|
|
3833
|
-
}
|
|
3834
|
-
for (i = 0; i < dim; i += 1) {
|
|
3835
|
-
e = C[i][i];
|
|
3836
|
-
if (e == 0) {
|
|
3837
|
-
for (ii = i + 1; ii < dim; ii += 1) {
|
|
3838
|
-
if (C[ii][i] != 0) {
|
|
3839
|
-
for (j = 0; j < dim; j++) {
|
|
3840
|
-
e = C[i][j];
|
|
3841
|
-
C[i][j] = C[ii][j];
|
|
3842
|
-
C[ii][j] = e;
|
|
3843
|
-
e = I[i][j];
|
|
3844
|
-
I[i][j] = I[ii][j];
|
|
3845
|
-
I[ii][j] = e;
|
|
3846
|
-
}
|
|
3847
|
-
break;
|
|
3848
|
-
}
|
|
3849
|
-
}
|
|
3850
|
-
e = C[i][i];
|
|
3851
|
-
if (e == 0) {
|
|
3852
|
-
return;
|
|
3853
|
-
}
|
|
3854
|
-
}
|
|
3855
|
-
for (j = 0; j < dim; j++) {
|
|
3856
|
-
C[i][j] = C[i][j] / e;
|
|
3857
|
-
I[i][j] = I[i][j] / e;
|
|
3858
|
-
}
|
|
3859
|
-
for (ii = 0; ii < dim; ii++) {
|
|
3860
|
-
if (ii == i) {
|
|
3861
|
-
continue;
|
|
3862
|
-
}
|
|
3863
|
-
e = C[ii][i];
|
|
3864
|
-
for (j = 0; j < dim; j++) {
|
|
3865
|
-
C[ii][j] -= e * C[i][j];
|
|
3866
|
-
I[ii][j] -= e * I[i][j];
|
|
3867
|
-
}
|
|
3868
|
-
}
|
|
3869
|
-
}
|
|
3870
|
-
return I;
|
|
3871
|
-
}
|
|
3962
|
+
|
|
3872
3963
|
/**
|
|
3873
3964
|
* @returns {Matrix}
|
|
3874
3965
|
*/
|
|
@@ -3877,292 +3968,383 @@ const matrix2=(...element)=>new Matrix(2, 2, element);
|
|
|
3877
3968
|
const matrix3=(...element)=>new Matrix(3, 3, element);
|
|
3878
3969
|
const matrix4=(...element)=>new Matrix(4, 4, element);
|
|
3879
3970
|
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
this.a=a.a;
|
|
3889
|
-
this.b=a.b;
|
|
3890
|
-
}
|
|
3891
|
-
else if(("a" in a && "z" in a)){
|
|
3892
|
-
this.a=a.a;
|
|
3893
|
-
this.b=sqrt$2((a.z**2)-(a.a**2));
|
|
3894
|
-
}
|
|
3895
|
-
else if(("a" in a && "phi" in a)){
|
|
3896
|
-
this.a=a.a;
|
|
3897
|
-
this.b=a.a*tan(a.phi);
|
|
3898
|
-
}
|
|
3899
|
-
else if(("b" in a && "z" in a)){
|
|
3900
|
-
this.b=a.b;
|
|
3901
|
-
this.a=sqrt$2((a.z**2)-(a.b**2));
|
|
3902
|
-
}
|
|
3903
|
-
else if(("b" in a && "phi" in a)){
|
|
3904
|
-
this.b=b;
|
|
3905
|
-
this.a=a.b/tan(a.phi);
|
|
3906
|
-
}
|
|
3907
|
-
else if(("z" in a && "phi" in a)){
|
|
3908
|
-
this.a=a.z*cos$2(a.phi);
|
|
3909
|
-
this.a=a.z*sin$2(a.phi);
|
|
3971
|
+
const powerSet=originalSet=>{
|
|
3972
|
+
const subSets = [];
|
|
3973
|
+
const NUMBER_OF_COMBINATIONS = 2 ** originalSet.length;
|
|
3974
|
+
for (let i = 0; i < NUMBER_OF_COMBINATIONS; i += 1) {
|
|
3975
|
+
const subSet = [];
|
|
3976
|
+
for (let j = 0; j < originalSet.length; j += 1) {
|
|
3977
|
+
if (i & (1 << j)) {
|
|
3978
|
+
subSet.push(originalSet[j]);
|
|
3910
3979
|
}
|
|
3911
3980
|
}
|
|
3912
|
-
|
|
3913
|
-
this.a = +a.toFixed(32);
|
|
3914
|
-
this.b = +b.toFixed(32);
|
|
3915
|
-
}
|
|
3916
|
-
}
|
|
3917
|
-
isComplex(){
|
|
3918
|
-
return true
|
|
3919
|
-
}
|
|
3920
|
-
toString(){
|
|
3921
|
-
let str = "";
|
|
3922
|
-
if (this.a !== 0)
|
|
3923
|
-
this.b >= 0
|
|
3924
|
-
? (str = `${this.a}+${this.b}*i`)
|
|
3925
|
-
: (str = `${this.a}-${Math.abs(this.b)}*i`);
|
|
3926
|
-
else
|
|
3927
|
-
this.b >= 0
|
|
3928
|
-
? (str = `${this.b}*i`)
|
|
3929
|
-
: (str = `-${Math.abs(this.b)}*i`);
|
|
3930
|
-
return str;
|
|
3931
|
-
}
|
|
3932
|
-
|
|
3933
|
-
get clone() {
|
|
3934
|
-
return new Complex(this.a, this.b);
|
|
3935
|
-
}
|
|
3936
|
-
get z(){
|
|
3937
|
-
return hypot(this.a,this.b);
|
|
3938
|
-
}
|
|
3939
|
-
get phi(){
|
|
3940
|
-
return atan2(this.b , this.a);
|
|
3941
|
-
}
|
|
3942
|
-
static Zero() {
|
|
3943
|
-
return new Complex(0, 0);
|
|
3944
|
-
}
|
|
3945
|
-
get conj() {
|
|
3946
|
-
return new Complex(this.a, -this.b);
|
|
3947
|
-
}
|
|
3948
|
-
get inv() {
|
|
3949
|
-
return new Complex(this.a / (pow$1(this.a, 2) + pow$1(this.b, 2)), -this.b / (pow$1(this.a, 2) + pow$1(this.b, 2)));
|
|
3950
|
-
}
|
|
3951
|
-
add(...z) {
|
|
3952
|
-
for (let i = 0; i < z.length; i++) {
|
|
3953
|
-
if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
|
|
3954
|
-
}
|
|
3955
|
-
let re = z.map((n) => n.a);
|
|
3956
|
-
let im = z.map((n) => n.b);
|
|
3957
|
-
this.a+=+sum(...re).toFixed(15);
|
|
3958
|
-
this.b+=+sum(...im).toFixed(15);
|
|
3959
|
-
return this;
|
|
3960
|
-
}
|
|
3961
|
-
sub(...z) {
|
|
3962
|
-
for (let i = 0; i < z.length; i++) {
|
|
3963
|
-
if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
|
|
3964
|
-
}
|
|
3965
|
-
let re = z.map((n) => n.a);
|
|
3966
|
-
let im = z.map((n) => n.b);
|
|
3967
|
-
this.a-=+sum(...re).toFixed(15);
|
|
3968
|
-
this.b-=+sum(...im).toFixed(15);
|
|
3969
|
-
return this;
|
|
3970
|
-
}
|
|
3971
|
-
mul(...z){
|
|
3972
|
-
for (let i = 0; i < z.length; i++) {
|
|
3973
|
-
if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
|
|
3974
|
-
}
|
|
3975
|
-
let Z=+prod(this.z,...z.map(n=>n.z)).toFixed(15);
|
|
3976
|
-
let phi=+sum(this.phi,...z.map(n=>n.phi)).toFixed(15);
|
|
3977
|
-
this.a=+(Z*cos$2(phi).toFixed(15)).toFixed(14);
|
|
3978
|
-
this.b=+(Z*sin$2(phi).toFixed(15)).toFixed(14);
|
|
3979
|
-
return this;
|
|
3980
|
-
}
|
|
3981
|
-
div(...z) {
|
|
3982
|
-
for (let i = 0; i < z.length; i++) {
|
|
3983
|
-
if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
|
|
3984
|
-
}
|
|
3985
|
-
let Z=+(this.z/prod(...z.map(n=>n.z))).toFixed(15);
|
|
3986
|
-
let phi=+(this.phi-sum(...z.map(n=>n.phi))).toFixed(15);
|
|
3987
|
-
this.a=+(Z*cos$2(phi).toFixed(15)).toFixed(15);
|
|
3988
|
-
this.b=+(Z*sin$2(phi).toFixed(15)).toFixed(15);
|
|
3989
|
-
return this;
|
|
3990
|
-
}
|
|
3991
|
-
pow(n) {
|
|
3992
|
-
if (floor(n) === n && n > 0) {
|
|
3993
|
-
let z=+(this.z**n).toFixed(15);
|
|
3994
|
-
let phi=+(this.phi*n).toFixed(15);
|
|
3995
|
-
this.a=+(z*cos$2(phi).toFixed(15)).toFixed(15);
|
|
3996
|
-
this.b=+(z*sin$2(phi).toFixed(15)).toFixed(15);
|
|
3997
|
-
}
|
|
3998
|
-
return this;
|
|
3981
|
+
subSets.push(subSet);
|
|
3999
3982
|
}
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
3983
|
+
return subSets;
|
|
3984
|
+
};
|
|
3985
|
+
|
|
3986
|
+
// const subSet = (...arr) => {
|
|
3987
|
+
// let list = arange(0, 2 ** arr.length, 1);
|
|
3988
|
+
// let bin = list.map((n) => n.toString(2).padStart(arr.length, '0')).map((n) => n.split("").map((n) => +n));
|
|
3989
|
+
// let sub = bin.map((n) => n.map((m, i) => (m === 1 ? arr[i] : null))).map((n) => n.filter((x) => x !== null));
|
|
3990
|
+
// return sub;
|
|
3991
|
+
// };
|
|
3992
|
+
const subSet = null;
|
|
3993
|
+
|
|
3994
|
+
const Base={
|
|
3995
|
+
_mode:Number,
|
|
3996
|
+
_map:function(func,number,toBase){
|
|
3997
|
+
if (number instanceof Matrix)
|
|
3998
|
+
return new Matrix(
|
|
3999
|
+
number.rows,
|
|
4000
|
+
number.cols,
|
|
4001
|
+
number.arr.flat(1).map(n=>func(n,toBase))
|
|
4004
4002
|
);
|
|
4003
|
+
else if (number instanceof Complex) return new Complex(func(number.a,toBase),func(number.b,toBase));
|
|
4004
|
+
else if (number instanceof Array) return number.map((n) =>func(n,toBase));
|
|
4005
|
+
},
|
|
4006
|
+
dec2base(dec,base){
|
|
4007
|
+
base<=10?this._mode=Number:this._mode=String;
|
|
4008
|
+
//this._mode=String
|
|
4009
|
+
if (typeof dec === "number") return this._mode((dec >>> 0).toString(base));
|
|
4010
|
+
return this._map(this.dec2base,dec,base)
|
|
4011
|
+
},
|
|
4012
|
+
dec2bin(dec){
|
|
4013
|
+
return this.dec2base(dec,2);
|
|
4014
|
+
},
|
|
4015
|
+
dec2oct(dec){
|
|
4016
|
+
return this.dec2base(dec,8);
|
|
4017
|
+
},
|
|
4018
|
+
dec2hex(dec){
|
|
4019
|
+
return this.dec2base(dec,16);
|
|
4020
|
+
},
|
|
4021
|
+
bin2base(bin, base) {
|
|
4022
|
+
return this.dec2base(this.bin2dec(bin),base)
|
|
4023
|
+
},
|
|
4024
|
+
bin2dec(bin){
|
|
4025
|
+
return this._mode("0b"+bin);
|
|
4026
|
+
},
|
|
4027
|
+
bin2oct(bin){
|
|
4028
|
+
return this.bin2base(bin,8);
|
|
4029
|
+
},
|
|
4030
|
+
bin2hex(bin){
|
|
4031
|
+
return this.bin2base(bin,16);
|
|
4032
|
+
},
|
|
4033
|
+
oct2dec(oct){
|
|
4034
|
+
return this._mode("0o"+oct);
|
|
4035
|
+
},
|
|
4036
|
+
oct2bin(oct){
|
|
4037
|
+
return this.dec2bin(this.oct2dec(oct))
|
|
4038
|
+
},
|
|
4039
|
+
oct2hex(oct){
|
|
4040
|
+
return this.dec2hex(this.oct2dec(oct))
|
|
4041
|
+
},
|
|
4042
|
+
oct2base(oct, base) {
|
|
4043
|
+
return this.dec2base(this.oct2dec(oct),base)
|
|
4044
|
+
},
|
|
4045
|
+
hex2dec(hex){
|
|
4046
|
+
return this._mode("0x"+hex);
|
|
4047
|
+
},
|
|
4048
|
+
hex2bin(hex){
|
|
4049
|
+
return this.dec2bin(this.hex2dec(hex))
|
|
4050
|
+
},
|
|
4051
|
+
hex2oct(hex){
|
|
4052
|
+
return this.dec2oct(this.hex2dec(hex))
|
|
4053
|
+
},
|
|
4054
|
+
hex2base(hex, base) {
|
|
4055
|
+
return this.dec2base(this.hex2dec(hex),base)
|
|
4056
|
+
},
|
|
4057
|
+
IEEE32toDec(Bin){
|
|
4058
|
+
let IEEE32=Bin.split(" ").join("").padEnd(32,"0");
|
|
4059
|
+
let s=IEEE32[0];
|
|
4060
|
+
let e=2**(+("0b"+IEEE32.slice(1,9))-127);
|
|
4061
|
+
let m=IEEE32.slice(9,32).split("").map(n=>+n);
|
|
4062
|
+
let M=m.map((n,i)=>n*(2**(-i-1))).reduce((a,b)=>a+b,0);
|
|
4063
|
+
let dec=(-1)**s*(1+M)*e;
|
|
4064
|
+
return dec
|
|
4065
|
+
},
|
|
4066
|
+
IEEE64toDec(Bin){
|
|
4067
|
+
let IEEE64=Bin.split(" ").join("").padEnd(64,"0");
|
|
4068
|
+
let s=IEEE64[0];
|
|
4069
|
+
let e=2**(+("0b"+IEEE64.slice(1,12))-1023);
|
|
4070
|
+
let m=IEEE64.slice(13,64).split("").map(n=>+n);
|
|
4071
|
+
let M=m.map((n,i)=>n*(2**(-i-1))).reduce((a,b)=>a+b,0);
|
|
4072
|
+
let dec=(-1)**s*(1+M)*e;
|
|
4073
|
+
return dec;
|
|
4005
4074
|
}
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4075
|
+
};
|
|
4076
|
+
|
|
4077
|
+
const Logic$1={
|
|
4078
|
+
_mode:Number,
|
|
4079
|
+
_map:function(func,a,b){
|
|
4080
|
+
if (a instanceof Matrix)
|
|
4081
|
+
return new Matrix(
|
|
4082
|
+
a.rows,
|
|
4083
|
+
a.cols,
|
|
4084
|
+
a.arr.flat(1).map((n) => func(n, b))
|
|
4085
|
+
);
|
|
4086
|
+
else if (a instanceof Complex) return new Complex(func(a.a, b), func(a.b, b));
|
|
4087
|
+
else if (a instanceof Array) return a.map((n) => func(n, b));
|
|
4088
|
+
},
|
|
4089
|
+
not:function(input){
|
|
4090
|
+
if(["number","boolean"].includes(typeof input)) return Logic$1._mode(!input);
|
|
4091
|
+
else return this._map(this.not,input)
|
|
4092
|
+
},
|
|
4093
|
+
and:function(a, ...b){
|
|
4094
|
+
if(["number","boolean"].includes(typeof a))return Logic$1._mode(b.reduce((n, m) => (n &= m), a));
|
|
4095
|
+
else return this._map(this.and,a,b)
|
|
4096
|
+
},
|
|
4097
|
+
or:function(a, ...b) {
|
|
4098
|
+
if(["number","boolean"].includes(typeof a)) return Logic$1._mode(b.reduce((n, m) => (n |= m), a));
|
|
4099
|
+
else return this._map(this.or,a,b);
|
|
4100
|
+
},
|
|
4101
|
+
nand:function(a, ...b) {
|
|
4102
|
+
return this.not(this.and(a, b));
|
|
4103
|
+
},
|
|
4104
|
+
nor:function(a, ...b) {
|
|
4105
|
+
return this.not(this.or(a, b));
|
|
4106
|
+
},
|
|
4107
|
+
xor:function(a,...b){
|
|
4108
|
+
let arr=[a,...b];
|
|
4109
|
+
if(["number","boolean"].includes(typeof a))return this._mode(arr.reduce((length,cur)=>{
|
|
4110
|
+
if(+cur===1)length+=1;
|
|
4111
|
+
return length;
|
|
4112
|
+
},0)===1);
|
|
4113
|
+
else return this._map(this.xor,a,b);
|
|
4114
|
+
},
|
|
4115
|
+
xnor:function(a,...b){
|
|
4116
|
+
return Logic$1.not(Logic$1.xor(a,b))
|
|
4017
4117
|
}
|
|
4018
|
-
|
|
4019
|
-
|
|
4118
|
+
|
|
4119
|
+
};
|
|
4120
|
+
|
|
4121
|
+
class Permutation {
|
|
4122
|
+
static withDiscount(arr, l = arr.length) {
|
|
4123
|
+
if (l === 1) return arr.map((n) => [n]);
|
|
4124
|
+
const permutations = [];
|
|
4125
|
+
let smallerPermutations;
|
|
4126
|
+
smallerPermutations = this.withDiscount(arr, l - 1);
|
|
4127
|
+
arr.forEach((currentOption) => {
|
|
4128
|
+
smallerPermutations.forEach((smallerPermutation) => {
|
|
4129
|
+
permutations.push([currentOption].concat(smallerPermutation));
|
|
4130
|
+
});
|
|
4131
|
+
});
|
|
4132
|
+
return permutations;
|
|
4020
4133
|
}
|
|
4021
|
-
static
|
|
4022
|
-
|
|
4134
|
+
static withoutDiscount(arr) {
|
|
4135
|
+
const l = arr.length;
|
|
4136
|
+
if (l === 1) return arr.map((n) => [n]);
|
|
4137
|
+
const permutations = [];
|
|
4138
|
+
const smallerPermutations = this.withoutDiscount(arr.slice(1));
|
|
4139
|
+
const firstOption = arr[0];
|
|
4140
|
+
for (let i = 0; i < smallerPermutations.length; i++) {
|
|
4141
|
+
const smallerPermutation = smallerPermutations[i];
|
|
4142
|
+
for (let j = 0; j <= smallerPermutation.length; j++) {
|
|
4143
|
+
const permutationPrefix = smallerPermutation.slice(0, j);
|
|
4144
|
+
const permutationSuffix = smallerPermutation.slice(j);
|
|
4145
|
+
permutations.push(permutationPrefix.concat([firstOption], permutationSuffix));
|
|
4146
|
+
}
|
|
4147
|
+
}
|
|
4148
|
+
return permutations;
|
|
4023
4149
|
}
|
|
4024
|
-
|
|
4025
|
-
|
|
4150
|
+
}
|
|
4151
|
+
|
|
4152
|
+
class Combinaison {
|
|
4153
|
+
static withDiscount(comboOptions, comboLength) {
|
|
4154
|
+
if (comboLength === 1) {
|
|
4155
|
+
return comboOptions.map((comboOption) => [comboOption]);
|
|
4156
|
+
}
|
|
4157
|
+
const combos = [];
|
|
4158
|
+
comboOptions.forEach((currentOption, optionIndex) => {
|
|
4159
|
+
const smallerCombos = this.withDiscount(comboOptions.slice(optionIndex), comboLength - 1);
|
|
4160
|
+
smallerCombos.forEach((smallerCombo) => {
|
|
4161
|
+
combos.push([currentOption].concat(smallerCombo));
|
|
4162
|
+
});
|
|
4163
|
+
});
|
|
4164
|
+
return combos;
|
|
4026
4165
|
}
|
|
4027
|
-
|
|
4028
|
-
|
|
4166
|
+
static withoutDiscount(comboOptions, comboLength) {
|
|
4167
|
+
if (comboLength === 1) {
|
|
4168
|
+
return comboOptions.map((comboOption) => [comboOption]);
|
|
4169
|
+
}
|
|
4170
|
+
const combos = [];
|
|
4171
|
+
comboOptions.forEach((currentOption, optionIndex) => {
|
|
4172
|
+
const smallerCombos = this.withoutDiscount(comboOptions.slice(optionIndex + 1), comboLength - 1);
|
|
4173
|
+
smallerCombos.forEach((smallerCombo) => {
|
|
4174
|
+
combos.push([currentOption].concat(smallerCombo));
|
|
4175
|
+
});
|
|
4176
|
+
});
|
|
4177
|
+
|
|
4178
|
+
return combos;
|
|
4029
4179
|
}
|
|
4030
|
-
|
|
4031
|
-
|
|
4180
|
+
}
|
|
4181
|
+
const combinaison=(comboOptions, comboLength, discount=false)=>Combinaison[discount?"withDiscount":"withoutDiscount"](comboOptions, comboLength);
|
|
4182
|
+
|
|
4183
|
+
class Random {
|
|
4184
|
+
static float(a = 1, b) {
|
|
4185
|
+
return b ? Math.random() * (b - a) + a : a * Math.random();
|
|
4032
4186
|
}
|
|
4033
|
-
|
|
4034
|
-
return
|
|
4187
|
+
static int(a, b) {
|
|
4188
|
+
return Math.floor(this.float(a, b));
|
|
4035
4189
|
}
|
|
4036
|
-
|
|
4037
|
-
|
|
4190
|
+
static char(upperCase){
|
|
4191
|
+
upperCase=upperCase??this.bool();
|
|
4192
|
+
const Char=String.fromCharCode(this.int(97,120));
|
|
4193
|
+
return upperCase?Char.toUpperCase():Char;
|
|
4038
4194
|
}
|
|
4039
|
-
|
|
4040
|
-
return
|
|
4195
|
+
static bool(){
|
|
4196
|
+
return [false,true][Math.floor(Math.random()*2)];
|
|
4041
4197
|
}
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4198
|
+
static string(length,upperCase){
|
|
4199
|
+
return length instanceof Array?
|
|
4200
|
+
new Array(this.int(...length)).fill(0).map(() => this.char(upperCase)).join(""):
|
|
4201
|
+
new Array(length).fill(0).map(() => this.char(upperCase)).join("");
|
|
4045
4202
|
}
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
if((a instanceof Array||ArrayBuffer.isView(a)) && (b instanceof Array||ArrayBuffer.isView(a)))return a.map((n,i)=>complex(a[i],b[i]));
|
|
4049
|
-
if(a instanceof Matrix && b instanceof Matrix){
|
|
4050
|
-
if((a.shape[0]!==b.shape[0])||(a.shape[1]!==b.shape[1]))return Error(0)
|
|
4051
|
-
const arr=a.arr.map((n,i)=>complex(a.arr[i],b.arr[i]));
|
|
4052
|
-
return new Matrix(a.rows,a.cols,...arr)
|
|
4203
|
+
static bin() {
|
|
4204
|
+
return this.int(2);
|
|
4053
4205
|
}
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
const abs=(...x)=>mapfun$1(Math.abs,...x);
|
|
4058
|
-
const sqrt$2=(...x)=>mapfun$1(Math.sqrt,...x);
|
|
4059
|
-
const pow$1=(x,n)=>{
|
|
4060
|
-
if(typeof x === "number"){
|
|
4061
|
-
if(typeof n === "number")return Math.pow(x,n);
|
|
4062
|
-
else if(n instanceof Complex)return Complex.fromExpo(x**n.a,n.b*ln(x))
|
|
4063
|
-
else return mapfun$1(a=>pow$1(x,a),...n);
|
|
4206
|
+
static oct() {
|
|
4207
|
+
return this.int(8);
|
|
4064
4208
|
}
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
else if(n instanceof Complex)return Complex.fromExpo(
|
|
4068
|
-
x.z**n.a*e(-x.phi*n.b),
|
|
4069
|
-
ln(x.z)*n.b+n.a*x.phi
|
|
4070
|
-
)
|
|
4071
|
-
else return mapfun$1(a=>pow$1(x,a),...n);
|
|
4209
|
+
static dec() {
|
|
4210
|
+
return this.int(8);
|
|
4072
4211
|
}
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
else if(n instanceof Array){
|
|
4076
|
-
const Y=[];
|
|
4077
|
-
for(let i=0;i<x.length;i++){
|
|
4078
|
-
Y.push(mapfun$1(a=>pow$1(x[i],a),...n));
|
|
4079
|
-
}
|
|
4080
|
-
return Y;
|
|
4081
|
-
}
|
|
4212
|
+
static hex() {
|
|
4213
|
+
return this.int(16);
|
|
4082
4214
|
}
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4215
|
+
static choice(choices = [1, 2, 3], p = new Array(choices.length).fill(1 / choices.length)) {
|
|
4216
|
+
let newchoice = new Array(100);
|
|
4217
|
+
p=Utils.accum(...p).map(n=>n*100);
|
|
4218
|
+
newchoice.fill(choices[0], 0, p[0]);
|
|
4219
|
+
for (let i = 1; i < choices.length; i++) newchoice.fill(choices[i], p[i - 1], p[i]);
|
|
4220
|
+
return newchoice[this.int(newchoice.length - 1)];
|
|
4088
4221
|
}
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
else return mapfun$1(a=>sqrtn(x,a),...n);
|
|
4222
|
+
static shuffleArr(arr){
|
|
4223
|
+
return arr.sort(()=>0.5-Math.random())
|
|
4092
4224
|
}
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
else if(n instanceof Array){
|
|
4096
|
-
const Y=[];
|
|
4097
|
-
for(let i=0;i<x.length;i++){
|
|
4098
|
-
Y.push(mapfun$1(a=>sqrtn(x[i],a),...n));
|
|
4099
|
-
}
|
|
4100
|
-
return Y;
|
|
4101
|
-
}
|
|
4225
|
+
static floats(n, a, b) {
|
|
4226
|
+
return new Array(n).fill(0).map(() => this.float(a, b));
|
|
4102
4227
|
}
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
const ln=(...x) => mapfun$1(Math.log,...x);
|
|
4106
|
-
const cos$2=(...x) => mapfun$1(Fixed.cos,...x);
|
|
4107
|
-
const sin$2=(...x) => mapfun$1(Fixed.sin,...x);
|
|
4108
|
-
const tan=(...x) => mapfun$1(Fixed.tan,...x);
|
|
4109
|
-
const sec=(...x) => mapfun$1(Fixed.sec,...x);
|
|
4110
|
-
const sinc=(...x) => mapfun$1(Fixed.sinc,...x);
|
|
4111
|
-
const csc=(...x) => mapfun$1(Fixed.csc,...x);
|
|
4112
|
-
const cot=(...x) => mapfun$1(Fixed.cot,...x);
|
|
4113
|
-
const acos$1=(...x) => mapfun$1(Fixed.acos,...x);
|
|
4114
|
-
const asin=(...x) => mapfun$1(Fixed.asin,...x);
|
|
4115
|
-
const atan=(...x) => mapfun$1(Fixed.atan,...x);
|
|
4116
|
-
const acot=(...x) => mapfun$1(Fixed.acot,...x);
|
|
4117
|
-
const cosh$1=(...x) => mapfun$1(Fixed.cosh,...x);
|
|
4118
|
-
const sinh$1=(...x) => mapfun$1(Fixed.sinh,...x);
|
|
4119
|
-
const tanh=(...x) => mapfun$1(Fixed.tanh,...x);
|
|
4120
|
-
const coth=(...x) => mapfun$1(Fixed.coth,...x);
|
|
4121
|
-
const acosh=(...x) => mapfun$1(Fixed.acosh,...x);
|
|
4122
|
-
const asinh=(...x) => mapfun$1(Fixed.asinh,...x);
|
|
4123
|
-
const atanh=(...x) => mapfun$1(Fixed.atanh,...x);
|
|
4124
|
-
const ceil=(...x) => mapfun$1(Math.ceil,...x);
|
|
4125
|
-
const floor=(...x) => mapfun$1(Math.floor,...x);
|
|
4126
|
-
const round=(...x) => mapfun$1(Math.round,...x);
|
|
4127
|
-
const atan2=(x,y,rad=true)=>{
|
|
4128
|
-
if(typeof x === "number"){
|
|
4129
|
-
if(typeof y === "number")return rad?Math.atan2(x,y):Math.atan2(x,y)*180/Math.PI;
|
|
4130
|
-
else return mapfun$1(a=>atan2(x,a,rad),...y);
|
|
4228
|
+
static ints(n, a, b) {
|
|
4229
|
+
return new Array(n).fill(0).map(() => this.int(a, b));
|
|
4131
4230
|
}
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4231
|
+
static bools(n){
|
|
4232
|
+
return new Array(n).fill(0).map(() => this.bool());
|
|
4233
|
+
}
|
|
4234
|
+
static bins(n) {
|
|
4235
|
+
return new Array(n).fill(0).map(() => this.int(2));
|
|
4236
|
+
}
|
|
4237
|
+
static octs(n) {
|
|
4238
|
+
return new Array(n).fill(0).map(() => this.int(8));
|
|
4239
|
+
}
|
|
4240
|
+
static decs(n) {
|
|
4241
|
+
return new Array(n).fill(0).map(() => this.int(10));
|
|
4242
|
+
}
|
|
4243
|
+
static hexs(n) {
|
|
4244
|
+
return new Array(n).fill(0).map(() => this.int(16));
|
|
4245
|
+
}
|
|
4246
|
+
static choices(n, choices, p) {
|
|
4247
|
+
return new Array(n).fill(0).map(() => this.choice(choices, p));
|
|
4248
|
+
}
|
|
4249
|
+
static perm(...arr) {
|
|
4250
|
+
// permutation
|
|
4251
|
+
return arr.permS[this.int(arr.length)];
|
|
4252
|
+
}
|
|
4253
|
+
static color() {
|
|
4254
|
+
return "#" + Base.dec2hex(this.float(16777216)).padStart(6,0);
|
|
4255
|
+
}
|
|
4256
|
+
static colors(n) {
|
|
4257
|
+
return new Array(n).fill(null).map(()=>this.color());
|
|
4145
4258
|
}
|
|
4146
|
-
};
|
|
4147
|
-
const fact=(...x)=>mapfun$1(n=> {
|
|
4148
|
-
let i,
|
|
4149
|
-
y = 1;
|
|
4150
|
-
if (n == 0) y = 1;
|
|
4151
|
-
else if (n > 0) for (i = 1; i <= n; i++) y *= i;
|
|
4152
|
-
else y = NaN;
|
|
4153
|
-
return y;
|
|
4154
|
-
},...x);
|
|
4155
|
-
const sign=(...x)=>mapfun$1(Math.sign,...x);
|
|
4156
|
-
|
|
4157
|
-
const sig=(...x)=>mapfun$1(n=>1/(1+e(-n)),...x);
|
|
4158
4259
|
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
)
|
|
4165
|
-
|
|
4260
|
+
// Should be Moved to Matrix and Complex to avoid Circular dependencies
|
|
4261
|
+
// static complex(a = [0,1], b = [0,1]) {
|
|
4262
|
+
// return a instanceof Array?
|
|
4263
|
+
// new Complex(
|
|
4264
|
+
// this.float(a[0], a[1]),
|
|
4265
|
+
// this.float(b[0], b[1])
|
|
4266
|
+
// ):
|
|
4267
|
+
// new Complex(
|
|
4268
|
+
// ...this.floats(2,a,b)
|
|
4269
|
+
// )
|
|
4270
|
+
|
|
4271
|
+
// }
|
|
4272
|
+
// static complexInt(a = [0,1], b = [0,1]) {
|
|
4273
|
+
// return new Complex(
|
|
4274
|
+
// this.int(a[0], a[1]),
|
|
4275
|
+
// this.int(b[0], b[1])
|
|
4276
|
+
// );
|
|
4277
|
+
// }
|
|
4278
|
+
// static complexBin() {
|
|
4279
|
+
// return new Complex(...this.bins(2));
|
|
4280
|
+
// }
|
|
4281
|
+
// static complexOct() {
|
|
4282
|
+
// return new Complex(...this.octs(2));
|
|
4283
|
+
// }
|
|
4284
|
+
// static complexDec() {
|
|
4285
|
+
// return new Complex(...this.decs(10));
|
|
4286
|
+
// }
|
|
4287
|
+
// static complexHex() {
|
|
4288
|
+
// return new Complex(...this.octs(2));
|
|
4289
|
+
// }
|
|
4290
|
+
// static complexes(n, a = 0, b = 1) {
|
|
4291
|
+
// return new Array(n).fill(0).map(() => this.complex(a, b));
|
|
4292
|
+
// }
|
|
4293
|
+
// static complexesInt(n, a = 0, b = 1) {
|
|
4294
|
+
// return new Array(n).fill(0).map(() => this.complexInt(a, b));
|
|
4295
|
+
// }
|
|
4296
|
+
// static complexesBin(n) {
|
|
4297
|
+
// return new Array(n).fill(0).map(() => this.complexBin());
|
|
4298
|
+
// }
|
|
4299
|
+
// static complexesOct(n) {
|
|
4300
|
+
// return new Array(n).fill(0).map(() => this.complexOct());
|
|
4301
|
+
// }
|
|
4302
|
+
// static complexesDec(n) {
|
|
4303
|
+
// return new Array(n).fill(0).map(() => this.complexDec());
|
|
4304
|
+
// }
|
|
4305
|
+
// static complexesHex(n) {
|
|
4306
|
+
// return new Array(n).fill(0).map(() => this.complexHex());
|
|
4307
|
+
// }
|
|
4308
|
+
// static matrix(r,c,min,max){
|
|
4309
|
+
// return matrix(r,c,this.floats(r*c,min,max))
|
|
4310
|
+
// }
|
|
4311
|
+
// static matrixInt(r,c,min,max){
|
|
4312
|
+
// return matrix(r,c,this.ints(r*c,min,max))
|
|
4313
|
+
// }
|
|
4314
|
+
// static matrixBin(r,c){
|
|
4315
|
+
// return matrix(r,c,this.bins(r*c))
|
|
4316
|
+
// }
|
|
4317
|
+
// static matrixOct(r,c){
|
|
4318
|
+
// return matrix(r,c,this.octs(r*c))
|
|
4319
|
+
// }
|
|
4320
|
+
// static matrixDec(r,c){
|
|
4321
|
+
// return matrix(r,c,this.decs(r*c))
|
|
4322
|
+
// }
|
|
4323
|
+
// static matrixHex(r,c){
|
|
4324
|
+
// return matrix(r,c,this.hex(r*c))
|
|
4325
|
+
// }
|
|
4326
|
+
// static matrixColor(r,c){
|
|
4327
|
+
// return matrix(r,c,this.colors(r*c))
|
|
4328
|
+
// }
|
|
4329
|
+
// static matrixComplex(r,c,a,b){
|
|
4330
|
+
// return matrix(r,c,this.complexes(r*c,a,b))
|
|
4331
|
+
// }
|
|
4332
|
+
// static matrixComplexInt(r,c,a,b){
|
|
4333
|
+
// return matrix(r,c,this.complexesInt(r*c,a,b))
|
|
4334
|
+
// }
|
|
4335
|
+
// static matrixComplexBin(r,c){
|
|
4336
|
+
// return matrix(r,c,this.complexesBin(r*c))
|
|
4337
|
+
// }
|
|
4338
|
+
// static matrixComplexOct(r,c){
|
|
4339
|
+
// return matrix(r,c,this.complexesBin(r*c))
|
|
4340
|
+
// }
|
|
4341
|
+
// static matrixComplexDec(r,c){
|
|
4342
|
+
// return matrix(r,c,this.complexesBin(r*c))
|
|
4343
|
+
// }
|
|
4344
|
+
// static matrixComplexHex(r,c){
|
|
4345
|
+
// return matrix(r,c,this.complexesBin(r*c))
|
|
4346
|
+
// }
|
|
4347
|
+
}
|
|
4166
4348
|
|
|
4167
4349
|
const { PI, sqrt: sqrt$1, cos: cos$1, sin: sin$1, acos, pow } = Math;
|
|
4168
4350
|
|