@wemap/geo 3.1.11 → 3.1.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/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/geo"
13
13
  },
14
14
  "name": "@wemap/geo",
15
- "version": "3.1.11",
15
+ "version": "3.1.15",
16
16
  "bugs": {
17
17
  "url": "https://github.com/wemap/wemap-modules-js/issues"
18
18
  },
@@ -28,10 +28,10 @@
28
28
  "license": "ISC",
29
29
  "dependencies": {
30
30
  "@wemap/logger": "^3.0.0",
31
- "@wemap/maths": "^3.1.11",
31
+ "@wemap/maths": "^3.1.15",
32
32
  "lodash.isfinite": "^3.3.2",
33
33
  "lodash.isnumber": "^3.0.3",
34
34
  "lodash.isstring": "^4.0.1"
35
35
  },
36
- "gitHead": "1e72b637bcc6e4d378bdb7c93870228636bdcb35"
36
+ "gitHead": "44d9ad40afa3e6522a01bc86891082a753199f9a"
37
37
  }
@@ -3,11 +3,84 @@ import chai from 'chai';
3
3
  import chaiAlmost from 'chai-almost';
4
4
 
5
5
  import Attitude from './Attitude';
6
- import { deg2rad } from '@wemap/maths';
6
+ import {
7
+ deg2rad, Quaternion, Utils
8
+ } from '@wemap/maths';
7
9
 
8
10
  const expect = chai.expect;
9
11
  chai.use(chaiAlmost());
10
12
 
13
+
14
+ const checkAngles = (val, expected, range = [-Math.PI, Math.PI]) => {
15
+ expect(Utils.diffAngle(val, expected)).almost.equal(0);
16
+ expect(val).least(range[0]);
17
+ expect(val).most(range[1]);
18
+ };
19
+
20
+
21
+ const LAYED_PORTRAIT_NORTH = Quaternion.identity;
22
+ const LAYED_PORTRAIT_EAST = Quaternion.fromAxisAngle([0, 0, 1], - Math.PI / 2);
23
+ const LAYED_PORTRAIT_SOUTH = Quaternion.fromAxisAngle([0, 0, 1], Math.PI);
24
+ const LAYED_PORTRAIT_WEST = Quaternion.fromAxisAngle([0, 0, 1], Math.PI / 2);
25
+
26
+ const STAND_PORTRAIT_NORTH = Quaternion.multiply(
27
+ LAYED_PORTRAIT_NORTH,
28
+ Quaternion.fromAxisAngle([1, 0, 0], Math.PI / 2)
29
+ );
30
+ const STAND_PORTRAIT_EAST = Quaternion.multiply(
31
+ LAYED_PORTRAIT_EAST,
32
+ Quaternion.fromAxisAngle([1, 0, 0], Math.PI / 2)
33
+ );
34
+ const STAND_PORTRAIT_SOUTH = Quaternion.multiply(
35
+ LAYED_PORTRAIT_SOUTH,
36
+ Quaternion.fromAxisAngle([1, 0, 0], Math.PI / 2)
37
+ );
38
+ const STAND_PORTRAIT_WEST = Quaternion.multiply(
39
+ LAYED_PORTRAIT_WEST,
40
+ Quaternion.fromAxisAngle([1, 0, 0], Math.PI / 2)
41
+ );
42
+
43
+ const STAND_PORTRAIT_NORTH_SKY = Quaternion.multiply(
44
+ STAND_PORTRAIT_NORTH,
45
+ Quaternion.fromAxisAngle([1, 0, 0], 3 * Math.PI / 8)
46
+ );
47
+ const STAND_PORTRAIT_EAST_SKY = Quaternion.multiply(
48
+ STAND_PORTRAIT_EAST,
49
+ Quaternion.fromAxisAngle([1, 0, 0], 3 * Math.PI / 8)
50
+ );
51
+ const STAND_PORTRAIT_SOUTH_SKY = Quaternion.multiply(
52
+ STAND_PORTRAIT_SOUTH,
53
+ Quaternion.fromAxisAngle([1, 0, 0], 3 * Math.PI / 8)
54
+ );
55
+ const STAND_PORTRAIT_WEST_SKY = Quaternion.multiply(
56
+ STAND_PORTRAIT_WEST,
57
+ Quaternion.fromAxisAngle([1, 0, 0], 3 * Math.PI / 8)
58
+ );
59
+
60
+
61
+ // Landscape = Top to the left
62
+ const LAYED_LANDSCAPE_NORTH = Quaternion.fromAxisAngle([0, 0, 1], Math.PI / 2);
63
+ const LAYED_LANDSCAPE_EAST = [1, 0, 0, 0];
64
+ const LAYED_LANDSCAPE_SOUTH = Quaternion.fromAxisAngle([0, 0, 1], -Math.PI / 2);
65
+ const LAYED_LANDSCAPE_WEST = Quaternion.fromAxisAngle([0, 0, 1], Math.PI);
66
+
67
+ const STAND_LANDSCAPE_NORTH = Quaternion.multiply(
68
+ LAYED_LANDSCAPE_NORTH,
69
+ Quaternion.fromAxisAngle([0, 1, 0], -Math.PI / 2)
70
+ );
71
+ const STAND_LANDSCAPE_EAST = Quaternion.multiply(
72
+ LAYED_LANDSCAPE_EAST,
73
+ Quaternion.fromAxisAngle([0, 1, 0], -Math.PI / 2)
74
+ );
75
+ const STAND_LANDSCAPE_SOUTH = Quaternion.multiply(
76
+ LAYED_LANDSCAPE_SOUTH,
77
+ Quaternion.fromAxisAngle([0, 1, 0], -Math.PI / 2)
78
+ );
79
+ const STAND_LANDSCAPE_WEST = Quaternion.multiply(
80
+ LAYED_LANDSCAPE_WEST,
81
+ Quaternion.fromAxisAngle([0, 1, 0], -Math.PI / 2)
82
+ );
83
+
11
84
  describe('Attitude', () => {
12
85
 
13
86
  it('creation', () => {
@@ -75,21 +148,40 @@ describe('Attitude', () => {
75
148
  });
76
149
 
77
150
  it('heading', () => {
78
- const attitude = new Attitude([1, 0, 0, 0]);
79
- expect(attitude.heading).equals(0);
80
- expect(attitude.heading).equals(0);
151
+ checkAngles(new Attitude(LAYED_PORTRAIT_NORTH).heading, 0);
152
+ checkAngles(new Attitude(STAND_PORTRAIT_NORTH).heading, 0);
153
+ checkAngles(new Attitude(STAND_PORTRAIT_NORTH_SKY).heading, 0);
154
+
155
+ checkAngles(new Attitude(LAYED_PORTRAIT_EAST).heading, Math.PI / 2);
156
+ checkAngles(new Attitude(STAND_PORTRAIT_EAST).heading, Math.PI / 2);
157
+ checkAngles(new Attitude(STAND_PORTRAIT_EAST_SKY).heading, Math.PI / 2);
158
+
159
+ checkAngles(new Attitude(LAYED_PORTRAIT_SOUTH).heading, Math.PI);
160
+ checkAngles(new Attitude(STAND_PORTRAIT_SOUTH).heading, Math.PI);
161
+ checkAngles(new Attitude(STAND_PORTRAIT_SOUTH_SKY).heading, Math.PI);
162
+
163
+ checkAngles(new Attitude(LAYED_PORTRAIT_WEST).heading, -Math.PI / 2);
164
+ checkAngles(new Attitude(STAND_PORTRAIT_WEST).heading, -Math.PI / 2);
165
+ checkAngles(new Attitude(STAND_PORTRAIT_WEST_SKY).heading, -Math.PI / 2);
81
166
 
82
- expect(new Attitude([Math.sqrt(2) / 2, Math.sqrt(2) / 2, 0, 0]).heading).equals(0);
83
- expect(new Attitude([-0.5, 0.5, 0.5, 0.5]).heading).equals(Math.PI / 2);
84
167
 
85
168
  const tmpWindow = global.window;
86
169
  global.window = { orientation: 90 };
87
- expect(new Attitude([1, 0, 0, 0]).heading).equals(Math.PI / 2);
88
- expect(new Attitude([Math.sqrt(2) / 2, Math.sqrt(2) / 2, 0, 0]).heading).equals(Math.PI / 2);
89
- expect(new Attitude([-0.5, 0.5, 0.5, 0.5]).heading).equals(Math.PI);
170
+
171
+ checkAngles(new Attitude(LAYED_LANDSCAPE_NORTH).heading, 0);
172
+ checkAngles(new Attitude(STAND_LANDSCAPE_NORTH).heading, 0);
173
+
174
+ checkAngles(new Attitude(LAYED_LANDSCAPE_EAST).heading, Math.PI / 2);
175
+ checkAngles(new Attitude(STAND_LANDSCAPE_EAST).heading, Math.PI / 2);
176
+
177
+ checkAngles(new Attitude(LAYED_LANDSCAPE_SOUTH).heading, Math.PI);
178
+ checkAngles(new Attitude(STAND_LANDSCAPE_SOUTH).heading, Math.PI);
179
+
180
+ checkAngles(new Attitude(LAYED_LANDSCAPE_WEST).heading, -Math.PI / 2);
181
+ checkAngles(new Attitude(STAND_LANDSCAPE_WEST).heading, -Math.PI / 2);
182
+
90
183
  global.window = tmpWindow;
91
184
 
92
- expect(new Attitude([-0.5, 0.5, 0.5, 0.5]).headingDegrees).equals(90);
93
185
  });
94
186
 
95
187
  it('equalsTo', () => {