@wemap/geo 2.7.9 → 3.0.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.js +10 -4
- package/package.json +4 -4
- package/src/Utils.js +3 -3
- package/src/Utils.spec.js +5 -5
- package/src/coordinates/BoundingBox.js +17 -17
- package/src/coordinates/BoundingBox.spec.js +38 -38
- package/src/coordinates/{WGS84.js → Coordinates.js} +16 -16
- package/src/coordinates/Coordinates.spec.js +268 -0
- package/src/coordinates/GeoRelativePosition.js +9 -0
- package/src/coordinates/RelativePosition.js +166 -0
- package/src/coordinates/{WGS84UserPosition.js → UserPosition.js} +18 -42
- package/src/coordinates/UserPosition.spec.js +220 -0
- package/src/rotations/AbsoluteHeading.js +138 -0
- package/src/rotations/Attitude.js +64 -1
- package/src/rotations/Attitude.spec.js +38 -0
- package/src/coordinates/WGS84.spec.js +0 -268
- package/src/coordinates/WGS84UserPosition.spec.js +0 -247
package/index.js
CHANGED
|
@@ -2,18 +2,24 @@ import Constants from './src/Constants';
|
|
|
2
2
|
import Utils from './src/Utils';
|
|
3
3
|
|
|
4
4
|
import Attitude from './src/rotations/Attitude';
|
|
5
|
+
import AbsoluteHeading from './src/rotations/AbsoluteHeading';
|
|
5
6
|
|
|
6
7
|
import BoundingBox from './src/coordinates/BoundingBox';
|
|
8
|
+
import GeoRelativePosition from './src/coordinates/GeoRelativePosition';
|
|
7
9
|
import Level from './src/coordinates/Level';
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
+
import RelativePosition from './src/coordinates/RelativePosition';
|
|
11
|
+
import Coordinates from './src/coordinates/Coordinates';
|
|
12
|
+
import UserPosition from './src/coordinates/UserPosition';
|
|
10
13
|
|
|
11
14
|
export {
|
|
15
|
+
AbsoluteHeading,
|
|
12
16
|
Attitude,
|
|
13
17
|
BoundingBox,
|
|
14
18
|
Constants,
|
|
19
|
+
GeoRelativePosition,
|
|
15
20
|
Level,
|
|
21
|
+
RelativePosition,
|
|
16
22
|
Utils,
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
Coordinates,
|
|
24
|
+
UserPosition
|
|
19
25
|
};
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"directory": "packages/geo"
|
|
13
13
|
},
|
|
14
14
|
"name": "@wemap/geo",
|
|
15
|
-
"version": "
|
|
15
|
+
"version": "3.0.0",
|
|
16
16
|
"bugs": {
|
|
17
17
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
18
18
|
},
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
],
|
|
28
28
|
"license": "ISC",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@wemap/logger": "^
|
|
31
|
-
"@wemap/maths": "^
|
|
30
|
+
"@wemap/logger": "^3.0.0",
|
|
31
|
+
"@wemap/maths": "^3.0.0",
|
|
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": "
|
|
36
|
+
"gitHead": "2bbb4840a99b90eaae989291cb728ac87cebade8"
|
|
37
37
|
}
|
package/src/Utils.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Coordinates from './coordinates/Coordinates';
|
|
2
2
|
|
|
3
3
|
class Utils {
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Sample a route of
|
|
7
|
-
* @param {Array.<
|
|
6
|
+
* Sample a route of Coordinates
|
|
7
|
+
* @param {Array.<Coordinates>} route ordered points
|
|
8
8
|
* @param {*} stepSize step size to sample
|
|
9
9
|
* @param {*} maxLength max route length to sample
|
|
10
10
|
*/
|
package/src/Utils.spec.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
2
|
|
|
3
3
|
import Utils from './Utils';
|
|
4
|
-
import
|
|
4
|
+
import Coordinates from './coordinates/Coordinates';
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
describe('Geo Utils', () => {
|
|
@@ -11,10 +11,10 @@ describe('Geo Utils', () => {
|
|
|
11
11
|
let samples;
|
|
12
12
|
|
|
13
13
|
const route = [
|
|
14
|
-
new
|
|
15
|
-
new
|
|
16
|
-
new
|
|
17
|
-
new
|
|
14
|
+
new Coordinates(45.0, 5.0),
|
|
15
|
+
new Coordinates(45.000735, 5.0007303),
|
|
16
|
+
new Coordinates(45.000735, 5.0007303),
|
|
17
|
+
new Coordinates(45.0003702, 5.0011008)
|
|
18
18
|
];
|
|
19
19
|
|
|
20
20
|
samples = Utils.sampleRoute(route, 10);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Coordinates from './Coordinates';
|
|
2
2
|
import isNumber from 'lodash.isnumber';
|
|
3
3
|
import isFinite from 'lodash.isfinite';
|
|
4
4
|
|
|
@@ -23,18 +23,18 @@ class BoundingBox {
|
|
|
23
23
|
/**
|
|
24
24
|
* Returns the geographical coordinate equidistant from the bounding box's corners.
|
|
25
25
|
*
|
|
26
|
-
* @returns {
|
|
26
|
+
* @returns {Coordinates} The bounding box's center.
|
|
27
27
|
*/
|
|
28
28
|
get center() {
|
|
29
29
|
const latCenter = (this.southWest.lat + this.northEast.lat) / 2;
|
|
30
30
|
const lngCenter = (this.northEast.lng + this.southWest.lng) / 2;
|
|
31
|
-
return new
|
|
31
|
+
return new Coordinates(latCenter, lngCenter);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Check if a point is contained in the bounding box.
|
|
36
36
|
*
|
|
37
|
-
* @returns {
|
|
37
|
+
* @returns {Coordinates} The point to analyze.
|
|
38
38
|
*/
|
|
39
39
|
contains(point) {
|
|
40
40
|
return point.lat <= this.northEast.lat
|
|
@@ -46,7 +46,7 @@ class BoundingBox {
|
|
|
46
46
|
/**
|
|
47
47
|
* Extend the bounds to include a given LngLat or LngLatBounds.
|
|
48
48
|
*
|
|
49
|
-
* @param {
|
|
49
|
+
* @param {Coordinates|BoundingBox} obj object to extend to
|
|
50
50
|
* @returns {BoundingBox} `this`
|
|
51
51
|
*/
|
|
52
52
|
extend(obj) {
|
|
@@ -54,7 +54,7 @@ class BoundingBox {
|
|
|
54
54
|
ne = this.northEast;
|
|
55
55
|
let sw2, ne2;
|
|
56
56
|
|
|
57
|
-
if (obj instanceof
|
|
57
|
+
if (obj instanceof Coordinates) {
|
|
58
58
|
sw2 = obj;
|
|
59
59
|
ne2 = obj;
|
|
60
60
|
|
|
@@ -70,15 +70,15 @@ class BoundingBox {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
if (!sw && !ne) {
|
|
73
|
-
this.southWest = new
|
|
74
|
-
this.northEast = new
|
|
73
|
+
this.southWest = new Coordinates(sw2.lat, sw2.lng);
|
|
74
|
+
this.northEast = new Coordinates(ne2.lat, ne2.lng);
|
|
75
75
|
|
|
76
76
|
} else {
|
|
77
|
-
this.southWest = new
|
|
77
|
+
this.southWest = new Coordinates(
|
|
78
78
|
Math.min(sw2.lat, sw.lat),
|
|
79
79
|
Math.min(sw2.lng, sw.lng)
|
|
80
80
|
);
|
|
81
|
-
this.northEast = new
|
|
81
|
+
this.northEast = new Coordinates(
|
|
82
82
|
Math.max(ne2.lat, ne.lat),
|
|
83
83
|
Math.max(ne2.lng, ne.lng)
|
|
84
84
|
);
|
|
@@ -112,7 +112,7 @@ class BoundingBox {
|
|
|
112
112
|
/**
|
|
113
113
|
* Returns the southwest corner of the bounding box.
|
|
114
114
|
*
|
|
115
|
-
* @returns {
|
|
115
|
+
* @returns {Coordinates} The southwest corner of the bounding box.
|
|
116
116
|
*/
|
|
117
117
|
getSouthWest() {
|
|
118
118
|
return this.southWest;
|
|
@@ -121,7 +121,7 @@ class BoundingBox {
|
|
|
121
121
|
/**
|
|
122
122
|
* Returns the northeast corner of the bounding box.
|
|
123
123
|
*
|
|
124
|
-
* @returns {
|
|
124
|
+
* @returns {Coordinates} The northeast corner of the bounding box.
|
|
125
125
|
*/
|
|
126
126
|
getNorthEast() {
|
|
127
127
|
return this.northEast;
|
|
@@ -130,10 +130,10 @@ class BoundingBox {
|
|
|
130
130
|
/**
|
|
131
131
|
* Returns the northwest corner of the bounding box.
|
|
132
132
|
*
|
|
133
|
-
* @returns {
|
|
133
|
+
* @returns {Coordinates} The northwest corner of the bounding box.
|
|
134
134
|
*/
|
|
135
135
|
getNorthWest() {
|
|
136
|
-
return new
|
|
136
|
+
return new Coordinates(this.getNorth(), this.getWest());
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
/**
|
|
@@ -142,7 +142,7 @@ class BoundingBox {
|
|
|
142
142
|
* @returns {LngLat} The southeast corner of the bounding box.
|
|
143
143
|
*/
|
|
144
144
|
getSouthEast() {
|
|
145
|
-
return new
|
|
145
|
+
return new Coordinates(this.getSouth(), this.getEast());
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
/**
|
|
@@ -182,8 +182,8 @@ class BoundingBox {
|
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
static equalsTo(bb1, bb2) {
|
|
185
|
-
return
|
|
186
|
-
&&
|
|
185
|
+
return Coordinates.equalsTo(bb1.northEast, bb2.northEast)
|
|
186
|
+
&& Coordinates.equalsTo(bb1.southWest, bb2.southWest);
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
equalsTo(other) {
|
|
@@ -4,15 +4,15 @@ import chaiAlmost from 'chai-almost';
|
|
|
4
4
|
|
|
5
5
|
import BoundingBox from './BoundingBox';
|
|
6
6
|
import Logger from '@wemap/logger';
|
|
7
|
-
import
|
|
7
|
+
import Coordinates from './Coordinates';
|
|
8
8
|
|
|
9
9
|
const expect = chai.expect;
|
|
10
10
|
chai.use(chaiAlmost());
|
|
11
11
|
Logger.enable(false);
|
|
12
12
|
|
|
13
13
|
let boundingBox;
|
|
14
|
-
const northEast = new
|
|
15
|
-
const southWest = new
|
|
14
|
+
const northEast = new Coordinates(10, 40);
|
|
15
|
+
const southWest = new Coordinates(-5, -20);
|
|
16
16
|
|
|
17
17
|
const checkBounds = (bb, [north, east, south, west]) => {
|
|
18
18
|
return north === bb.northEast.lat
|
|
@@ -28,7 +28,7 @@ describe('Bounding Box', () => {
|
|
|
28
28
|
expect(boundingBox.northEast).is.null;
|
|
29
29
|
expect(boundingBox.southWest).is.null;
|
|
30
30
|
|
|
31
|
-
expect(() => new BoundingBox(new
|
|
31
|
+
expect(() => new BoundingBox(new Coordinates(10, -20), new Coordinates(-5, 40))).is.throw(Error);
|
|
32
32
|
|
|
33
33
|
boundingBox = new BoundingBox(northEast, southWest);
|
|
34
34
|
expect(boundingBox.northEast).equals(northEast);
|
|
@@ -39,16 +39,16 @@ describe('Bounding Box', () => {
|
|
|
39
39
|
it('equalsTo', () => {
|
|
40
40
|
boundingBox = new BoundingBox(northEast, southWest);
|
|
41
41
|
expect(boundingBox.equalsTo(new BoundingBox(
|
|
42
|
-
new
|
|
42
|
+
new Coordinates(10, 40), new Coordinates(-5, -20)
|
|
43
43
|
))).true;
|
|
44
44
|
expect(BoundingBox.equalsTo(boundingBox, new BoundingBox(
|
|
45
|
-
new
|
|
45
|
+
new Coordinates(10, 40), new Coordinates(-5, -20)
|
|
46
46
|
))).true;
|
|
47
47
|
expect(BoundingBox.equalsTo(boundingBox, new BoundingBox(
|
|
48
|
-
new
|
|
48
|
+
new Coordinates(10, 10), new Coordinates(-5, -20)
|
|
49
49
|
))).false;
|
|
50
50
|
expect(BoundingBox.equalsTo(boundingBox, new BoundingBox(
|
|
51
|
-
new
|
|
51
|
+
new Coordinates(10, 40), new Coordinates(-15, -20)
|
|
52
52
|
))).false;
|
|
53
53
|
});
|
|
54
54
|
|
|
@@ -59,12 +59,12 @@ describe('Bounding Box', () => {
|
|
|
59
59
|
expect(boundingBox.getEast()).equals(northEast.lng);
|
|
60
60
|
expect(boundingBox.getSouth()).equals(southWest.lat);
|
|
61
61
|
expect(boundingBox.getWest()).equals(southWest.lng);
|
|
62
|
-
expect(
|
|
63
|
-
expect(
|
|
64
|
-
expect(
|
|
65
|
-
new
|
|
66
|
-
expect(
|
|
67
|
-
new
|
|
62
|
+
expect(Coordinates.equalsTo(boundingBox.getNorthEast(), northEast)).true;
|
|
63
|
+
expect(Coordinates.equalsTo(boundingBox.getSouthWest(), southWest)).true;
|
|
64
|
+
expect(Coordinates.equalsTo(boundingBox.getNorthWest(),
|
|
65
|
+
new Coordinates(northEast.lat, southWest.lng))).true;
|
|
66
|
+
expect(Coordinates.equalsTo(boundingBox.getSouthEast(),
|
|
67
|
+
new Coordinates(southWest.lat, northEast.lng))).true;
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
|
|
@@ -81,47 +81,47 @@ describe('Bounding Box', () => {
|
|
|
81
81
|
|
|
82
82
|
it('contains', () => {
|
|
83
83
|
boundingBox = new BoundingBox();
|
|
84
|
-
expect(() => boundingBox.contains(new
|
|
84
|
+
expect(() => boundingBox.contains(new Coordinates(0, 0))).is.throw(Error);
|
|
85
85
|
|
|
86
86
|
boundingBox = new BoundingBox(northEast, southWest);
|
|
87
87
|
expect(() => boundingBox.contains(null)).is.throw(Error);
|
|
88
|
-
expect(boundingBox.contains(new
|
|
89
|
-
expect(boundingBox.contains(new
|
|
90
|
-
expect(boundingBox.contains(new
|
|
91
|
-
expect(boundingBox.contains(new
|
|
92
|
-
expect(boundingBox.contains(new
|
|
93
|
-
expect(boundingBox.contains(new
|
|
94
|
-
expect(boundingBox.contains(new
|
|
95
|
-
expect(boundingBox.contains(new
|
|
96
|
-
expect(boundingBox.contains(new
|
|
88
|
+
expect(boundingBox.contains(new Coordinates(0, 0))).true;
|
|
89
|
+
expect(boundingBox.contains(new Coordinates(10, 0))).true;
|
|
90
|
+
expect(boundingBox.contains(new Coordinates(0, 10))).true;
|
|
91
|
+
expect(boundingBox.contains(new Coordinates(-10, 0))).false;
|
|
92
|
+
expect(boundingBox.contains(new Coordinates(0, -10))).true;
|
|
93
|
+
expect(boundingBox.contains(new Coordinates(50, 50))).false;
|
|
94
|
+
expect(boundingBox.contains(new Coordinates(-50, 50))).false;
|
|
95
|
+
expect(boundingBox.contains(new Coordinates(50, -50))).false;
|
|
96
|
+
expect(boundingBox.contains(new Coordinates(-50, -50))).false;
|
|
97
97
|
});
|
|
98
98
|
|
|
99
99
|
it('extend', () => {
|
|
100
100
|
boundingBox = new BoundingBox();
|
|
101
|
-
expect(() => boundingBox.extend(new
|
|
101
|
+
expect(() => boundingBox.extend(new Coordinates(0, 0))).is.throw;
|
|
102
102
|
|
|
103
103
|
boundingBox = new BoundingBox(northEast, southWest);
|
|
104
104
|
expect(() => boundingBox.extend(null)).is.throw(Error);
|
|
105
105
|
expect(checkBounds(
|
|
106
|
-
boundingBox.extend(new
|
|
106
|
+
boundingBox.extend(new Coordinates(0, 0)),
|
|
107
107
|
[10, 40, -5, -20]
|
|
108
108
|
)).true;
|
|
109
109
|
expect(checkBounds(
|
|
110
|
-
boundingBox.extend(new
|
|
110
|
+
boundingBox.extend(new Coordinates(20, 0)),
|
|
111
111
|
[20, 40, -5, -20]
|
|
112
112
|
)).true;
|
|
113
113
|
expect(checkBounds(
|
|
114
|
-
boundingBox.extend(new
|
|
114
|
+
boundingBox.extend(new Coordinates(20, 40)),
|
|
115
115
|
[20, 40, -5, -20]
|
|
116
116
|
)).true;
|
|
117
117
|
expect(checkBounds(
|
|
118
|
-
boundingBox.extend(new
|
|
118
|
+
boundingBox.extend(new Coordinates(30, 40)),
|
|
119
119
|
[30, 40, -5, -20]
|
|
120
120
|
)).true;
|
|
121
121
|
|
|
122
122
|
boundingBox = new BoundingBox(northEast, southWest);
|
|
123
123
|
boundingBox.extend(new BoundingBox(
|
|
124
|
-
new
|
|
124
|
+
new Coordinates(10, 10), new Coordinates(-10, -10)
|
|
125
125
|
));
|
|
126
126
|
expect(checkBounds(boundingBox, [10, 40, -10, -20])).true;
|
|
127
127
|
|
|
@@ -147,26 +147,26 @@ describe('Bounding Box', () => {
|
|
|
147
147
|
boundingBox = new BoundingBox(northEast, southWest);
|
|
148
148
|
measure = 50000;
|
|
149
149
|
extended = boundingBox.extendsWithMeasure(measure);
|
|
150
|
-
expect(new
|
|
150
|
+
expect(new Coordinates(extended.northEast.lat, northEast.lng).distanceTo(northEast))
|
|
151
151
|
.be.closeTo(measure, 0.05 * measure);
|
|
152
|
-
expect(new
|
|
152
|
+
expect(new Coordinates(northEast.lat, extended.northEast.lng).distanceTo(northEast))
|
|
153
153
|
.be.closeTo(measure, 0.05 * measure);
|
|
154
|
-
expect(new
|
|
154
|
+
expect(new Coordinates(extended.southWest.lat, southWest.lng).distanceTo(southWest))
|
|
155
155
|
.be.closeTo(measure, 0.05 * measure);
|
|
156
|
-
expect(new
|
|
156
|
+
expect(new Coordinates(southWest.lat, extended.southWest.lng).distanceTo(southWest))
|
|
157
157
|
.be.closeTo(measure, 0.05 * measure);
|
|
158
158
|
|
|
159
159
|
|
|
160
160
|
boundingBox = new BoundingBox(northEast, southWest);
|
|
161
161
|
measure = 50;
|
|
162
162
|
extended = boundingBox.extendsWithMeasure(measure);
|
|
163
|
-
expect(new
|
|
163
|
+
expect(new Coordinates(extended.northEast.lat, northEast.lng).distanceTo(northEast))
|
|
164
164
|
.be.closeTo(measure, 0.05 * measure);
|
|
165
|
-
expect(new
|
|
165
|
+
expect(new Coordinates(northEast.lat, extended.northEast.lng).distanceTo(northEast))
|
|
166
166
|
.be.closeTo(measure, 0.05 * measure);
|
|
167
|
-
expect(new
|
|
167
|
+
expect(new Coordinates(extended.southWest.lat, southWest.lng).distanceTo(southWest))
|
|
168
168
|
.be.closeTo(measure, 0.05 * measure);
|
|
169
|
-
expect(new
|
|
169
|
+
expect(new Coordinates(southWest.lat, extended.southWest.lng).distanceTo(southWest))
|
|
170
170
|
.be.closeTo(measure, 0.05 * measure);
|
|
171
171
|
});
|
|
172
172
|
|
|
@@ -7,17 +7,17 @@ import isFinite from 'lodash.isfinite';
|
|
|
7
7
|
import Level from './Level';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* A
|
|
10
|
+
* A Coordinates position using at least latitude (lat) and longitude (lng).
|
|
11
11
|
* Optionnal fields are: altitude (alt) and level.
|
|
12
12
|
*
|
|
13
13
|
* Basic geo methods are directly accessibles from here:
|
|
14
14
|
* distanceTo, bearingTo, toEcef...
|
|
15
15
|
*
|
|
16
16
|
* /!\ This class has been adapted to use earth as a sphere and not as an ellipsoid
|
|
17
|
-
* /!\ So, this class does not stricly represent
|
|
17
|
+
* /!\ So, this class does not stricly represent Coordinates coordinates anymore
|
|
18
18
|
* /!\ This modifications have been made for computational improvements.
|
|
19
19
|
*/
|
|
20
|
-
class
|
|
20
|
+
class Coordinates {
|
|
21
21
|
|
|
22
22
|
constructor(lat, lng, alt, level) {
|
|
23
23
|
this.lat = lat;
|
|
@@ -89,7 +89,7 @@ class WGS84 {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
clone() {
|
|
92
|
-
const output = new
|
|
92
|
+
const output = new Coordinates(this.lat, this.lng, this.alt);
|
|
93
93
|
if (this.level) {
|
|
94
94
|
output.level = this.level.clone();
|
|
95
95
|
}
|
|
@@ -97,9 +97,9 @@ class WGS84 {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
|
-
* Compares two
|
|
101
|
-
* @param {
|
|
102
|
-
* @param {
|
|
100
|
+
* Compares two Coordinates
|
|
101
|
+
* @param {Coordinates} pos1 position 1
|
|
102
|
+
* @param {Coordinates} pos2 position 2
|
|
103
103
|
* @param {Number} eps latitude and longitude epsilon in degrees (default: 1e-8 [~1mm at lat=0])
|
|
104
104
|
* @param {Number} epsAlt altitude epsilon in meters (default: 1e-3 [= 1mm])
|
|
105
105
|
*/
|
|
@@ -110,7 +110,7 @@ class WGS84 {
|
|
|
110
110
|
return true;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
if (!(pos1 instanceof
|
|
113
|
+
if (!(pos1 instanceof Coordinates) || !(pos2 instanceof Coordinates)) {
|
|
114
114
|
return false;
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -123,7 +123,7 @@ class WGS84 {
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
equalsTo(other) {
|
|
126
|
-
return
|
|
126
|
+
return Coordinates.equalsTo(this, other);
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
destinationPoint(distance, bearing, elevation) {
|
|
@@ -167,7 +167,7 @@ class WGS84 {
|
|
|
167
167
|
|
|
168
168
|
/**
|
|
169
169
|
* Returns a distance between two points in meters
|
|
170
|
-
* @param {
|
|
170
|
+
* @param {Coordinates} location2 latitude / longitude point
|
|
171
171
|
* @return {Number} distance in meters
|
|
172
172
|
*/
|
|
173
173
|
distanceTo(location2) {
|
|
@@ -265,7 +265,7 @@ class WGS84 {
|
|
|
265
265
|
|
|
266
266
|
lng = lng % (2 * Math.PI);
|
|
267
267
|
|
|
268
|
-
const newPoint = new
|
|
268
|
+
const newPoint = new Coordinates(rad2deg(lat), rad2deg(lng), alt);
|
|
269
269
|
newPoint._ecef = ecef;
|
|
270
270
|
return newPoint;
|
|
271
271
|
}
|
|
@@ -288,9 +288,9 @@ class WGS84 {
|
|
|
288
288
|
const t = Vector3.normalize(Vector3.cross(G, F));
|
|
289
289
|
|
|
290
290
|
const posECEF = Vector3.multiplyScalar(t, Constants.R_MAJOR);
|
|
291
|
-
const
|
|
291
|
+
const poseCoordinates = Coordinates.fromECEF(posECEF);
|
|
292
292
|
|
|
293
|
-
//
|
|
293
|
+
// poseCoordinates.alt is not 0 here due to the ECEF transformation residual.
|
|
294
294
|
// So if p1.alt and p2.alt are defined we take the middle elevation between p1 and p2.
|
|
295
295
|
// Otherwise we remove alt from projection because the residual has no sense.
|
|
296
296
|
let alt;
|
|
@@ -298,7 +298,7 @@ class WGS84 {
|
|
|
298
298
|
// This formula is maybe not the best one.
|
|
299
299
|
alt = (p1.alt + p2.alt) / 2;
|
|
300
300
|
}
|
|
301
|
-
const projection = new
|
|
301
|
+
const projection = new Coordinates(poseCoordinates.lat, poseCoordinates.lng,
|
|
302
302
|
alt, Level.intersect(p1.level, p2.level));
|
|
303
303
|
|
|
304
304
|
if (Math.abs((p1.distanceTo(p2) - p1.distanceTo(projection) - p2.distanceTo(projection))) > 1e-6) {
|
|
@@ -339,9 +339,9 @@ class WGS84 {
|
|
|
339
339
|
}
|
|
340
340
|
|
|
341
341
|
static fromJson(json) {
|
|
342
|
-
return new
|
|
342
|
+
return new Coordinates(json.lat, json.lng, json.alt, Level.fromString(json.level));
|
|
343
343
|
}
|
|
344
344
|
|
|
345
345
|
}
|
|
346
346
|
|
|
347
|
-
export default
|
|
347
|
+
export default Coordinates;
|