@wemap/maths 10.6.0 → 10.7.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 +4 -1
- package/package.json +2 -2
- package/src/Matrix4.js +29 -3
package/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ declare module '@wemap/maths' {
|
|
|
5
5
|
export type Polygon_t = Point2_t[];
|
|
6
6
|
export type Quaternion_t = [number, number, number, number];
|
|
7
7
|
export type Vector3_t = [number, number, number];
|
|
8
|
+
export type Vector4_t = [number, number, number, number];
|
|
8
9
|
export type Vector16_t = [number, number, number, number,
|
|
9
10
|
number, number, number, number,
|
|
10
11
|
number, number, number, number,
|
|
@@ -120,12 +121,14 @@ declare module '@wemap/maths' {
|
|
|
120
121
|
static transpose(m: Matrix3_t): Matrix3_t;
|
|
121
122
|
}
|
|
122
123
|
|
|
123
|
-
export class Matrix4
|
|
124
|
+
export class Matrix4 {
|
|
124
125
|
static get identity(): Matrix4_t;
|
|
125
126
|
|
|
126
127
|
static fromMatrix3(m: Matrix3_t): Matrix4_t;
|
|
127
128
|
static fromVector(v: Vector16_t): Matrix4_t;
|
|
128
129
|
static multiply(a: Matrix4_t, b: Matrix4_t): Matrix4_t;
|
|
130
|
+
static multiplyVector(a: Matrix4_t, v: Vector4_t): Vector4_t;
|
|
131
|
+
static multiplyVector3(a: Matrix4_t, v: Vector3_t): Vector3_t;
|
|
129
132
|
static sum(m1: Matrix4_t, m2: Matrix4_t): Matrix4_t;
|
|
130
133
|
static subtract(m1: Matrix4_t, m2: Matrix4_t): Matrix4_t;
|
|
131
134
|
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.7.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": "d9e85b1ff0458dc3f904dbdbe8fa098f02cf8d87"
|
|
30
30
|
}
|
package/src/Matrix4.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
class Matrix4 extends Matrix {
|
|
1
|
+
class Matrix4 {
|
|
4
2
|
|
|
5
3
|
static get identity() {
|
|
6
4
|
return [
|
|
@@ -56,5 +54,33 @@ class Matrix4 extends Matrix {
|
|
|
56
54
|
];
|
|
57
55
|
}
|
|
58
56
|
|
|
57
|
+
static multiply(a, b) {
|
|
58
|
+
const m = new Array(4);
|
|
59
|
+
for (let r = 0; r < 4; ++r) {
|
|
60
|
+
m[r] = new Array(4);
|
|
61
|
+
for (let c = 0; c < 4; ++c) {
|
|
62
|
+
m[r][c] = 0;
|
|
63
|
+
for (let i = 0; i < 4; ++i) {
|
|
64
|
+
m[r][c] += a[r][i] * b[i][c];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return m;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static multiplyVector(a, v) {
|
|
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] * v[c];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return output;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static multiplyVector3(a, v) {
|
|
83
|
+
return Matrix4.multiplyVector(a, [...v, 1]).slice(0, 3);
|
|
84
|
+
}
|
|
59
85
|
}
|
|
60
86
|
export default Matrix4;
|