ziko 0.54.0 → 0.54.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ziko.cjs +998 -837
- package/dist/ziko.js +214 -91
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +207 -92
- package/package.json +1 -1
- package/src/math/complex/index.js +25 -5
- package/src/math/functions/arithmetic/index.js +1 -1
- package/src/math/functions/index.js +1 -0
- package/src/math/functions/mapfun/index.js +14 -0
- package/src/math/functions/nested/index.js +0 -3
- package/src/math/functions/signal/index.js +104 -0
- package/src/math/functions/stats/index.js +49 -0
- package/src/math/functions/utils/index.js +90 -50
- package/src/math/statistics/functions/index.js +32 -32
- package/src/math/statistics/index.js +4 -4
- package/src/math/stats/index.js +1 -4
- package/src/math/stats/{position → percentile}/index.js +0 -3
package/dist/ziko.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/*
|
|
3
3
|
Project: ziko.js
|
|
4
4
|
Author: Zakaria Elalaoui
|
|
5
|
-
Date :
|
|
5
|
+
Date : Wed Dec 10 2025 13:44:02 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
|
|
@@ -36,6 +36,20 @@
|
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
return Y.length==1? Y[0]: Y;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const apply_fun = (x, fn) => {
|
|
42
|
+
if (x.isComplex?.()) return new x.constructor(
|
|
43
|
+
fn(x.a),
|
|
44
|
+
fn(x.b)
|
|
45
|
+
)
|
|
46
|
+
if (x.isMatrix?.()) return new x.constructor(
|
|
47
|
+
x.rows,
|
|
48
|
+
x.cols,
|
|
49
|
+
x.arr.flat(1).map(fn)
|
|
50
|
+
)
|
|
51
|
+
if (x instanceof Array) mapfun(fn, ...x);
|
|
52
|
+
return fn(x)
|
|
39
53
|
};
|
|
40
54
|
|
|
41
55
|
// import {sum,prod,deg2rad} from "../utils/index.js";
|
|
@@ -95,7 +109,16 @@
|
|
|
95
109
|
: (str = `-${Math.abs(this.b)}*i`);
|
|
96
110
|
return str;
|
|
97
111
|
}
|
|
98
|
-
|
|
112
|
+
toFixed(n){
|
|
113
|
+
this.a = + this.a.toFixed(n);
|
|
114
|
+
this.b = + this.b.toFixed(n);
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
toPrecision(n){
|
|
118
|
+
this.a = + this.a.toPrecision(n);
|
|
119
|
+
this.b = + this.b.toPrecision(n);
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
99
122
|
clone() {
|
|
100
123
|
return new Complex(this.a, this.b);
|
|
101
124
|
}
|
|
@@ -138,10 +161,10 @@
|
|
|
138
161
|
for (let i = 0; i < c.length; i++) {
|
|
139
162
|
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
140
163
|
z *= c[i].z;
|
|
141
|
-
phi += c[i].
|
|
164
|
+
phi += c[i].phi;
|
|
142
165
|
}
|
|
143
|
-
this.a = z*Math.cos(phi);
|
|
144
|
-
this.b = z*Math.sin(phi);
|
|
166
|
+
this.a = z * Math.cos(phi);
|
|
167
|
+
this.b = z * Math.sin(phi);
|
|
145
168
|
return this;
|
|
146
169
|
}
|
|
147
170
|
div(...c){
|
|
@@ -149,7 +172,7 @@
|
|
|
149
172
|
for (let i = 0; i < c.length; i++) {
|
|
150
173
|
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
151
174
|
z /= c[i].z;
|
|
152
|
-
phi -= c[i].
|
|
175
|
+
phi -= c[i].phi;
|
|
153
176
|
}
|
|
154
177
|
this.a = z*Math.cos(phi);
|
|
155
178
|
this.b = z*Math.sin(phi);
|
|
@@ -163,6 +186,17 @@
|
|
|
163
186
|
}
|
|
164
187
|
return this;
|
|
165
188
|
}
|
|
189
|
+
pow(...c){
|
|
190
|
+
let {z, phi} = this;
|
|
191
|
+
for (let i = 0; i < c.length; i++) {
|
|
192
|
+
if (typeof c[i] === "number") c[i] = new Complex(c[i], 0);
|
|
193
|
+
z *= Math.exp(c[i].a * Math.log(z) - c[i].b * phi);
|
|
194
|
+
phi += c[i].b * Math.log(z) + c[i].a * phi;
|
|
195
|
+
}
|
|
196
|
+
this.a = z * Math.cos(phi);
|
|
197
|
+
this.b = z * Math.sin(phi);
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
166
200
|
static fromExpo(z, phi) {
|
|
167
201
|
return new Complex(
|
|
168
202
|
+(z * cos(phi)).toFixed(13),
|
|
@@ -227,9 +261,6 @@
|
|
|
227
261
|
return new Complex(a,b)
|
|
228
262
|
};
|
|
229
263
|
|
|
230
|
-
const deg2rad = (...deg) => mapfun(x => x * Math.PI / 180, ...deg);
|
|
231
|
-
const rad2deg = (...rad) => mapfun(x => x / Math.PI * 180, ...rad);
|
|
232
|
-
|
|
233
264
|
const abs = (...x) => mapfun(
|
|
234
265
|
x =>{
|
|
235
266
|
if(x.isComplex?.()) return x.z;
|
|
@@ -618,7 +649,7 @@
|
|
|
618
649
|
if(y.isComplex?.()) return y.clone().mul(x);
|
|
619
650
|
}
|
|
620
651
|
if(x.isComplex?.()){
|
|
621
|
-
if(typeof y === 'number' || y.isComplex?.()) return
|
|
652
|
+
if(typeof y === 'number' || y.isComplex?.()) return x.clone().mul(y);
|
|
622
653
|
}
|
|
623
654
|
};
|
|
624
655
|
|
|
@@ -673,57 +704,83 @@
|
|
|
673
704
|
return res;
|
|
674
705
|
};
|
|
675
706
|
|
|
676
|
-
const
|
|
677
|
-
|
|
678
|
-
norm(x.a, min, max),
|
|
679
|
-
norm(x.b, min, max)
|
|
680
|
-
)
|
|
681
|
-
if(x.isMatrix?.()) return new x.constructor(
|
|
682
|
-
x.rows,
|
|
683
|
-
x.cols,
|
|
684
|
-
norm(x.arr.flat(1), min, max)
|
|
685
|
-
);
|
|
686
|
-
return min !== max ? (value - min) / (max - min) : 0;
|
|
687
|
-
};
|
|
707
|
+
const deg2rad = (...deg) => mapfun(x => x * Math.PI / 180, ...deg);
|
|
708
|
+
const rad2deg = (...rad) => mapfun(x => x / Math.PI * 180, ...rad);
|
|
688
709
|
|
|
689
|
-
const
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
710
|
+
const norm = (x, min, max) => apply_fun(
|
|
711
|
+
x,
|
|
712
|
+
v => min !== max ? (v - min) / (max - min) : 0
|
|
713
|
+
);
|
|
714
|
+
const lerp = (x, min, max) => apply_fun(
|
|
715
|
+
x,
|
|
716
|
+
v => (max - min) * v + min
|
|
717
|
+
);
|
|
718
|
+
const clamp = (x, min, max) => apply_fun(
|
|
719
|
+
x,
|
|
720
|
+
v => Math.min(Math.max(v, min), max)
|
|
721
|
+
);
|
|
722
|
+
const map$1 = (x, a, b, c, d) => apply_fun(
|
|
723
|
+
x,
|
|
724
|
+
v => lerp(norm(v, a, b), c, d)
|
|
725
|
+
);
|
|
701
726
|
|
|
702
|
-
const map$1 = (x, min, max) => {
|
|
703
|
-
if(x.isComplex?.()) return new x.constructor(
|
|
704
|
-
map$1(x.a),
|
|
705
|
-
map$1(x.b)
|
|
706
|
-
)
|
|
707
|
-
if(x.isMatrix?.()) return new x.constructor(
|
|
708
|
-
x.rows,
|
|
709
|
-
x.cols,
|
|
710
|
-
map$1(x.arr.flat(1))
|
|
711
|
-
);
|
|
712
|
-
return lerp(norm(x, a, b), c, d);
|
|
713
|
-
};
|
|
714
727
|
|
|
715
|
-
const
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
728
|
+
// export const norm = (x, min, max) => {
|
|
729
|
+
// if(x.isComplex?.()) return new x.constructor(
|
|
730
|
+
// norm(x.a, min, max),
|
|
731
|
+
// norm(x.b, min, max)
|
|
732
|
+
// )
|
|
733
|
+
// if(x.isMatrix?.()) return new x.constructor(
|
|
734
|
+
// x.rows,
|
|
735
|
+
// x.cols,
|
|
736
|
+
// norm(x.arr.flat(1), min, max)
|
|
737
|
+
// );
|
|
738
|
+
// if(x instanceof Array) return mapfun(n => norm(n, min, max), ...x);
|
|
739
|
+
// return min !== max ? (x - min) / (max - min) : 0;
|
|
740
|
+
// }
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
// export const lerp = (x, min, max) => {
|
|
744
|
+
// if(x.isComplex?.()) return new x.constructor(
|
|
745
|
+
// lerp(x.a, min, max),
|
|
746
|
+
// lerp(x.b, min, max)
|
|
747
|
+
// )
|
|
748
|
+
// if(x.isMatrix?.()) return new x.constructor(
|
|
749
|
+
// x.rows,
|
|
750
|
+
// x.cols,
|
|
751
|
+
// lerp(x.arr.flat(1), min, max)
|
|
752
|
+
// );
|
|
753
|
+
// if(x instanceof Array) return mapfun(n => lerp(n, min, max), ...x);
|
|
754
|
+
// return (max - min) * x + min;
|
|
755
|
+
// }
|
|
756
|
+
|
|
757
|
+
// export const map = (x, a, b, c, d) => {
|
|
758
|
+
// if(x.isComplex?.()) return new x.constructor(
|
|
759
|
+
// map(x.a, a, b, c, d),
|
|
760
|
+
// map(x.b, a, b, c, d)
|
|
761
|
+
// )
|
|
762
|
+
// if(x.isMatrix?.()) return new x.constructor(
|
|
763
|
+
// x.rows,
|
|
764
|
+
// x.cols,
|
|
765
|
+
// map(x.arr.flat(1), a, b, c, d)
|
|
766
|
+
// );
|
|
767
|
+
// if(x instanceof Array) return mapfun(n => map(n, a, b, c, d), ...x);
|
|
768
|
+
// return lerp(norm(x, a, b), c, d);
|
|
769
|
+
// }
|
|
770
|
+
|
|
771
|
+
// export const clamp = (x, min, max) => {
|
|
772
|
+
// if(x.isComplex?.()) return new x.constructor(
|
|
773
|
+
// clamp(x.a, min, max),
|
|
774
|
+
// clamp(x.b, min, max)
|
|
775
|
+
// )
|
|
776
|
+
// if(x.isMatrix?.()) return new x.constructor(
|
|
777
|
+
// x.rows,
|
|
778
|
+
// x.cols,
|
|
779
|
+
// clamp(x.arr.flat(1), min, max)
|
|
780
|
+
// );
|
|
781
|
+
// if(x instanceof Array) return mapfun(n => clamp(n, min, max), ...x);
|
|
782
|
+
// return Math.min(Math.max(x, min), max)
|
|
783
|
+
// }
|
|
727
784
|
|
|
728
785
|
const hypot = (...x) => {
|
|
729
786
|
const c0 = x.find(a => a.isComplex?.());
|
|
@@ -735,10 +792,68 @@
|
|
|
735
792
|
};
|
|
736
793
|
|
|
737
794
|
|
|
738
|
-
const atan2 = (
|
|
795
|
+
const atan2 = (y, x, rad = true) => {
|
|
796
|
+
if (y instanceof Array && !(x instanceof Array))
|
|
797
|
+
return mapfun(n => atan2(n, x, rad), ...y);
|
|
798
|
+
|
|
799
|
+
if (x instanceof Array && !(y instanceof Array))
|
|
800
|
+
return mapfun(n => atan2(y, n, rad), ...x);
|
|
739
801
|
|
|
802
|
+
if (y instanceof Array && x instanceof Array)
|
|
803
|
+
return y.map((v, i) => atan2(v, x[i], rad));
|
|
804
|
+
|
|
805
|
+
const phi = Math.atan2(y, x);
|
|
806
|
+
return rad ? phi : phi * 180 / Math.PI;
|
|
740
807
|
};
|
|
741
808
|
|
|
809
|
+
const min$1 = (...x) => Math.min(...x);
|
|
810
|
+
const max$1 = (...x) => Math.max(...x);
|
|
811
|
+
|
|
812
|
+
const mean = (...x) => x.reduce((a, b) => a + b) / x.length;
|
|
813
|
+
|
|
814
|
+
const variance = (...x) => {
|
|
815
|
+
const n = x.length;
|
|
816
|
+
if (n === 0) return NaN;
|
|
817
|
+
const x_mean = mean(...x);
|
|
818
|
+
return x.reduce((sum, xi) => sum + (xi - x_mean) ** 2, 0) / n;
|
|
819
|
+
};
|
|
820
|
+
|
|
821
|
+
const std = (...x) => Math.sqrt(variance(...x));
|
|
822
|
+
|
|
823
|
+
const accum_sum = (...x) => {
|
|
824
|
+
let result = [];
|
|
825
|
+
let total = 0, i; n = x.length;
|
|
826
|
+
for(i = 0; i < n ; i++){
|
|
827
|
+
total = add(total, x[i]);
|
|
828
|
+
result.push(total);
|
|
829
|
+
}
|
|
830
|
+
return result;
|
|
831
|
+
};
|
|
832
|
+
|
|
833
|
+
const accum_prod = (...x) => {
|
|
834
|
+
let result = [];
|
|
835
|
+
let prod = 1, i; n = x.length;
|
|
836
|
+
for(i = 0; i < n ; i++){
|
|
837
|
+
prod = mul(prod, x[i]);
|
|
838
|
+
result.push(prod);
|
|
839
|
+
}
|
|
840
|
+
return result;
|
|
841
|
+
};
|
|
842
|
+
|
|
843
|
+
const percentile = (X, p) => {
|
|
844
|
+
if (X.length === 0)
|
|
845
|
+
return NaN;
|
|
846
|
+
let a = [...X].sort((x, y) => x - y);
|
|
847
|
+
let index = (p / 100) * (a.length - 1);
|
|
848
|
+
let i = Math.floor(index);
|
|
849
|
+
let f = index - i;
|
|
850
|
+
if (i === a.length - 1)
|
|
851
|
+
return a[i];
|
|
852
|
+
return a[i] * (1 - f) + a[i + 1] * f;
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
const median = X => percentile(X, 50);
|
|
856
|
+
|
|
742
857
|
const preload=(url)=>{
|
|
743
858
|
const xhr = new XMLHttpRequest();
|
|
744
859
|
xhr.open("GET", url, false);
|
|
@@ -3526,7 +3641,7 @@
|
|
|
3526
3641
|
// return result;
|
|
3527
3642
|
// }
|
|
3528
3643
|
map(Imin, Imax, Fmin, Fmax) {
|
|
3529
|
-
this.arr = map$1(this.arr);
|
|
3644
|
+
this.arr = map$1(this.arr, Imin, Imax, Fmin, Fmax);
|
|
3530
3645
|
return this;
|
|
3531
3646
|
}
|
|
3532
3647
|
lerp(min, max) {
|
|
@@ -3925,36 +4040,36 @@
|
|
|
3925
4040
|
}
|
|
3926
4041
|
return Y.length===1?Y[0]:Y;
|
|
3927
4042
|
};
|
|
3928
|
-
const min
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
}
|
|
3943
|
-
const max
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
}
|
|
4043
|
+
// const min=(...num)=>{
|
|
4044
|
+
// if(num.every(n=>typeof n==="number"))return Math.min(...num);
|
|
4045
|
+
// const Y=[];
|
|
4046
|
+
// for(let i=0;i<num.length;i++){
|
|
4047
|
+
// if(num[i] instanceof Array)Y.push(min(...num[i]));
|
|
4048
|
+
// else if(num[i] instanceof Object){
|
|
4049
|
+
// Y.push(
|
|
4050
|
+
// Object.fromEntries(
|
|
4051
|
+
// [Object.entries(num[i]).sort((a,b)=>a[1]-b[1])[0]]
|
|
4052
|
+
// )
|
|
4053
|
+
// )
|
|
4054
|
+
// }
|
|
4055
|
+
// }
|
|
4056
|
+
// return Y.length===1?Y[0]:Y;
|
|
4057
|
+
// }
|
|
4058
|
+
// const max=(...num)=>{
|
|
4059
|
+
// if(num.every(n=>typeof n==="number"))return Math.max(...num);
|
|
4060
|
+
// const Y=[];
|
|
4061
|
+
// for(let i=0;i<num.length;i++){
|
|
4062
|
+
// if(num[i] instanceof Array)Y.push(min(...num[i]));
|
|
4063
|
+
// else if(num[i] instanceof Object){
|
|
4064
|
+
// Y.push(
|
|
4065
|
+
// Object.fromEntries(
|
|
4066
|
+
// [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
|
|
4067
|
+
// )
|
|
4068
|
+
// )
|
|
4069
|
+
// }
|
|
4070
|
+
// }
|
|
4071
|
+
// return Y.length===1?Y[0]:Y;
|
|
4072
|
+
// }
|
|
3958
4073
|
const accum=(...num)=>{
|
|
3959
4074
|
if(num.every(n=>typeof n==="number")){
|
|
3960
4075
|
let acc = num.reduce((x, y) => [...x, x[x.length - 1] + y], [0]);
|
|
@@ -4608,7 +4723,7 @@
|
|
|
4608
4723
|
this.t += this.state.step;
|
|
4609
4724
|
this.i++;
|
|
4610
4725
|
|
|
4611
|
-
this.tx = map$1(this.t, 0, this.state.duration);
|
|
4726
|
+
this.tx = map$1(this.t, 0, this.state.duration, 0, 1);
|
|
4612
4727
|
this.ty = this.state.ease(this.tx);
|
|
4613
4728
|
|
|
4614
4729
|
this.callback(this);
|
|
@@ -5658,11 +5773,14 @@
|
|
|
5658
5773
|
exports.ZikoUIText = ZikoUIText;
|
|
5659
5774
|
exports.abs = abs;
|
|
5660
5775
|
exports.accum = accum;
|
|
5776
|
+
exports.accum_prod = accum_prod;
|
|
5777
|
+
exports.accum_sum = accum_sum;
|
|
5661
5778
|
exports.acos = acos$1;
|
|
5662
5779
|
exports.acosh = acosh;
|
|
5663
5780
|
exports.acot = acot;
|
|
5664
5781
|
exports.add = add;
|
|
5665
5782
|
exports.animation = animation;
|
|
5783
|
+
exports.apply_fun = apply_fun;
|
|
5666
5784
|
exports.arange = arange;
|
|
5667
5785
|
exports.arc = arc;
|
|
5668
5786
|
exports.arr2str = arr2str;
|
|
@@ -5757,6 +5875,8 @@
|
|
|
5757
5875
|
exports.matrix3 = matrix3;
|
|
5758
5876
|
exports.matrix4 = matrix4;
|
|
5759
5877
|
exports.max = max$1;
|
|
5878
|
+
exports.mean = mean;
|
|
5879
|
+
exports.median = median;
|
|
5760
5880
|
exports.min = min$1;
|
|
5761
5881
|
exports.modulo = modulo;
|
|
5762
5882
|
exports.mul = mul;
|
|
@@ -5775,6 +5895,7 @@
|
|
|
5775
5895
|
exports.out_quart = out_quart;
|
|
5776
5896
|
exports.out_quint = out_quint;
|
|
5777
5897
|
exports.out_sin = out_sin;
|
|
5898
|
+
exports.percentile = percentile;
|
|
5778
5899
|
exports.pgcd = pgcd;
|
|
5779
5900
|
exports.pow = pow$1;
|
|
5780
5901
|
exports.powerSet = powerSet;
|
|
@@ -5790,6 +5911,7 @@
|
|
|
5790
5911
|
exports.sinh = sinh$1;
|
|
5791
5912
|
exports.sleep = sleep;
|
|
5792
5913
|
exports.sqrt = sqrt$2;
|
|
5914
|
+
exports.std = std;
|
|
5793
5915
|
exports.step = step;
|
|
5794
5916
|
exports.step_fps = step_fps;
|
|
5795
5917
|
exports.sub = sub;
|
|
@@ -5821,6 +5943,7 @@
|
|
|
5821
5943
|
exports.useState = useState;
|
|
5822
5944
|
exports.useThread = useThread;
|
|
5823
5945
|
exports.useTitle = useTitle;
|
|
5946
|
+
exports.variance = variance;
|
|
5824
5947
|
exports.wait = wait;
|
|
5825
5948
|
exports.waitForUIElm = waitForUIElm;
|
|
5826
5949
|
exports.waitForUIElmSync = waitForUIElmSync;
|