@wemap/positioning 2.4.5 → 2.4.6

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
@@ -8,10 +8,10 @@
8
8
  "Guillaume Pannetier <guillaume.pannetier@getwemap.com>"
9
9
  ],
10
10
  "dependencies": {
11
- "@wemap/geo": "^0.3.6",
11
+ "@wemap/geo": "^0.3.7",
12
12
  "@wemap/logger": "^0.1.6",
13
13
  "@wemap/maths": "^0.2.1",
14
- "@wemap/osm": "^0.2.8",
14
+ "@wemap/osm": "^0.2.9",
15
15
  "@wemap/utils": "^0.1.2",
16
16
  "geomagnetism": "^0.1.0",
17
17
  "lodash.isempty": "^4.4.0",
@@ -80,5 +80,5 @@
80
80
  "lint": "eslint --ext .js,.jsx --quiet src",
81
81
  "test": "mocha -r esm \"src/**/*.spec.js\""
82
82
  },
83
- "version": "2.4.5"
83
+ "version": "2.4.6"
84
84
  }
@@ -1,6 +1,5 @@
1
- /* eslint-disable max-statements */
1
+ /* eslint max-statements: ["error", 27]*/
2
2
  import { WGS84UserPosition } from '@wemap/geo';
3
- import { rad2deg } from '@wemap/maths';
4
3
 
5
4
  // Generated positions by second
6
5
  const GEN_FREQUENCY = 60;
@@ -18,49 +17,50 @@ class Smoother {
18
17
  /**
19
18
  * Calculate smoothed positions for the next milliseconds given a new position
20
19
  */
21
- generateNextPositions(newPosition, flyby = false) {
20
+ generateNextPositions(_newPosition, flyby = false) {
22
21
 
23
- if (!(newPosition instanceof WGS84UserPosition)) {
22
+ if (!(_newPosition instanceof WGS84UserPosition)) {
24
23
  throw new TypeError('newPosition is not instance of WGS84UserPosition');
25
24
  }
26
25
 
26
+ const newPosition = _newPosition.clone();
27
27
  if (!newPosition.hasOwnProperty('time')) {
28
28
  throw new Error('newPosition does not have time property');
29
29
  }
30
30
 
31
- if (this.previousPosition) {
31
+ if (!this.previousPosition) {
32
+ this.previousPosition = newPosition;
33
+ this.positionsQueue.push(this.previousPosition);
34
+ return;
35
+ }
32
36
 
33
- const distance = this.previousPosition.distanceTo(newPosition);
34
- const azimuth = this.previousPosition.bearingTo(newPosition);
37
+ const distance = this.previousPosition.distanceTo(newPosition);
38
+ const azimuth = this.previousPosition.bearingTo(newPosition);
35
39
 
36
- let refTimestamp = newPosition.time;
40
+ let refTimestamp = newPosition.time;
37
41
 
38
- const queueLength = this.positionsQueue.length;
39
- if (queueLength) {
40
- refTimestamp = Math.max(refTimestamp, this.positionsQueue[queueLength - 1].time);
41
- }
42
+ const queueLength = this.positionsQueue.length;
43
+ if (queueLength) {
44
+ refTimestamp = Math.max(refTimestamp, this.positionsQueue[queueLength - 1].time);
45
+ }
42
46
 
43
- let diffTime = newPosition.time - this.previousPosition.time;
47
+ let diffTime = newPosition.time - this.previousPosition.time;
44
48
 
45
- if (flyby) {
46
- diffTime = MAX_FLYBY_TIME;
47
- }
49
+ if (flyby) {
50
+ diffTime = MAX_FLYBY_TIME;
51
+ }
48
52
 
49
- const nSamples = GEN_FREQUENCY * Math.min(Math.max(MIN_FLYBY_TIME, diffTime), MAX_FLYBY_TIME);
53
+ const nSamples = GEN_FREQUENCY * Math.min(Math.max(MIN_FLYBY_TIME, diffTime), MAX_FLYBY_TIME);
50
54
 
51
- let i = 1;
52
- while (i < nSamples) {
53
- i = Math.min(i, nSamples);
54
- const smoothedPosition = this.previousPosition.destinationPoint(distance * i / nSamples, azimuth);
55
- smoothedPosition.time = refTimestamp + (i - 1) / GEN_FREQUENCY;
56
- smoothedPosition.bearing = rad2deg(azimuth);
57
- this.positionsQueue.push(smoothedPosition);
58
- i++;
59
- }
60
- newPosition.bearing = rad2deg(azimuth);
55
+ let i = 1;
56
+ while (i < nSamples + 1) {
57
+ i = Math.min(i, nSamples);
58
+ const smoothedPosition = this.previousPosition.destinationPoint(distance * i / nSamples, azimuth);
59
+ smoothedPosition.time = refTimestamp + (i - 1) / GEN_FREQUENCY;
60
+ this.positionsQueue.push(smoothedPosition);
61
+ i++;
61
62
  }
62
63
 
63
- this.positionsQueue.push(newPosition);
64
64
  this.previousPosition = newPosition;
65
65
  }
66
66