@wemap/geo 0.1.1 → 0.1.3

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
@@ -1,3 +1,4 @@
1
+ import Attitude from './src/rotations/Attitude';
1
2
  import Constants from './src/Constants';
2
3
  import Edge from './src/graph/Edge';
3
4
  import Itinerary from './src/graph/Itinerary';
@@ -7,6 +8,7 @@ import WGS84 from './src/coordinates/WGS84';
7
8
  import WGS84UserPosition from './src/coordinates/WGS84UserPosition';
8
9
 
9
10
  export {
11
+ Attitude,
10
12
  Constants,
11
13
  Edge,
12
14
  Itinerary,
package/package.json CHANGED
@@ -1,26 +1,30 @@
1
1
  {
2
2
  "author": "Wemap",
3
3
  "contributors": [
4
- {
5
- "name": "Thibaud Michel",
6
- "email": "thibaud@getwemap.com"
7
- },
8
- {
9
- "name": "Guillaume Pannetier",
10
- "email": "guillaume.pannetier@getwemap.com"
11
- }
4
+ "Thibaud Michel <thibaud@getwemap.com>",
5
+ "Guillaume Pannetier <guillaume.pannetier@getwemap.com>"
12
6
  ],
13
- "description": "A package using different geoloc systems",
14
- "dependencies": {
15
- "@wemap/maths": "latest"
16
- },
7
+ "description": "Wemap geo utils package",
8
+ "main": "index.js",
17
9
  "repository": {
18
10
  "type": "git",
19
- "url": "https://github.com/wemap/wemap-utils-js.git",
11
+ "url": "git+https://github.com/wemap/wemap-utils-js.git",
20
12
  "directory": "packages/geo"
21
13
  },
22
- "main": "index.js",
23
14
  "name": "@wemap/geo",
24
- "version": "0.1.1",
25
- "gitHead": "00ed0bae7da0086bb47d6e958343fd2020bac2b1"
15
+ "version": "0.1.3",
16
+ "bugs": {
17
+ "url": "https://github.com/wemap/wemap-utils-js/issues"
18
+ },
19
+ "homepage": "https://github.com/wemap/wemap-utils-js#readme",
20
+ "scripts": {
21
+ "test": "mocha -r esm \\\"src/**/*.spec.js\\\""
22
+ },
23
+ "keywords": [
24
+ "utils",
25
+ "geo",
26
+ "wemap"
27
+ ],
28
+ "license": "ISC",
29
+ "gitHead": "ef6adedf5dcc796a359fab0e9e8e92b233ded1be"
26
30
  }
@@ -0,0 +1,65 @@
1
+ import {
2
+ Rotations, Utils as MathUtils, Quaternion
3
+ } from '@wemap/maths';
4
+
5
+ const rotxM90 = Quaternion.fromAxisAngle([1, 0, 0], -Math.PI / 2);
6
+
7
+ class Attitude {
8
+
9
+ quaternion = [1, 0, 0, 0];
10
+ quaternionThreeJsV = null;
11
+ headingV = null;
12
+ headingDegreesV = null;
13
+ eulerAnglesV = null;
14
+ eulerAnglesDegreesV = null;
15
+
16
+ constructor(quaternion) {
17
+ this.quaternion = quaternion;
18
+ }
19
+
20
+ get eulerAngles() {
21
+ if (!this.eulerAnglesV) {
22
+ this.eulerAnglesV = Rotations.quaternionToEulerZXY(this.quaternion);
23
+ }
24
+ return this.eulerAnglesV;
25
+ }
26
+
27
+ get eulerAnglesDegrees() {
28
+ if (!this.eulerAnglesDegreesV) {
29
+ this.eulerAnglesDegreesV = Rotations.quaternionToEulerZXYDegrees(this.quaternion);
30
+ }
31
+ return this.eulerAnglesDegreesV;
32
+ }
33
+
34
+ get heading() {
35
+ if (!this.headingV) {
36
+ this.headingV = Rotations.getHeadingFromQuaternion(this.quaternion) + MathUtils.deg2rad(window.orientation || 0);
37
+ }
38
+ return this.headingV;
39
+ }
40
+
41
+ get headingDegrees() {
42
+ if (!this.headingDegreesV) {
43
+ this.headingDegreesV = MathUtils.rad2deg(Rotations.getHeadingFromQuaternion(this.quaternion)) + (window.orientation || 0);
44
+ }
45
+ return this.headingDegreesV;
46
+ }
47
+
48
+ get quaternionThreeJs() {
49
+ if (!this.quaternionThreeJsV) {
50
+ this.quaternionThreeJsV = Quaternion.wxyz2xyzw(Quaternion.multiply(rotxM90, this.quaternion));
51
+ }
52
+ return this.quaternionThreeJsV;
53
+ }
54
+
55
+ toMessage() {
56
+ return this.quaternion;
57
+ }
58
+
59
+ static fromMessage(message) {
60
+ return new Attitude(message);
61
+ }
62
+
63
+ }
64
+
65
+ export default Attitude;