@wemap/geo 1.0.4 → 2.7.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 CHANGED
@@ -1,4 +1,5 @@
1
1
  import Constants from './src/Constants';
2
+ import Utils from './src/Utils';
2
3
 
3
4
  import Attitude from './src/rotations/Attitude';
4
5
 
@@ -12,6 +13,7 @@ export {
12
13
  BoundingBox,
13
14
  Constants,
14
15
  Level,
16
+ Utils,
15
17
  WGS84,
16
18
  WGS84UserPosition
17
19
  };
package/package.json CHANGED
@@ -8,15 +8,15 @@
8
8
  "main": "index.js",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "git+https://github.com/wemap/wemap-utils-js.git",
11
+ "url": "git+https://github.com/wemap/wemap-modules-js.git",
12
12
  "directory": "packages/geo"
13
13
  },
14
14
  "name": "@wemap/geo",
15
- "version": "1.0.4",
15
+ "version": "2.7.0",
16
16
  "bugs": {
17
- "url": "https://github.com/wemap/wemap-utils-js/issues"
17
+ "url": "https://github.com/wemap/wemap-modules-js/issues"
18
18
  },
19
- "homepage": "https://github.com/wemap/wemap-utils-js#readme",
19
+ "homepage": "https://github.com/wemap/wemap-modules-js#readme",
20
20
  "scripts": {
21
21
  "test": "mocha -r esm \"src/**/*.spec.js\""
22
22
  },
@@ -27,10 +27,11 @@
27
27
  ],
28
28
  "license": "ISC",
29
29
  "dependencies": {
30
- "@wemap/maths": "^1.0.0",
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": "cab48c01923850987968f072a8f7075a34b3cc32"
36
+ "gitHead": "6a8ce3404ef84070ad5210c7cd50ee9f4807afc1"
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
- EARTH_RADIUS_KM: 6371
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
+ });
@@ -183,6 +183,7 @@ class Level {
183
183
  } else {
184
184
  this.val *= factor;
185
185
  }
186
+ return this;
186
187
  }
187
188
 
188
189
  toString() {
@@ -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(0, 1), new Level(1)), new Level(1)));
145
- expect(Level.equalsTo(Level.intersect(new Level(0, 2), new Level(1)), new Level(1)));
146
- expect(Level.equalsTo(Level.intersect(new Level(-1, 2), new Level(1)), new Level(1)));
147
- expect(Level.equalsTo(Level.intersect(new Level(1), new Level(0, 1)), new Level(1)));
148
- expect(Level.equalsTo(Level.intersect(new Level(1), new Level(0, 2)), new Level(1)));
149
- expect(Level.equalsTo(Level.intersect(new Level(1), new Level(-1, 2)), new Level(1)));
150
- expect(Level.equalsTo(Level.intersect(new Level(1, 2), new Level(-1, 2)), new Level(1, 2)));
151
- expect(Level.equalsTo(Level.intersect(new Level(-3, 1), new Level(-1, 2)), new Level(-1, 1)));
152
- expect(Level.equalsTo(Level.intersect(new Level(-3, -1), new Level(-1, 2)), new Level(-1)));
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(0, 1), new Level(1)), new Level(0, 1)));
168
- expect(Level.equalsTo(Level.union(new Level(0, 2), new Level(1)), new Level(0, 2)));
169
- expect(Level.equalsTo(Level.union(new Level(-1, 2), new Level(1)), new Level(-1, 2)));
170
- expect(Level.equalsTo(Level.union(new Level(1), new Level(0, 1)), new Level(0, 1)));
171
- expect(Level.equalsTo(Level.union(new Level(1), new Level(0, 2)), new Level(0, 2)));
172
- expect(Level.equalsTo(Level.union(new Level(1), new Level(-1, 2)), new Level(-1, 2)));
173
- expect(Level.equalsTo(Level.union(new Level(1, 2), new Level(-1, 2)), new Level(-1, 2)));
174
- expect(Level.equalsTo(Level.union(new Level(-3, 1), new Level(-1, 2)), new Level(-3, 2)));
175
- expect(Level.equalsTo(Level.union(new Level(-3, -1), new Level(-1, 2)), new Level(-3, 2)));
176
- expect(Level.equalsTo(Level.union(new Level(-3, -2), new Level(-1, 2)), new Level(-3, 2)));
177
- expect(Level.equalsTo(Level.union(new Level(-1, 2), new Level(-3, -2)), new Level(-3, 2)));
178
- expect(Level.equalsTo(Level.union(new Level(0), new Level(1, 2)), new Level(0, 2)));
179
- expect(Level.equalsTo(Level.union(new Level(1, 2), new Level(0)), new Level(0, 2)));
180
-
181
- expect(Level.equalsTo(new Level(0, 1).union(new Level(1)), new Level(0, 1)));
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
  });