@wemap/maths 10.7.0 → 10.8.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/index.d.ts +5 -0
- package/package.json +2 -2
- package/src/Matrix3.js +24 -0
- package/src/Matrix3.spec.js +27 -0
- package/src/Matrix4.js +20 -0
package/index.d.ts
CHANGED
|
@@ -116,6 +116,9 @@ declare module '@wemap/maths' {
|
|
|
116
116
|
static multiply(a: Matrix3_t, b: Matrix3_t): Matrix3_t;
|
|
117
117
|
static multiplyScalar(m: Matrix3_t, s: number): Matrix3_t;
|
|
118
118
|
static multiplyVector(a: Matrix3_t, v: Vector3_t): Vector3_t;
|
|
119
|
+
static rotX(theta: number): Matrix3_t;
|
|
120
|
+
static rotY(theta: number): Matrix3_t;
|
|
121
|
+
static rotZ(theta: number): Matrix3_t;
|
|
119
122
|
static skew(v: Vector3_t): Matrix3_t;
|
|
120
123
|
static sum(m1: Matrix3_t, m2: Matrix3_t): Matrix3_t;
|
|
121
124
|
static transpose(m: Matrix3_t): Matrix3_t;
|
|
@@ -127,8 +130,10 @@ declare module '@wemap/maths' {
|
|
|
127
130
|
static fromMatrix3(m: Matrix3_t): Matrix4_t;
|
|
128
131
|
static fromVector(v: Vector16_t): Matrix4_t;
|
|
129
132
|
static multiply(a: Matrix4_t, b: Matrix4_t): Matrix4_t;
|
|
133
|
+
static multiplyScalar(a: Matrix4_t, b: number): Matrix4_t;
|
|
130
134
|
static multiplyVector(a: Matrix4_t, v: Vector4_t): Vector4_t;
|
|
131
135
|
static multiplyVector3(a: Matrix4_t, v: Vector3_t): Vector3_t;
|
|
136
|
+
static scaleScalar(a: Matrix4_t, b: number): Matrix4_t;
|
|
132
137
|
static sum(m1: Matrix4_t, m2: Matrix4_t): Matrix4_t;
|
|
133
138
|
static subtract(m1: Matrix4_t, m2: Matrix4_t): Matrix4_t;
|
|
134
139
|
static toVector(m: Matrix4_t): Vector16_t;
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"directory": "packages/maths"
|
|
14
14
|
},
|
|
15
15
|
"name": "@wemap/maths",
|
|
16
|
-
"version": "10.
|
|
16
|
+
"version": "10.8.0",
|
|
17
17
|
"bugs": {
|
|
18
18
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
19
19
|
},
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"wemap"
|
|
27
27
|
],
|
|
28
28
|
"license": "ISC",
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "7f3a7c46f450721f5a7b801a5ae444c458a37308"
|
|
30
30
|
}
|
package/src/Matrix3.js
CHANGED
|
@@ -24,6 +24,30 @@ class Matrix3 {
|
|
|
24
24
|
];
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
static rotX(theta) {
|
|
28
|
+
return [
|
|
29
|
+
[1, 0, 0],
|
|
30
|
+
[0, Math.cos(theta), -Math.sin(theta)],
|
|
31
|
+
[0, Math.sin(theta), Math.cos(theta)]
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static rotY(theta) {
|
|
36
|
+
return [
|
|
37
|
+
[Math.cos(theta), 0, Math.sin(theta)],
|
|
38
|
+
[0, 1, 0],
|
|
39
|
+
[-Math.sin(theta), 0, Math.cos(theta)]
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static rotZ(theta) {
|
|
44
|
+
return [
|
|
45
|
+
[Math.cos(theta), -Math.sin(theta), 0],
|
|
46
|
+
[-Math.sin(theta), Math.cos(theta), 0],
|
|
47
|
+
[0, 0, 1]
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
|
|
27
51
|
static transpose(m) {
|
|
28
52
|
return [
|
|
29
53
|
[m[0][0], m[1][0], m[2][0]],
|
package/src/Matrix3.spec.js
CHANGED
|
@@ -102,4 +102,31 @@ describe('Matrix3', () => {
|
|
|
102
102
|
expect(result).is.null;
|
|
103
103
|
|
|
104
104
|
});
|
|
105
|
+
|
|
106
|
+
it('rotX', () => {
|
|
107
|
+
const result = Matrix3.rotX(Math.PI / 2);
|
|
108
|
+
expect(result).deep.almost([
|
|
109
|
+
[1, 0, 0],
|
|
110
|
+
[0, 0, -1],
|
|
111
|
+
[0, 1, 0]
|
|
112
|
+
]);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('rotY', () => {
|
|
116
|
+
const result = Matrix3.rotY(Math.PI / 2);
|
|
117
|
+
expect(result).deep.almost([
|
|
118
|
+
[0, 0, 1],
|
|
119
|
+
[0, 1, 0],
|
|
120
|
+
[-1, 0, 0]
|
|
121
|
+
]);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('rotZ', () => {
|
|
125
|
+
const result = Matrix3.rotZ(Math.PI / 2);
|
|
126
|
+
expect(result).deep.almost([
|
|
127
|
+
[0, -1, 0],
|
|
128
|
+
[-1, 0, 0],
|
|
129
|
+
[0, 0, 1]
|
|
130
|
+
]);
|
|
131
|
+
});
|
|
105
132
|
});
|
package/src/Matrix4.js
CHANGED
|
@@ -68,6 +68,17 @@ class Matrix4 {
|
|
|
68
68
|
return m;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
static multiplyScalar(a, s) {
|
|
72
|
+
const output = new Array(4);
|
|
73
|
+
for (let r = 0; r < 4; ++r) {
|
|
74
|
+
output[r] = 0;
|
|
75
|
+
for (let c = 0; c < 4; ++c) {
|
|
76
|
+
output[r] += a[r][c] * s;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return output;
|
|
80
|
+
}
|
|
81
|
+
|
|
71
82
|
static multiplyVector(a, v) {
|
|
72
83
|
const output = new Array(4);
|
|
73
84
|
for (let r = 0; r < 4; ++r) {
|
|
@@ -82,5 +93,14 @@ class Matrix4 {
|
|
|
82
93
|
static multiplyVector3(a, v) {
|
|
83
94
|
return Matrix4.multiplyVector(a, [...v, 1]).slice(0, 3);
|
|
84
95
|
}
|
|
96
|
+
|
|
97
|
+
static scaleScalar(m, s) {
|
|
98
|
+
return [
|
|
99
|
+
[m[0][0] * s, m[0][1], m[0][2], m[0][3]],
|
|
100
|
+
[m[1][0], m[1][1] * s, m[1][2], m[1][3]],
|
|
101
|
+
[m[2][0], m[2][1], m[2][2] * s, m[2][3]],
|
|
102
|
+
[m[3][0], m[3][1], m[3][2], m[3][3] * s]
|
|
103
|
+
];
|
|
104
|
+
}
|
|
85
105
|
}
|
|
86
106
|
export default Matrix4;
|