@fi4f/hg 0.0.0 → 0.0.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/.github/workflows/publish.yml +25 -23
- package/package.json +27 -29
- package/src/asset.ts +248 -248
- package/src/event.ts +173 -173
- package/src/hg.ts +20 -20
- package/src/math.ts +4 -4
- package/src/matrix2.ts +214 -214
- package/src/matrix3.ts +301 -301
- package/src/matrix4.ts +414 -414
- package/src/scene.ts +44 -44
- package/src/stage.ts +481 -481
- package/src/vector2.ts +79 -79
- package/src/vector3.ts +87 -87
- package/src/vector4.ts +95 -95
- package/src/version.ts +25 -25
- package/tsconfig.json +44 -44
package/src/vector2.ts
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
import { ADD, SUB, MUL, DIV, MOD } from "./math.js";
|
|
2
|
-
|
|
3
|
-
export type Vector2 = [number, number]
|
|
4
|
-
|
|
5
|
-
export const X = 0 as const;
|
|
6
|
-
export const Y = 1 as const;
|
|
7
|
-
|
|
8
|
-
export const __get__ = {
|
|
9
|
-
x(a: Vector2) { return a[X] },
|
|
10
|
-
y(a: Vector2) { return a[Y] },
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const __set__ = {
|
|
14
|
-
x(a: Vector2, x: number) { return a[X] = x },
|
|
15
|
-
y(a: Vector2, y: number) { return a[Y] = y },
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function x(a: Vector2, x ?: number) {
|
|
19
|
-
return x === undefined ? __get__.x(a) : __set__.x(a, x)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function y(a: Vector2, y ?: number) {
|
|
23
|
-
return y === undefined ? __get__.y(a) : __set__.y(a, y)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const Vector2 = {
|
|
27
|
-
X, Y,
|
|
28
|
-
__get__,
|
|
29
|
-
__set__,
|
|
30
|
-
x, y,
|
|
31
|
-
|
|
32
|
-
new(...a: Array<number>) {
|
|
33
|
-
if (a.length === 1) return [ a[X]! , a[X]! ] satisfies Vector2
|
|
34
|
-
else return [ a[X] ?? 0, a[Y] ?? 0 ] satisfies Vector2
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
from(a: number | Array<number>) {
|
|
38
|
-
if (typeof a === "number") return [ a , a ] satisfies Vector2
|
|
39
|
-
else return [ a[X] ?? 0, a[Y] ?? 0 ] satisfies Vector2
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
el(op: (a: number, b: number) => number, a: number | Vector2, b: number | Vector2, out: Vector2 = Vector2.new()) {
|
|
43
|
-
const [ xa, ya ] = Vector2.from(a)
|
|
44
|
-
const [ xb, yb ] = Vector2.from(b)
|
|
45
|
-
__set__.x(out, op(xa, xb))
|
|
46
|
-
__set__.y(out, op(ya, yb))
|
|
47
|
-
return out
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
add(a: number | Vector2, b: number | Vector2, out: Vector2 = Vector2.new()) {
|
|
51
|
-
return Vector2.el(ADD, a, b, out)
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
sub(a: number | Vector2, b: number | Vector2, out: Vector2 = Vector2.new()) {
|
|
55
|
-
return Vector2.el(SUB, a, b, out)
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
hmul(a: number | Vector2, b: number | Vector2, out: Vector2 = Vector2.new()) {
|
|
59
|
-
return Vector2.el(MUL, a, b, out)
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
hdiv(a: number | Vector2, b: number | Vector2, out: Vector2 = Vector2.new()) {
|
|
63
|
-
return Vector2.el(DIV, a, b, out)
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
hmod(a: number | Vector2, b: number | Vector2, out: Vector2 = Vector2.new()) {
|
|
67
|
-
return Vector2.el(MOD, a, b, out)
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
dot(a: number | Vector2, b: number | Vector2 = a) {
|
|
71
|
-
const [xa, ya] = Vector2.from(a)
|
|
72
|
-
const [xb, yb] = Vector2.from(b)
|
|
73
|
-
return xa * xb + ya * yb
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
toString(a: number | Vector2) {
|
|
77
|
-
const [x, y] = Vector2.from(a)
|
|
78
|
-
return `vec2<${x}, ${y}>`
|
|
79
|
-
}
|
|
1
|
+
import { ADD, SUB, MUL, DIV, MOD } from "./math.js";
|
|
2
|
+
|
|
3
|
+
export type Vector2 = [number, number]
|
|
4
|
+
|
|
5
|
+
export const X = 0 as const;
|
|
6
|
+
export const Y = 1 as const;
|
|
7
|
+
|
|
8
|
+
export const __get__ = {
|
|
9
|
+
x(a: Vector2) { return a[X] },
|
|
10
|
+
y(a: Vector2) { return a[Y] },
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const __set__ = {
|
|
14
|
+
x(a: Vector2, x: number) { return a[X] = x },
|
|
15
|
+
y(a: Vector2, y: number) { return a[Y] = y },
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function x(a: Vector2, x ?: number) {
|
|
19
|
+
return x === undefined ? __get__.x(a) : __set__.x(a, x)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function y(a: Vector2, y ?: number) {
|
|
23
|
+
return y === undefined ? __get__.y(a) : __set__.y(a, y)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const Vector2 = {
|
|
27
|
+
X, Y,
|
|
28
|
+
__get__,
|
|
29
|
+
__set__,
|
|
30
|
+
x, y,
|
|
31
|
+
|
|
32
|
+
new(...a: Array<number>) {
|
|
33
|
+
if (a.length === 1) return [ a[X]! , a[X]! ] satisfies Vector2
|
|
34
|
+
else return [ a[X] ?? 0, a[Y] ?? 0 ] satisfies Vector2
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
from(a: number | Array<number>) {
|
|
38
|
+
if (typeof a === "number") return [ a , a ] satisfies Vector2
|
|
39
|
+
else return [ a[X] ?? 0, a[Y] ?? 0 ] satisfies Vector2
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
el(op: (a: number, b: number) => number, a: number | Vector2, b: number | Vector2, out: Vector2 = Vector2.new()) {
|
|
43
|
+
const [ xa, ya ] = Vector2.from(a)
|
|
44
|
+
const [ xb, yb ] = Vector2.from(b)
|
|
45
|
+
__set__.x(out, op(xa, xb))
|
|
46
|
+
__set__.y(out, op(ya, yb))
|
|
47
|
+
return out
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
add(a: number | Vector2, b: number | Vector2, out: Vector2 = Vector2.new()) {
|
|
51
|
+
return Vector2.el(ADD, a, b, out)
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
sub(a: number | Vector2, b: number | Vector2, out: Vector2 = Vector2.new()) {
|
|
55
|
+
return Vector2.el(SUB, a, b, out)
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
hmul(a: number | Vector2, b: number | Vector2, out: Vector2 = Vector2.new()) {
|
|
59
|
+
return Vector2.el(MUL, a, b, out)
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
hdiv(a: number | Vector2, b: number | Vector2, out: Vector2 = Vector2.new()) {
|
|
63
|
+
return Vector2.el(DIV, a, b, out)
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
hmod(a: number | Vector2, b: number | Vector2, out: Vector2 = Vector2.new()) {
|
|
67
|
+
return Vector2.el(MOD, a, b, out)
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
dot(a: number | Vector2, b: number | Vector2 = a) {
|
|
71
|
+
const [xa, ya] = Vector2.from(a)
|
|
72
|
+
const [xb, yb] = Vector2.from(b)
|
|
73
|
+
return xa * xb + ya * yb
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
toString(a: number | Vector2) {
|
|
77
|
+
const [x, y] = Vector2.from(a)
|
|
78
|
+
return `vec2<${x}, ${y}>`
|
|
79
|
+
}
|
|
80
80
|
}
|
package/src/vector3.ts
CHANGED
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
import { ADD, SUB, MUL, DIV, MOD } from "./math.js";
|
|
2
|
-
|
|
3
|
-
export type Vector3 = [number, number, number]
|
|
4
|
-
|
|
5
|
-
export const X = 0 as const;
|
|
6
|
-
export const Y = 1 as const;
|
|
7
|
-
export const Z = 2 as const;
|
|
8
|
-
|
|
9
|
-
export const __get__ = {
|
|
10
|
-
x(a: Vector3) { return a[X] },
|
|
11
|
-
y(a: Vector3) { return a[Y] },
|
|
12
|
-
z(a: Vector3) { return a[Z] },
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const __set__ = {
|
|
16
|
-
x(a: Vector3, x: number) { return a[X] = x },
|
|
17
|
-
y(a: Vector3, y: number) { return a[Y] = y },
|
|
18
|
-
z(a: Vector3, z: number) { return a[Z] = z },
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function x(a: Vector3, x ?: number) {
|
|
22
|
-
return x === undefined ? __get__.x(a) : __set__.x(a, x)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function y(a: Vector3, y ?: number) {
|
|
26
|
-
return y === undefined ? __get__.y(a) : __set__.y(a, y)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function z(a: Vector3, z ?: number) {
|
|
30
|
-
return z === undefined ? __get__.z(a) : __set__.z(a, z)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const Vector3 = {
|
|
34
|
-
X, Y, Z,
|
|
35
|
-
__get__,
|
|
36
|
-
__set__,
|
|
37
|
-
x, y, z,
|
|
38
|
-
|
|
39
|
-
new(...a: Array<number>) {
|
|
40
|
-
if (a.length === 1) return [ a[X]! , a[X]! , a[X]! ] satisfies Vector3
|
|
41
|
-
else return [ a[X] ?? 0, a[Y] ?? 0, a[Z] ?? 0 ] satisfies Vector3
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
from(a: number | Array<number>) {
|
|
45
|
-
if (typeof a === "number") return [ a , a , a ] satisfies Vector3
|
|
46
|
-
else return [ a[X] ?? 0, a[Y] ?? 0, a[Z] ?? 0 ] satisfies Vector3
|
|
47
|
-
},
|
|
48
|
-
|
|
49
|
-
el(op: (a: number, b: number) => number, a: number | Vector3, b: number | Vector3, out: Vector3 = Vector3.new()) {
|
|
50
|
-
const [ xa, ya, za ] = Vector3.from(a)
|
|
51
|
-
const [ xb, yb, zb ] = Vector3.from(b)
|
|
52
|
-
__set__.x(out, op(xa, xb))
|
|
53
|
-
__set__.y(out, op(ya, yb))
|
|
54
|
-
__set__.z(out, op(za, zb))
|
|
55
|
-
return out
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
add(a: number | Vector3, b: number | Vector3, out: Vector3 = Vector3.new()) {
|
|
59
|
-
return Vector3.el(ADD, a, b, out)
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
sub(a: number | Vector3, b: number | Vector3, out: Vector3 = Vector3.new()) {
|
|
63
|
-
return Vector3.el(SUB, a, b, out)
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
hmul(a: number | Vector3, b: number | Vector3, out: Vector3 = Vector3.new()) {
|
|
67
|
-
return Vector3.el(MUL, a, b, out)
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
hdiv(a: number | Vector3, b: number | Vector3, out: Vector3 = Vector3.new()) {
|
|
71
|
-
return Vector3.el(DIV, a, b, out)
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
hmod(a: number | Vector3, b: number | Vector3, out: Vector3 = Vector3.new()) {
|
|
75
|
-
return Vector3.el(MOD, a, b, out)
|
|
76
|
-
},
|
|
77
|
-
|
|
78
|
-
dot(a: number | Vector3, b: number | Vector3 = a) {
|
|
79
|
-
const [xa, ya, za] = Vector3.from(a)
|
|
80
|
-
const [xb, yb, zb] = Vector3.from(b)
|
|
81
|
-
return xa * xb + ya * yb + za * zb
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
toString(a: number | Vector3) {
|
|
85
|
-
const [x, y, z] = Vector3.from(a)
|
|
86
|
-
return `vec3<${x}, ${y}, ${z}>`
|
|
87
|
-
}
|
|
1
|
+
import { ADD, SUB, MUL, DIV, MOD } from "./math.js";
|
|
2
|
+
|
|
3
|
+
export type Vector3 = [number, number, number]
|
|
4
|
+
|
|
5
|
+
export const X = 0 as const;
|
|
6
|
+
export const Y = 1 as const;
|
|
7
|
+
export const Z = 2 as const;
|
|
8
|
+
|
|
9
|
+
export const __get__ = {
|
|
10
|
+
x(a: Vector3) { return a[X] },
|
|
11
|
+
y(a: Vector3) { return a[Y] },
|
|
12
|
+
z(a: Vector3) { return a[Z] },
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const __set__ = {
|
|
16
|
+
x(a: Vector3, x: number) { return a[X] = x },
|
|
17
|
+
y(a: Vector3, y: number) { return a[Y] = y },
|
|
18
|
+
z(a: Vector3, z: number) { return a[Z] = z },
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function x(a: Vector3, x ?: number) {
|
|
22
|
+
return x === undefined ? __get__.x(a) : __set__.x(a, x)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function y(a: Vector3, y ?: number) {
|
|
26
|
+
return y === undefined ? __get__.y(a) : __set__.y(a, y)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function z(a: Vector3, z ?: number) {
|
|
30
|
+
return z === undefined ? __get__.z(a) : __set__.z(a, z)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const Vector3 = {
|
|
34
|
+
X, Y, Z,
|
|
35
|
+
__get__,
|
|
36
|
+
__set__,
|
|
37
|
+
x, y, z,
|
|
38
|
+
|
|
39
|
+
new(...a: Array<number>) {
|
|
40
|
+
if (a.length === 1) return [ a[X]! , a[X]! , a[X]! ] satisfies Vector3
|
|
41
|
+
else return [ a[X] ?? 0, a[Y] ?? 0, a[Z] ?? 0 ] satisfies Vector3
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
from(a: number | Array<number>) {
|
|
45
|
+
if (typeof a === "number") return [ a , a , a ] satisfies Vector3
|
|
46
|
+
else return [ a[X] ?? 0, a[Y] ?? 0, a[Z] ?? 0 ] satisfies Vector3
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
el(op: (a: number, b: number) => number, a: number | Vector3, b: number | Vector3, out: Vector3 = Vector3.new()) {
|
|
50
|
+
const [ xa, ya, za ] = Vector3.from(a)
|
|
51
|
+
const [ xb, yb, zb ] = Vector3.from(b)
|
|
52
|
+
__set__.x(out, op(xa, xb))
|
|
53
|
+
__set__.y(out, op(ya, yb))
|
|
54
|
+
__set__.z(out, op(za, zb))
|
|
55
|
+
return out
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
add(a: number | Vector3, b: number | Vector3, out: Vector3 = Vector3.new()) {
|
|
59
|
+
return Vector3.el(ADD, a, b, out)
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
sub(a: number | Vector3, b: number | Vector3, out: Vector3 = Vector3.new()) {
|
|
63
|
+
return Vector3.el(SUB, a, b, out)
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
hmul(a: number | Vector3, b: number | Vector3, out: Vector3 = Vector3.new()) {
|
|
67
|
+
return Vector3.el(MUL, a, b, out)
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
hdiv(a: number | Vector3, b: number | Vector3, out: Vector3 = Vector3.new()) {
|
|
71
|
+
return Vector3.el(DIV, a, b, out)
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
hmod(a: number | Vector3, b: number | Vector3, out: Vector3 = Vector3.new()) {
|
|
75
|
+
return Vector3.el(MOD, a, b, out)
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
dot(a: number | Vector3, b: number | Vector3 = a) {
|
|
79
|
+
const [xa, ya, za] = Vector3.from(a)
|
|
80
|
+
const [xb, yb, zb] = Vector3.from(b)
|
|
81
|
+
return xa * xb + ya * yb + za * zb
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
toString(a: number | Vector3) {
|
|
85
|
+
const [x, y, z] = Vector3.from(a)
|
|
86
|
+
return `vec3<${x}, ${y}, ${z}>`
|
|
87
|
+
}
|
|
88
88
|
}
|
package/src/vector4.ts
CHANGED
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
import { ADD, SUB, MUL, DIV, MOD } from "./math.js";
|
|
2
|
-
|
|
3
|
-
export type Vector4 = [number, number, number, number]
|
|
4
|
-
|
|
5
|
-
export const X = 0 as const;
|
|
6
|
-
export const Y = 1 as const;
|
|
7
|
-
export const Z = 2 as const;
|
|
8
|
-
export const W = 3 as const;
|
|
9
|
-
|
|
10
|
-
export const __get__ = {
|
|
11
|
-
x(a: Vector4) { return a[X] },
|
|
12
|
-
y(a: Vector4) { return a[Y] },
|
|
13
|
-
z(a: Vector4) { return a[Z] },
|
|
14
|
-
w(a: Vector4) { return a[W] },
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const __set__ = {
|
|
18
|
-
x(a: Vector4, x: number) { return a[X] = x },
|
|
19
|
-
y(a: Vector4, y: number) { return a[Y] = y },
|
|
20
|
-
z(a: Vector4, z: number) { return a[Z] = z },
|
|
21
|
-
w(a: Vector4, w: number) { return a[W] = w },
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function x(a: Vector4, x ?: number) {
|
|
25
|
-
return x === undefined ? __get__.x(a) : __set__.x(a, x)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function y(a: Vector4, y ?: number) {
|
|
29
|
-
return y === undefined ? __get__.y(a) : __set__.y(a, y)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function z(a: Vector4, z ?: number) {
|
|
33
|
-
return z === undefined ? __get__.z(a) : __set__.z(a, z)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function w(a: Vector4, w ?: number) {
|
|
37
|
-
return w === undefined ? __get__.w(a) : __set__.w(a, w)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const Vector4 = {
|
|
41
|
-
X, Y, Z, W,
|
|
42
|
-
__get__,
|
|
43
|
-
__set__,
|
|
44
|
-
x, y, z, w,
|
|
45
|
-
|
|
46
|
-
new(...a: Array<number>) {
|
|
47
|
-
if (a.length === 1) return [ a[X]! , a[X]! , a[X]! , a[X]! ] satisfies Vector4
|
|
48
|
-
else return [ a[X] ?? 0, a[Y] ?? 0, a[Z] ?? 0, a[W] ?? 0 ] satisfies Vector4
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
from(a: number | Array<number>) {
|
|
52
|
-
if (typeof a === "number") return [ a , a , a , a ] satisfies Vector4
|
|
53
|
-
else return [ a[X] ?? 0, a[Y] ?? 0, a[Z] ?? 0, a[W] ?? 0 ] satisfies Vector4
|
|
54
|
-
},
|
|
55
|
-
|
|
56
|
-
el(op: (a: number, b: number) => number, a: number | Vector4, b: number | Vector4, out: Vector4 = Vector4.new()) {
|
|
57
|
-
const [ xa, ya, za, wa ] = Vector4.from(a)
|
|
58
|
-
const [ xb, yb, zb, wb ] = Vector4.from(b)
|
|
59
|
-
__set__.x(out, op(xa, xb))
|
|
60
|
-
__set__.y(out, op(ya, yb))
|
|
61
|
-
__set__.z(out, op(za, zb))
|
|
62
|
-
__set__.w(out, op(wa, wb))
|
|
63
|
-
return out
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
add(a: number | Vector4, b: number | Vector4, out: Vector4 = Vector4.new()) {
|
|
67
|
-
return Vector4.el(ADD, a, b, out)
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
sub(a: number | Vector4, b: number | Vector4, out: Vector4 = Vector4.new()) {
|
|
71
|
-
return Vector4.el(SUB, a, b, out)
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
hmul(a: number | Vector4, b: number | Vector4, out: Vector4 = Vector4.new()) {
|
|
75
|
-
return Vector4.el(MUL, a, b, out)
|
|
76
|
-
},
|
|
77
|
-
|
|
78
|
-
hdiv(a: number | Vector4, b: number | Vector4, out: Vector4 = Vector4.new()) {
|
|
79
|
-
return Vector4.el(DIV, a, b, out)
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
hmod(a: number | Vector4, b: number | Vector4, out: Vector4 = Vector4.new()) {
|
|
83
|
-
return Vector4.el(MOD, a, b, out)
|
|
84
|
-
},
|
|
85
|
-
|
|
86
|
-
dot(a: number | Vector4, b: number | Vector4 = a) {
|
|
87
|
-
const [xa, ya, za, wa] = Vector4.from(a)
|
|
88
|
-
const [xb, yb, zb, wb] = Vector4.from(b)
|
|
89
|
-
return xa * xb + ya * yb + za * zb + wa * wb
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
toString(a: number | Vector4) {
|
|
93
|
-
const [x, y, z, w] = Vector4.from(a)
|
|
94
|
-
return `vec4<${x}, ${y}, ${z}, ${w}>`
|
|
95
|
-
}
|
|
1
|
+
import { ADD, SUB, MUL, DIV, MOD } from "./math.js";
|
|
2
|
+
|
|
3
|
+
export type Vector4 = [number, number, number, number]
|
|
4
|
+
|
|
5
|
+
export const X = 0 as const;
|
|
6
|
+
export const Y = 1 as const;
|
|
7
|
+
export const Z = 2 as const;
|
|
8
|
+
export const W = 3 as const;
|
|
9
|
+
|
|
10
|
+
export const __get__ = {
|
|
11
|
+
x(a: Vector4) { return a[X] },
|
|
12
|
+
y(a: Vector4) { return a[Y] },
|
|
13
|
+
z(a: Vector4) { return a[Z] },
|
|
14
|
+
w(a: Vector4) { return a[W] },
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const __set__ = {
|
|
18
|
+
x(a: Vector4, x: number) { return a[X] = x },
|
|
19
|
+
y(a: Vector4, y: number) { return a[Y] = y },
|
|
20
|
+
z(a: Vector4, z: number) { return a[Z] = z },
|
|
21
|
+
w(a: Vector4, w: number) { return a[W] = w },
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function x(a: Vector4, x ?: number) {
|
|
25
|
+
return x === undefined ? __get__.x(a) : __set__.x(a, x)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function y(a: Vector4, y ?: number) {
|
|
29
|
+
return y === undefined ? __get__.y(a) : __set__.y(a, y)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function z(a: Vector4, z ?: number) {
|
|
33
|
+
return z === undefined ? __get__.z(a) : __set__.z(a, z)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function w(a: Vector4, w ?: number) {
|
|
37
|
+
return w === undefined ? __get__.w(a) : __set__.w(a, w)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const Vector4 = {
|
|
41
|
+
X, Y, Z, W,
|
|
42
|
+
__get__,
|
|
43
|
+
__set__,
|
|
44
|
+
x, y, z, w,
|
|
45
|
+
|
|
46
|
+
new(...a: Array<number>) {
|
|
47
|
+
if (a.length === 1) return [ a[X]! , a[X]! , a[X]! , a[X]! ] satisfies Vector4
|
|
48
|
+
else return [ a[X] ?? 0, a[Y] ?? 0, a[Z] ?? 0, a[W] ?? 0 ] satisfies Vector4
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
from(a: number | Array<number>) {
|
|
52
|
+
if (typeof a === "number") return [ a , a , a , a ] satisfies Vector4
|
|
53
|
+
else return [ a[X] ?? 0, a[Y] ?? 0, a[Z] ?? 0, a[W] ?? 0 ] satisfies Vector4
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
el(op: (a: number, b: number) => number, a: number | Vector4, b: number | Vector4, out: Vector4 = Vector4.new()) {
|
|
57
|
+
const [ xa, ya, za, wa ] = Vector4.from(a)
|
|
58
|
+
const [ xb, yb, zb, wb ] = Vector4.from(b)
|
|
59
|
+
__set__.x(out, op(xa, xb))
|
|
60
|
+
__set__.y(out, op(ya, yb))
|
|
61
|
+
__set__.z(out, op(za, zb))
|
|
62
|
+
__set__.w(out, op(wa, wb))
|
|
63
|
+
return out
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
add(a: number | Vector4, b: number | Vector4, out: Vector4 = Vector4.new()) {
|
|
67
|
+
return Vector4.el(ADD, a, b, out)
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
sub(a: number | Vector4, b: number | Vector4, out: Vector4 = Vector4.new()) {
|
|
71
|
+
return Vector4.el(SUB, a, b, out)
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
hmul(a: number | Vector4, b: number | Vector4, out: Vector4 = Vector4.new()) {
|
|
75
|
+
return Vector4.el(MUL, a, b, out)
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
hdiv(a: number | Vector4, b: number | Vector4, out: Vector4 = Vector4.new()) {
|
|
79
|
+
return Vector4.el(DIV, a, b, out)
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
hmod(a: number | Vector4, b: number | Vector4, out: Vector4 = Vector4.new()) {
|
|
83
|
+
return Vector4.el(MOD, a, b, out)
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
dot(a: number | Vector4, b: number | Vector4 = a) {
|
|
87
|
+
const [xa, ya, za, wa] = Vector4.from(a)
|
|
88
|
+
const [xb, yb, zb, wb] = Vector4.from(b)
|
|
89
|
+
return xa * xb + ya * yb + za * zb + wa * wb
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
toString(a: number | Vector4) {
|
|
93
|
+
const [x, y, z, w] = Vector4.from(a)
|
|
94
|
+
return `vec4<${x}, ${y}, ${z}, ${w}>`
|
|
95
|
+
}
|
|
96
96
|
}
|
package/src/version.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
export type Version = {
|
|
2
|
-
readonly moniker: string;
|
|
3
|
-
readonly major : number;
|
|
4
|
-
readonly minor : number;
|
|
5
|
-
readonly patch : number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const Version = {
|
|
9
|
-
new(o ?: {
|
|
10
|
-
moniker ?: string,
|
|
11
|
-
major ?: number,
|
|
12
|
-
minor ?: number,
|
|
13
|
-
patch ?: number,
|
|
14
|
-
}) {
|
|
15
|
-
return {
|
|
16
|
-
moniker: o?.moniker ?? "hg",
|
|
17
|
-
major : o?.major ?? 0,
|
|
18
|
-
minor : o?.minor ?? 0,
|
|
19
|
-
patch : o?.patch ?? 0,
|
|
20
|
-
} satisfies Version;
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
toString(a: Version) {
|
|
24
|
-
return `${a.moniker} ${a.major}.${a.minor}.${a.patch}`;
|
|
25
|
-
}
|
|
1
|
+
export type Version = {
|
|
2
|
+
readonly moniker: string;
|
|
3
|
+
readonly major : number;
|
|
4
|
+
readonly minor : number;
|
|
5
|
+
readonly patch : number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const Version = {
|
|
9
|
+
new(o ?: {
|
|
10
|
+
moniker ?: string,
|
|
11
|
+
major ?: number,
|
|
12
|
+
minor ?: number,
|
|
13
|
+
patch ?: number,
|
|
14
|
+
}) {
|
|
15
|
+
return {
|
|
16
|
+
moniker: o?.moniker ?? "hg",
|
|
17
|
+
major : o?.major ?? 0,
|
|
18
|
+
minor : o?.minor ?? 0,
|
|
19
|
+
patch : o?.patch ?? 0,
|
|
20
|
+
} satisfies Version;
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
toString(a: Version) {
|
|
24
|
+
return `${a.moniker} ${a.major}.${a.minor}.${a.patch}`;
|
|
25
|
+
}
|
|
26
26
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Visit https://aka.ms/tsconfig to read more about this file
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
// File Layout
|
|
5
|
-
"rootDir": "./src",
|
|
6
|
-
"outDir": "./dist",
|
|
7
|
-
|
|
8
|
-
// Environment Settings
|
|
9
|
-
// See also https://aka.ms/tsconfig/module
|
|
10
|
-
"module": "nodenext",
|
|
11
|
-
"target": "esnext",
|
|
12
|
-
"types": [],
|
|
13
|
-
// For nodejs:
|
|
14
|
-
// "lib": ["esnext"],
|
|
15
|
-
// "types": ["node"],
|
|
16
|
-
// and npm install -D @types/node
|
|
17
|
-
|
|
18
|
-
// Other Outputs
|
|
19
|
-
"sourceMap": true,
|
|
20
|
-
"declaration": true,
|
|
21
|
-
"declarationMap": true,
|
|
22
|
-
|
|
23
|
-
// Stricter Typechecking Options
|
|
24
|
-
"noUncheckedIndexedAccess": true,
|
|
25
|
-
"exactOptionalPropertyTypes": true,
|
|
26
|
-
|
|
27
|
-
// Style Options
|
|
28
|
-
// "noImplicitReturns": true,
|
|
29
|
-
// "noImplicitOverride": true,
|
|
30
|
-
// "noUnusedLocals": true,
|
|
31
|
-
// "noUnusedParameters": true,
|
|
32
|
-
// "noFallthroughCasesInSwitch": true,
|
|
33
|
-
// "noPropertyAccessFromIndexSignature": true,
|
|
34
|
-
|
|
35
|
-
// Recommended Options
|
|
36
|
-
"strict": true,
|
|
37
|
-
"jsx": "react-jsx",
|
|
38
|
-
"verbatimModuleSyntax": true,
|
|
39
|
-
"isolatedModules": true,
|
|
40
|
-
"noUncheckedSideEffectImports": true,
|
|
41
|
-
"moduleDetection": "force",
|
|
42
|
-
"skipLibCheck": true,
|
|
43
|
-
}
|
|
44
|
-
}
|
|
1
|
+
{
|
|
2
|
+
// Visit https://aka.ms/tsconfig to read more about this file
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
// File Layout
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
|
|
8
|
+
// Environment Settings
|
|
9
|
+
// See also https://aka.ms/tsconfig/module
|
|
10
|
+
"module": "nodenext",
|
|
11
|
+
"target": "esnext",
|
|
12
|
+
"types": [],
|
|
13
|
+
// For nodejs:
|
|
14
|
+
// "lib": ["esnext"],
|
|
15
|
+
// "types": ["node"],
|
|
16
|
+
// and npm install -D @types/node
|
|
17
|
+
|
|
18
|
+
// Other Outputs
|
|
19
|
+
"sourceMap": true,
|
|
20
|
+
"declaration": true,
|
|
21
|
+
"declarationMap": true,
|
|
22
|
+
|
|
23
|
+
// Stricter Typechecking Options
|
|
24
|
+
"noUncheckedIndexedAccess": true,
|
|
25
|
+
"exactOptionalPropertyTypes": true,
|
|
26
|
+
|
|
27
|
+
// Style Options
|
|
28
|
+
// "noImplicitReturns": true,
|
|
29
|
+
// "noImplicitOverride": true,
|
|
30
|
+
// "noUnusedLocals": true,
|
|
31
|
+
// "noUnusedParameters": true,
|
|
32
|
+
// "noFallthroughCasesInSwitch": true,
|
|
33
|
+
// "noPropertyAccessFromIndexSignature": true,
|
|
34
|
+
|
|
35
|
+
// Recommended Options
|
|
36
|
+
"strict": true,
|
|
37
|
+
"jsx": "react-jsx",
|
|
38
|
+
"verbatimModuleSyntax": true,
|
|
39
|
+
"isolatedModules": true,
|
|
40
|
+
"noUncheckedSideEffectImports": true,
|
|
41
|
+
"moduleDetection": "force",
|
|
42
|
+
"skipLibCheck": true,
|
|
43
|
+
}
|
|
44
|
+
}
|