@wemap/geo 1.0.5 → 2.7.1
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 +2 -0
- package/package.json +4 -3
- package/src/Constants.js +11 -1
- package/src/Utils.js +46 -0
- package/src/Utils.spec.js +39 -0
- package/src/coordinates/Level.js +1 -0
- package/src/coordinates/Level.spec.js +39 -30
- package/src/coordinates/WGS84.js +150 -134
- package/src/coordinates/WGS84.spec.js +268 -0
- package/src/coordinates/WGS84UserPosition.js +136 -23
- package/src/coordinates/WGS84UserPosition.spec.js +247 -0
- package/src/rotations/Attitude.js +56 -30
- package/src/rotations/Attitude.spec.js +82 -0
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"directory": "packages/geo"
|
|
13
13
|
},
|
|
14
14
|
"name": "@wemap/geo",
|
|
15
|
-
"version": "
|
|
15
|
+
"version": "2.7.1",
|
|
16
16
|
"bugs": {
|
|
17
17
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
18
18
|
},
|
|
@@ -27,10 +27,11 @@
|
|
|
27
27
|
],
|
|
28
28
|
"license": "ISC",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@wemap/
|
|
30
|
+
"@wemap/logger": "^2.7.0",
|
|
31
|
+
"@wemap/maths": "^2.7.0",
|
|
31
32
|
"lodash.isfinite": "^3.3.2",
|
|
32
33
|
"lodash.isnumber": "^3.0.3",
|
|
33
34
|
"lodash.isstring": "^4.0.1"
|
|
34
35
|
},
|
|
35
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "3d332f1dce308ba28f2a551c2e709e840c54bd83"
|
|
36
37
|
}
|
package/src/Constants.js
CHANGED
|
@@ -2,7 +2,17 @@ const Constants = {
|
|
|
2
2
|
R_MAJOR: 6378137.0,
|
|
3
3
|
R_MINOR: 6356752.3142,
|
|
4
4
|
EARTH_GRAVITY: 9.80665,
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* latitude and longitude epsilon in degrees
|
|
8
|
+
* 1e-8° correspond to ~1mm at latitude = 0
|
|
9
|
+
*/
|
|
10
|
+
EPS_DEG_MM: 1e-8,
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* epsilon in meters which corresponds to q millimeter
|
|
14
|
+
*/
|
|
15
|
+
EPS_MM: 1e-3
|
|
6
16
|
};
|
|
7
17
|
|
|
8
18
|
Constants.ELLIPSOID_FLATNESS = (Constants.R_MAJOR - Constants.R_MINOR) / Constants.R_MAJOR;
|
package/src/Utils.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import WGS84 from './coordinates/WGS84';
|
|
2
|
+
|
|
3
|
+
class Utils {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Sample a route of WGS84
|
|
7
|
+
* @param {Array.<WGS84>} route ordered points
|
|
8
|
+
* @param {*} stepSize step size to sample
|
|
9
|
+
* @param {*} maxLength max route length to sample
|
|
10
|
+
*/
|
|
11
|
+
static sampleRoute(route, stepSize = 0.7, maxLength = Number.MAX_VALUE) {
|
|
12
|
+
|
|
13
|
+
let p1, p2 = null;
|
|
14
|
+
let bearing, distance;
|
|
15
|
+
|
|
16
|
+
const sampledRoute = [];
|
|
17
|
+
let reportedDistance = 0;
|
|
18
|
+
let totalDistance = 0;
|
|
19
|
+
|
|
20
|
+
for (let i = 0; i < route.length - 1; i++) {
|
|
21
|
+
|
|
22
|
+
p1 = route[i];
|
|
23
|
+
p2 = route[i + 1];
|
|
24
|
+
|
|
25
|
+
bearing = p1.bearingTo(p2);
|
|
26
|
+
distance = p1.distanceTo(p2);
|
|
27
|
+
|
|
28
|
+
if (distance > 0) {
|
|
29
|
+
let ratio = reportedDistance / distance;
|
|
30
|
+
while (ratio < 1 && totalDistance < maxLength) {
|
|
31
|
+
const newPoint = p1.destinationPoint(ratio * distance, bearing);
|
|
32
|
+
newPoint.bearing = bearing;
|
|
33
|
+
sampledRoute.push(newPoint);
|
|
34
|
+
ratio += stepSize / distance;
|
|
35
|
+
totalDistance += stepSize;
|
|
36
|
+
}
|
|
37
|
+
reportedDistance = (ratio - 1) * distance;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
sampledRoute.push(p2);
|
|
41
|
+
|
|
42
|
+
return sampledRoute;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default Utils;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
|
|
3
|
+
import Utils from './Utils';
|
|
4
|
+
import WGS84 from './coordinates/WGS84';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
describe('Geo Utils', () => {
|
|
8
|
+
|
|
9
|
+
it('sampleRoute', () => {
|
|
10
|
+
|
|
11
|
+
let samples;
|
|
12
|
+
|
|
13
|
+
const route = [
|
|
14
|
+
new WGS84(45.0, 5.0),
|
|
15
|
+
new WGS84(45.000735, 5.0007303),
|
|
16
|
+
new WGS84(45.000735, 5.0007303),
|
|
17
|
+
new WGS84(45.0003702, 5.0011008)
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
samples = Utils.sampleRoute(route, 10);
|
|
21
|
+
expect(samples.length).equals(16);
|
|
22
|
+
|
|
23
|
+
// Do not consider the last point
|
|
24
|
+
for (let i = 0; i < samples.length - 2; i++) {
|
|
25
|
+
// Do not consider the turn, only straight lines
|
|
26
|
+
if (i === 9) {
|
|
27
|
+
i++;
|
|
28
|
+
}
|
|
29
|
+
expect(10 - samples[i].distanceTo(samples[i + 1])).is.below(1e-8);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
samples = Utils.sampleRoute(route, 10, 100);
|
|
33
|
+
expect(samples.length).equals(11);
|
|
34
|
+
|
|
35
|
+
samples = Utils.sampleRoute(route);
|
|
36
|
+
expect(samples.length).equals(216);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
});
|
package/src/coordinates/Level.js
CHANGED
|
@@ -98,6 +98,7 @@ describe('Level', () => {
|
|
|
98
98
|
it('equalsTo', () => {
|
|
99
99
|
const level = new Level(1);
|
|
100
100
|
expect(Level.equalsTo(null, null)).true;
|
|
101
|
+
expect(Level.equalsTo(null, false)).true;
|
|
101
102
|
expect(Level.equalsTo(level, level)).true;
|
|
102
103
|
expect(Level.equalsTo(level, null)).false;
|
|
103
104
|
expect(Level.equalsTo(null, level)).false;
|
|
@@ -141,19 +142,25 @@ describe('Level', () => {
|
|
|
141
142
|
expect(Level.intersect(null, level)).equals(null);
|
|
142
143
|
expect(Level.intersect(level, level)).equals(level);
|
|
143
144
|
|
|
144
|
-
expect(Level.equalsTo(Level.intersect(new Level(
|
|
145
|
-
expect(Level.
|
|
146
|
-
|
|
147
|
-
expect(Level.equalsTo(Level.intersect(new Level(1), new Level(
|
|
148
|
-
expect(Level.equalsTo(Level.intersect(new Level(
|
|
149
|
-
expect(Level.equalsTo(Level.intersect(new Level(1), new Level(
|
|
150
|
-
expect(Level.equalsTo(Level.intersect(new Level(1
|
|
151
|
-
expect(Level.equalsTo(Level.intersect(new Level(
|
|
152
|
-
expect(Level.equalsTo(Level.intersect(new Level(
|
|
145
|
+
expect(Level.equalsTo(Level.intersect(new Level(1), new Level(1)), new Level(1))).true;
|
|
146
|
+
expect(Level.intersect(new Level(1), new Level(2))).is.null;
|
|
147
|
+
|
|
148
|
+
expect(Level.equalsTo(Level.intersect(new Level(0, 1), new Level(1)), new Level(1))).true;
|
|
149
|
+
expect(Level.equalsTo(Level.intersect(new Level(0, 2), new Level(1)), new Level(1))).true;
|
|
150
|
+
expect(Level.equalsTo(Level.intersect(new Level(-1, 2), new Level(1)), new Level(1))).true;
|
|
151
|
+
expect(Level.equalsTo(Level.intersect(new Level(1), new Level(0, 1)), new Level(1))).true;
|
|
152
|
+
expect(Level.equalsTo(Level.intersect(new Level(1), new Level(0, 2)), new Level(1))).true;
|
|
153
|
+
expect(Level.equalsTo(Level.intersect(new Level(1), new Level(-1, 2)), new Level(1))).true;
|
|
154
|
+
expect(Level.equalsTo(Level.intersect(new Level(1, 2), new Level(-1, 2)), new Level(1, 2))).true;
|
|
155
|
+
expect(Level.equalsTo(Level.intersect(new Level(-3, 1), new Level(-1, 2)), new Level(-1, 1))).true;
|
|
156
|
+
expect(Level.equalsTo(Level.intersect(new Level(-3, -1), new Level(-1, 2)), new Level(-1))).true;
|
|
153
157
|
expect(Level.intersect(new Level(-3, -2), new Level(-1, 2))).is.null;
|
|
154
158
|
expect(Level.intersect(new Level(-1, 2), new Level(-3, -2))).is.null;
|
|
155
159
|
expect(Level.intersect(new Level(0), new Level(1, 2))).is.null;
|
|
156
160
|
expect(Level.intersect(new Level(1, 2), new Level(0))).is.null;
|
|
161
|
+
|
|
162
|
+
expect(new Level(1, 2).intersect(new Level(0))).is.null;
|
|
163
|
+
expect(Level.equalsTo(new Level(-3, -1).intersect(new Level(-1, 2)), new Level(-1))).true;
|
|
157
164
|
});
|
|
158
165
|
|
|
159
166
|
it('union', () => {
|
|
@@ -164,31 +171,33 @@ describe('Level', () => {
|
|
|
164
171
|
expect(Level.union(null, level)).equals(level);
|
|
165
172
|
expect(Level.union(level, level)).equals(level);
|
|
166
173
|
|
|
167
|
-
expect(Level.equalsTo(Level.union(new Level(
|
|
168
|
-
expect(Level.equalsTo(Level.union(new Level(
|
|
169
|
-
expect(Level.equalsTo(Level.union(new Level(
|
|
170
|
-
expect(Level.equalsTo(Level.union(new Level(
|
|
171
|
-
expect(Level.equalsTo(Level.union(new Level(1), new Level(
|
|
172
|
-
expect(Level.equalsTo(Level.union(new Level(1), new Level(
|
|
173
|
-
expect(Level.equalsTo(Level.union(new Level(1
|
|
174
|
-
expect(Level.equalsTo(Level.union(new Level(
|
|
175
|
-
expect(Level.equalsTo(Level.union(new Level(
|
|
176
|
-
expect(Level.equalsTo(Level.union(new Level(-3,
|
|
177
|
-
expect(Level.equalsTo(Level.union(new Level(-
|
|
178
|
-
expect(Level.equalsTo(Level.union(new Level(
|
|
179
|
-
expect(Level.equalsTo(Level.union(new Level(1, 2), new Level(
|
|
180
|
-
|
|
181
|
-
expect(Level.equalsTo(new Level(
|
|
174
|
+
expect(Level.equalsTo(Level.union(new Level(1), new Level(1)), new Level(1))).true;
|
|
175
|
+
expect(Level.equalsTo(Level.union(new Level(1), new Level(2)), new Level(1, 2))).true;
|
|
176
|
+
expect(Level.equalsTo(Level.union(new Level(0, 1), new Level(1)), new Level(0, 1))).true;
|
|
177
|
+
expect(Level.equalsTo(Level.union(new Level(0, 2), new Level(1)), new Level(0, 2))).true;
|
|
178
|
+
expect(Level.equalsTo(Level.union(new Level(-1, 2), new Level(1)), new Level(-1, 2))).true;
|
|
179
|
+
expect(Level.equalsTo(Level.union(new Level(1), new Level(0, 1)), new Level(0, 1))).true;
|
|
180
|
+
expect(Level.equalsTo(Level.union(new Level(1), new Level(0, 2)), new Level(0, 2))).true;
|
|
181
|
+
expect(Level.equalsTo(Level.union(new Level(1), new Level(-1, 2)), new Level(-1, 2))).true;
|
|
182
|
+
expect(Level.equalsTo(Level.union(new Level(1, 2), new Level(-1, 2)), new Level(-1, 2))).true;
|
|
183
|
+
expect(Level.equalsTo(Level.union(new Level(-3, 1), new Level(-1, 2)), new Level(-3, 2))).true;
|
|
184
|
+
expect(Level.equalsTo(Level.union(new Level(-3, -1), new Level(-1, 2)), new Level(-3, 2))).true;
|
|
185
|
+
expect(Level.equalsTo(Level.union(new Level(-3, -2), new Level(-1, 2)), new Level(-3, 2))).true;
|
|
186
|
+
expect(Level.equalsTo(Level.union(new Level(-1, 2), new Level(-3, -2)), new Level(-3, 2))).true;
|
|
187
|
+
expect(Level.equalsTo(Level.union(new Level(0), new Level(1, 2)), new Level(0, 2))).true;
|
|
188
|
+
expect(Level.equalsTo(Level.union(new Level(1, 2), new Level(0)), new Level(0, 2))).true;
|
|
189
|
+
|
|
190
|
+
expect(Level.equalsTo(new Level(0, 1).union(new Level(1)), new Level(0, 1))).true;
|
|
182
191
|
});
|
|
183
192
|
|
|
184
193
|
|
|
185
194
|
it('multiplyBy', () => {
|
|
186
|
-
expect(Level.equalsTo(new Level(0).multiplyBy(5), new Level(0)));
|
|
187
|
-
expect(Level.equalsTo(new Level(3).multiplyBy(2), new Level(6)));
|
|
188
|
-
expect(Level.equalsTo(new Level(-1).multiplyBy(5), new Level(-5)));
|
|
189
|
-
expect(Level.equalsTo(new Level(0, 1).multiplyBy(5), new Level(0, 5)));
|
|
190
|
-
expect(Level.equalsTo(new Level(-1, 1).multiplyBy(5), new Level(-5, 5)));
|
|
191
|
-
expect(Level.equalsTo(new Level(1, -1).multiplyBy(5), new Level(-5, 5)));
|
|
195
|
+
expect(Level.equalsTo(new Level(0).multiplyBy(5), new Level(0))).true;
|
|
196
|
+
expect(Level.equalsTo(new Level(3).multiplyBy(2), new Level(6))).true;
|
|
197
|
+
expect(Level.equalsTo(new Level(-1).multiplyBy(5), new Level(-5))).true;
|
|
198
|
+
expect(Level.equalsTo(new Level(0, 1).multiplyBy(5), new Level(0, 5))).true;
|
|
199
|
+
expect(Level.equalsTo(new Level(-1, 1).multiplyBy(5), new Level(-5, 5))).true;
|
|
200
|
+
expect(Level.equalsTo(new Level(1, -1).multiplyBy(5), new Level(-5, 5))).true;
|
|
192
201
|
});
|
|
193
202
|
|
|
194
203
|
});
|