@wemap/geo 11.0.0-alpha.16 → 11.0.0-alpha.2
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/dist/index.js +82 -89
- package/dist/index.js.map +1 -1
- package/package.json +5 -11
- package/src/Utils.ts +4 -4
- package/src/graph/GraphEdge.ts +8 -8
- package/src/graph/GraphNode.spec.ts +3 -5
- package/src/graph/GraphNode.ts +12 -12
- package/src/graph/GraphProjection.ts +3 -3
- package/src/graph/GraphUtils.ts +5 -5
- package/src/graph/MapMatching.ts +7 -7
- package/src/graph/Network.spec.ts +2 -5
- package/src/graph/Network.ts +21 -23
- package/src/router/GraphItinerary.spec.ts +1 -1
- package/src/router/GraphItinerary.ts +11 -11
- package/src/router/GraphRouter.spec.ts +16 -16
- package/src/router/GraphRouter.ts +34 -34
- package/src/router/GraphRouterOptions.ts +3 -3
- package/tests/CommonTest.ts +6 -8
- package/dist/index.mjs +0 -1846
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
3
|
var __publicField = (obj, key, value) => {
|
|
5
4
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
5
|
return value;
|
|
7
6
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const Logger = require("@wemap/logger");
|
|
11
|
-
const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
|
|
12
|
-
const Logger__default = /* @__PURE__ */ _interopDefaultLegacy(Logger);
|
|
7
|
+
import { wrap, deg2rad, rad2deg, Quaternion, Vector3, positiveMod, Rotations, diffAngleLines } from "@wemap/maths";
|
|
8
|
+
import Logger from "@wemap/logger";
|
|
13
9
|
const R_MAJOR = 6378137;
|
|
14
10
|
const R_MINOR = 63567523142e-4;
|
|
15
11
|
const EARTH_GRAVITY = 9.80665;
|
|
@@ -331,7 +327,7 @@ class Coordinates {
|
|
|
331
327
|
}
|
|
332
328
|
wrap() {
|
|
333
329
|
if (this._lng <= -180 || this._lng > 180) {
|
|
334
|
-
this._lng =
|
|
330
|
+
this._lng = wrap(this._lng, -180, 180);
|
|
335
331
|
}
|
|
336
332
|
}
|
|
337
333
|
static equals(pos1, pos2, eps = EPS_DEG_MM, epsAlt = EPS_MM) {
|
|
@@ -355,8 +351,8 @@ class Coordinates {
|
|
|
355
351
|
const dR = distance / R_MAJOR;
|
|
356
352
|
const cosDr = Math.cos(dR);
|
|
357
353
|
const sinDr = Math.sin(dR);
|
|
358
|
-
const phi1 =
|
|
359
|
-
const lambda1 =
|
|
354
|
+
const phi1 = deg2rad(this.lat);
|
|
355
|
+
const lambda1 = deg2rad(this.lng);
|
|
360
356
|
const phi2 = Math.asin(
|
|
361
357
|
Math.sin(phi1) * cosDr + Math.cos(phi1) * sinDr * Math.cos(bearing)
|
|
362
358
|
);
|
|
@@ -364,8 +360,8 @@ class Coordinates {
|
|
|
364
360
|
Math.sin(bearing) * sinDr * Math.cos(phi1),
|
|
365
361
|
cosDr - Math.sin(phi1) * Math.sin(phi2)
|
|
366
362
|
);
|
|
367
|
-
this.lat =
|
|
368
|
-
this.lng =
|
|
363
|
+
this.lat = rad2deg(phi2);
|
|
364
|
+
this.lng = rad2deg(lambda2);
|
|
369
365
|
if (elevation !== null) {
|
|
370
366
|
if (this.alt === null) {
|
|
371
367
|
throw new Error("Point altitude is not defined");
|
|
@@ -379,13 +375,13 @@ class Coordinates {
|
|
|
379
375
|
const lng1 = this.lng;
|
|
380
376
|
const lat2 = location2.lat;
|
|
381
377
|
const lng2 = location2.lng;
|
|
382
|
-
const dlat =
|
|
383
|
-
const dlng =
|
|
378
|
+
const dlat = deg2rad(lat2 - lat1);
|
|
379
|
+
const dlng = deg2rad(lng2 - lng1);
|
|
384
380
|
const dlngsin = Math.sin(dlng / 2);
|
|
385
381
|
const dlatsin = Math.sin(dlat / 2);
|
|
386
|
-
const lat1rad =
|
|
382
|
+
const lat1rad = deg2rad(lat1);
|
|
387
383
|
const lat1cos = Math.cos(lat1rad);
|
|
388
|
-
const lat2rad =
|
|
384
|
+
const lat2rad = deg2rad(lat2);
|
|
389
385
|
const lat2cos = Math.cos(lat2rad);
|
|
390
386
|
const angle = dlatsin * dlatsin + lat1cos * lat2cos * dlngsin * dlngsin;
|
|
391
387
|
const tangy = Math.sqrt(angle);
|
|
@@ -397,9 +393,9 @@ class Coordinates {
|
|
|
397
393
|
return point1.distanceTo(point2);
|
|
398
394
|
}
|
|
399
395
|
bearingTo(location2) {
|
|
400
|
-
const lat1 =
|
|
401
|
-
const lat2 =
|
|
402
|
-
const diffLng =
|
|
396
|
+
const lat1 = deg2rad(this.lat);
|
|
397
|
+
const lat2 = deg2rad(location2.lat);
|
|
398
|
+
const diffLng = deg2rad(location2.lng - this.lng);
|
|
403
399
|
return Math.atan2(
|
|
404
400
|
Math.sin(diffLng) * Math.cos(lat2),
|
|
405
401
|
Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(diffLng)
|
|
@@ -409,19 +405,19 @@ class Coordinates {
|
|
|
409
405
|
return point1.bearingTo(point2);
|
|
410
406
|
}
|
|
411
407
|
get enuToEcefRotation() {
|
|
412
|
-
const rot1 =
|
|
413
|
-
const rot2 =
|
|
414
|
-
return
|
|
408
|
+
const rot1 = Quaternion.fromAxisAngle([0, 0, 1], Math.PI / 2 + deg2rad(this.lng));
|
|
409
|
+
const rot2 = Quaternion.fromAxisAngle([1, 0, 0], Math.PI / 2 - deg2rad(this.lat));
|
|
410
|
+
return Quaternion.multiply(rot1, rot2);
|
|
415
411
|
}
|
|
416
412
|
get ecefToEnuRotation() {
|
|
417
|
-
const rot1 =
|
|
418
|
-
const rot2 =
|
|
419
|
-
return
|
|
413
|
+
const rot1 = Quaternion.fromAxisAngle([1, 0, 0], deg2rad(this.lat) - Math.PI / 2);
|
|
414
|
+
const rot2 = Quaternion.fromAxisAngle([0, 0, 1], -deg2rad(this.lng) - Math.PI / 2);
|
|
415
|
+
return Quaternion.multiply(rot1, rot2);
|
|
420
416
|
}
|
|
421
417
|
get ecef() {
|
|
422
418
|
if (!this._ecef) {
|
|
423
|
-
const lat =
|
|
424
|
-
const lng =
|
|
419
|
+
const lat = deg2rad(this.lat);
|
|
420
|
+
const lng = deg2rad(this.lng);
|
|
425
421
|
const alt = this.alt || 0;
|
|
426
422
|
const x = (R_MAJOR + alt) * Math.cos(lat) * Math.cos(lng);
|
|
427
423
|
const y = (R_MAJOR + alt) * Math.cos(lat) * Math.sin(lng);
|
|
@@ -439,21 +435,21 @@ class Coordinates {
|
|
|
439
435
|
const lat = Math.atan2(z, p);
|
|
440
436
|
const alt = p / Math.cos(lat) - R_MAJOR;
|
|
441
437
|
lng = lng % (2 * Math.PI);
|
|
442
|
-
const newPoint = new Coordinates(
|
|
438
|
+
const newPoint = new Coordinates(rad2deg(lat), rad2deg(lng), alt);
|
|
443
439
|
newPoint._ecef = ecef;
|
|
444
440
|
return newPoint;
|
|
445
441
|
}
|
|
446
442
|
getSegmentProjection(p1, p2) {
|
|
447
|
-
const a =
|
|
448
|
-
const b =
|
|
449
|
-
const c =
|
|
450
|
-
const G =
|
|
451
|
-
if (
|
|
443
|
+
const a = Vector3.normalize(p1.ecef);
|
|
444
|
+
const b = Vector3.normalize(p2.ecef);
|
|
445
|
+
const c = Vector3.normalize(this.ecef);
|
|
446
|
+
const G = Vector3.cross(a, b);
|
|
447
|
+
if (Vector3.norm(G) === 0) {
|
|
452
448
|
return null;
|
|
453
449
|
}
|
|
454
|
-
const F =
|
|
455
|
-
const t =
|
|
456
|
-
const posECEF =
|
|
450
|
+
const F = Vector3.cross(c, G);
|
|
451
|
+
const t = Vector3.normalize(Vector3.cross(G, F));
|
|
452
|
+
const posECEF = Vector3.multiplyScalar(t, R_MAJOR);
|
|
457
453
|
const poseCoordinates = Coordinates.fromECEF(posECEF);
|
|
458
454
|
let alt;
|
|
459
455
|
if (p1.alt !== null && p2.alt !== null) {
|
|
@@ -688,14 +684,14 @@ function trimRoute(route, startPosition = route[0], length = Number.MAX_VALUE) {
|
|
|
688
684
|
}
|
|
689
685
|
return newRoute;
|
|
690
686
|
}
|
|
691
|
-
function simplifyRoute(coords, precisionAngle =
|
|
687
|
+
function simplifyRoute(coords, precisionAngle = deg2rad(5)) {
|
|
692
688
|
const isClosed = coords[0].equals(coords[coords.length - 1]);
|
|
693
689
|
let newRoute = coords.slice(0, coords.length - (isClosed ? 1 : 0));
|
|
694
690
|
const len = newRoute.length;
|
|
695
691
|
for (let i = isClosed ? 0 : 1; i < len; i++) {
|
|
696
|
-
const p0 = coords[
|
|
692
|
+
const p0 = coords[positiveMod(i - 1, len)];
|
|
697
693
|
const p1 = coords[i];
|
|
698
|
-
const p2 = coords[
|
|
694
|
+
const p2 = coords[positiveMod(i + 1, len)];
|
|
699
695
|
const seg1Dir = p0.bearingTo(p1);
|
|
700
696
|
const seg2Dir = p1.bearingTo(p2);
|
|
701
697
|
if (Math.abs(seg2Dir - seg1Dir) < precisionAngle) {
|
|
@@ -715,7 +711,7 @@ function geolocationPositionToUserPosition(geolocationPosition) {
|
|
|
715
711
|
const userPosition = new UserPosition(latitude, longitude);
|
|
716
712
|
userPosition.time = geolocationPosition.timestamp;
|
|
717
713
|
userPosition.accuracy = accuracy;
|
|
718
|
-
userPosition.bearing = heading ?
|
|
714
|
+
userPosition.bearing = heading ? deg2rad(heading) : null;
|
|
719
715
|
return userPosition;
|
|
720
716
|
}
|
|
721
717
|
function calcDistance(coords) {
|
|
@@ -904,19 +900,19 @@ class GeoRef {
|
|
|
904
900
|
this.origin = origin;
|
|
905
901
|
}
|
|
906
902
|
localToWorld(localPosition) {
|
|
907
|
-
const enuTranslationScaled =
|
|
908
|
-
const rotationOffset =
|
|
909
|
-
const enuToEcefRotationOrigin =
|
|
910
|
-
const ecefTranslation =
|
|
911
|
-
const ecef =
|
|
903
|
+
const enuTranslationScaled = Vector3.multiplyScalar(localPosition, this.scale);
|
|
904
|
+
const rotationOffset = Quaternion.fromAxisAngle([0, 0, 1], this.heading);
|
|
905
|
+
const enuToEcefRotationOrigin = Quaternion.multiply(rotationOffset, this.origin.enuToEcefRotation);
|
|
906
|
+
const ecefTranslation = Quaternion.rotate(enuToEcefRotationOrigin, enuTranslationScaled);
|
|
907
|
+
const ecef = Vector3.sum(this.origin.ecef, ecefTranslation);
|
|
912
908
|
return Coordinates.fromECEF(ecef);
|
|
913
909
|
}
|
|
914
910
|
worldToLocal(coords) {
|
|
915
|
-
const rotationOffset =
|
|
916
|
-
const ecefToEnuRotationOrigin =
|
|
917
|
-
const ecefTranslation =
|
|
918
|
-
const ecefTranslationScaled =
|
|
919
|
-
return
|
|
911
|
+
const rotationOffset = Quaternion.fromAxisAngle([0, 0, 1], -this.heading);
|
|
912
|
+
const ecefToEnuRotationOrigin = Quaternion.multiply(this.origin.ecefToEnuRotation, rotationOffset);
|
|
913
|
+
const ecefTranslation = Vector3.subtract(coords.ecef, this.origin.ecef);
|
|
914
|
+
const ecefTranslationScaled = Vector3.multiplyScalar(ecefTranslation, 1 / this.scale);
|
|
915
|
+
return Quaternion.rotate(ecefToEnuRotationOrigin, ecefTranslationScaled);
|
|
920
916
|
}
|
|
921
917
|
toJson() {
|
|
922
918
|
return {
|
|
@@ -950,7 +946,7 @@ class Attitude {
|
|
|
950
946
|
return this._quaternion;
|
|
951
947
|
}
|
|
952
948
|
set quaternion(quaternion) {
|
|
953
|
-
if (Math.abs(1 -
|
|
949
|
+
if (Math.abs(1 - Quaternion.norm(quaternion)) > 1e-4) {
|
|
954
950
|
throw new Error("quaternion is not a unit quaternion");
|
|
955
951
|
}
|
|
956
952
|
this._quaternion = quaternion;
|
|
@@ -974,25 +970,25 @@ class Attitude {
|
|
|
974
970
|
}
|
|
975
971
|
get eulerAngles() {
|
|
976
972
|
if (this._eulerAngles === null) {
|
|
977
|
-
this._eulerAngles =
|
|
973
|
+
this._eulerAngles = Rotations.quaternionToEulerZXY(this.quaternion);
|
|
978
974
|
}
|
|
979
975
|
return this._eulerAngles;
|
|
980
976
|
}
|
|
981
977
|
get eulerAnglesDegrees() {
|
|
982
|
-
return this.eulerAngles.map((x) =>
|
|
978
|
+
return this.eulerAngles.map((x) => rad2deg(x));
|
|
983
979
|
}
|
|
984
980
|
get heading() {
|
|
985
981
|
if (this._heading === null) {
|
|
986
982
|
let offset = 0;
|
|
987
983
|
if (typeof window !== "undefined" && window && window.orientation) {
|
|
988
|
-
offset =
|
|
984
|
+
offset = deg2rad(window.orientation);
|
|
989
985
|
}
|
|
990
|
-
this._heading =
|
|
986
|
+
this._heading = Rotations.getHeadingFromQuaternion(this.quaternion) + offset;
|
|
991
987
|
}
|
|
992
988
|
return this._heading;
|
|
993
989
|
}
|
|
994
990
|
get headingDegrees() {
|
|
995
|
-
return
|
|
991
|
+
return rad2deg(this.heading);
|
|
996
992
|
}
|
|
997
993
|
static equals(att1, att2) {
|
|
998
994
|
if (att1 === null && att1 === att2) {
|
|
@@ -1004,7 +1000,7 @@ class Attitude {
|
|
|
1004
1000
|
if (att1 === att2) {
|
|
1005
1001
|
return true;
|
|
1006
1002
|
}
|
|
1007
|
-
return
|
|
1003
|
+
return Quaternion.equals(att1.quaternion, att2.quaternion);
|
|
1008
1004
|
}
|
|
1009
1005
|
equals(other) {
|
|
1010
1006
|
return Attitude.equals(this, other);
|
|
@@ -1029,8 +1025,8 @@ class Attitude {
|
|
|
1029
1025
|
return new Attitude(this.quaternion.slice(0), this.time, this.accuracy);
|
|
1030
1026
|
}
|
|
1031
1027
|
static diff(attitudeStart, attitudeEnd) {
|
|
1032
|
-
const quaternionDiff =
|
|
1033
|
-
|
|
1028
|
+
const quaternionDiff = Quaternion.multiply(
|
|
1029
|
+
Quaternion.inverse(attitudeStart.quaternion),
|
|
1034
1030
|
attitudeEnd.quaternion
|
|
1035
1031
|
);
|
|
1036
1032
|
let timeDiff = null;
|
|
@@ -1064,7 +1060,7 @@ class AbsoluteHeading {
|
|
|
1064
1060
|
}
|
|
1065
1061
|
toAttitude() {
|
|
1066
1062
|
return new Attitude(
|
|
1067
|
-
|
|
1063
|
+
Quaternion.fromAxisAngle([0, 0, 1], -this.heading),
|
|
1068
1064
|
this.time,
|
|
1069
1065
|
this.accuracy
|
|
1070
1066
|
);
|
|
@@ -1394,12 +1390,7 @@ Nodes
|
|
|
1394
1390
|
network.nodes.push(newNode);
|
|
1395
1391
|
return newNode;
|
|
1396
1392
|
};
|
|
1397
|
-
const createEdgeFromNodes = (node1, node2) => new GraphEdge(
|
|
1398
|
-
node1,
|
|
1399
|
-
node2,
|
|
1400
|
-
Level.union(node1.coords.level, node2.coords.level),
|
|
1401
|
-
null
|
|
1402
|
-
);
|
|
1393
|
+
const createEdgeFromNodes = (node1, node2) => new GraphEdge(node1, node2, Level.union(node1.coords.level, node2.coords.level), null);
|
|
1403
1394
|
for (const segment of segments) {
|
|
1404
1395
|
let previousNode = null;
|
|
1405
1396
|
for (const coords of segment) {
|
|
@@ -1466,7 +1457,7 @@ const _MapMatching = class {
|
|
|
1466
1457
|
}
|
|
1467
1458
|
if (useBearing) {
|
|
1468
1459
|
if (checkEdge) {
|
|
1469
|
-
const diffAngle =
|
|
1460
|
+
const diffAngle = diffAngleLines(edge.bearing, location.bearing);
|
|
1470
1461
|
if (diffAngle > this._maxAngleBearing) {
|
|
1471
1462
|
checkEdge = false;
|
|
1472
1463
|
}
|
|
@@ -1596,7 +1587,7 @@ class GraphItinerary {
|
|
|
1596
1587
|
const prevNode = arr[idx - 1];
|
|
1597
1588
|
const edge = getEdgeByNodes(prevNode.edges, prevNode, node);
|
|
1598
1589
|
if (!edge) {
|
|
1599
|
-
|
|
1590
|
+
Logger.error("Cannot retrieve edge to create itinerary");
|
|
1600
1591
|
return;
|
|
1601
1592
|
}
|
|
1602
1593
|
const newEdge = new GraphEdge(
|
|
@@ -1728,7 +1719,7 @@ class GraphRouter {
|
|
|
1728
1719
|
createNodeInsideEdge(edge, point) {
|
|
1729
1720
|
const a = edge.node1;
|
|
1730
1721
|
const b = edge.node2;
|
|
1731
|
-
const m = new GraphNode(point,
|
|
1722
|
+
const m = new GraphNode(point, edge.builtFrom);
|
|
1732
1723
|
m.coords.level = edge.level;
|
|
1733
1724
|
const u = edge.clone();
|
|
1734
1725
|
u.node1 = a;
|
|
@@ -1824,25 +1815,27 @@ class GraphRouter {
|
|
|
1824
1815
|
return GraphItinerary.fromNetworkNodes(start.coords, end.coords, path, edgesWeights);
|
|
1825
1816
|
}
|
|
1826
1817
|
}
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1818
|
+
export {
|
|
1819
|
+
AbsoluteHeading,
|
|
1820
|
+
Attitude,
|
|
1821
|
+
BoundingBox,
|
|
1822
|
+
Constants,
|
|
1823
|
+
Coordinates,
|
|
1824
|
+
GeoRef,
|
|
1825
|
+
GeoRelativePosition,
|
|
1826
|
+
GraphEdge,
|
|
1827
|
+
GraphItinerary,
|
|
1828
|
+
GraphNode,
|
|
1829
|
+
GraphProjection,
|
|
1830
|
+
GraphRouter,
|
|
1831
|
+
GraphRouterOptions,
|
|
1832
|
+
GraphUtils,
|
|
1833
|
+
Level,
|
|
1834
|
+
MapMatching,
|
|
1835
|
+
Network,
|
|
1836
|
+
NoRouteFoundError,
|
|
1837
|
+
RelativePosition,
|
|
1838
|
+
UserPosition,
|
|
1839
|
+
Utils
|
|
1840
|
+
};
|
|
1848
1841
|
//# sourceMappingURL=index.js.map
|