@fi4f/hg 0.0.1 → 0.0.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/package.json +4 -6
- package/.gitattributes +0 -2
- package/.github/workflows/publish.yml +0 -25
- package/src/asset.ts +0 -249
- package/src/event.ts +0 -174
- package/src/hg.ts +0 -21
- package/src/math.ts +0 -5
- package/src/matrix2.ts +0 -215
- package/src/matrix3.ts +0 -302
- package/src/matrix4.ts +0 -415
- package/src/scene.ts +0 -45
- package/src/stage.ts +0 -481
- package/src/types.ts +0 -1
- package/src/vector2.ts +0 -80
- package/src/vector3.ts +0 -88
- package/src/vector4.ts +0 -96
- package/src/version.ts +0 -26
- package/tsconfig.json +0 -44
package/src/matrix2.ts
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import { Vector2 } from "./vector2.js";
|
|
2
|
-
import { ADD, SUB, MUL, DIV, MOD } from "./math.js";
|
|
3
|
-
|
|
4
|
-
export type Matrix2 = [
|
|
5
|
-
number, number,
|
|
6
|
-
number, number,
|
|
7
|
-
]
|
|
8
|
-
|
|
9
|
-
export const XX = 0 as const;
|
|
10
|
-
export const XY = 1 as const;
|
|
11
|
-
export const YX = 2 as const;
|
|
12
|
-
export const YY = 3 as const;
|
|
13
|
-
|
|
14
|
-
export const __get__ = {
|
|
15
|
-
xx(a: Matrix2) { return a[XX] },
|
|
16
|
-
xy(a: Matrix2) { return a[XY] },
|
|
17
|
-
yx(a: Matrix2) { return a[YX] },
|
|
18
|
-
yy(a: Matrix2) { return a[YY] },
|
|
19
|
-
|
|
20
|
-
r0(a: Matrix2) { return [ a[XX], a[XY] ] satisfies Vector2 },
|
|
21
|
-
r1(a: Matrix2) { return [ a[YX], a[YY] ] satisfies Vector2 },
|
|
22
|
-
|
|
23
|
-
c0(a: Matrix2) { return [ a[XX], a[YX] ] satisfies Vector2 },
|
|
24
|
-
c1(a: Matrix2) { return [ a[XY], a[YY] ] satisfies Vector2 },
|
|
25
|
-
|
|
26
|
-
row(a: Matrix2, i: 0 | 1) { switch (i) {
|
|
27
|
-
case 0: return __get__.r0(a)
|
|
28
|
-
case 1: return __get__.r1(a)
|
|
29
|
-
}},
|
|
30
|
-
|
|
31
|
-
col(a: Matrix2, j: 0 | 1) { switch (j) {
|
|
32
|
-
case 0: return __get__.c0(a)
|
|
33
|
-
case 1: return __get__.c1(a)
|
|
34
|
-
}},
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export const __set__ = {
|
|
38
|
-
xx(a: Matrix2, xx: number) { return a[XX] = xx },
|
|
39
|
-
xy(a: Matrix2, xy: number) { return a[XY] = xy },
|
|
40
|
-
yx(a: Matrix2, yx: number) { return a[YX] = yx },
|
|
41
|
-
yy(a: Matrix2, yy: number) { return a[YY] = yy },
|
|
42
|
-
|
|
43
|
-
r0(a: Matrix2, r0: number | Vector2) {
|
|
44
|
-
const [x, y] = Vector2.from(r0)
|
|
45
|
-
__set__.xx(a, x)
|
|
46
|
-
__set__.xy(a, y)
|
|
47
|
-
return [x, y] satisfies Vector2
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
r1(a: Matrix2, r1: number | Vector2) {
|
|
51
|
-
const [x, y] = Vector2.from(r1)
|
|
52
|
-
__set__.yx(a, x)
|
|
53
|
-
__set__.yy(a, y)
|
|
54
|
-
return [x, y] satisfies Vector2
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
c0(a: Matrix2, c0: number | Vector2) {
|
|
58
|
-
const [x, y] = Vector2.from(c0)
|
|
59
|
-
__set__.xx(a, x)
|
|
60
|
-
__set__.yx(a, y)
|
|
61
|
-
return [x, y] satisfies Vector2
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
c1(a: Matrix2, c1: number | Vector2) {
|
|
65
|
-
const [x, y] = Vector2.from(c1)
|
|
66
|
-
__set__.xy(a, x)
|
|
67
|
-
__set__.yy(a, y)
|
|
68
|
-
return [x, y] satisfies Vector2
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
row(a: Matrix2, i: 0 | 1, ri: number | Vector2) {
|
|
72
|
-
switch (i) {
|
|
73
|
-
case 0: return __set__.r0(a, ri)
|
|
74
|
-
case 1: return __set__.r1(a, ri)
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
|
|
78
|
-
col(a: Matrix2, j: 0 | 1, cj: number | Vector2) {
|
|
79
|
-
switch (j) {
|
|
80
|
-
case 0: return __set__.c0(a, cj)
|
|
81
|
-
case 1: return __set__.c1(a, cj)
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function xx(a: Matrix2, xx ?: number) {
|
|
87
|
-
return xx === undefined ? __get__.xx(a) : __set__.xx(a, xx)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function xy(a: Matrix2, xy ?: number) {
|
|
91
|
-
return xy === undefined ? __get__.xy(a) : __set__.xy(a, xy)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function yx(a: Matrix2, yx ?: number) {
|
|
95
|
-
return yx === undefined ? __get__.yx(a) : __set__.yx(a, yx)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function yy(a: Matrix2, yy ?: number) {
|
|
99
|
-
return yy === undefined ? __get__.yy(a) : __set__.yy(a, yy)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function r0(a: Matrix2, r0 ?: number | Vector2) {
|
|
103
|
-
return r0 === undefined ? __get__.r0(a) : __set__.r0(a, r0)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function r1(a: Matrix2, r1 ?: number | Vector2) {
|
|
107
|
-
return r1 === undefined ? __get__.r1(a) : __set__.r1(a, r1)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export function c0(a: Matrix2, c0 ?: number | Vector2) {
|
|
111
|
-
return c0 === undefined ? __get__.c0(a) : __set__.c0(a, c0)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export function c1(a: Matrix2, c1 ?: number | Vector2) {
|
|
115
|
-
return c1 === undefined ? __get__.c1(a) : __set__.c1(a, c1)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export function row(a: Matrix2, i: 0 | 1, ri ?: number | Vector2) {
|
|
119
|
-
return ri === undefined ? __get__.row(a, i) : __set__.row(a, i, ri)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function col(a: Matrix2, j: 0 | 1, cj ?: number | Vector2) {
|
|
123
|
-
return cj === undefined ? __get__.col(a, j) : __set__.col(a, j, cj)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export const Matrix2 = {
|
|
127
|
-
XX, XY, YX, YY,
|
|
128
|
-
__get__,
|
|
129
|
-
__set__,
|
|
130
|
-
xx, xy, yx, yy,
|
|
131
|
-
|
|
132
|
-
id(a: number = 1) {
|
|
133
|
-
return [
|
|
134
|
-
a, 0,
|
|
135
|
-
0, a
|
|
136
|
-
] satisfies Matrix2
|
|
137
|
-
},
|
|
138
|
-
|
|
139
|
-
new(...a: Array<number>) {
|
|
140
|
-
if (a.length === 1) return [
|
|
141
|
-
a[XX]!, a[XX]!,
|
|
142
|
-
a[XX]!, a[XX]!
|
|
143
|
-
] satisfies Matrix2
|
|
144
|
-
else return [
|
|
145
|
-
a[XX] ?? 0, a[XY] ?? 0,
|
|
146
|
-
a[YX] ?? 0, a[YY] ?? 0
|
|
147
|
-
] satisfies Matrix2
|
|
148
|
-
},
|
|
149
|
-
|
|
150
|
-
from(a: number | Array<number>) {
|
|
151
|
-
if (typeof a === "number") return [
|
|
152
|
-
a, a,
|
|
153
|
-
a, a
|
|
154
|
-
] satisfies Matrix2
|
|
155
|
-
else return [
|
|
156
|
-
a[XX] ?? 0, a[XY] ?? 0,
|
|
157
|
-
a[YX] ?? 0, a[YY] ?? 0
|
|
158
|
-
] satisfies Matrix2
|
|
159
|
-
},
|
|
160
|
-
|
|
161
|
-
el(op: (a: number, b: number) => number, a: number | Matrix2, b: number | Matrix2, out: Matrix2 = Matrix2.new()) {
|
|
162
|
-
const [ xxa, xya, yxa, yya ] = Matrix2.from(a)
|
|
163
|
-
const [ xxb, xyb, yxb, yyb ] = Matrix2.from(b)
|
|
164
|
-
__set__.xx(out, op(xxa, xxb))
|
|
165
|
-
__set__.xy(out, op(xya, xyb))
|
|
166
|
-
__set__.yx(out, op(yxa, yxb))
|
|
167
|
-
__set__.yy(out, op(yya, yyb))
|
|
168
|
-
return out
|
|
169
|
-
},
|
|
170
|
-
|
|
171
|
-
add(a: number | Matrix2, b: number | Matrix2, out: Matrix2 = Matrix2.new()) {
|
|
172
|
-
return Matrix2.el(ADD, a, b, out)
|
|
173
|
-
},
|
|
174
|
-
|
|
175
|
-
sub(a: number | Matrix2, b: number | Matrix2, out: Matrix2 = Matrix2.new()) {
|
|
176
|
-
return Matrix2.el(SUB, a, b, out)
|
|
177
|
-
},
|
|
178
|
-
|
|
179
|
-
hmul(a: number | Matrix2, b: number | Matrix2, out: Matrix2 = Matrix2.new()) {
|
|
180
|
-
return Matrix2.el(MUL, a, b, out)
|
|
181
|
-
},
|
|
182
|
-
|
|
183
|
-
hdiv(a: number | Matrix2, b: number | Matrix2, out: Matrix2 = Matrix2.new()) {
|
|
184
|
-
return Matrix2.el(DIV, a, b, out)
|
|
185
|
-
},
|
|
186
|
-
|
|
187
|
-
hmod(a: number | Matrix2, b: number | Matrix2, out: Matrix2 = Matrix2.new()) {
|
|
188
|
-
return Matrix2.el(MOD, a, b, out)
|
|
189
|
-
},
|
|
190
|
-
|
|
191
|
-
mul(a: number | Matrix2, b: number | Matrix2, out: Matrix2 = Matrix2.new()) {
|
|
192
|
-
const A = Matrix2.from(a)
|
|
193
|
-
const B = Matrix2.from(b)
|
|
194
|
-
const r0 = __get__.r0(A)
|
|
195
|
-
const r1 = __get__.r1(A)
|
|
196
|
-
const c0 = __get__.c0(B)
|
|
197
|
-
const c1 = __get__.c1(B)
|
|
198
|
-
|
|
199
|
-
__set__.xx(out, Vector2.dot(r0, c0))
|
|
200
|
-
__set__.xy(out, Vector2.dot(r0, c1))
|
|
201
|
-
__set__.yx(out, Vector2.dot(r1, c0))
|
|
202
|
-
__set__.yy(out, Vector2.dot(r1, c1))
|
|
203
|
-
|
|
204
|
-
return out
|
|
205
|
-
},
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
toString(a: number | Matrix2) {
|
|
209
|
-
const [
|
|
210
|
-
xx, xy,
|
|
211
|
-
yx, yy
|
|
212
|
-
] = Matrix2.from(a)
|
|
213
|
-
return `mat2<${xx}, ${xy}, ${yx}, ${yy}>`
|
|
214
|
-
}
|
|
215
|
-
}
|
package/src/matrix3.ts
DELETED
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
import { Vector3 } from "./vector3.js";
|
|
2
|
-
import { ADD, SUB, MUL, DIV, MOD } from "./math.js";
|
|
3
|
-
|
|
4
|
-
export type Matrix3 = [
|
|
5
|
-
number, number, number,
|
|
6
|
-
number, number, number,
|
|
7
|
-
number, number, number
|
|
8
|
-
]
|
|
9
|
-
|
|
10
|
-
export const XX = 0 as const;
|
|
11
|
-
export const XY = 1 as const;
|
|
12
|
-
export const XZ = 2 as const;
|
|
13
|
-
export const YX = 3 as const;
|
|
14
|
-
export const YY = 4 as const;
|
|
15
|
-
export const YZ = 5 as const;
|
|
16
|
-
export const ZX = 6 as const;
|
|
17
|
-
export const ZY = 7 as const;
|
|
18
|
-
export const ZZ = 8 as const;
|
|
19
|
-
|
|
20
|
-
export const __get__ = {
|
|
21
|
-
xx(a: Matrix3) { return a[XX] },
|
|
22
|
-
xy(a: Matrix3) { return a[XY] },
|
|
23
|
-
xz(a: Matrix3) { return a[XZ] },
|
|
24
|
-
yx(a: Matrix3) { return a[YX] },
|
|
25
|
-
yy(a: Matrix3) { return a[YY] },
|
|
26
|
-
yz(a: Matrix3) { return a[YZ] },
|
|
27
|
-
zx(a: Matrix3) { return a[ZX] },
|
|
28
|
-
zy(a: Matrix3) { return a[ZY] },
|
|
29
|
-
zz(a: Matrix3) { return a[ZZ] },
|
|
30
|
-
|
|
31
|
-
r0(a: Matrix3) { return [ a[XX], a[XY], a[XZ] ] satisfies Vector3 },
|
|
32
|
-
r1(a: Matrix3) { return [ a[YX], a[YY], a[YZ] ] satisfies Vector3 },
|
|
33
|
-
r2(a: Matrix3) { return [ a[ZX], a[ZY], a[ZZ] ] satisfies Vector3 },
|
|
34
|
-
|
|
35
|
-
c0(a: Matrix3) { return [ a[XX], a[YX], a[ZX] ] satisfies Vector3 },
|
|
36
|
-
c1(a: Matrix3) { return [ a[XY], a[YY], a[ZY] ] satisfies Vector3 },
|
|
37
|
-
c2(a: Matrix3) { return [ a[XZ], a[YZ], a[ZZ] ] satisfies Vector3 },
|
|
38
|
-
|
|
39
|
-
row(a: Matrix3, i: 0 | 1 | 2) { switch (i) {
|
|
40
|
-
case 0: return __get__.r0(a)
|
|
41
|
-
case 1: return __get__.r1(a)
|
|
42
|
-
case 2: return __get__.r2(a)
|
|
43
|
-
}},
|
|
44
|
-
|
|
45
|
-
col(a: Matrix3, j: 0 | 1 | 2) { switch (j) {
|
|
46
|
-
case 0: return __get__.c0(a)
|
|
47
|
-
case 1: return __get__.c1(a)
|
|
48
|
-
case 2: return __get__.c2(a)
|
|
49
|
-
}},
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const __set__ = {
|
|
53
|
-
xx(a: Matrix3, xx: number) { return a[XX] = xx },
|
|
54
|
-
xy(a: Matrix3, xy: number) { return a[XY] = xy },
|
|
55
|
-
xz(a: Matrix3, xz: number) { return a[XZ] = xz },
|
|
56
|
-
yx(a: Matrix3, yx: number) { return a[YX] = yx },
|
|
57
|
-
yy(a: Matrix3, yy: number) { return a[YY] = yy },
|
|
58
|
-
yz(a: Matrix3, yz: number) { return a[YZ] = yz },
|
|
59
|
-
zx(a: Matrix3, zx: number) { return a[ZX] = zx },
|
|
60
|
-
zy(a: Matrix3, zy: number) { return a[ZY] = zy },
|
|
61
|
-
zz(a: Matrix3, zz: number) { return a[ZZ] = zz },
|
|
62
|
-
|
|
63
|
-
r0(a: Matrix3, r0: number | Vector3) {
|
|
64
|
-
const [x, y, z] = Vector3.from(r0)
|
|
65
|
-
__set__.xx(a, x)
|
|
66
|
-
__set__.xy(a, y)
|
|
67
|
-
__set__.xz(a, z)
|
|
68
|
-
return [x, y, z] satisfies Vector3
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
r1(a: Matrix3, r1: number | Vector3) {
|
|
72
|
-
const [x, y, z] = Vector3.from(r1)
|
|
73
|
-
__set__.yx(a, x)
|
|
74
|
-
__set__.yy(a, y)
|
|
75
|
-
__set__.yz(a, z)
|
|
76
|
-
return [x, y, z] satisfies Vector3
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
r2(a: Matrix3, r2: number | Vector3) {
|
|
80
|
-
const [x, y, z] = Vector3.from(r2)
|
|
81
|
-
__set__.zx(a, x)
|
|
82
|
-
__set__.zy(a, y)
|
|
83
|
-
__set__.zz(a, z)
|
|
84
|
-
return [x, y, z] satisfies Vector3
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
c0(a: Matrix3, c0: number | Vector3) {
|
|
88
|
-
const [x, y, z] = Vector3.from(c0)
|
|
89
|
-
__set__.xx(a, x)
|
|
90
|
-
__set__.yx(a, y)
|
|
91
|
-
__set__.zx(a, z)
|
|
92
|
-
return [x, y, z] satisfies Vector3
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
c1(a: Matrix3, c1: number | Vector3) {
|
|
96
|
-
const [x, y, z] = Vector3.from(c1)
|
|
97
|
-
__set__.xy(a, x)
|
|
98
|
-
__set__.yy(a, y)
|
|
99
|
-
__set__.zy(a, y)
|
|
100
|
-
return [x, y, z] satisfies Vector3
|
|
101
|
-
},
|
|
102
|
-
|
|
103
|
-
c2(a: Matrix3, c2: number | Vector3) {
|
|
104
|
-
const [x, y, z] = Vector3.from(c2)
|
|
105
|
-
__set__.xz(a, x)
|
|
106
|
-
__set__.yz(a, y)
|
|
107
|
-
__set__.zz(a, z)
|
|
108
|
-
return [x, y, z] satisfies Vector3
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
row(a: Matrix3, i: 0 | 1 | 2, ri: number | Vector3) {
|
|
112
|
-
switch (i) {
|
|
113
|
-
case 0: return __set__.r0(a, ri)
|
|
114
|
-
case 1: return __set__.r1(a, ri)
|
|
115
|
-
case 2: return __set__.r2(a, ri)
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
|
|
119
|
-
col(a: Matrix3, j: 0 | 1 | 2, cj: number | Vector3) {
|
|
120
|
-
switch (j) {
|
|
121
|
-
case 0: return __set__.c0(a, cj)
|
|
122
|
-
case 1: return __set__.c1(a, cj)
|
|
123
|
-
case 2: return __set__.c2(a, cj)
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export function xx(a: Matrix3, xx ?: number) {
|
|
129
|
-
return xx === undefined ? __get__.xx(a) : __set__.xx(a, xx)
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export function xy(a: Matrix3, xy ?: number) {
|
|
133
|
-
return xy === undefined ? __get__.xy(a) : __set__.xy(a, xy)
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export function xz(a: Matrix3, xz ?: number) {
|
|
137
|
-
return xz === undefined ? __get__.xz(a) : __set__.xz(a, xz)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export function yx(a: Matrix3, yx ?: number) {
|
|
141
|
-
return yx === undefined ? __get__.yx(a) : __set__.yx(a, yx)
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export function yy(a: Matrix3, yy ?: number) {
|
|
145
|
-
return yy === undefined ? __get__.yy(a) : __set__.yy(a, yy)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export function yz(a: Matrix3, yz ?: number) {
|
|
149
|
-
return yz === undefined ? __get__.yz(a) : __set__.yz(a, yz)
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export function zx(a: Matrix3, zx ?: number) {
|
|
153
|
-
return zx === undefined ? __get__.zx(a) : __set__.zx(a, zx)
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export function zy(a: Matrix3, zy ?: number) {
|
|
157
|
-
return zy === undefined ? __get__.zy(a) : __set__.zy(a, zy)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export function zz(a: Matrix3, zz ?: number) {
|
|
161
|
-
return zz === undefined ? __get__.zz(a) : __set__.zz(a, zz)
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export function r0(a: Matrix3, r0 ?: number | Vector3) {
|
|
165
|
-
return r0 === undefined ? __get__.r0(a) : __set__.r0(a, r0)
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export function r1(a: Matrix3, r1 ?: number | Vector3) {
|
|
169
|
-
return r1 === undefined ? __get__.r1(a) : __set__.r1(a, r1)
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export function r2(a: Matrix3, r2 ?: number | Vector3) {
|
|
173
|
-
return r2 === undefined ? __get__.r2(a) : __set__.r2(a, r2)
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export function c0(a: Matrix3, c0 ?: number | Vector3) {
|
|
177
|
-
return c0 === undefined ? __get__.c0(a) : __set__.c0(a, c0)
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export function c1(a: Matrix3, c1 ?: number | Vector3) {
|
|
181
|
-
return c1 === undefined ? __get__.c1(a) : __set__.c1(a, c1)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export function c2(a: Matrix3, c2 ?: number | Vector3) {
|
|
185
|
-
return c2 === undefined ? __get__.c2(a) : __set__.c2(a, c2)
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export function row(a: Matrix3, i: 0 | 1 | 2, ri ?: number | Vector3) {
|
|
189
|
-
return ri === undefined ? __get__.row(a, i) : __set__.row(a, i, ri)
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export function col(a: Matrix3, j: 0 | 1 | 2, cj ?: number | Vector3) {
|
|
193
|
-
return cj === undefined ? __get__.col(a, j) : __set__.col(a, j, cj)
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export const Matrix3 = {
|
|
197
|
-
XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ,
|
|
198
|
-
__get__,
|
|
199
|
-
__set__,
|
|
200
|
-
xx, xy, xz, yx, yy, yz, zx, zy, zz,
|
|
201
|
-
|
|
202
|
-
id(a: number = 1) {
|
|
203
|
-
return [
|
|
204
|
-
a, 0, 0,
|
|
205
|
-
0, a, 0,
|
|
206
|
-
0, 0, a
|
|
207
|
-
] satisfies Matrix3
|
|
208
|
-
},
|
|
209
|
-
|
|
210
|
-
new(...a: Array<number>) {
|
|
211
|
-
if (a.length === 1) return [
|
|
212
|
-
a[XX]!, a[XX]!, a[XX]!,
|
|
213
|
-
a[XX]!, a[XX]!, a[XX]!,
|
|
214
|
-
a[XX]!, a[XX]!, a[XX]!
|
|
215
|
-
] satisfies Matrix3
|
|
216
|
-
else return [
|
|
217
|
-
a[XX] ?? 0, a[XY] ?? 0, a[XZ] ?? 0,
|
|
218
|
-
a[YX] ?? 0, a[YY] ?? 0, a[YZ] ?? 0,
|
|
219
|
-
a[ZX] ?? 0, a[ZY] ?? 0, a[ZZ] ?? 0
|
|
220
|
-
] satisfies Matrix3
|
|
221
|
-
},
|
|
222
|
-
|
|
223
|
-
from(a: number | Array<number>) {
|
|
224
|
-
if (typeof a === "number") return [
|
|
225
|
-
a, a, a,
|
|
226
|
-
a, a, a,
|
|
227
|
-
a, a, a
|
|
228
|
-
] satisfies Matrix3
|
|
229
|
-
else return [
|
|
230
|
-
a[XX] ?? 0, a[XY] ?? 0, a[XZ] ?? 0,
|
|
231
|
-
a[YX] ?? 0, a[YY] ?? 0, a[YZ] ?? 0,
|
|
232
|
-
a[ZX] ?? 0, a[ZY] ?? 0, a[ZZ] ?? 0
|
|
233
|
-
] satisfies Matrix3
|
|
234
|
-
},
|
|
235
|
-
|
|
236
|
-
el(op: (a: number, b: number) => number, a: number | Matrix3, b: number | Matrix3, out: Matrix3 = Matrix3.new()) {
|
|
237
|
-
const [ xxa, xya, xza, yxa, yya, yza, zxa, zya, zza ] = Matrix3.from(a)
|
|
238
|
-
const [ xxb, xyb, xzb, yxb, yyb, yzb, zxb, zyb, zzb ] = Matrix3.from(b)
|
|
239
|
-
__set__.xx(out, op(xxa, xxb))
|
|
240
|
-
__set__.xy(out, op(xya, xyb))
|
|
241
|
-
__set__.xz(out, op(xza, xzb))
|
|
242
|
-
__set__.yx(out, op(yxa, yxb))
|
|
243
|
-
__set__.yy(out, op(yya, yyb))
|
|
244
|
-
__set__.yz(out, op(yza, yzb))
|
|
245
|
-
__set__.zx(out, op(zxa, zxb))
|
|
246
|
-
__set__.zy(out, op(zya, zyb))
|
|
247
|
-
__set__.zz(out, op(zza, zzb))
|
|
248
|
-
return out
|
|
249
|
-
},
|
|
250
|
-
|
|
251
|
-
add(a: number | Matrix3, b: number | Matrix3, out: Matrix3 = Matrix3.new()) {
|
|
252
|
-
return Matrix3.el(ADD, a, b, out)
|
|
253
|
-
},
|
|
254
|
-
|
|
255
|
-
sub(a: number | Matrix3, b: number | Matrix3, out: Matrix3 = Matrix3.new()) {
|
|
256
|
-
return Matrix3.el(SUB, a, b, out)
|
|
257
|
-
},
|
|
258
|
-
|
|
259
|
-
hmul(a: number | Matrix3, b: number | Matrix3, out: Matrix3 = Matrix3.new()) {
|
|
260
|
-
return Matrix3.el(MUL, a, b, out)
|
|
261
|
-
},
|
|
262
|
-
|
|
263
|
-
hdiv(a: number | Matrix3, b: number | Matrix3, out: Matrix3 = Matrix3.new()) {
|
|
264
|
-
return Matrix3.el(DIV, a, b, out)
|
|
265
|
-
},
|
|
266
|
-
|
|
267
|
-
hmod(a: number | Matrix3, b: number | Matrix3, out: Matrix3 = Matrix3.new()) {
|
|
268
|
-
return Matrix3.el(MOD, a, b, out)
|
|
269
|
-
},
|
|
270
|
-
|
|
271
|
-
mul(a: number | Matrix3, b: number | Matrix3, out: Matrix3 = Matrix3.new()) {
|
|
272
|
-
const A = Matrix3.from(a)
|
|
273
|
-
const B = Matrix3.from(b)
|
|
274
|
-
const r0 = __get__.r0(A)
|
|
275
|
-
const r1 = __get__.r1(A)
|
|
276
|
-
const r2 = __get__.r2(A)
|
|
277
|
-
const c0 = __get__.c0(B)
|
|
278
|
-
const c1 = __get__.c1(B)
|
|
279
|
-
const c2 = __get__.c2(B)
|
|
280
|
-
|
|
281
|
-
__set__.xx(out, Vector3.dot(r0, c0))
|
|
282
|
-
__set__.xy(out, Vector3.dot(r0, c1))
|
|
283
|
-
__set__.xz(out, Vector3.dot(r0, c2))
|
|
284
|
-
__set__.yx(out, Vector3.dot(r1, c0))
|
|
285
|
-
__set__.yy(out, Vector3.dot(r1, c1))
|
|
286
|
-
__set__.yz(out, Vector3.dot(r1, c2))
|
|
287
|
-
__set__.zx(out, Vector3.dot(r2, c0))
|
|
288
|
-
__set__.zy(out, Vector3.dot(r2, c1))
|
|
289
|
-
__set__.zz(out, Vector3.dot(r2, c2))
|
|
290
|
-
|
|
291
|
-
return out
|
|
292
|
-
},
|
|
293
|
-
|
|
294
|
-
toString(a: number | Matrix3) {
|
|
295
|
-
const [
|
|
296
|
-
xx, xy, xz,
|
|
297
|
-
yx, yy, yz,
|
|
298
|
-
zx, zy, zz
|
|
299
|
-
] = Matrix3.from(a)
|
|
300
|
-
return `mat3<${xx}, ${xy}, ${xz}, ${yx}, ${yy}, ${yz}, ${zx}, ${zy}, ${zz}>`
|
|
301
|
-
}
|
|
302
|
-
}
|