@wemap/maths 10.6.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 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,
@@ -115,17 +116,24 @@ declare module '@wemap/maths' {
115
116
  static multiply(a: Matrix3_t, b: Matrix3_t): Matrix3_t;
116
117
  static multiplyScalar(m: Matrix3_t, s: number): Matrix3_t;
117
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;
118
122
  static skew(v: Vector3_t): Matrix3_t;
119
123
  static sum(m1: Matrix3_t, m2: Matrix3_t): Matrix3_t;
120
124
  static transpose(m: Matrix3_t): Matrix3_t;
121
125
  }
122
126
 
123
- export class Matrix4 extends Matrix {
127
+ export class Matrix4 {
124
128
  static get identity(): Matrix4_t;
125
129
 
126
130
  static fromMatrix3(m: Matrix3_t): Matrix4_t;
127
131
  static fromVector(v: Vector16_t): Matrix4_t;
128
132
  static multiply(a: Matrix4_t, b: Matrix4_t): Matrix4_t;
133
+ static multiplyScalar(a: Matrix4_t, b: number): Matrix4_t;
134
+ static multiplyVector(a: Matrix4_t, v: Vector4_t): Vector4_t;
135
+ static multiplyVector3(a: Matrix4_t, v: Vector3_t): Vector3_t;
136
+ static scaleScalar(a: Matrix4_t, b: number): Matrix4_t;
129
137
  static sum(m1: Matrix4_t, m2: Matrix4_t): Matrix4_t;
130
138
  static subtract(m1: Matrix4_t, m2: Matrix4_t): Matrix4_t;
131
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.6.0",
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": "4b046adea2d82a474aa3099f9ebea3c9f15eba19"
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]],
@@ -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
@@ -1,6 +1,4 @@
1
- import Matrix from './Matrix.js';
2
-
3
- class Matrix4 extends Matrix {
1
+ class Matrix4 {
4
2
 
5
3
  static get identity() {
6
4
  return [
@@ -56,5 +54,53 @@ 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 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
+
82
+ static multiplyVector(a, v) {
83
+ const output = new Array(4);
84
+ for (let r = 0; r < 4; ++r) {
85
+ output[r] = 0;
86
+ for (let c = 0; c < 4; ++c) {
87
+ output[r] += a[r][c] * v[c];
88
+ }
89
+ }
90
+ return output;
91
+ }
92
+
93
+ static multiplyVector3(a, v) {
94
+ return Matrix4.multiplyVector(a, [...v, 1]).slice(0, 3);
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
+ }
59
105
  }
60
106
  export default Matrix4;