@jarenjs/core 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +800 -0
- package/LICENSE +21 -0
- package/README.md +68 -0
- package/dist/types/array.d.ts +28 -0
- package/dist/types/bigint.d.ts +5 -0
- package/dist/types/dates.d.ts +79 -0
- package/dist/types/float.d.ts +32 -0
- package/dist/types/function.d.ts +22 -0
- package/dist/types/index.d.ts +119 -0
- package/dist/types/integer.d.ts +24 -0
- package/dist/types/math/float64.d.ts +121 -0
- package/dist/types/math/index.d.ts +5 -0
- package/dist/types/math/int32.d.ts +41 -0
- package/dist/types/math/vec2f64.d.ts +346 -0
- package/dist/types/math/vec2i32.d.ts +43 -0
- package/dist/types/math/vec3f64.d.ts +61 -0
- package/dist/types/number.d.ts +39 -0
- package/dist/types/object.d.ts +44 -0
- package/dist/types/scan.d.ts +64 -0
- package/dist/types/string.d.ts +65 -0
- package/dist/types/text/base64.d.ts +4 -0
- package/dist/types/text/basic.d.ts +5 -0
- package/dist/types/text/email.d.ts +3 -0
- package/dist/types/text/host.d.ts +14 -0
- package/dist/types/text/i18n.d.ts +13 -0
- package/dist/types/text/identifiers.d.ts +5 -0
- package/dist/types/text/index.d.ts +8 -0
- package/dist/types/text/iregexp.d.ts +36 -0
- package/dist/types/text/misc.d.ts +4 -0
- package/dist/types/text/punycode.d.ts +86 -0
- package/package.json +101 -0
- package/src/array.js +57 -0
- package/src/bigint.js +30 -0
- package/src/dates.js +371 -0
- package/src/float.js +107 -0
- package/src/function.js +56 -0
- package/src/index.js +223 -0
- package/src/integer.js +77 -0
- package/src/math/float64.js +316 -0
- package/src/math/index.js +5 -0
- package/src/math/int32.js +235 -0
- package/src/math/vec2f64.js +706 -0
- package/src/math/vec2i32.js +250 -0
- package/src/math/vec3f64.js +225 -0
- package/src/number.js +63 -0
- package/src/object.js +240 -0
- package/src/scan.js +96 -0
- package/src/string.js +194 -0
- package/src/text/base64.js +54 -0
- package/src/text/basic.js +23 -0
- package/src/text/email.js +61 -0
- package/src/text/host.js +335 -0
- package/src/text/i18n.js +294 -0
- package/src/text/identifiers.js +27 -0
- package/src/text/index.js +11 -0
- package/src/text/iregexp.js +308 -0
- package/src/text/misc.js +19 -0
- package/src/text/punycode.js +407 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mathi32_MULTIPLIER,
|
|
3
|
+
mathi32_sqrt,
|
|
4
|
+
mathi32_asin,
|
|
5
|
+
mathi32_atan2,
|
|
6
|
+
} from './int32.js';
|
|
7
|
+
|
|
8
|
+
export class Vec2i32 {
|
|
9
|
+
/**
|
|
10
|
+
* @param {number | undefined} x
|
|
11
|
+
* @param {number | undefined} y
|
|
12
|
+
*/
|
|
13
|
+
constructor(x = 0, y = 0) {
|
|
14
|
+
this.x = x | 0;
|
|
15
|
+
this.y = y | 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static new(x = 0, y = 0) {
|
|
19
|
+
return new Vec2i32(x | 0, y | 0);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
new() {
|
|
23
|
+
return new Vec2i32(this.x | 0, this.y | 0);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#region static primitive operators
|
|
27
|
+
|
|
28
|
+
static neg(v = def_Vec2i32) {
|
|
29
|
+
return new Vec2i32(-(v.x | 0) | 0, -(v.y | 0) | 0);
|
|
30
|
+
}
|
|
31
|
+
static add(a = def_Vec2i32, b = def_Vec2i32) {
|
|
32
|
+
return new Vec2i32(
|
|
33
|
+
((a.x | 0) + (b.x | 0)) | 0,
|
|
34
|
+
((a.y | 0) + (b.y | 0)) | 0,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
static adds(v = def_Vec2i32, scalar = 0) {
|
|
38
|
+
scalar = scalar | 0;
|
|
39
|
+
return new Vec2i32(((v.x | 0) + scalar) | 0, ((v.y | 0) + scalar) | 0);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static sub(a = def_Vec2i32, b = def_Vec2i32) {
|
|
43
|
+
return new Vec2i32(
|
|
44
|
+
((a.x | 0) - (b.x | 0)) | 0,
|
|
45
|
+
((a.y | 0) - (b.y | 0)) | 0,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
static subs(a = def_Vec2i32, scalar = 0) {
|
|
49
|
+
scalar = scalar | 0;
|
|
50
|
+
return new Vec2i32(((a.x | 0) - scalar) | 0, ((a.y | 0) - scalar) | 0);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static mul(a = def_Vec2i32, b = def_Vec2i32) {
|
|
54
|
+
return new Vec2i32(
|
|
55
|
+
((a.x | 0) * (b.x | 0)) | 0,
|
|
56
|
+
((a.y | 0) * (b.y | 0)) | 0,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
static muls(v = def_Vec2i32, scalar = 0) {
|
|
60
|
+
scalar = scalar | 0;
|
|
61
|
+
return new Vec2i32(((v.x | 0) * scalar) | 0, ((v.y | 0) * scalar) | 0);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static div(a = def_Vec2i32, b = def_Vec2i32) {
|
|
65
|
+
return new Vec2i32(
|
|
66
|
+
((a.x | 0) / (b.x | 0)) | 0,
|
|
67
|
+
((a.y | 0) / (b.y | 0)) | 0,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
static divs(v = def_Vec2i32, scalar = 0) {
|
|
71
|
+
scalar = scalar | 0;
|
|
72
|
+
return new Vec2i32(((v.x | 0) / scalar) | 0, ((v.y | 0) / scalar) | 0);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
|
|
77
|
+
//#region static scalar products
|
|
78
|
+
|
|
79
|
+
static mag2(v = def_Vec2i32) {
|
|
80
|
+
return ((v.x | 0) * (v.x | 0) + (v.y | 0) * (v.y | 0)) | 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static mag(v = def_Vec2i32) {
|
|
84
|
+
return mathi32_sqrt(+Vec2i32.mag2(v)) | 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static dot(a = def_Vec2i32, b = def_Vec2i32) {
|
|
88
|
+
return ((a.x | 0) * (b.x | 0) + (a.y | 0) * (b.y | 0)) | 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
static cross(a = def_Vec2i32, b = def_Vec2i32) {
|
|
92
|
+
return ((a.x | 0) * (b.y | 0) - (a.y | 0) * (b.x | 0)) | 0;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static cross3(a = def_Vec2i32, b = def_Vec2i32, c = def_Vec2i32) {
|
|
96
|
+
return (
|
|
97
|
+
((b.x | 0) - (a.x | 0)) * ((c.y | 0) - (a.y | 0)) -
|
|
98
|
+
((b.y | 0) - (a.y | 0)) * ((c.x | 0) - (a.x | 0))
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static thetaEx(v = def_Vec2i32) {
|
|
103
|
+
return (mathi32_MULTIPLIER * mathi32_atan2(v.y | 0, v.x | 0)) | 0;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static phiEx(v = def_Vec2i32) {
|
|
107
|
+
return (mathi32_MULTIPLIER * mathi32_asin((v.y | 0) / Vec2i32.mag(v))) | 0;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
//#endregion
|
|
111
|
+
|
|
112
|
+
//#region static advanced functions
|
|
113
|
+
|
|
114
|
+
static norm(v = def_Vec2i32) {
|
|
115
|
+
return Vec2i32.divs(v, Vec2i32.mag(v) | 0);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
static rotn90(v = def_Vec2i32) {
|
|
119
|
+
return new Vec2i32(v.y | 0, -(v.x | 0) | 0);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static rot90(v = def_Vec2i32) {
|
|
123
|
+
return new Vec2i32(-(v.y | 0) | 0, v.x | 0);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//#endregion
|
|
127
|
+
|
|
128
|
+
//#region instance primitive operators
|
|
129
|
+
|
|
130
|
+
ineg() {
|
|
131
|
+
this.x = -(this.x | 0) | 0;
|
|
132
|
+
this.y = -(this.y | 0) | 0;
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
iadd(v = def_Vec2i32) {
|
|
137
|
+
this.x += v.x | 0 | 0;
|
|
138
|
+
this.y += v.y | 0 | 0;
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
iadds(scalar = 0) {
|
|
143
|
+
scalar = scalar | 0;
|
|
144
|
+
this.x += scalar | 0;
|
|
145
|
+
this.y += scalar | 0;
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
isub(v = def_Vec2i32) {
|
|
150
|
+
this.x -= v.x | 0 | 0;
|
|
151
|
+
this.y -= v.y | 0 | 0;
|
|
152
|
+
return this;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
isubs(scalar = 0) {
|
|
156
|
+
scalar = scalar | 0;
|
|
157
|
+
this.x -= scalar | 0;
|
|
158
|
+
this.y -= scalar | 0;
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
imul(v = def_Vec2i32) {
|
|
163
|
+
this.x *= v.x | 0 | 0;
|
|
164
|
+
this.y *= v.y | 0 | 0;
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
imuls(scalar = 0) {
|
|
169
|
+
scalar = scalar | 0;
|
|
170
|
+
this.x *= scalar;
|
|
171
|
+
this.y *= scalar;
|
|
172
|
+
return this;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
idiv(v = def_Vec2i32) {
|
|
176
|
+
this.x = ((this.x | 0) / (v.x | 0)) | 0;
|
|
177
|
+
this.y = ((this.y | 0) / (v.y | 0)) | 0;
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
idivs(scalar = 0) {
|
|
182
|
+
scalar = scalar | 0;
|
|
183
|
+
this.x = ((this.x | 0) / scalar) | 0;
|
|
184
|
+
this.y = ((this.y | 0) / scalar) | 0;
|
|
185
|
+
return this;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
//#endregion
|
|
189
|
+
|
|
190
|
+
//#region instance advanced functions
|
|
191
|
+
inorm() {
|
|
192
|
+
return this.idivs(Vec2i32.mag(this) | 0);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
irotn90() {
|
|
196
|
+
const t = this.x | 0;
|
|
197
|
+
this.x = this.y | 0;
|
|
198
|
+
this.y = -t | 0;
|
|
199
|
+
return this;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
irot90() {
|
|
203
|
+
const t = this.x | 0;
|
|
204
|
+
this.x = -(this.y | 0) | 0;
|
|
205
|
+
this.y = t | 0;
|
|
206
|
+
return this;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
//#endregion
|
|
210
|
+
|
|
211
|
+
/** Just Some Notes
|
|
212
|
+
const fastSin_B = 1.2732395; // 4/pi
|
|
213
|
+
const fastSin_C = -0.40528473; // -4 / (pi²)
|
|
214
|
+
export function fastSin(value) {
|
|
215
|
+
// See for graph and equations
|
|
216
|
+
// https://www.desmos.com/calculator/8nkxlrmp7a
|
|
217
|
+
// logic explained here : http://devmaster.net/posts/9648/fast-and-accurate-sine-cosine
|
|
218
|
+
|
|
219
|
+
return (value > 0)
|
|
220
|
+
? fastSin_B * value - fastSin_C * value * value
|
|
221
|
+
: fastSin_B * value + fastSin_C * value * value;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function fastSin2(a) {
|
|
225
|
+
let b, c;
|
|
226
|
+
return a *= 5214
|
|
227
|
+
, c = a << 17
|
|
228
|
+
, a -= 8192
|
|
229
|
+
, a <<= 18
|
|
230
|
+
, a >>= 18
|
|
231
|
+
, a = a * a >> 12
|
|
232
|
+
, b = 19900 - (3516 * a >> 14)
|
|
233
|
+
, b = 4096 - (a * b >> 16)
|
|
234
|
+
, 0 > c && (b = -b)
|
|
235
|
+
, 2.44E-4 * b;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
export function fastSin3(a) {
|
|
239
|
+
a *= 5214;
|
|
240
|
+
let b = a << 17;
|
|
241
|
+
a = a - 8192 << 18 >> 18;
|
|
242
|
+
a = a * a >> 12;
|
|
243
|
+
a = 4096 - (a * (19900 - (3516 * a >> 14)) >> 16);
|
|
244
|
+
0 > b && (a = -a);
|
|
245
|
+
return 2.44E-4 * a
|
|
246
|
+
};
|
|
247
|
+
*/
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export const def_Vec2i32 = Object.freeze(Object.seal(Vec2i32.new()));
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
//@ts-check
|
|
2
|
+
|
|
3
|
+
import { mathf64_sqrt } from './float64.js';
|
|
4
|
+
|
|
5
|
+
import { Vec2f64 } from './vec2f64.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @class Vec3f64
|
|
9
|
+
* @classdesc A 3-dimensional vector of float64 values
|
|
10
|
+
* @property {double} x - The x component of the vector
|
|
11
|
+
* @property {double} y - The y component of the vector
|
|
12
|
+
* @property {double} z - The z component of the vector
|
|
13
|
+
*/
|
|
14
|
+
export class Vec3f64 {
|
|
15
|
+
constructor(x = 0.0, y = 0.0, z = 0.0) {
|
|
16
|
+
this.x = +x;
|
|
17
|
+
this.y = +y;
|
|
18
|
+
this.z = +z;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Create a new 3 dimensional vector
|
|
23
|
+
* @param {number | Vec3f64 | Vec2f64} x a floating point number or a Vec3f64 instance or a vec2f64 instance
|
|
24
|
+
* @param {number | undefined} y a floating point number
|
|
25
|
+
* @param {number | undefined} z a floating point number
|
|
26
|
+
* @returns {Vec3f64} a new vector structure
|
|
27
|
+
*/
|
|
28
|
+
static new(x = 0.0, y = 0.0, z = 0.0) {
|
|
29
|
+
return (x instanceof Vec3f64)
|
|
30
|
+
? new Vec3f64(+x.x, +x.y, +x.z)
|
|
31
|
+
: (x instanceof Vec2f64)
|
|
32
|
+
? new Vec3f64(+x.x, +x.y, +z) // TODO: check this
|
|
33
|
+
: new Vec3f64(+x, +y, +z);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#region static vec3f pure operators
|
|
37
|
+
|
|
38
|
+
static add(a = def_Vec3f64, b = def_Vec3f64) {
|
|
39
|
+
return new Vec3f64(
|
|
40
|
+
+(+a.x + +b.x),
|
|
41
|
+
+(+a.y + +b.y),
|
|
42
|
+
+(+a.z + +b.z),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static adds(a = def_Vec3f64, scalar = 0.0) {
|
|
47
|
+
return new Vec3f64(
|
|
48
|
+
+(+a.x + +scalar),
|
|
49
|
+
+(+a.y + +scalar),
|
|
50
|
+
+(+a.z + +scalar),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static sub(a = def_Vec3f64, b = def_Vec3f64) {
|
|
55
|
+
return new Vec3f64(
|
|
56
|
+
+(+a.x - +b.x),
|
|
57
|
+
+(+a.y - +b.y),
|
|
58
|
+
+(+a.z - +b.z),
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static subs(a = def_Vec3f64, scalar = 0.0) {
|
|
63
|
+
return new Vec3f64(
|
|
64
|
+
+(+a.x - +scalar),
|
|
65
|
+
+(+a.y - +scalar),
|
|
66
|
+
+(+a.z - +scalar),
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static div(a = def_Vec3f64, b = def_Vec3f64) {
|
|
71
|
+
return new Vec3f64(
|
|
72
|
+
+(+a.x / +b.x),
|
|
73
|
+
+(+a.y / +b.y),
|
|
74
|
+
+(+a.z / +b.z),
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
static divs(v = def_Vec3f64, scalar = 0.0) {
|
|
78
|
+
return new Vec3f64(
|
|
79
|
+
+(+v.x / +scalar),
|
|
80
|
+
+(+v.y / +scalar),
|
|
81
|
+
+(+v.z / +scalar),
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static mul(a = def_Vec3f64, b = def_Vec3f64) {
|
|
86
|
+
return new Vec3f64(
|
|
87
|
+
+(+a.x * +b.x),
|
|
88
|
+
+(+a.y * +b.y),
|
|
89
|
+
+(+a.z * +b.z),
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
static muls(v = def_Vec3f64, scalar = 0.0) {
|
|
93
|
+
return new Vec3f64(
|
|
94
|
+
+(+v.x * +scalar),
|
|
95
|
+
+(+v.y * +scalar),
|
|
96
|
+
+(+v.z * +scalar),
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Returns the dot product of two 3d vectors
|
|
102
|
+
* @param {Vec3f64} a the base vector
|
|
103
|
+
* @param {Vec3f64} b the target vector
|
|
104
|
+
* @returns {number} the dot product of two vectors
|
|
105
|
+
*/
|
|
106
|
+
static dot(a = def_Vec3f64, b = def_Vec3f64) {
|
|
107
|
+
return +(+(+a.x * +b.x) + +(+a.y * +b.y) + +(+a.z * +b.z));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Returns the cross product of two 3d vectors
|
|
112
|
+
* @param {Vec3f64} a the base vector
|
|
113
|
+
* @param {Vec3f64} b the target vector
|
|
114
|
+
* @returns {Vec3f64} the cross product of two vectors
|
|
115
|
+
*/
|
|
116
|
+
static cross(a = def_Vec3f64, b = def_Vec3f64) {
|
|
117
|
+
return new Vec3f64(
|
|
118
|
+
+(+(+a.y * +b.z) - +(+a.z * +b.y)),
|
|
119
|
+
+(+(+a.z * +b.x) - +(+a.x * +b.z)),
|
|
120
|
+
+(+(+a.x * +b.y) - +(+a.y * +b.x)),
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
static mag2(v = def_Vec3f64) {
|
|
125
|
+
return +Vec3f64.dot(v, v);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
static mag(v = def_Vec3f64) {
|
|
129
|
+
return +mathf64_sqrt(+Vec3f64.mag2(v));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
static unit(v = def_Vec3f64) {
|
|
133
|
+
return Vec3f64.divs(v, +Vec3f64.mag(v));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
//#endregion
|
|
137
|
+
|
|
138
|
+
//#region vec3f in-place operators
|
|
139
|
+
|
|
140
|
+
iadd(v = def_Vec3f64) {
|
|
141
|
+
this.x += +(+v.x);
|
|
142
|
+
this.y += +(+v.y);
|
|
143
|
+
this.z += +(+v.z);
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
iadds(scalar = 0.0) {
|
|
148
|
+
this.x += +scalar;
|
|
149
|
+
this.y += +scalar;
|
|
150
|
+
this.z += +scalar;
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
isub(v = def_Vec3f64) {
|
|
155
|
+
this.x -= +(+v.x);
|
|
156
|
+
this.y -= +(+v.y);
|
|
157
|
+
this.z -= +(+v.z);
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
isubs(scalar = 0.0) {
|
|
162
|
+
this.x -= +scalar;
|
|
163
|
+
this.y -= +scalar;
|
|
164
|
+
this.z -= +scalar;
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
idiv(v = def_Vec3f64) {
|
|
169
|
+
this.x /= +(+v.x);
|
|
170
|
+
this.y /= +(+v.y);
|
|
171
|
+
this.z /= +(+v.z);
|
|
172
|
+
return this;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
idivs(scalar = 0.0) {
|
|
176
|
+
this.x /= +scalar;
|
|
177
|
+
this.y /= +scalar;
|
|
178
|
+
this.z /= +scalar;
|
|
179
|
+
return this;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
imul(v = def_Vec3f64) {
|
|
183
|
+
this.x *= +(+v.x);
|
|
184
|
+
this.y *= +(+v.y);
|
|
185
|
+
this.z *= +(+v.z);
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
imuls(scalar = 0.0) {
|
|
190
|
+
this.x *= +scalar;
|
|
191
|
+
this.y *= +scalar;
|
|
192
|
+
this.z *= +scalar;
|
|
193
|
+
return this;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
dot(v = def_Vec3f64) {
|
|
197
|
+
return Vec3f64.dot(this, v);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
icross(v = def_Vec3f64) {
|
|
201
|
+
const x = +this.x;
|
|
202
|
+
const y = +this.y;
|
|
203
|
+
const z = +this.z;
|
|
204
|
+
this.x = +(+(y * +v.z) - +(z * +v.y));
|
|
205
|
+
this.y = +(+(z * +v.x) - +(x * +v.z));
|
|
206
|
+
this.z = +(+(x * +v.y) - +(y * +v.x));
|
|
207
|
+
return this;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
mag2() {
|
|
211
|
+
return Vec3f64.mag2(this);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
mag() {
|
|
215
|
+
return Vec3f64.mag(this);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
iunit() {
|
|
219
|
+
return this.idivs(+this.mag());
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
//#endregion
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export const def_Vec3f64 = Object.freeze(Object.seal(Vec3f64.new()));
|
package/src/number.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
//@ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks if the given data is of boolean type or boolean-like (the strings 'true' or 'false').
|
|
5
|
+
* @param {any} data - The data to check.
|
|
6
|
+
* @returns {boolean} - True if the data is boolean or boolean-like, otherwise false.
|
|
7
|
+
*/
|
|
8
|
+
export function isBoolishType(data) {
|
|
9
|
+
return data === true
|
|
10
|
+
|| data === false
|
|
11
|
+
|| data === 'true'
|
|
12
|
+
|| data === 'false';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Checks if the given object is a boolean type or a boolean-like string ('true' or 'false') and returns it, otherwise returns the default value.
|
|
17
|
+
* @param {any} obj - The object to check.
|
|
18
|
+
* @param {boolean|undefined} [def=undefined] - The default value to return if the object is not a boolean or boolean-like string.
|
|
19
|
+
* @returns {boolean|undefined} - The boolean/boolean-like value or the default value.
|
|
20
|
+
*/
|
|
21
|
+
export function getBoolishType(obj, def = undefined) {
|
|
22
|
+
return isBoolishType(obj) || obj === 'true' || obj === 'false'
|
|
23
|
+
? obj
|
|
24
|
+
: def;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Checks if the given data is number-like (can be converted to a number).
|
|
29
|
+
* @param {any} data - The data to check.
|
|
30
|
+
* @returns {boolean} - True if the data is number-like, otherwise false.
|
|
31
|
+
*/
|
|
32
|
+
export function isNumbishType(data) {
|
|
33
|
+
return typeof data !== 'bigint' && !Number.isNaN(Number(data));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Checks if the given data is an integer-like type.
|
|
38
|
+
* @param {any} data - The data to check.
|
|
39
|
+
* @returns {boolean} - True if the data is an integer-like type, otherwise false.
|
|
40
|
+
*/
|
|
41
|
+
export function isIntishType(data) {
|
|
42
|
+
return Number.isInteger(Number(data));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Checks if the given object is a number-like type and returns it as a number, otherwise returns the default value.
|
|
47
|
+
* @param {any} obj - The object to check.
|
|
48
|
+
* @param {number|undefined} [def=undefined] - The default value to return if the object is not a number-like type.
|
|
49
|
+
* @returns {number|undefined} - The number value or the default value.
|
|
50
|
+
*/
|
|
51
|
+
export function getNumbishType(obj, def = undefined) {
|
|
52
|
+
return isNumbishType(obj) ? Number(obj) : def;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Checks if the given object is an integer-like type and returns it as a number, otherwise returns the default value.
|
|
57
|
+
* @param {any} obj - The object to check.
|
|
58
|
+
* @param {number|undefined} [def=undefined] - The default value to return if the object is not an integer-like type.
|
|
59
|
+
* @returns {number|undefined} - The integer value or the default value.
|
|
60
|
+
*/
|
|
61
|
+
export function getIntishType(obj, def = undefined) {
|
|
62
|
+
return isIntishType(obj) ? Number(obj) : def;
|
|
63
|
+
}
|