@wemap/maths 3.2.1 → 3.2.15

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.js CHANGED
@@ -10,7 +10,7 @@ import Vector from './src/Vector.js';
10
10
  import Vector3 from './src/Vector3.js';
11
11
 
12
12
  const {
13
- deg2rad, diffAngle, positiveMod, rad2deg
13
+ deg2rad, diffAngle, positiveMod, rad2deg, wrap
14
14
  } = Utils;
15
15
 
16
16
  export {
@@ -18,6 +18,7 @@ export {
18
18
  diffAngle,
19
19
  positiveMod,
20
20
  rad2deg,
21
+ wrap,
21
22
  Matrix,
22
23
  Matrix3,
23
24
  Matrix4,
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/maths"
13
13
  },
14
14
  "name": "@wemap/maths",
15
- "version": "3.2.1",
15
+ "version": "3.2.15",
16
16
  "bugs": {
17
17
  "url": "https://github.com/wemap/wemap-modules-js/issues"
18
18
  },
@@ -25,5 +25,5 @@
25
25
  "wemap"
26
26
  ],
27
27
  "license": "ISC",
28
- "gitHead": "0d430815358a23068c8473b2c310b2945667b2c1"
28
+ "gitHead": "adde2357c87a5429e7b3bea068729d6e06c9c3ca"
29
29
  }
package/src/Quaternion.js CHANGED
@@ -2,6 +2,18 @@ import Vector3 from './Vector3.js';
2
2
 
3
3
  class Quaternion {
4
4
 
5
+ static ROTX_PI2 = this.rotX(Math.PI / 2);
6
+ static ROTX_PI = this.rotX(Math.PI);
7
+ static ROTX_MPI2 = this.rotX(-Math.PI / 2);
8
+
9
+ static ROTY_PI2 = this.rotY(Math.PI / 2);
10
+ static ROTY_PI = this.rotY(Math.PI);
11
+ static ROTY_MPI2 = this.rotY(-Math.PI / 2);
12
+
13
+ static ROTZ_PI2 = this.rotZ(Math.PI / 2);
14
+ static ROTZ_PI = this.rotZ(Math.PI);
15
+ static ROTZ_MPI2 = this.rotZ(-Math.PI / 2);
16
+
5
17
  static get identity() {
6
18
  return [1, 0, 0, 0];
7
19
  }
@@ -50,6 +62,30 @@ class Quaternion {
50
62
  return [Math.cos(angle / 2), axis[0] * s, axis[1] * s, axis[2] * s];
51
63
  }
52
64
 
65
+ /**
66
+ * Rotation around x-axis
67
+ * @param {Number} angle in radians
68
+ */
69
+ static rotX(angle) {
70
+ return this.fromAxisAngle([1, 0, 0], angle);
71
+ }
72
+
73
+ /**
74
+ * Rotation around x-axis
75
+ * @param {Number} angle in radians
76
+ */
77
+ static rotY(angle) {
78
+ return this.fromAxisAngle([0, 1, 0], angle);
79
+ }
80
+
81
+ /**
82
+ * Rotation around x-axis
83
+ * @param {Number} angle in radians
84
+ */
85
+ static rotZ(angle) {
86
+ return this.fromAxisAngle([0, 0, 1], angle);
87
+ }
88
+
53
89
  static fromMatrix3(m) {
54
90
  const qw = Math.sqrt(1 + m[0][0] + m[1][1] + m[2][2]) / 2;
55
91
  const qx = (m[1][2] - m[2][1]) / (4 * qw);
package/src/Utils.js CHANGED
@@ -26,6 +26,21 @@ class Utils {
26
26
  static positiveMod(n, m) {
27
27
  return ((n % m) + m) % m;
28
28
  }
29
+
30
+ /**
31
+ * constrain n to the given range, excluding the minimum, via modular arithmetic
32
+ *
33
+ * @param {number} n value
34
+ * @param {number} min the minimum value to be returned, exclusive
35
+ * @param {number} max the maximum value to be returned, inclusive
36
+ * @returns {number} constrained number
37
+ */
38
+ static wrap(n, min, max) {
39
+ const d = max - min;
40
+ const w = ((n - min) % d + d) % d + min;
41
+ return (w === min) ? max : w;
42
+ }
43
+
29
44
  }
30
45
 
31
46
  export default Utils;