@wemap/maths 10.0.0-alpha.7 → 10.3.0-alpha.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 +121 -4
- package/index.js +1 -0
- package/package.json +2 -2
- package/src/EulerAngles.js +8 -0
- package/src/Matrix.js +1 -1
- package/src/Matrix.spec.js +2 -2
- package/src/Matrix3.js +10 -4
- package/src/Matrix3.spec.js +2 -2
- package/src/Matrix4.js +1 -1
- package/src/Matrix4.spec.js +2 -2
- package/src/Quaternion.js +5 -5
- package/src/Quaternion.spec.js +1 -1
- package/src/Vector3.js +1 -1
- package/src/Vector3.spec.js +2 -2
package/index.d.ts
CHANGED
|
@@ -1,28 +1,145 @@
|
|
|
1
1
|
declare module '@wemap/maths' {
|
|
2
2
|
|
|
3
|
+
export type Point2_t = [number, number];
|
|
4
|
+
export type Line_t = [Point2_t, Point2_t];
|
|
5
|
+
export type Polygon_t = Point2_t[];
|
|
3
6
|
export type Quaternion_t = [number, number, number, number];
|
|
4
7
|
export type Vector3_t = [number, number, number];
|
|
8
|
+
export type Vector_t = number[];
|
|
5
9
|
export type Matrix3_t = [[number, number, number], [number, number, number], [number, number, number]];
|
|
10
|
+
export type Matrix4_t = [[number, number, number, number],
|
|
11
|
+
[number, number, number, number],
|
|
12
|
+
[number, number, number, number],
|
|
13
|
+
[number, number, number, number]];
|
|
14
|
+
export type Matrix_t = number[][];
|
|
15
|
+
export type EulerAngles_t = Vector3_t;
|
|
16
|
+
export type EulerAnglesDegrees_t = Vector3_t;
|
|
17
|
+
|
|
18
|
+
// Geometry
|
|
19
|
+
export function linesIntersect(line1: Line_t, line2: Line_t, detectIntersectionAtBounds?: number): boolean;
|
|
20
|
+
export function isPolygonClockwise(polygon: Polygon_t): boolean;
|
|
21
|
+
|
|
22
|
+
// Utils
|
|
23
|
+
export function average(arr: number[]): number;
|
|
24
|
+
export function deg2rad(angle: number): number;
|
|
25
|
+
export function diffAngle(angle1: number, angle2: number): number;
|
|
26
|
+
export function diffAngleDegrees(angle1: number, angle2: number): number;
|
|
27
|
+
export function diffAngleLines(angle1: number, angle2: number): number;
|
|
28
|
+
export function positiveMod(n: number, m: number): number;
|
|
29
|
+
export function rad2deg(angle: number): number;
|
|
30
|
+
export function std(arr: number[]): number;
|
|
31
|
+
export function wrap(n: number, min: number, max: number): number;
|
|
32
|
+
|
|
33
|
+
export class EulerAngles {
|
|
34
|
+
static toString(eulerAngles: EulerAngles_t | EulerAnglesDegrees_t): string;
|
|
35
|
+
}
|
|
6
36
|
|
|
7
37
|
export class Quaternion {
|
|
8
|
-
static
|
|
9
|
-
static
|
|
38
|
+
static ROTX_PI2: Quaternion_t;
|
|
39
|
+
static ROTX_PI: Quaternion_t;
|
|
40
|
+
static ROTX_MPI2: Quaternion_t;
|
|
41
|
+
static ROTY_PI2: Quaternion_t;
|
|
42
|
+
static ROTY_PI: Quaternion_t;
|
|
43
|
+
static ROTY_MPI2: Quaternion_t;
|
|
44
|
+
static ROTZ_PI2: Quaternion_t;
|
|
45
|
+
static ROTZ_PI: Quaternion_t;
|
|
46
|
+
static ROTZ_MPI2: Quaternion_t;
|
|
47
|
+
|
|
48
|
+
static get identity(): Quaternion_t;
|
|
49
|
+
|
|
50
|
+
static distance(q1: Quaternion_t, q2: Quaternion_t): number;
|
|
51
|
+
static dot(q1: Quaternion_t, q2: Quaternion_t): number;
|
|
52
|
+
static equals(q1: Quaternion_t, q2: Quaternion_t): boolean;
|
|
10
53
|
static fromAxisAngle(axis: Vector3_t, angle: number): Quaternion_t;
|
|
11
54
|
static fromMatrix3(m: Matrix3_t): Quaternion_t;
|
|
12
|
-
static
|
|
55
|
+
static getRotationBetweenTwoVectors(from: Vector3_t, to: Vector3_t): Quaternion_t;
|
|
13
56
|
static inverse(q: Quaternion_t): Quaternion_t;
|
|
57
|
+
static multiply(...quaternions: Quaternion_t[]): Quaternion_t;
|
|
58
|
+
static norm(quaternion: Quaternion_t): number;
|
|
59
|
+
static normalize(quaternion: Quaternion_t): Quaternion_t;
|
|
60
|
+
static rotate(q: Quaternion_t, v: Vector3_t): Vector3_t;
|
|
61
|
+
static rotX(angle: number): Quaternion_t;
|
|
62
|
+
static rotY(angle: number): Quaternion_t;
|
|
63
|
+
static rotZ(angle: number): Quaternion_t;
|
|
64
|
+
static slerp(a: Quaternion_t, b: Quaternion_t, t: number): Quaternion_t;
|
|
65
|
+
static sum(q1: Quaternion_t, q2: Quaternion_t): Quaternion_t;
|
|
66
|
+
static toMatrix3(q: Quaternion_t): Matrix3_t;
|
|
67
|
+
static toString(q: Quaternion_t): string;
|
|
68
|
+
static wxyz2xyzw(wxyz: Quaternion_t): Quaternion_t;
|
|
69
|
+
static xyzw2wxyz(xyzw: Quaternion_t): Quaternion_t;
|
|
70
|
+
|
|
71
|
+
static rotateMatlab(q: Quaternion_t, v: Vector3_t): Vector3_t;
|
|
72
|
+
static fromMatrix3Matlab(m: Matrix3_t): Quaternion_t;
|
|
14
73
|
}
|
|
15
74
|
|
|
16
|
-
export class
|
|
75
|
+
export class Vector {
|
|
76
|
+
static concat(v1: Vector_t, v2: Vector_t): Vector_t;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export class Vector3 extends Vector {
|
|
80
|
+
static cross(v1: Vector3_t, v2: Vector3_t): Vector3_t;
|
|
17
81
|
static distance(v1: Vector3_t, v2: Vector3_t): number;
|
|
82
|
+
static dot(v1: Vector3_t, v2: Vector3_t): number;
|
|
18
83
|
static multiplyScalar(v: Vector3_t, s: number): Vector3_t;
|
|
84
|
+
static norm(vector: Vector3_t): number;
|
|
85
|
+
static normalize(vector: Vector3_t): Vector3_t;
|
|
86
|
+
static sutract(v1: Vector3_t, v2: Vector3_t): Vector3_t;
|
|
87
|
+
static sum(v1: Vector3_t, v2: Vector3_t): Vector3_t;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export class Matrix {
|
|
91
|
+
static concatRow(m1: Matrix_t, m2: Matrix_t): Matrix_t;
|
|
92
|
+
static concatLine(m1: Matrix_t, m2: Matrix_t): Matrix_t;
|
|
93
|
+
static diag(arr: Vector_t): Matrix_t;
|
|
94
|
+
static inverse(m: Matrix_t): Matrix_t;
|
|
95
|
+
static multiply(m1: Matrix_t, m2: Matrix_t): Matrix_t;
|
|
96
|
+
static multiplyScalar(m: Matrix_t, s: number): Matrix_t;
|
|
97
|
+
static multiplyVector(a: Matrix_t, v: Vector_t): Matrix_t;
|
|
98
|
+
static sum(m1: Matrix_t, m2: Matrix_t): Matrix_t;
|
|
99
|
+
static transpose(m: Matrix_t): Matrix_t;
|
|
19
100
|
}
|
|
20
101
|
|
|
21
102
|
export class Matrix3 {
|
|
103
|
+
static get identity(): Matrix3_t;
|
|
104
|
+
static get zeros(): Matrix3_t;
|
|
105
|
+
|
|
106
|
+
static diag(arr: Vector3_t): Matrix3_t;
|
|
107
|
+
static inverse(q: Matrix3_t): Matrix3_t;
|
|
22
108
|
static multiply(a: Matrix3_t, b: Matrix3_t): Matrix3_t;
|
|
109
|
+
static multiplyScalar(m: Matrix3_t, s: number): Matrix3_t;
|
|
23
110
|
static multiplyVector(a: Matrix3_t, v: Vector3_t): Vector3_t;
|
|
111
|
+
static skew(v: Vector3_t): Matrix3_t;
|
|
112
|
+
static sum(m1: Matrix3_t, m2: Matrix3_t): Matrix3_t;
|
|
24
113
|
static transpose(m: Matrix3_t): Matrix3_t;
|
|
25
114
|
}
|
|
26
115
|
|
|
116
|
+
export class Matrix4 extends Matrix {
|
|
117
|
+
static get identity(): Matrix4_t;
|
|
118
|
+
|
|
119
|
+
static sum(m1: Matrix4_t, m2: Matrix4_t): Matrix4_t;
|
|
120
|
+
static subtract(m1: Matrix4_t, m2: Matrix4_t): Matrix4_t;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export class Point2 {
|
|
124
|
+
static distanceToPoint(p1: Point2_t, p2: Point2_t): number;
|
|
125
|
+
static distanceToSegment(p: Point2_t, v: Point2_t, w: Point2_t): number;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export class Polygon {
|
|
129
|
+
static distanceToOtherRectangle(poly1: Polygon_t, poly2: Polygon_t): number;
|
|
130
|
+
static distanceToPoint(polygon: Polygon_t, point: Point2_t): number;
|
|
131
|
+
static isPointInside(polygon: Polygon_t, point: Point2_t): boolean;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export class Rotations {
|
|
135
|
+
static eulerToQuaternionZXYDegrees(eulerAnglesDegrees: EulerAnglesDegrees_t): Quaternion_t;
|
|
136
|
+
static eulerToQuaternionZXY(eulerAngles: EulerAngles_t): Quaternion_t;
|
|
137
|
+
static eulerToQuaternion(eulerAngles: EulerAngles_t, order: string): Quaternion_t;
|
|
138
|
+
static getHeadingFromQuaternion(quaternion: Quaternion_t): number;
|
|
139
|
+
static quaternionToEulerZXYDegrees(quaternion: Quaternion_t): EulerAnglesDegrees_t;
|
|
140
|
+
static quaternionToEulerZXY(quaternion: Quaternion_t): EulerAngles_t;
|
|
141
|
+
static quaternionToEuler(quaternion: Quaternion_t, order: string): EulerAngles_t;
|
|
142
|
+
}
|
|
143
|
+
|
|
27
144
|
}
|
|
28
145
|
|
package/index.js
CHANGED
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.3.0-alpha.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": "d08f3459ff3cb996212da48efb454b1518c2f7fb"
|
|
30
30
|
}
|
package/src/Matrix.js
CHANGED
package/src/Matrix.spec.js
CHANGED
package/src/Matrix3.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
class Matrix3 extends Matrix {
|
|
1
|
+
class Matrix3 {
|
|
4
2
|
|
|
5
3
|
static get identity() {
|
|
6
4
|
return [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
|
|
@@ -10,7 +8,15 @@ class Matrix3 extends Matrix {
|
|
|
10
8
|
return [[0, 0, 0], [0, 0, 0], [0, 0, 0]];
|
|
11
9
|
}
|
|
12
10
|
|
|
13
|
-
static
|
|
11
|
+
static diag(arr) {
|
|
12
|
+
return [
|
|
13
|
+
[arr[0], 0, 0],
|
|
14
|
+
[0, arr[1], 0],
|
|
15
|
+
[0, 0, arr[2]]
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static sum(m1, m2) {
|
|
14
20
|
return [
|
|
15
21
|
[m1[0][0] + m2[0][0], m1[0][1] + m2[0][1], m1[0][2] + m2[0][2]],
|
|
16
22
|
[m1[1][0] + m2[1][0], m1[1][1] + m2[1][1], m1[1][2] + m2[1][2]],
|
package/src/Matrix3.spec.js
CHANGED
package/src/Matrix4.js
CHANGED
|
@@ -11,7 +11,7 @@ class Matrix4 extends Matrix {
|
|
|
11
11
|
];
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
static
|
|
14
|
+
static sum(m1, m2) {
|
|
15
15
|
return [
|
|
16
16
|
[m1[0][0] + m2[0][0], m1[0][1] + m2[0][1], m1[0][2] + m2[0][2], m1[0][3] + m2[0][3]],
|
|
17
17
|
[m1[1][0] + m2[1][0], m1[1][1] + m2[1][1], m1[1][2] + m2[1][2], m1[1][3] + m2[1][3]],
|
package/src/Matrix4.spec.js
CHANGED
package/src/Quaternion.js
CHANGED
|
@@ -18,8 +18,8 @@ class Quaternion {
|
|
|
18
18
|
return [1, 0, 0, 0];
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
static
|
|
22
|
-
return [
|
|
21
|
+
static sum(q1, q2) {
|
|
22
|
+
return [q1[0] + q2[0], q1[1] + q2[1], q1[2] + q2[2], q1[3] + q2[3]];
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// From https://www.mathworks.com/help/aerotbx/ug/quatrotate.html
|
|
@@ -38,9 +38,9 @@ class Quaternion {
|
|
|
38
38
|
const [qw, qx, qy, qz] = q;
|
|
39
39
|
const thisVec = [qx, qy, qz];
|
|
40
40
|
let uv = Vector3.cross(thisVec, v);
|
|
41
|
-
uv = Vector3.
|
|
42
|
-
const tmp1 = Vector3.
|
|
43
|
-
return Vector3.
|
|
41
|
+
uv = Vector3.sum(uv, uv);
|
|
42
|
+
const tmp1 = Vector3.sum(v, Vector3.multiplyScalar(uv, qw));
|
|
43
|
+
return Vector3.sum(tmp1, Vector3.cross(thisVec, uv));
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/**
|
package/src/Quaternion.spec.js
CHANGED
|
@@ -25,7 +25,7 @@ const angle = 1.5;
|
|
|
25
25
|
describe('Quaternion', () => {
|
|
26
26
|
|
|
27
27
|
it('add', () => {
|
|
28
|
-
const result = Quaternion.
|
|
28
|
+
const result = Quaternion.sum(q1, q2);
|
|
29
29
|
expect(result).deep.almost(
|
|
30
30
|
[0.561623207624507, 0.820007197817453, 1.078391188010398, 1.336775178203344]
|
|
31
31
|
);
|
package/src/Vector3.js
CHANGED
package/src/Vector3.spec.js
CHANGED
|
@@ -18,8 +18,8 @@ describe('Vector3', () => {
|
|
|
18
18
|
expect(result).deep.equal([1 / Math.sqrt(14), 2 / Math.sqrt(14), 3 / Math.sqrt(14)]);
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
it('
|
|
22
|
-
const result = Vector3.
|
|
21
|
+
it('sum', () => {
|
|
22
|
+
const result = Vector3.sum(v1, v1);
|
|
23
23
|
expect(result).deep.equal([2, 4, 6]);
|
|
24
24
|
});
|
|
25
25
|
|