@wemap/geo 3.1.19 → 3.1.21

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.19",
15
+ "version": "3.1.21",
16
16
  "bugs": {
17
17
  "url": "https://github.com/wemap/wemap-modules-js/issues"
18
18
  },
@@ -28,10 +28,7 @@
28
28
  "license": "ISC",
29
29
  "dependencies": {
30
30
  "@wemap/logger": "^3.0.0",
31
- "@wemap/maths": "^3.1.15",
32
- "lodash.isfinite": "^3.3.2",
33
- "lodash.isnumber": "^3.0.3",
34
- "lodash.isstring": "^4.0.1"
31
+ "@wemap/maths": "^3.1.15"
35
32
  },
36
- "gitHead": "4a4167fd2159c856b90e6a566595ae5945f92d2e"
33
+ "gitHead": "17f72afdcf6098bf90d3dffc2cf0b15f9284d4d4"
37
34
  }
package/src/Constants.js CHANGED
@@ -10,7 +10,7 @@ const Constants = {
10
10
  EPS_DEG_MM: 1e-8,
11
11
 
12
12
  /**
13
- * epsilon in meters which corresponds to q millimeter
13
+ * epsilon in meters which corresponds to 1 millimeter
14
14
  */
15
15
  EPS_MM: 1e-3
16
16
  };
package/src/Utils.js CHANGED
@@ -66,6 +66,61 @@ class Utils {
66
66
  return sampledRoute;
67
67
  }
68
68
 
69
+ /**
70
+ * Trim a route of Coordinates
71
+ * @param {Array.<Coordinates>} route ordered points
72
+ * @param {Coordinates} startPosition position where the trim starts. startPosition has to be on the route.
73
+ * @param {*} maxLength max route length
74
+ */
75
+ static trimRoute(route, startPosition = route[0], length = Number.MAX_VALUE) {
76
+
77
+ const newRoute = [];
78
+ let previousPoint;
79
+
80
+ let currentPointIndex;
81
+ let cumulativeDistance = 0;
82
+
83
+ for (currentPointIndex = 1; currentPointIndex < route.length; currentPointIndex++) {
84
+
85
+ const p1 = route[currentPointIndex - 1];
86
+ const p2 = route[currentPointIndex];
87
+
88
+ if (startPosition.equalsTo(p1)) {
89
+ newRoute.push(p1);
90
+ previousPoint = p1;
91
+ break;
92
+ }
93
+
94
+ const proj = startPosition.getSegmentProjection(p1, p2);
95
+ if (proj && proj.equalsTo(startPosition) && !proj.equalsTo(p2)) {
96
+ newRoute.push(proj);
97
+ previousPoint = proj;
98
+ break;
99
+ }
100
+ }
101
+
102
+ if (!newRoute.length) {
103
+ throw new Error('startPosition is not on the route');
104
+ }
105
+
106
+ while (currentPointIndex < route.length) {
107
+ const currentPoint = route[currentPointIndex];
108
+ const dist = previousPoint.distanceTo(currentPoint);
109
+ if (cumulativeDistance + dist >= length) {
110
+ const bearing = previousPoint.bearingTo(currentPoint);
111
+ const remainingLength = length - cumulativeDistance;
112
+ const end = previousPoint.destinationPoint(remainingLength, bearing);
113
+ newRoute.push(end);
114
+ break;
115
+ }
116
+ newRoute.push(currentPoint);
117
+ previousPoint = currentPoint;
118
+ cumulativeDistance += dist;
119
+ currentPointIndex++;
120
+ }
121
+
122
+ return newRoute;
123
+ }
69
124
  }
70
125
 
71
126
  export default Utils;
package/src/Utils.spec.js CHANGED
@@ -49,4 +49,57 @@ describe('Geo Utils', () => {
49
49
  expect(samples.length).equals(2);
50
50
 
51
51
  });
52
+
53
+ it('trimRoute', () => {
54
+
55
+ let newRoute;
56
+
57
+ const p1 = new Coordinates(45.0, 5.0);
58
+ const p2 = p1.destinationPoint(100, Math.PI / 4);
59
+ const p3 = p2.destinationPoint(49.9, Math.PI / 2);
60
+ const route = [p1, p2, p3];
61
+
62
+ expect(() => Utils.trimRoute(route, new Coordinates(0, 0))).throw(Error);
63
+
64
+ newRoute = Utils.trimRoute(route);
65
+ expect(newRoute.length).equals(3);
66
+ for (let i = 0; i < newRoute.length - 1; i++) {
67
+ expect(newRoute[i].equalsTo(route[i])).true;
68
+ }
69
+
70
+ newRoute = Utils.trimRoute(route, p1, 100);
71
+ expect(newRoute.length).equals(2);
72
+ expect(newRoute[0].equalsTo(p1)).true;
73
+ expect(newRoute[1].equalsTo(p2)).true;
74
+
75
+ newRoute = Utils.trimRoute(route, p1, 90);
76
+ expect(newRoute.length).equals(2);
77
+ expect(newRoute[0].equalsTo(p1)).true;
78
+ expect(newRoute[1].equalsTo(p1.destinationPoint(90, Math.PI / 4))).true;
79
+
80
+ newRoute = Utils.trimRoute(route, p2, 10);
81
+ expect(newRoute.length).equals(2);
82
+ expect(newRoute[0].equalsTo(p2)).true;
83
+ expect(newRoute[1].equalsTo(p2.destinationPoint(10, Math.PI / 2))).true;
84
+
85
+ const p4 = p1.destinationPoint(20, Math.PI / 4);
86
+ newRoute = Utils.trimRoute(route, p4);
87
+ expect(newRoute.length).equals(3);
88
+ expect(newRoute[0].equalsTo(p4)).true;
89
+ expect(newRoute[1].equalsTo(p2)).true;
90
+ expect(newRoute[2].equalsTo(p3)).true;
91
+
92
+ const p5 = p2.destinationPoint(20, Math.PI / 2);
93
+ newRoute = Utils.trimRoute(route, p4, 100);
94
+ expect(newRoute.length).equals(3);
95
+ expect(newRoute[0].equalsTo(p4)).true;
96
+ expect(newRoute[1].equalsTo(p2)).true;
97
+ expect(newRoute[2].equalsTo(p5)).true;
98
+
99
+ newRoute = Utils.trimRoute(route, p4, 200);
100
+ expect(newRoute.length).equals(3);
101
+ expect(newRoute[0].equalsTo(p4)).true;
102
+ expect(newRoute[1].equalsTo(p2)).true;
103
+ expect(newRoute[2].equalsTo(p3)).true;
104
+ });
52
105
  });
@@ -1,6 +1,4 @@
1
1
  import Coordinates from './Coordinates';
2
- import isNumber from 'lodash.isnumber';
3
- import isFinite from 'lodash.isfinite';
4
2
 
5
3
  class BoundingBox {
6
4
 
@@ -86,11 +84,11 @@ class BoundingBox {
86
84
  /**
87
85
  * This method extends the bounding box with a value in meters
88
86
  * /*\ This method is not precise as distance differs in function of latitude
89
- * @param {Number} measure in meters
87
+ * @param {!number} measure in meters
90
88
  */
91
89
  extendsWithMeasure(measure) {
92
90
 
93
- if (!isNumber(measure) || !isFinite(measure)) {
91
+ if (typeof measure !== 'number') {
94
92
  throw new Error('measure is not a number');
95
93
  }
96
94
 
@@ -2,8 +2,6 @@ import {
2
2
  Utils, Vector3, Quaternion, rad2deg
3
3
  } from '@wemap/maths';
4
4
  import Constants from '../Constants';
5
- import isNumber from 'lodash.isnumber';
6
- import isFinite from 'lodash.isfinite';
7
5
  import Level from './Level';
8
6
 
9
7
  /**
@@ -48,7 +46,7 @@ class Coordinates {
48
46
  }
49
47
 
50
48
  set lat(lat) {
51
- if (isNumber(lat) && Math.abs(lat) <= 90) {
49
+ if (typeof lat === 'number' && Math.abs(lat) <= 90) {
52
50
  this._lat = lat;
53
51
  } else {
54
52
  throw new Error('lat argument is not in [-90; 90]');
@@ -57,7 +55,7 @@ class Coordinates {
57
55
  }
58
56
 
59
57
  set lng(lng) {
60
- if (isNumber(lng)) {
58
+ if (typeof lng === 'number') {
61
59
  this._lng = lng;
62
60
  if (Math.abs(lng) >= 180) {
63
61
  // from https://stackoverflow.com/a/2323034/2239938
@@ -74,7 +72,7 @@ class Coordinates {
74
72
  }
75
73
 
76
74
  set alt(alt) {
77
- if (isNumber(alt) && isFinite(alt)) {
75
+ if (typeof alt === 'number') {
78
76
  this._alt = alt;
79
77
  } else {
80
78
  if (typeof alt !== 'undefined' && alt !== null) {
@@ -162,7 +160,7 @@ class Coordinates {
162
160
  this.lat = Utils.rad2deg(phi2);
163
161
  this.lng = Utils.rad2deg(lambda2);
164
162
 
165
- if (isNumber(elevation) && isFinite(elevation)) {
163
+ if (typeof elevation === 'number') {
166
164
  if (this.alt === null) {
167
165
  throw new Error('Point altitude is not defined');
168
166
  }
@@ -23,7 +23,6 @@ describe('Coordinates', () => {
23
23
  expect(() => new Coordinates(45, 5, false)).throw(Error);
24
24
  expect(() => new Coordinates(45, 5, null)).not.throw(Error);
25
25
  expect(() => new Coordinates(45, 5, 0)).not.throw(Error);
26
- expect(() => new Coordinates(45, 5, Number.POSITIVE_INFINITY)).throw(Error);
27
26
 
28
27
  expect(() => new Coordinates(45, 5, null, null)).not.throw(Error);
29
28
  expect(() => new Coordinates(45, 5, null, true)).throw(Error);
@@ -1,6 +1,4 @@
1
1
  import Logger from '@wemap/logger';
2
- import isFinite from 'lodash.isfinite';
3
- import isString from 'lodash.isstring';
4
2
 
5
3
  /**
6
4
  * A Level is the representation of a building floor number
@@ -13,14 +11,14 @@ class Level {
13
11
  * Level constructor
14
12
  * 1 argument: level is not a range and first argument is the level
15
13
  * 2 arguments: level is a range
16
- * @param {Number} arg1 if arg2: low value, otherwise: level
17
- * @param {Number} arg2 (optional) up value
14
+ * @param {number} arg1 if arg2: low value, otherwise: level
15
+ * @param {number} arg2 (optional) up value
18
16
  */
19
17
  constructor(arg1, arg2) {
20
- if (!isFinite(arg1)) {
18
+ if (typeof arg1 !== 'number' || isNaN(arg1)) {
21
19
  throw new Error('first argument is mandatory');
22
20
  }
23
- if (isFinite(arg2)) {
21
+ if (typeof arg2 === 'number' && !isNaN(arg2)) {
24
22
  if (arg1 === arg2) {
25
23
  this.isRange = false;
26
24
  this.val = arg1;
@@ -46,24 +44,22 @@ class Level {
46
44
 
47
45
  /**
48
46
  * Create a level from a string
49
- * @param {*} str level in str format (eg. 1, -2, 1;2, -2;3, 2;-1, 0.5;1 ...)
47
+ * @param {string} str level in str format (eg. 1, -2, 1;2, -2;3, 2;-1, 0.5;1 ...)
50
48
  */
51
49
  static fromString(str) {
52
50
 
53
- if (!isString(str)) {
51
+ if (typeof str !== 'string') {
54
52
  return null;
55
53
  }
56
54
 
57
55
  if (!isNaN(Number(str))) {
58
- return new Level(Number(str));
56
+ return new Level(parseFloat(str));
59
57
  }
60
58
 
61
59
  const splited = str.split(';');
62
60
  if (splited.length === 2) {
63
- const num1 = Number(splited[0]);
64
- const num2 = Number(splited[1]);
65
- if (!isNaN(num1) && !isNaN(num2)) {
66
- return new Level(num1, num2);
61
+ if (!isNaN(Number(splited[0])) && !isNaN(Number(splited[1]))) {
62
+ return new Level(parseFloat(splited[0]), parseFloat(splited[1]));
67
63
  }
68
64
  }
69
65
 
@@ -1,6 +1,3 @@
1
- import isNumber from 'lodash.isnumber';
2
- import isFinite from 'lodash.isfinite';
3
-
4
1
  import Constants from '../Constants';
5
2
 
6
3
  class RelativePosition {
@@ -26,7 +23,7 @@ class RelativePosition {
26
23
  }
27
24
 
28
25
  set x(x) {
29
- if (isNumber(x) && isFinite(x)) {
26
+ if (typeof x === 'number') {
30
27
  this._x = x;
31
28
  } else if (typeof x !== 'undefined' && x !== null) {
32
29
  throw new Error('x argument is not a number');
@@ -38,7 +35,7 @@ class RelativePosition {
38
35
  }
39
36
 
40
37
  set y(y) {
41
- if (isNumber(y) && isFinite(y)) {
38
+ if (typeof y === 'number') {
42
39
  this._y = y;
43
40
  } else if (typeof y !== 'undefined' && y !== null) {
44
41
  throw new Error('y argument is not a number');
@@ -50,7 +47,7 @@ class RelativePosition {
50
47
  }
51
48
 
52
49
  set z(z) {
53
- if (isNumber(z) && isFinite(z)) {
50
+ if (typeof z === 'number') {
54
51
  this._z = z;
55
52
  } else if (typeof z !== 'undefined' && z !== null) {
56
53
  throw new Error('z argument is not a number');
@@ -62,7 +59,7 @@ class RelativePosition {
62
59
  }
63
60
 
64
61
  set time(time) {
65
- if (isNumber(time) && isFinite(time)) {
62
+ if (typeof time === 'number') {
66
63
  this._time = time;
67
64
  } else {
68
65
  if (typeof time !== 'undefined' && time !== null) {
@@ -78,7 +75,7 @@ class RelativePosition {
78
75
  }
79
76
 
80
77
  set accuracy(accuracy) {
81
- if (isNumber(accuracy) && isFinite(accuracy) && accuracy >= 0) {
78
+ if (typeof accuracy === 'number' && accuracy >= 0) {
82
79
  this._accuracy = accuracy;
83
80
  } else {
84
81
  if (typeof accuracy !== 'undefined' && accuracy !== null) {
@@ -94,7 +91,7 @@ class RelativePosition {
94
91
  }
95
92
 
96
93
  set bearing(bearing) {
97
- if (isNumber(bearing) && isFinite(bearing)) {
94
+ if (typeof bearing === 'number') {
98
95
  this._bearing = bearing % (2 * Math.PI);
99
96
  } else {
100
97
  if (typeof bearing !== 'undefined' && bearing !== null) {
@@ -1,6 +1,3 @@
1
- import isNumber from 'lodash.isnumber';
2
- import isFinite from 'lodash.isfinite';
3
-
4
1
  import Coordinates from './Coordinates';
5
2
  import Constants from '../Constants';
6
3
 
@@ -25,7 +22,7 @@ class UserPosition extends Coordinates {
25
22
  }
26
23
 
27
24
  set time(time) {
28
- if (isNumber(time) && isFinite(time)) {
25
+ if (typeof time === 'number') {
29
26
  this._time = time;
30
27
  } else {
31
28
  if (typeof time !== 'undefined' && time !== null) {
@@ -41,7 +38,7 @@ class UserPosition extends Coordinates {
41
38
  }
42
39
 
43
40
  set accuracy(accuracy) {
44
- if (isNumber(accuracy) && isFinite(accuracy) && accuracy >= 0) {
41
+ if (typeof accuracy === 'number' && accuracy >= 0) {
45
42
  this._accuracy = accuracy;
46
43
  } else {
47
44
  if (typeof accuracy !== 'undefined' && accuracy !== null) {
@@ -57,7 +54,7 @@ class UserPosition extends Coordinates {
57
54
  }
58
55
 
59
56
  set bearing(bearing) {
60
- if (isNumber(bearing) && isFinite(bearing)) {
57
+ if (typeof bearing === 'number') {
61
58
  this._bearing = bearing % (2 * Math.PI);
62
59
  } else {
63
60
  if (typeof bearing !== 'undefined' && bearing !== null) {
@@ -24,13 +24,11 @@ describe('UserPosition', () => {
24
24
  expect(() => new UserPosition(45, 5, null, null, 0)).not.throw(Error);
25
25
  expect(() => new UserPosition(45, 5, null, null, 10)).not.throw(Error);
26
26
  expect(() => new UserPosition(45, 5, null, null, -10)).not.throw(Error);
27
- expect(() => new UserPosition(45, 5, null, null, Number.POSITIVE_INFINITY)).throw(Error);
28
27
 
29
28
  expect(() => new UserPosition(45, 5, null, null, null, null)).not.throw(Error);
30
29
  expect(() => new UserPosition(45, 5, null, null, null, 0)).not.throw(Error);
31
30
  expect(() => new UserPosition(45, 5, null, null, null, 10)).not.throw(Error);
32
31
  expect(() => new UserPosition(45, 5, null, null, null, -10)).throw(Error);
33
- expect(() => new UserPosition(45, 5, null, null, null, Number.POSITIVE_INFINITY)).throw(Error);
34
32
 
35
33
  expect(() => new UserPosition(45, 5, null, null, null,
36
34
  null, null)).not.throw(Error);
@@ -40,8 +38,6 @@ describe('UserPosition', () => {
40
38
  null, 10)).not.throw(Error);
41
39
  expect(() => new UserPosition(45, 5, null, null, null,
42
40
  null, -10)).not.throw(Error);
43
- expect(() => new UserPosition(45, 5, null, null, null,
44
- null, Number.POSITIVE_INFINITY)).throw(Error);
45
41
 
46
42
  const position = new UserPosition(45, 5, 0, new Level(2), 123456, 10, Math.PI, 'foo');
47
43
  expect(position.lat).equals(45);
@@ -1,6 +1,3 @@
1
- import isNumber from 'lodash.isnumber';
2
- import isFinite from 'lodash.isfinite';
3
-
4
1
  import { Quaternion } from '@wemap/maths';
5
2
  import Attitude from './Attitude';
6
3
 
@@ -33,7 +30,7 @@ class AbsoluteHeading {
33
30
  * @param {Number} heading
34
31
  */
35
32
  set heading(heading) {
36
- if (isNumber(heading) && isFinite(heading)) {
33
+ if (typeof heading === 'number') {
37
34
  this._heading = heading;
38
35
  } else {
39
36
  throw new Error('heading argument is not a number');
@@ -51,7 +48,7 @@ class AbsoluteHeading {
51
48
  * @param {Number} time
52
49
  */
53
50
  set time(time) {
54
- if (isNumber(time) && isFinite(time)) {
51
+ if (typeof time === 'number') {
55
52
  this._time = time;
56
53
  } else {
57
54
  if (typeof time !== 'undefined' && time !== null) {
@@ -72,7 +69,7 @@ class AbsoluteHeading {
72
69
  * @param {Number} accuracy
73
70
  */
74
71
  set accuracy(accuracy) {
75
- if (isNumber(accuracy) && accuracy >= 0 && accuracy <= Math.PI) {
72
+ if (typeof accuracy === 'number' && accuracy >= 0 && accuracy <= Math.PI) {
76
73
  this._accuracy = accuracy;
77
74
  } else {
78
75
  if (typeof accuracy !== 'undefined' && accuracy !== null) {
@@ -1,6 +1,3 @@
1
- import isNumber from 'lodash.isnumber';
2
- import isFinite from 'lodash.isfinite';
3
-
4
1
  import {
5
2
  Rotations, Quaternion, rad2deg, deg2rad
6
3
  } from '@wemap/maths';
@@ -61,7 +58,7 @@ class Attitude {
61
58
  * @param {Number} time
62
59
  */
63
60
  set time(time) {
64
- if (isNumber(time) && isFinite(time)) {
61
+ if (typeof time === 'number') {
65
62
  this._time = time;
66
63
  } else {
67
64
  if (typeof time !== 'undefined' && time !== null) {
@@ -82,7 +79,7 @@ class Attitude {
82
79
  * @param {Number} accuracy
83
80
  */
84
81
  set accuracy(accuracy) {
85
- if (isNumber(accuracy) && accuracy >= 0 && accuracy <= Math.PI) {
82
+ if (typeof accuracy === 'number' && accuracy >= 0 && accuracy <= Math.PI) {
86
83
  this._accuracy = accuracy;
87
84
  } else {
88
85
  if (typeof accuracy !== 'undefined' && accuracy !== null) {
@@ -103,7 +103,6 @@ describe('Attitude', () => {
103
103
  expect(() => new Attitude([1, 0, 0, 0], false)).throw(Error);
104
104
  expect(() => new Attitude([1, 0, 0, 0], true)).throw(Error);
105
105
  expect(() => new Attitude([1, 0, 0, 0], null)).not.throw(Error);
106
- expect(() => new Attitude([1, 0, 0, 0], Number.POSITIVE_INFINITY)).throw(Error);
107
106
 
108
107
  expect(() => new Attitude([1, 0, 0, 0], 10, deg2rad(10))).not.throw(Error);
109
108
  expect(() => new Attitude([1, 0, 0, 0], 10, -1)).throw(Error);