@limitlesspc/std 0.21.1 → 0.23.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/array.d.ts +21 -4
- package/dist/array.js +5 -4
- package/dist/async/index.d.ts +1 -1
- package/dist/async/index.js +1 -13
- package/dist/{chunk-65SNM7MP.js → chunk-4POIKW4G.js} +9 -13
- package/dist/{chunk-WBSY6KRH.js → chunk-CCBSTDYA.js} +1 -1
- package/dist/{chunk-WNQNVZFS.js → chunk-ONMV3ICF.js} +219 -282
- package/dist/{chunk-O3YCU3KN.js → chunk-SSSOLDLG.js} +2 -2
- package/dist/cmath/index.js +1 -1
- package/dist/events.js +5 -6
- package/dist/fn/index.d.ts +14 -1
- package/dist/fn/index.js +1 -2
- package/dist/gfx/index.d.ts +1 -1
- package/dist/gfx/index.js +5 -6
- package/dist/iter/index.js +2 -3
- package/dist/math/index.d.ts +58 -58
- package/dist/math/index.js +7 -14
- package/dist/random.js +4 -5
- package/dist/string/index.js +5 -3
- package/dist/structs/index.d.ts +2 -75
- package/dist/structs/index.js +232 -18
- package/dist/types.js +0 -1
- package/dist/{vec3-S_YuL-W1.d.ts → vec3-BQ6mZ-wg.d.ts} +14 -24
- package/package.json +46 -50
- package/dist/chunk-6F4PWJZI.js +0 -0
- package/dist/chunk-DYKZK6B5.js +0 -523
- package/dist/easing.d.ts +0 -37
- package/dist/easing.js +0 -157
- /package/dist/{chunk-MG5VQSTV.js → chunk-NXILTE26.js} +0 -0
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
random
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SSSOLDLG.js";
|
|
4
4
|
import {
|
|
5
5
|
chunk,
|
|
6
6
|
collect,
|
|
7
7
|
filter,
|
|
8
8
|
map,
|
|
9
|
-
range
|
|
10
|
-
|
|
11
|
-
} from "./chunk-WBSY6KRH.js";
|
|
9
|
+
range
|
|
10
|
+
} from "./chunk-CCBSTDYA.js";
|
|
12
11
|
import {
|
|
13
12
|
pipe,
|
|
14
13
|
reverseCurry
|
|
15
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-NXILTE26.js";
|
|
16
15
|
|
|
17
16
|
// src/math/stats.ts
|
|
18
17
|
function min(iter) {
|
|
@@ -74,11 +73,12 @@ function median(array) {
|
|
|
74
73
|
if (!length) {
|
|
75
74
|
return 0;
|
|
76
75
|
}
|
|
77
|
-
const sorted =
|
|
76
|
+
const sorted = array.toSorted((a, b) => a - b);
|
|
77
|
+
const halfLen = length / 2;
|
|
78
78
|
if (length % 2) {
|
|
79
|
-
return sorted[
|
|
79
|
+
return sorted[Math.floor(halfLen)];
|
|
80
80
|
}
|
|
81
|
-
return (sorted[
|
|
81
|
+
return (sorted[halfLen - 1] + sorted[halfLen]) / 2;
|
|
82
82
|
}
|
|
83
83
|
function mode(iter) {
|
|
84
84
|
const counts = /* @__PURE__ */ new Map();
|
|
@@ -95,33 +95,34 @@ function mode(iter) {
|
|
|
95
95
|
);
|
|
96
96
|
}
|
|
97
97
|
function variance(iter) {
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
map(
|
|
102
|
-
const d =
|
|
98
|
+
const mean = avg(iter);
|
|
99
|
+
return pipe(
|
|
100
|
+
iter,
|
|
101
|
+
map((x) => {
|
|
102
|
+
const d = x - mean;
|
|
103
103
|
return d * d;
|
|
104
|
-
})
|
|
104
|
+
}),
|
|
105
|
+
avg
|
|
105
106
|
);
|
|
106
107
|
}
|
|
107
108
|
function stddev(iter) {
|
|
108
109
|
return Math.sqrt(variance(iter));
|
|
109
110
|
}
|
|
110
111
|
function meanAbsDev(iter) {
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
const mean = avg(iter);
|
|
113
|
+
return pipe(
|
|
114
|
+
iter,
|
|
115
|
+
map((x) => Math.abs(x - mean)),
|
|
116
|
+
avg
|
|
117
|
+
);
|
|
114
118
|
}
|
|
115
119
|
|
|
116
120
|
// src/math/funcs.ts
|
|
117
121
|
function isNumber(x) {
|
|
118
122
|
return typeof x === "number" && !Number.isNaN(x);
|
|
119
123
|
}
|
|
120
|
-
function
|
|
121
|
-
return
|
|
122
|
-
}
|
|
123
|
-
function isInteger(x) {
|
|
124
|
-
return Number.isInteger(x);
|
|
124
|
+
function sq(x) {
|
|
125
|
+
return x * x;
|
|
125
126
|
}
|
|
126
127
|
function roundToMultiple(x, n) {
|
|
127
128
|
return Math.floor(x / n) * n;
|
|
@@ -161,7 +162,7 @@ function overlap(min1, max1, min2, max2) {
|
|
|
161
162
|
return range1 + range2 - range3;
|
|
162
163
|
}
|
|
163
164
|
function closer(x, a, b) {
|
|
164
|
-
return Math.abs(x - a
|
|
165
|
+
return Math.abs(x - a) < Math.abs(x - b) ? a : b;
|
|
165
166
|
}
|
|
166
167
|
function round(n, precision = 0) {
|
|
167
168
|
const factor = 10 ** precision;
|
|
@@ -216,23 +217,6 @@ function fibonacci(n) {
|
|
|
216
217
|
}
|
|
217
218
|
var celsius = (fahrenheit2) => (fahrenheit2 - 32) * (5 / 9);
|
|
218
219
|
var fahrenheit = (celsius2) => celsius2 * (9 / 5) + 32;
|
|
219
|
-
function lineOfBestFit(points) {
|
|
220
|
-
const xs = points.map((p) => p.x);
|
|
221
|
-
const ys = points.map((p) => p.y);
|
|
222
|
-
const meanX = avg(xs);
|
|
223
|
-
const meanY = avg(ys);
|
|
224
|
-
let n = 0;
|
|
225
|
-
let den = 0;
|
|
226
|
-
for (let i = 0; i < points.length; i++) {
|
|
227
|
-
const x = xs[i];
|
|
228
|
-
const y = ys[i];
|
|
229
|
-
n += (x - meanX) * (y - meanY);
|
|
230
|
-
den += (x - meanX) ** 2;
|
|
231
|
-
}
|
|
232
|
-
const m = n / den;
|
|
233
|
-
const b = meanY - m * meanX;
|
|
234
|
-
return [m, b];
|
|
235
|
-
}
|
|
236
220
|
function permutations(n, k) {
|
|
237
221
|
if (k > n) {
|
|
238
222
|
return 0;
|
|
@@ -245,20 +229,6 @@ function combinations(n, k) {
|
|
|
245
229
|
}
|
|
246
230
|
return permutations(n, k) / factorial(k);
|
|
247
231
|
}
|
|
248
|
-
function dot(a, b) {
|
|
249
|
-
const iter1 = a[Symbol.iterator]();
|
|
250
|
-
const iter2 = b[Symbol.iterator]();
|
|
251
|
-
let total = 0;
|
|
252
|
-
while (true) {
|
|
253
|
-
const result1 = iter1.next();
|
|
254
|
-
const result2 = iter2.next();
|
|
255
|
-
if (result1.done && result2.done) {
|
|
256
|
-
break;
|
|
257
|
-
}
|
|
258
|
-
total += (result1.value || 0) * (result2.value || 0);
|
|
259
|
-
}
|
|
260
|
-
return total;
|
|
261
|
-
}
|
|
262
232
|
|
|
263
233
|
// src/iter/repeat.ts
|
|
264
234
|
var repeat = reverseCurry(function* repeat2(iter, n) {
|
|
@@ -827,43 +797,27 @@ function mat4(matrix) {
|
|
|
827
797
|
|
|
828
798
|
// src/math/trig.ts
|
|
829
799
|
var DEG2RAD = Math.PI / 180;
|
|
830
|
-
var degrees = (radians2) => radians2 / DEG2RAD;
|
|
831
800
|
var radians = (degrees2) => degrees2 * DEG2RAD;
|
|
801
|
+
var degrees = (radians2) => radians2 / DEG2RAD;
|
|
832
802
|
|
|
833
803
|
// src/math/vector/vec2.ts
|
|
834
|
-
var Vec2 = class _Vec2
|
|
835
|
-
|
|
804
|
+
var Vec2 = class _Vec2 {
|
|
805
|
+
x;
|
|
806
|
+
y;
|
|
836
807
|
constructor(x = 0, y) {
|
|
837
|
-
super([0, 0]);
|
|
838
808
|
if (typeof x === "number") {
|
|
839
809
|
this.x = x;
|
|
840
810
|
this.y = y ?? x;
|
|
841
811
|
} else {
|
|
842
|
-
|
|
812
|
+
this.x = x.x;
|
|
813
|
+
this.y = x.y;
|
|
843
814
|
}
|
|
844
815
|
}
|
|
845
|
-
/* prettier-ignore */
|
|
846
|
-
get x() {
|
|
847
|
-
return this[0] || 0;
|
|
848
|
-
}
|
|
849
|
-
/* prettier-ignore */
|
|
850
|
-
set x(value) {
|
|
851
|
-
this[0] = value;
|
|
852
|
-
}
|
|
853
|
-
/* prettier-ignore */
|
|
854
|
-
get y() {
|
|
855
|
-
return this[1] || 0;
|
|
856
|
-
}
|
|
857
|
-
/* prettier-ignore */
|
|
858
|
-
set y(value) {
|
|
859
|
-
this[1] = value;
|
|
860
|
-
}
|
|
861
816
|
toString() {
|
|
862
|
-
|
|
863
|
-
return `vec2 <${x}, ${y}>`;
|
|
817
|
+
return `vec2 <${this.x}, ${this.y}>`;
|
|
864
818
|
}
|
|
865
819
|
copy() {
|
|
866
|
-
return vec2(
|
|
820
|
+
return vec2(this);
|
|
867
821
|
}
|
|
868
822
|
static random(mag = 1) {
|
|
869
823
|
return vec2(1, 0).rotate(random(Math.PI * 2)).setMag(mag);
|
|
@@ -872,15 +826,25 @@ var Vec2 = class _Vec2 extends Float32Array {
|
|
|
872
826
|
if (typeof x === "number") {
|
|
873
827
|
return this.x === x && this.y === (y ?? x);
|
|
874
828
|
}
|
|
875
|
-
return this.x === x
|
|
829
|
+
return this.x === x.x && this.y === x.y;
|
|
830
|
+
}
|
|
831
|
+
set(x, y) {
|
|
832
|
+
if (typeof x === "number") {
|
|
833
|
+
this.x = x;
|
|
834
|
+
this.y = y ?? x;
|
|
835
|
+
} else {
|
|
836
|
+
this.x = x.x;
|
|
837
|
+
this.y = x.y;
|
|
838
|
+
}
|
|
839
|
+
return this;
|
|
876
840
|
}
|
|
877
841
|
add(x, y) {
|
|
878
842
|
if (typeof x === "number") {
|
|
879
843
|
this.x += x;
|
|
880
844
|
this.y += y ?? x;
|
|
881
845
|
} else {
|
|
882
|
-
this.x += x
|
|
883
|
-
this.y += x
|
|
846
|
+
this.x += x.x;
|
|
847
|
+
this.y += x.y;
|
|
884
848
|
}
|
|
885
849
|
return this;
|
|
886
850
|
}
|
|
@@ -892,8 +856,8 @@ var Vec2 = class _Vec2 extends Float32Array {
|
|
|
892
856
|
this.x -= x;
|
|
893
857
|
this.y -= y ?? x;
|
|
894
858
|
} else {
|
|
895
|
-
this.x -= x
|
|
896
|
-
this.y -= x
|
|
859
|
+
this.x -= x.x;
|
|
860
|
+
this.y -= x.y;
|
|
897
861
|
}
|
|
898
862
|
return this;
|
|
899
863
|
}
|
|
@@ -905,8 +869,8 @@ var Vec2 = class _Vec2 extends Float32Array {
|
|
|
905
869
|
this.x *= x;
|
|
906
870
|
this.y *= y ?? x;
|
|
907
871
|
} else {
|
|
908
|
-
this.x *= x
|
|
909
|
-
this.y *= x
|
|
872
|
+
this.x *= x.x;
|
|
873
|
+
this.y *= x.y;
|
|
910
874
|
}
|
|
911
875
|
return this;
|
|
912
876
|
}
|
|
@@ -918,8 +882,8 @@ var Vec2 = class _Vec2 extends Float32Array {
|
|
|
918
882
|
this.x /= x;
|
|
919
883
|
this.y /= y ?? x;
|
|
920
884
|
} else {
|
|
921
|
-
this.x /= x
|
|
922
|
-
this.y /= x
|
|
885
|
+
this.x /= x.x;
|
|
886
|
+
this.y /= x.y;
|
|
923
887
|
}
|
|
924
888
|
return this;
|
|
925
889
|
}
|
|
@@ -927,19 +891,19 @@ var Vec2 = class _Vec2 extends Float32Array {
|
|
|
927
891
|
return v1.copy().div(x, y);
|
|
928
892
|
}
|
|
929
893
|
static fma(a, b, c) {
|
|
930
|
-
return vec2(a
|
|
894
|
+
return vec2(a.x * b.x + c.x, a.y * b.y + c.y);
|
|
931
895
|
}
|
|
932
|
-
lt(
|
|
933
|
-
return vec2(this.x < x
|
|
896
|
+
lt(v) {
|
|
897
|
+
return vec2(this.x < v.x ? 1 : 0, this.y < v.y ? 1 : 0);
|
|
934
898
|
}
|
|
935
|
-
lte(
|
|
936
|
-
return vec2(this.x <= x
|
|
899
|
+
lte(v) {
|
|
900
|
+
return vec2(this.x <= v.x ? 1 : 0, this.y <= v.y ? 1 : 0);
|
|
937
901
|
}
|
|
938
|
-
gt(
|
|
939
|
-
return vec2(this.x > x
|
|
902
|
+
gt(v) {
|
|
903
|
+
return vec2(this.x > v.x ? 1 : 0, this.y > v.y ? 1 : 0);
|
|
940
904
|
}
|
|
941
|
-
gte(
|
|
942
|
-
return vec2(this.x >= x
|
|
905
|
+
gte(v) {
|
|
906
|
+
return vec2(this.x >= v.x ? 1 : 0, this.y >= v.y ? 1 : 0);
|
|
943
907
|
}
|
|
944
908
|
mag() {
|
|
945
909
|
return Math.sqrt(this.magSq());
|
|
@@ -976,15 +940,15 @@ var Vec2 = class _Vec2 extends Float32Array {
|
|
|
976
940
|
return _Vec2.sub(v, this).magSq();
|
|
977
941
|
}
|
|
978
942
|
dot(v) {
|
|
979
|
-
return this.x * v
|
|
943
|
+
return this.x * v.x + this.y * v.y;
|
|
980
944
|
}
|
|
981
945
|
cross(v) {
|
|
982
|
-
return this.x * v
|
|
946
|
+
return this.x * v.y - this.y * v.x;
|
|
983
947
|
}
|
|
984
948
|
lerp(v, norm2) {
|
|
985
949
|
const { x, y } = this;
|
|
986
|
-
this.x = lerp(x, v
|
|
987
|
-
this.y = lerp(y, v
|
|
950
|
+
this.x = lerp(x, v.x, norm2);
|
|
951
|
+
this.y = lerp(y, v.y, norm2);
|
|
988
952
|
return this;
|
|
989
953
|
}
|
|
990
954
|
static lerp(v1, v2, norm2) {
|
|
@@ -992,8 +956,8 @@ var Vec2 = class _Vec2 extends Float32Array {
|
|
|
992
956
|
}
|
|
993
957
|
clamp(min2, max2) {
|
|
994
958
|
const { x, y } = this;
|
|
995
|
-
this.x = clamp(x, min2
|
|
996
|
-
this.y = clamp(y, min2
|
|
959
|
+
this.x = clamp(x, min2.x, max2.x);
|
|
960
|
+
this.y = clamp(y, min2.y, max2.y);
|
|
997
961
|
return this;
|
|
998
962
|
}
|
|
999
963
|
static clamp(v, min2, max2) {
|
|
@@ -1032,13 +996,13 @@ var Vec2 = class _Vec2 extends Float32Array {
|
|
|
1032
996
|
return this.sub(_Vec2.mul(normal, 2 * this.dot(normal)));
|
|
1033
997
|
}
|
|
1034
998
|
refract(normal, eta) {
|
|
1035
|
-
const
|
|
1036
|
-
const k = 1 - eta * eta * (1 -
|
|
999
|
+
const dot = this.dot(normal);
|
|
1000
|
+
const k = 1 - eta * eta * (1 - dot * dot);
|
|
1037
1001
|
if (k < 0) {
|
|
1038
1002
|
this.x = this.y = 0;
|
|
1039
1003
|
return this;
|
|
1040
1004
|
}
|
|
1041
|
-
return this.mul(eta).sub(_Vec2.mul(normal, eta *
|
|
1005
|
+
return this.mul(eta).sub(_Vec2.mul(normal, eta * dot + Math.sqrt(k)));
|
|
1042
1006
|
}
|
|
1043
1007
|
};
|
|
1044
1008
|
function vec2(x, y) {
|
|
@@ -1046,72 +1010,50 @@ function vec2(x, y) {
|
|
|
1046
1010
|
}
|
|
1047
1011
|
|
|
1048
1012
|
// src/math/vector/vec3.ts
|
|
1049
|
-
var Vec3 = class _Vec3
|
|
1050
|
-
|
|
1013
|
+
var Vec3 = class _Vec3 {
|
|
1014
|
+
x;
|
|
1015
|
+
y;
|
|
1016
|
+
z;
|
|
1051
1017
|
constructor(x = 0, y, z) {
|
|
1052
|
-
super([0, 0, 0]);
|
|
1053
1018
|
if (typeof x === "number") {
|
|
1054
1019
|
this.x = x;
|
|
1055
1020
|
this.y = y ?? x;
|
|
1056
1021
|
this.z = z ?? (y === void 0 ? x : 0);
|
|
1057
1022
|
} else {
|
|
1058
|
-
|
|
1023
|
+
this.x = x.x;
|
|
1024
|
+
this.y = x.y;
|
|
1025
|
+
this.z = x.z;
|
|
1059
1026
|
}
|
|
1060
1027
|
}
|
|
1061
1028
|
/* prettier-ignore */
|
|
1062
|
-
get x() {
|
|
1063
|
-
return this[0] || 0;
|
|
1064
|
-
}
|
|
1065
|
-
/* prettier-ignore */
|
|
1066
|
-
set x(value) {
|
|
1067
|
-
this[0] = value;
|
|
1068
|
-
}
|
|
1069
|
-
/* prettier-ignore */
|
|
1070
|
-
get y() {
|
|
1071
|
-
return this[1] || 0;
|
|
1072
|
-
}
|
|
1073
|
-
/* prettier-ignore */
|
|
1074
|
-
set y(value) {
|
|
1075
|
-
this[1] = value;
|
|
1076
|
-
}
|
|
1077
|
-
/* prettier-ignore */
|
|
1078
|
-
get z() {
|
|
1079
|
-
return this[2] || 0;
|
|
1080
|
-
}
|
|
1081
|
-
/* prettier-ignore */
|
|
1082
|
-
set z(value) {
|
|
1083
|
-
this[2] = value;
|
|
1084
|
-
}
|
|
1085
|
-
/* prettier-ignore */
|
|
1086
1029
|
get r() {
|
|
1087
|
-
return this
|
|
1030
|
+
return this.x || 0;
|
|
1088
1031
|
}
|
|
1089
1032
|
/* prettier-ignore */
|
|
1090
1033
|
set r(value) {
|
|
1091
|
-
this
|
|
1034
|
+
this.x = value;
|
|
1092
1035
|
}
|
|
1093
1036
|
/* prettier-ignore */
|
|
1094
1037
|
get g() {
|
|
1095
|
-
return this
|
|
1038
|
+
return this.y || 0;
|
|
1096
1039
|
}
|
|
1097
1040
|
/* prettier-ignore */
|
|
1098
1041
|
set g(value) {
|
|
1099
|
-
this
|
|
1042
|
+
this.y = value;
|
|
1100
1043
|
}
|
|
1101
1044
|
/* prettier-ignore */
|
|
1102
1045
|
get b() {
|
|
1103
|
-
return this
|
|
1046
|
+
return this.z || 0;
|
|
1104
1047
|
}
|
|
1105
1048
|
/* prettier-ignore */
|
|
1106
1049
|
set b(value) {
|
|
1107
|
-
this
|
|
1050
|
+
this.z = value;
|
|
1108
1051
|
}
|
|
1109
1052
|
toString() {
|
|
1110
|
-
|
|
1111
|
-
return `vec3 <${x}, ${y}, ${z}>`;
|
|
1053
|
+
return `vec3 <${this.x}, ${this.y}, ${this.z}>`;
|
|
1112
1054
|
}
|
|
1113
1055
|
copy() {
|
|
1114
|
-
return vec3(
|
|
1056
|
+
return vec3(this);
|
|
1115
1057
|
}
|
|
1116
1058
|
static random(mag = 1) {
|
|
1117
1059
|
return vec3(0, 0, 1).rotateX(random(Math.PI * 2)).rotateY(random(Math.PI * 2)).setMag(mag);
|
|
@@ -1120,7 +1062,19 @@ var Vec3 = class _Vec3 extends Float32Array {
|
|
|
1120
1062
|
if (typeof x === "number") {
|
|
1121
1063
|
return this.x === x && this.y === (y ?? x) && this.z === (z ?? (y === void 0 ? x : 0));
|
|
1122
1064
|
}
|
|
1123
|
-
return this.x === x
|
|
1065
|
+
return this.x === x.x && this.y === x.y && this.z === x.z;
|
|
1066
|
+
}
|
|
1067
|
+
set(x, y, z) {
|
|
1068
|
+
if (typeof x === "number") {
|
|
1069
|
+
this.x = x;
|
|
1070
|
+
this.y = y ?? x;
|
|
1071
|
+
this.z = z ?? (y === void 0 ? x : 0);
|
|
1072
|
+
} else {
|
|
1073
|
+
this.x = x.x;
|
|
1074
|
+
this.y = x.y;
|
|
1075
|
+
this.z = x.z;
|
|
1076
|
+
}
|
|
1077
|
+
return this;
|
|
1124
1078
|
}
|
|
1125
1079
|
neg() {
|
|
1126
1080
|
return vec3(-this.x, -this.y, -this.z);
|
|
@@ -1131,9 +1085,9 @@ var Vec3 = class _Vec3 extends Float32Array {
|
|
|
1131
1085
|
this.y += y ?? x;
|
|
1132
1086
|
this.z += z ?? (y === void 0 ? x : 0);
|
|
1133
1087
|
} else {
|
|
1134
|
-
this.x += x
|
|
1135
|
-
this.y += x
|
|
1136
|
-
this.z += x
|
|
1088
|
+
this.x += x.x;
|
|
1089
|
+
this.y += x.y;
|
|
1090
|
+
this.z += x.z;
|
|
1137
1091
|
}
|
|
1138
1092
|
return this;
|
|
1139
1093
|
}
|
|
@@ -1146,9 +1100,9 @@ var Vec3 = class _Vec3 extends Float32Array {
|
|
|
1146
1100
|
this.y -= y ?? x;
|
|
1147
1101
|
this.z -= z ?? (y === void 0 ? x : 0);
|
|
1148
1102
|
} else {
|
|
1149
|
-
this.x -= x
|
|
1150
|
-
this.y -= x
|
|
1151
|
-
this.z -= x
|
|
1103
|
+
this.x -= x.x;
|
|
1104
|
+
this.y -= x.y;
|
|
1105
|
+
this.z -= x.z;
|
|
1152
1106
|
}
|
|
1153
1107
|
return this;
|
|
1154
1108
|
}
|
|
@@ -1161,9 +1115,9 @@ var Vec3 = class _Vec3 extends Float32Array {
|
|
|
1161
1115
|
this.y *= y ?? x;
|
|
1162
1116
|
this.z *= z ?? (y === void 0 ? x : 1);
|
|
1163
1117
|
} else {
|
|
1164
|
-
this.x *= x
|
|
1165
|
-
this.y *= x
|
|
1166
|
-
this.z *= x
|
|
1118
|
+
this.x *= x.x;
|
|
1119
|
+
this.y *= x.y;
|
|
1120
|
+
this.z *= x.z;
|
|
1167
1121
|
}
|
|
1168
1122
|
return this;
|
|
1169
1123
|
}
|
|
@@ -1176,9 +1130,9 @@ var Vec3 = class _Vec3 extends Float32Array {
|
|
|
1176
1130
|
this.y /= y ?? x;
|
|
1177
1131
|
this.z /= z ?? (y === void 0 ? x : 1);
|
|
1178
1132
|
} else {
|
|
1179
|
-
this.x /= x
|
|
1180
|
-
this.y /= x
|
|
1181
|
-
this.z /= x
|
|
1133
|
+
this.x /= x.x;
|
|
1134
|
+
this.y /= x.y;
|
|
1135
|
+
this.z /= x.z;
|
|
1182
1136
|
}
|
|
1183
1137
|
return this;
|
|
1184
1138
|
}
|
|
@@ -1186,34 +1140,34 @@ var Vec3 = class _Vec3 extends Float32Array {
|
|
|
1186
1140
|
return v1.copy().div(x, y, z);
|
|
1187
1141
|
}
|
|
1188
1142
|
static fma(a, b, c) {
|
|
1189
|
-
return vec3(a
|
|
1143
|
+
return vec3(a.x * b.x + c.x, a.y * b.y + c.y, a.z * b.z + c.z);
|
|
1190
1144
|
}
|
|
1191
|
-
lt(
|
|
1145
|
+
lt(v) {
|
|
1192
1146
|
return vec3(
|
|
1193
|
-
this.x < x
|
|
1194
|
-
this.y <
|
|
1195
|
-
this.z <
|
|
1147
|
+
this.x < v.x ? 1 : 0,
|
|
1148
|
+
this.y < v.y ? 1 : 0,
|
|
1149
|
+
this.z < v.z ? 1 : 0
|
|
1196
1150
|
);
|
|
1197
1151
|
}
|
|
1198
|
-
lte(
|
|
1152
|
+
lte(v) {
|
|
1199
1153
|
return vec3(
|
|
1200
|
-
this.x <= x
|
|
1201
|
-
this.y <=
|
|
1202
|
-
this.z <=
|
|
1154
|
+
this.x <= v.x ? 1 : 0,
|
|
1155
|
+
this.y <= v.y ? 1 : 0,
|
|
1156
|
+
this.z <= v.z ? 1 : 0
|
|
1203
1157
|
);
|
|
1204
1158
|
}
|
|
1205
|
-
gt(
|
|
1159
|
+
gt(v) {
|
|
1206
1160
|
return vec3(
|
|
1207
|
-
this.x > x
|
|
1208
|
-
this.y >
|
|
1209
|
-
this.z >
|
|
1161
|
+
this.x > v.x ? 1 : 0,
|
|
1162
|
+
this.y > v.y ? 1 : 0,
|
|
1163
|
+
this.z > v.z ? 1 : 0
|
|
1210
1164
|
);
|
|
1211
1165
|
}
|
|
1212
|
-
gte(
|
|
1166
|
+
gte(v) {
|
|
1213
1167
|
return vec3(
|
|
1214
|
-
this.x >= x
|
|
1215
|
-
this.y >=
|
|
1216
|
-
this.z >=
|
|
1168
|
+
this.x >= v.x ? 1 : 0,
|
|
1169
|
+
this.y >= v.y ? 1 : 0,
|
|
1170
|
+
this.z >= v.z ? 1 : 0
|
|
1217
1171
|
);
|
|
1218
1172
|
}
|
|
1219
1173
|
limit(max2) {
|
|
@@ -1252,17 +1206,17 @@ var Vec3 = class _Vec3 extends Float32Array {
|
|
|
1252
1206
|
}
|
|
1253
1207
|
dot(v) {
|
|
1254
1208
|
const { x, y, z } = this;
|
|
1255
|
-
return x * v
|
|
1209
|
+
return x * v.x + y * v.y + z * v.z;
|
|
1256
1210
|
}
|
|
1257
1211
|
cross(v) {
|
|
1258
1212
|
const { x, y, z } = this;
|
|
1259
|
-
return vec3(y * v
|
|
1213
|
+
return vec3(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
|
|
1260
1214
|
}
|
|
1261
1215
|
lerp(v, norm2) {
|
|
1262
1216
|
const { x, y, z } = this;
|
|
1263
|
-
this.x = lerp(x, v
|
|
1264
|
-
this.y = lerp(y, v
|
|
1265
|
-
this.z = lerp(z, v
|
|
1217
|
+
this.x = lerp(x, v.x, norm2);
|
|
1218
|
+
this.y = lerp(y, v.y, norm2);
|
|
1219
|
+
this.z = lerp(z, v.z, norm2);
|
|
1266
1220
|
return this;
|
|
1267
1221
|
}
|
|
1268
1222
|
static lerp(v1, v2, norm2) {
|
|
@@ -1270,9 +1224,9 @@ var Vec3 = class _Vec3 extends Float32Array {
|
|
|
1270
1224
|
}
|
|
1271
1225
|
clamp(min2, max2) {
|
|
1272
1226
|
const { x, y, z } = this;
|
|
1273
|
-
this.x = clamp(x, min2
|
|
1274
|
-
this.y = clamp(y, min2
|
|
1275
|
-
this.z = clamp(z, min2
|
|
1227
|
+
this.x = clamp(x, min2.x, max2.x);
|
|
1228
|
+
this.y = clamp(y, min2.y, max2.y);
|
|
1229
|
+
this.z = clamp(z, min2.z, max2.z);
|
|
1276
1230
|
return this;
|
|
1277
1231
|
}
|
|
1278
1232
|
static clamp(v, min2, max2) {
|
|
@@ -1323,95 +1277,81 @@ function vec3(x, y, z) {
|
|
|
1323
1277
|
}
|
|
1324
1278
|
|
|
1325
1279
|
// src/math/vector/vec4.ts
|
|
1326
|
-
var Vec4 = class _Vec4
|
|
1327
|
-
|
|
1280
|
+
var Vec4 = class _Vec4 {
|
|
1281
|
+
x;
|
|
1282
|
+
y;
|
|
1283
|
+
z;
|
|
1284
|
+
w;
|
|
1328
1285
|
constructor(x = 0, y, z, w) {
|
|
1329
|
-
super([0, 0, 0, 0]);
|
|
1330
1286
|
if (typeof x === "number") {
|
|
1331
1287
|
this.x = x;
|
|
1332
1288
|
this.y = y ?? x;
|
|
1333
1289
|
this.z = z ?? (y === void 0 ? x : 0);
|
|
1334
1290
|
this.w = w ?? (z === void 0 ? x : 0);
|
|
1335
1291
|
} else {
|
|
1336
|
-
|
|
1292
|
+
this.x = x.x;
|
|
1293
|
+
this.y = x.y;
|
|
1294
|
+
this.z = x.z;
|
|
1295
|
+
this.w = x.w;
|
|
1337
1296
|
}
|
|
1338
1297
|
}
|
|
1339
1298
|
/* prettier-ignore */
|
|
1340
|
-
get x() {
|
|
1341
|
-
return this[0] || 0;
|
|
1342
|
-
}
|
|
1343
|
-
/* prettier-ignore */
|
|
1344
|
-
set x(value) {
|
|
1345
|
-
this[0] = value;
|
|
1346
|
-
}
|
|
1347
|
-
/* prettier-ignore */
|
|
1348
|
-
get y() {
|
|
1349
|
-
return this[1] || 0;
|
|
1350
|
-
}
|
|
1351
|
-
/* prettier-ignore */
|
|
1352
|
-
set y(value) {
|
|
1353
|
-
this[1] = value;
|
|
1354
|
-
}
|
|
1355
|
-
/* prettier-ignore */
|
|
1356
|
-
get z() {
|
|
1357
|
-
return this[2] || 0;
|
|
1358
|
-
}
|
|
1359
|
-
/* prettier-ignore */
|
|
1360
|
-
set z(value) {
|
|
1361
|
-
this[2] = value;
|
|
1362
|
-
}
|
|
1363
|
-
/* prettier-ignore */
|
|
1364
|
-
get w() {
|
|
1365
|
-
return this[2] || 0;
|
|
1366
|
-
}
|
|
1367
|
-
/* prettier-ignore */
|
|
1368
|
-
set w(value) {
|
|
1369
|
-
this[2] = value;
|
|
1370
|
-
}
|
|
1371
|
-
/* prettier-ignore */
|
|
1372
1299
|
get r() {
|
|
1373
|
-
return this
|
|
1300
|
+
return this.x || 0;
|
|
1374
1301
|
}
|
|
1375
1302
|
/* prettier-ignore */
|
|
1376
1303
|
set r(value) {
|
|
1377
|
-
this
|
|
1304
|
+
this.x = value;
|
|
1378
1305
|
}
|
|
1379
1306
|
/* prettier-ignore */
|
|
1380
1307
|
get g() {
|
|
1381
|
-
return this
|
|
1308
|
+
return this.y || 0;
|
|
1382
1309
|
}
|
|
1383
1310
|
/* prettier-ignore */
|
|
1384
1311
|
set g(value) {
|
|
1385
|
-
this
|
|
1312
|
+
this.y = value;
|
|
1386
1313
|
}
|
|
1387
1314
|
/* prettier-ignore */
|
|
1388
1315
|
get b() {
|
|
1389
|
-
return this
|
|
1316
|
+
return this.z || 0;
|
|
1390
1317
|
}
|
|
1391
1318
|
/* prettier-ignore */
|
|
1392
1319
|
set b(value) {
|
|
1393
|
-
this
|
|
1320
|
+
this.z = value;
|
|
1394
1321
|
}
|
|
1395
1322
|
/* prettier-ignore */
|
|
1396
1323
|
get a() {
|
|
1397
|
-
return this
|
|
1324
|
+
return this.z || 0;
|
|
1398
1325
|
}
|
|
1399
1326
|
/* prettier-ignore */
|
|
1400
1327
|
set a(value) {
|
|
1401
|
-
this
|
|
1328
|
+
this.z = value;
|
|
1402
1329
|
}
|
|
1403
1330
|
toString() {
|
|
1404
|
-
|
|
1405
|
-
return `vec4 <${x}, ${y}, ${z}, ${w}>`;
|
|
1331
|
+
return `vec4 <${this.x}, ${this.y}, ${this.z}, ${this.w}>`;
|
|
1406
1332
|
}
|
|
1407
1333
|
copy() {
|
|
1408
|
-
return vec4(
|
|
1334
|
+
return vec4(this);
|
|
1409
1335
|
}
|
|
1410
1336
|
eq(x, y, z, w) {
|
|
1411
1337
|
if (typeof x === "number") {
|
|
1412
1338
|
return this.x === x && this.y === (y ?? x) && this.z === (z ?? (y === void 0 ? x : 0)) && this.w === (w ?? (z === void 0 ? x : 0));
|
|
1413
1339
|
}
|
|
1414
|
-
return this.x === x
|
|
1340
|
+
return this.x === x.x && this.y === x.y && this.z === x.z && this.w === x.w;
|
|
1341
|
+
}
|
|
1342
|
+
set(x, y, z, w) {
|
|
1343
|
+
if (typeof x === "number") {
|
|
1344
|
+
this.x = x;
|
|
1345
|
+
this.y = y ?? x;
|
|
1346
|
+
this.z = z ?? (y === void 0 ? x : 0);
|
|
1347
|
+
this.w = w ?? (z === void 0 ? x : 0);
|
|
1348
|
+
} else {
|
|
1349
|
+
this.x = x.x;
|
|
1350
|
+
this.y = x.y;
|
|
1351
|
+
this.z = x.z;
|
|
1352
|
+
this.w = x.w;
|
|
1353
|
+
}
|
|
1354
|
+
return this;
|
|
1415
1355
|
}
|
|
1416
1356
|
add(x, y, z, w) {
|
|
1417
1357
|
if (typeof x === "number") {
|
|
@@ -1420,10 +1360,10 @@ var Vec4 = class _Vec4 extends Float32Array {
|
|
|
1420
1360
|
this.z += z ?? (y === void 0 ? x : 0);
|
|
1421
1361
|
this.w += w ?? (z === void 0 ? x : 0);
|
|
1422
1362
|
} else {
|
|
1423
|
-
this.x += x
|
|
1424
|
-
this.y += x
|
|
1425
|
-
this.z += x
|
|
1426
|
-
this.w += x
|
|
1363
|
+
this.x += x.x;
|
|
1364
|
+
this.y += x.y;
|
|
1365
|
+
this.z += x.z;
|
|
1366
|
+
this.w += x.w;
|
|
1427
1367
|
}
|
|
1428
1368
|
return this;
|
|
1429
1369
|
}
|
|
@@ -1437,10 +1377,10 @@ var Vec4 = class _Vec4 extends Float32Array {
|
|
|
1437
1377
|
this.z -= z ?? (y === void 0 ? x : 0);
|
|
1438
1378
|
this.w -= w ?? (z === void 0 ? x : 0);
|
|
1439
1379
|
} else {
|
|
1440
|
-
this.x -= x
|
|
1441
|
-
this.y -= x
|
|
1442
|
-
this.z -= x
|
|
1443
|
-
this.w -= x
|
|
1380
|
+
this.x -= x.x;
|
|
1381
|
+
this.y -= x.y;
|
|
1382
|
+
this.z -= x.z;
|
|
1383
|
+
this.w -= x.w;
|
|
1444
1384
|
}
|
|
1445
1385
|
return this;
|
|
1446
1386
|
}
|
|
@@ -1454,10 +1394,10 @@ var Vec4 = class _Vec4 extends Float32Array {
|
|
|
1454
1394
|
this.z *= z ?? (y === void 0 ? x : 1);
|
|
1455
1395
|
this.w *= w ?? (z === void 0 ? x : 1);
|
|
1456
1396
|
} else {
|
|
1457
|
-
this.x *= x
|
|
1458
|
-
this.y *= x
|
|
1459
|
-
this.z *= x
|
|
1460
|
-
this.w *= x
|
|
1397
|
+
this.x *= x.x;
|
|
1398
|
+
this.y *= x.y;
|
|
1399
|
+
this.z *= x.z;
|
|
1400
|
+
this.w *= x.w;
|
|
1461
1401
|
}
|
|
1462
1402
|
return this;
|
|
1463
1403
|
}
|
|
@@ -1471,10 +1411,10 @@ var Vec4 = class _Vec4 extends Float32Array {
|
|
|
1471
1411
|
this.z /= z ?? (y === void 0 ? x : 1);
|
|
1472
1412
|
this.w /= w ?? (z === void 0 ? x : 1);
|
|
1473
1413
|
} else {
|
|
1474
|
-
this.x /= x
|
|
1475
|
-
this.y /= x
|
|
1476
|
-
this.z /= x
|
|
1477
|
-
this.w /= x
|
|
1414
|
+
this.x /= x.x;
|
|
1415
|
+
this.y /= x.y;
|
|
1416
|
+
this.z /= x.z;
|
|
1417
|
+
this.w /= x.w;
|
|
1478
1418
|
}
|
|
1479
1419
|
return this;
|
|
1480
1420
|
}
|
|
@@ -1483,42 +1423,42 @@ var Vec4 = class _Vec4 extends Float32Array {
|
|
|
1483
1423
|
}
|
|
1484
1424
|
static fma(a, b, c) {
|
|
1485
1425
|
return vec4(
|
|
1486
|
-
a
|
|
1487
|
-
a
|
|
1488
|
-
a
|
|
1489
|
-
a
|
|
1426
|
+
a.x * b.x + c.x,
|
|
1427
|
+
a.y * b.y + c.y,
|
|
1428
|
+
a.z * b.z + c.z,
|
|
1429
|
+
a.w * b.w + c.w
|
|
1490
1430
|
);
|
|
1491
1431
|
}
|
|
1492
|
-
lt(
|
|
1432
|
+
lt(v) {
|
|
1493
1433
|
return vec4(
|
|
1494
|
-
this.x < x
|
|
1495
|
-
this.y <
|
|
1496
|
-
this.z <
|
|
1497
|
-
this.w <
|
|
1434
|
+
this.x < v.x ? 1 : 0,
|
|
1435
|
+
this.y < v.y ? 1 : 0,
|
|
1436
|
+
this.z < v.z ? 1 : 0,
|
|
1437
|
+
this.w < v.w ? 1 : 0
|
|
1498
1438
|
);
|
|
1499
1439
|
}
|
|
1500
|
-
lte(
|
|
1440
|
+
lte(v) {
|
|
1501
1441
|
return vec4(
|
|
1502
|
-
this.x <= x
|
|
1503
|
-
this.y <=
|
|
1504
|
-
this.z <=
|
|
1505
|
-
this.w <=
|
|
1442
|
+
this.x <= v.x ? 1 : 0,
|
|
1443
|
+
this.y <= v.y ? 1 : 0,
|
|
1444
|
+
this.z <= v.z ? 1 : 0,
|
|
1445
|
+
this.w <= v.w ? 1 : 0
|
|
1506
1446
|
);
|
|
1507
1447
|
}
|
|
1508
|
-
gt(
|
|
1448
|
+
gt(v) {
|
|
1509
1449
|
return vec4(
|
|
1510
|
-
this.x > x
|
|
1511
|
-
this.y >
|
|
1512
|
-
this.z >
|
|
1513
|
-
this.w >
|
|
1450
|
+
this.x > v.x ? 1 : 0,
|
|
1451
|
+
this.y > v.y ? 1 : 0,
|
|
1452
|
+
this.z > v.z ? 1 : 0,
|
|
1453
|
+
this.w > v.w ? 1 : 0
|
|
1514
1454
|
);
|
|
1515
1455
|
}
|
|
1516
|
-
gte(
|
|
1456
|
+
gte(v) {
|
|
1517
1457
|
return vec4(
|
|
1518
|
-
this.x >= x
|
|
1519
|
-
this.y >=
|
|
1520
|
-
this.z >=
|
|
1521
|
-
this.w >=
|
|
1458
|
+
this.x >= v.x ? 1 : 0,
|
|
1459
|
+
this.y >= v.y ? 1 : 0,
|
|
1460
|
+
this.z >= v.z ? 1 : 0,
|
|
1461
|
+
this.w >= v.w ? 1 : 0
|
|
1522
1462
|
);
|
|
1523
1463
|
}
|
|
1524
1464
|
limit(max2) {
|
|
@@ -1557,14 +1497,14 @@ var Vec4 = class _Vec4 extends Float32Array {
|
|
|
1557
1497
|
}
|
|
1558
1498
|
dot(v) {
|
|
1559
1499
|
const { x, y, z, w } = this;
|
|
1560
|
-
return x * v
|
|
1500
|
+
return x * v.x + y * v.y + z * v.z + w * v.w;
|
|
1561
1501
|
}
|
|
1562
1502
|
lerp(v, norm2) {
|
|
1563
1503
|
const { x, y, z, w } = this;
|
|
1564
|
-
this.x = lerp(x, v
|
|
1565
|
-
this.y = lerp(y, v
|
|
1566
|
-
this.z = lerp(z, v
|
|
1567
|
-
this.w = lerp(w, v
|
|
1504
|
+
this.x = lerp(x, v.x, norm2);
|
|
1505
|
+
this.y = lerp(y, v.y, norm2);
|
|
1506
|
+
this.z = lerp(z, v.z, norm2);
|
|
1507
|
+
this.w = lerp(w, v.w, norm2);
|
|
1568
1508
|
return this;
|
|
1569
1509
|
}
|
|
1570
1510
|
static lerp(v1, v2, norm2) {
|
|
@@ -1572,10 +1512,10 @@ var Vec4 = class _Vec4 extends Float32Array {
|
|
|
1572
1512
|
}
|
|
1573
1513
|
clamp(min2, max2) {
|
|
1574
1514
|
const { x, y, z, w } = this;
|
|
1575
|
-
this.x = clamp(x, min2
|
|
1576
|
-
this.y = clamp(y, min2
|
|
1577
|
-
this.z = clamp(z, min2
|
|
1578
|
-
this.w = clamp(w, min2
|
|
1515
|
+
this.x = clamp(x, min2.x, max2.x);
|
|
1516
|
+
this.y = clamp(y, min2.y, max2.y);
|
|
1517
|
+
this.z = clamp(z, min2.z, max2.z);
|
|
1518
|
+
this.w = clamp(w, min2.w, max2.w);
|
|
1579
1519
|
return this;
|
|
1580
1520
|
}
|
|
1581
1521
|
static clamp(v, min2, max2) {
|
|
@@ -1614,8 +1554,7 @@ export {
|
|
|
1614
1554
|
stddev,
|
|
1615
1555
|
meanAbsDev,
|
|
1616
1556
|
isNumber,
|
|
1617
|
-
|
|
1618
|
-
isInteger,
|
|
1557
|
+
sq,
|
|
1619
1558
|
roundToMultiple,
|
|
1620
1559
|
roundToEven,
|
|
1621
1560
|
norm,
|
|
@@ -1640,10 +1579,8 @@ export {
|
|
|
1640
1579
|
fibonacci,
|
|
1641
1580
|
celsius,
|
|
1642
1581
|
fahrenheit,
|
|
1643
|
-
lineOfBestFit,
|
|
1644
1582
|
permutations,
|
|
1645
1583
|
combinations,
|
|
1646
|
-
dot,
|
|
1647
1584
|
Mat,
|
|
1648
1585
|
mat,
|
|
1649
1586
|
Mat2,
|
|
@@ -1653,8 +1590,8 @@ export {
|
|
|
1653
1590
|
Mat4,
|
|
1654
1591
|
mat4,
|
|
1655
1592
|
DEG2RAD,
|
|
1656
|
-
degrees,
|
|
1657
1593
|
radians,
|
|
1594
|
+
degrees,
|
|
1658
1595
|
Vec2,
|
|
1659
1596
|
vec2,
|
|
1660
1597
|
Vec3,
|