@wemap/geo 9.0.0-alpha.4 → 9.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.d.ts +3 -3
- package/package.json +4 -4
- package/src/Utils.js +3 -3
- package/src/Utils.spec.js +16 -16
- package/src/coordinates/BoundingBox.js +5 -5
- package/src/coordinates/BoundingBox.spec.js +10 -10
- package/src/coordinates/Coordinates.js +4 -4
- package/src/coordinates/Coordinates.spec.js +35 -35
- package/src/coordinates/Level.js +3 -3
- package/src/coordinates/Level.spec.js +9 -7
- package/src/coordinates/RelativePosition.js +3 -3
- package/src/coordinates/RelativePosition.spec.js +16 -16
- package/src/coordinates/UserPosition.js +4 -4
- package/src/coordinates/UserPosition.spec.js +20 -20
- package/src/graph/GraphEdge.js +4 -4
- package/src/graph/GraphEdge.spec.js +12 -12
- package/src/graph/GraphNode.js +2 -2
- package/src/graph/GraphNode.spec.js +36 -36
- package/src/graph/MapMatching.js +2 -2
- package/src/graph/MapMatching.spec.js +4 -4
- package/src/graph/Network.js +2 -2
- package/src/graph/Network.spec.js +3 -3
- package/src/rotations/AbsoluteHeading.js +3 -3
- package/src/rotations/AbsoluteHeading.spec.js +13 -13
- package/src/rotations/Attitude.js +4 -4
- package/src/rotations/Attitude.spec.js +10 -10
package/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ declare module '@wemap/geo' {
|
|
|
13
13
|
static union(first: Level_t, second: Level_t): Level_t;
|
|
14
14
|
static multiplyBy(level: Level_t, factor: number): Level_t;
|
|
15
15
|
static toString(level: Level_t): string;
|
|
16
|
-
static
|
|
16
|
+
static equals(first: Level_t, second: Level_t): boolean;
|
|
17
17
|
static diff(first: Level_t, second: Level_t): null | number;
|
|
18
18
|
|
|
19
19
|
/** @deprecated */
|
|
@@ -36,8 +36,8 @@ declare module '@wemap/geo' {
|
|
|
36
36
|
|
|
37
37
|
clone(): Coordinates;
|
|
38
38
|
wrap(): void;
|
|
39
|
-
static
|
|
40
|
-
|
|
39
|
+
static equals(pos1: Coordinates, pos2: Coordinates, eps?: number, epsAlt?: number): boolean;
|
|
40
|
+
equals(other: Coordinates): boolean;
|
|
41
41
|
|
|
42
42
|
destinationPoint(distance: number, bearing: number, elevation?: number): Coordinates;
|
|
43
43
|
move(distance: number, bearing: number, elevation?: number): void;
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"directory": "packages/geo"
|
|
14
14
|
},
|
|
15
15
|
"name": "@wemap/geo",
|
|
16
|
-
"version": "9.0.0
|
|
16
|
+
"version": "9.0.0",
|
|
17
17
|
"bugs": {
|
|
18
18
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
19
19
|
},
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
],
|
|
29
29
|
"license": "ISC",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@wemap/logger": "^9.0.0
|
|
32
|
-
"@wemap/maths": "^
|
|
31
|
+
"@wemap/logger": "^9.0.0",
|
|
32
|
+
"@wemap/maths": "^9.0.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "9f16c3cebf6f0e6d03a83835607528f5c37707cf"
|
|
35
35
|
}
|
package/src/Utils.js
CHANGED
|
@@ -94,14 +94,14 @@ export function trimRoute(route, startPosition = route[0], length = Number.MAX_V
|
|
|
94
94
|
const p1 = route[currentPointIndex - 1];
|
|
95
95
|
const p2 = route[currentPointIndex];
|
|
96
96
|
|
|
97
|
-
if (Coordinates.
|
|
97
|
+
if (Coordinates.equals(startPosition, p1)) {
|
|
98
98
|
newRoute.push(p1);
|
|
99
99
|
previousPoint = p1;
|
|
100
100
|
break;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
const proj = startPosition.getSegmentProjection(p1, p2);
|
|
104
|
-
if (proj && Coordinates.
|
|
104
|
+
if (proj && Coordinates.equals(startPosition, proj) && !proj.equals(p2)) {
|
|
105
105
|
newRoute.push(proj);
|
|
106
106
|
previousPoint = proj;
|
|
107
107
|
break;
|
|
@@ -139,7 +139,7 @@ export function trimRoute(route, startPosition = route[0], length = Number.MAX_V
|
|
|
139
139
|
*/
|
|
140
140
|
export function simplifyRoute(coords, precisionAngle = deg2rad(5)) {
|
|
141
141
|
|
|
142
|
-
const isClosed = (coords[0].
|
|
142
|
+
const isClosed = (coords[0].equals(coords[coords.length - 1]));
|
|
143
143
|
|
|
144
144
|
let newRoute = coords.slice(0, coords.length - (isClosed ? 1 : 0));
|
|
145
145
|
|
package/src/Utils.spec.js
CHANGED
|
@@ -66,43 +66,43 @@ describe('Geo Utils', () => {
|
|
|
66
66
|
newRoute = trimRoute(route);
|
|
67
67
|
expect(newRoute.length).equals(3);
|
|
68
68
|
for (let i = 0; i < newRoute.length - 1; i++) {
|
|
69
|
-
expect(newRoute[i].
|
|
69
|
+
expect(newRoute[i].equals(route[i])).true;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
newRoute = trimRoute(route, p1, 100);
|
|
73
73
|
expect(newRoute.length).equals(2);
|
|
74
|
-
expect(newRoute[0].
|
|
75
|
-
expect(newRoute[1].
|
|
74
|
+
expect(newRoute[0].equals(p1)).true;
|
|
75
|
+
expect(newRoute[1].equals(p2)).true;
|
|
76
76
|
|
|
77
77
|
newRoute = trimRoute(route, p1, 90);
|
|
78
78
|
expect(newRoute.length).equals(2);
|
|
79
|
-
expect(newRoute[0].
|
|
80
|
-
expect(newRoute[1].
|
|
79
|
+
expect(newRoute[0].equals(p1)).true;
|
|
80
|
+
expect(newRoute[1].equals(p1.destinationPoint(90, Math.PI / 4))).true;
|
|
81
81
|
|
|
82
82
|
newRoute = trimRoute(route, p2, 10);
|
|
83
83
|
expect(newRoute.length).equals(2);
|
|
84
|
-
expect(newRoute[0].
|
|
85
|
-
expect(newRoute[1].
|
|
84
|
+
expect(newRoute[0].equals(p2)).true;
|
|
85
|
+
expect(newRoute[1].equals(p2.destinationPoint(10, Math.PI / 2))).true;
|
|
86
86
|
|
|
87
87
|
const p4 = p1.destinationPoint(20, Math.PI / 4);
|
|
88
88
|
newRoute = trimRoute(route, p4);
|
|
89
89
|
expect(newRoute.length).equals(3);
|
|
90
|
-
expect(newRoute[0].
|
|
91
|
-
expect(newRoute[1].
|
|
92
|
-
expect(newRoute[2].
|
|
90
|
+
expect(newRoute[0].equals(p4)).true;
|
|
91
|
+
expect(newRoute[1].equals(p2)).true;
|
|
92
|
+
expect(newRoute[2].equals(p3)).true;
|
|
93
93
|
|
|
94
94
|
const p5 = p2.destinationPoint(20, Math.PI / 2);
|
|
95
95
|
newRoute = trimRoute(route, p4, 100);
|
|
96
96
|
expect(newRoute.length).equals(3);
|
|
97
|
-
expect(newRoute[0].
|
|
98
|
-
expect(newRoute[1].
|
|
99
|
-
expect(newRoute[2].
|
|
97
|
+
expect(newRoute[0].equals(p4)).true;
|
|
98
|
+
expect(newRoute[1].equals(p2)).true;
|
|
99
|
+
expect(newRoute[2].equals(p5)).true;
|
|
100
100
|
|
|
101
101
|
newRoute = trimRoute(route, p4, 200);
|
|
102
102
|
expect(newRoute.length).equals(3);
|
|
103
|
-
expect(newRoute[0].
|
|
104
|
-
expect(newRoute[1].
|
|
105
|
-
expect(newRoute[2].
|
|
103
|
+
expect(newRoute[0].equals(p4)).true;
|
|
104
|
+
expect(newRoute[1].equals(p2)).true;
|
|
105
|
+
expect(newRoute[2].equals(p3)).true;
|
|
106
106
|
});
|
|
107
107
|
|
|
108
108
|
it('simplifyRoute', () => {
|
|
@@ -195,13 +195,13 @@ class BoundingBox {
|
|
|
195
195
|
return this.northEast.lat;
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
static
|
|
199
|
-
return Coordinates.
|
|
200
|
-
&& Coordinates.
|
|
198
|
+
static equals(bb1, bb2) {
|
|
199
|
+
return Coordinates.equals(bb1.northEast, bb2.northEast)
|
|
200
|
+
&& Coordinates.equals(bb1.southWest, bb2.southWest);
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
|
|
204
|
-
return BoundingBox.
|
|
203
|
+
equals(other) {
|
|
204
|
+
return BoundingBox.equals(this, other);
|
|
205
205
|
}
|
|
206
206
|
|
|
207
207
|
/**
|
|
@@ -34,22 +34,22 @@ describe('Bounding Box', () => {
|
|
|
34
34
|
expect(boundingBox.southWest).equals(southWest);
|
|
35
35
|
|
|
36
36
|
const boundingBox2 = BoundingBox.fromArray([-20, -5, 40, 10]);
|
|
37
|
-
expect(boundingBox2.
|
|
37
|
+
expect(boundingBox2.equals(boundingBox)).is.true;
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
|
|
41
|
-
it('
|
|
41
|
+
it('equals', () => {
|
|
42
42
|
boundingBox = new BoundingBox(northEast, southWest);
|
|
43
|
-
expect(boundingBox.
|
|
43
|
+
expect(boundingBox.equals(new BoundingBox(
|
|
44
44
|
new Coordinates(10, 40), new Coordinates(-5, -20)
|
|
45
45
|
))).true;
|
|
46
|
-
expect(BoundingBox.
|
|
46
|
+
expect(BoundingBox.equals(boundingBox, new BoundingBox(
|
|
47
47
|
new Coordinates(10, 40), new Coordinates(-5, -20)
|
|
48
48
|
))).true;
|
|
49
|
-
expect(BoundingBox.
|
|
49
|
+
expect(BoundingBox.equals(boundingBox, new BoundingBox(
|
|
50
50
|
new Coordinates(10, 10), new Coordinates(-5, -20)
|
|
51
51
|
))).false;
|
|
52
|
-
expect(BoundingBox.
|
|
52
|
+
expect(BoundingBox.equals(boundingBox, new BoundingBox(
|
|
53
53
|
new Coordinates(10, 40), new Coordinates(-15, -20)
|
|
54
54
|
))).false;
|
|
55
55
|
});
|
|
@@ -60,11 +60,11 @@ describe('Bounding Box', () => {
|
|
|
60
60
|
expect(boundingBox.getEast()).equals(northEast.lng);
|
|
61
61
|
expect(boundingBox.getSouth()).equals(southWest.lat);
|
|
62
62
|
expect(boundingBox.getWest()).equals(southWest.lng);
|
|
63
|
-
expect(Coordinates.
|
|
64
|
-
expect(Coordinates.
|
|
65
|
-
expect(Coordinates.
|
|
63
|
+
expect(Coordinates.equals(boundingBox.getNorthEast(), northEast)).true;
|
|
64
|
+
expect(Coordinates.equals(boundingBox.getSouthWest(), southWest)).true;
|
|
65
|
+
expect(Coordinates.equals(boundingBox.getNorthWest(),
|
|
66
66
|
new Coordinates(northEast.lat, southWest.lng))).true;
|
|
67
|
-
expect(Coordinates.
|
|
67
|
+
expect(Coordinates.equals(boundingBox.getSouthEast(),
|
|
68
68
|
new Coordinates(southWest.lat, northEast.lng))).true;
|
|
69
69
|
});
|
|
70
70
|
|
|
@@ -162,7 +162,7 @@ class Coordinates {
|
|
|
162
162
|
* @param {Number} eps latitude and longitude epsilon in degrees (default: 1e-8 [~1mm at lat=0])
|
|
163
163
|
* @param {Number} epsAlt altitude epsilon in meters (default: 1e-3 [= 1mm])
|
|
164
164
|
*/
|
|
165
|
-
static
|
|
165
|
+
static equals(pos1, pos2, eps = Constants.EPS_DEG_MM, epsAlt = Constants.EPS_MM) {
|
|
166
166
|
|
|
167
167
|
// Handle null comparison
|
|
168
168
|
if (pos1 === null && pos1 === pos2) {
|
|
@@ -178,15 +178,15 @@ class Coordinates {
|
|
|
178
178
|
&& (pos1.alt === pos2.alt
|
|
179
179
|
|| pos1.alt !== null && pos2.alt !== null
|
|
180
180
|
&& Math.abs(pos2.alt - pos1.alt) < epsAlt)
|
|
181
|
-
&& Level.
|
|
181
|
+
&& Level.equals(pos1.level, pos2.level);
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
/**
|
|
185
185
|
* @param {Coordinates} other
|
|
186
186
|
* @returns {!Boolean}
|
|
187
187
|
*/
|
|
188
|
-
|
|
189
|
-
return Coordinates.
|
|
188
|
+
equals(other) {
|
|
189
|
+
return Coordinates.equals(this, other);
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
/**
|
|
@@ -74,34 +74,34 @@ describe('Coordinates', () => {
|
|
|
74
74
|
expect(clonePosition.level).not.equals(level);
|
|
75
75
|
});
|
|
76
76
|
|
|
77
|
-
it('
|
|
77
|
+
it('equals', () => {
|
|
78
78
|
let position;
|
|
79
79
|
|
|
80
80
|
position = new Coordinates(0, 0);
|
|
81
|
-
expect(Coordinates.
|
|
82
|
-
expect(Coordinates.
|
|
83
|
-
expect(Coordinates.
|
|
84
|
-
expect(Coordinates.
|
|
81
|
+
expect(Coordinates.equals(position, new Coordinates(0, 0))).true;
|
|
82
|
+
expect(Coordinates.equals(position, new Coordinates(0, 0, 0))).false;
|
|
83
|
+
expect(Coordinates.equals(position, new Coordinates(0, 0, null, 0))).false;
|
|
84
|
+
expect(Coordinates.equals(position, new Coordinates(0, 0, null, null))).true;
|
|
85
85
|
|
|
86
86
|
|
|
87
87
|
position = new Coordinates(45, 5, 0, 0);
|
|
88
|
-
expect(Coordinates.
|
|
89
|
-
expect(Coordinates.
|
|
90
|
-
expect(Coordinates.
|
|
91
|
-
expect(Coordinates.
|
|
88
|
+
expect(Coordinates.equals(position, new Coordinates(45, 5, 0, 0))).true;
|
|
89
|
+
expect(Coordinates.equals(position, new Coordinates(45, 5, 1, 0))).false;
|
|
90
|
+
expect(Coordinates.equals(position, new Coordinates(45, 5, 0, 1))).false;
|
|
91
|
+
expect(Coordinates.equals(position, {
|
|
92
92
|
lat: 45,
|
|
93
93
|
lng: 5
|
|
94
94
|
})).false;
|
|
95
|
-
expect(Coordinates.
|
|
95
|
+
expect(Coordinates.equals({
|
|
96
96
|
lat: 45,
|
|
97
97
|
lng: 5
|
|
98
98
|
}, position)).false;
|
|
99
|
-
expect(Coordinates.
|
|
100
|
-
expect(Coordinates.
|
|
101
|
-
expect(Coordinates.
|
|
99
|
+
expect(Coordinates.equals(position, null)).false;
|
|
100
|
+
expect(Coordinates.equals(null, position)).false;
|
|
101
|
+
expect(Coordinates.equals(null, null)).true;
|
|
102
102
|
|
|
103
|
-
expect(position.
|
|
104
|
-
expect(position.
|
|
103
|
+
expect(position.equals(new Coordinates(45, 5, 0, 0))).true;
|
|
104
|
+
expect(position.equals(new Coordinates(45, 5, 0, 1))).false;
|
|
105
105
|
});
|
|
106
106
|
|
|
107
107
|
it('toString', () => {
|
|
@@ -123,13 +123,13 @@ describe('Coordinates', () => {
|
|
|
123
123
|
let position;
|
|
124
124
|
|
|
125
125
|
position = new Coordinates(0, 0, 0, 0).move(100000, 0);
|
|
126
|
-
expect(Coordinates.
|
|
126
|
+
expect(Coordinates.equals(position, new Coordinates(0.8983152841195214, 0, 0, 0))).true;
|
|
127
127
|
|
|
128
128
|
position = new Coordinates(0, 0, 0, 0).move(100000, Math.PI / 2);
|
|
129
|
-
expect(Coordinates.
|
|
129
|
+
expect(Coordinates.equals(position, new Coordinates(0, 0.8983152841195212, 0, 0))).true;
|
|
130
130
|
|
|
131
131
|
position = new Coordinates(0, 0, 0).move(100000, 0, 10);
|
|
132
|
-
expect(Coordinates.
|
|
132
|
+
expect(Coordinates.equals(position, new Coordinates(0.8983152841195214, 0, 10))).true;
|
|
133
133
|
|
|
134
134
|
expect(() => new Coordinates(0, 0).move(100000, 0, 10)).throw(Error);
|
|
135
135
|
|
|
@@ -138,7 +138,7 @@ describe('Coordinates', () => {
|
|
|
138
138
|
const newPosition = position.destinationPoint(100000, 0);
|
|
139
139
|
expect(newPosition).not.equals(position);
|
|
140
140
|
expect(newPosition.level).not.equal(position.level);
|
|
141
|
-
expect(Coordinates.
|
|
141
|
+
expect(Coordinates.equals(newPosition, new Coordinates(0.8983152841195214, 0, null, level))).true;
|
|
142
142
|
});
|
|
143
143
|
|
|
144
144
|
|
|
@@ -149,7 +149,7 @@ describe('Coordinates', () => {
|
|
|
149
149
|
expect(position.ecef).deep.equals(
|
|
150
150
|
[4492868.9655526765, 393075.10119330435, 4510030.995104634]
|
|
151
151
|
);
|
|
152
|
-
expect(Coordinates.
|
|
152
|
+
expect(Coordinates.equals(Coordinates.fromECEF(position.ecef), position)).true;
|
|
153
153
|
expect(position.enuToEcefRotation).deep.equals(
|
|
154
154
|
[0.6241639651811595, 0.2585371795226045, 0.2821438218554906, 0.6811554412633039]
|
|
155
155
|
);
|
|
@@ -159,7 +159,7 @@ describe('Coordinates', () => {
|
|
|
159
159
|
|
|
160
160
|
position = new Coordinates(-15, 25, 1200);
|
|
161
161
|
expect(position.ecef).deep.equals([5584638.098155466, 2604159.5131940604, -1651093.9107271794]);
|
|
162
|
-
expect(Coordinates.
|
|
162
|
+
expect(Coordinates.equals(Coordinates.fromECEF(position.ecef), position)).true;
|
|
163
163
|
expect(position.enuToEcefRotation).deep.equals(
|
|
164
164
|
[0.32708727738303844, 0.42626843901912514, 0.6691074207087071, 0.5134241817667833]
|
|
165
165
|
);
|
|
@@ -181,10 +181,10 @@ describe('Coordinates', () => {
|
|
|
181
181
|
p2 = new Coordinates(0, 30);
|
|
182
182
|
|
|
183
183
|
projection = new Coordinates(45, 5).getSegmentProjection(p1, p2);
|
|
184
|
-
expect(Coordinates.
|
|
184
|
+
expect(Coordinates.equals(projection, new Coordinates(0, 5))).true;
|
|
185
185
|
|
|
186
186
|
projection = new Coordinates(-10, 30).getSegmentProjection(p1, p2);
|
|
187
|
-
expect(Coordinates.
|
|
187
|
+
expect(Coordinates.equals(projection, new Coordinates(0, 30))).true;
|
|
188
188
|
|
|
189
189
|
projection = new Coordinates(10, 50).getSegmentProjection(p1, p2);
|
|
190
190
|
expect(projection).is.null;
|
|
@@ -193,10 +193,10 @@ describe('Coordinates', () => {
|
|
|
193
193
|
p2 = new Coordinates(30, 10);
|
|
194
194
|
|
|
195
195
|
projection = new Coordinates(10, -30).getSegmentProjection(p1, p2);
|
|
196
|
-
expect(Coordinates.
|
|
196
|
+
expect(Coordinates.equals(projection, new Coordinates(1.5735557770204767, 0.473398796436419))).true;
|
|
197
197
|
|
|
198
198
|
projection = new Coordinates(0, 10).getSegmentProjection(p1, p2);
|
|
199
|
-
expect(Coordinates.
|
|
199
|
+
expect(Coordinates.equals(projection, new Coordinates(2.7840283663153627, 0.8380346611000419))).true;
|
|
200
200
|
|
|
201
201
|
projection = new Coordinates(45, 5).getSegmentProjection(p1, p2);
|
|
202
202
|
expect(projection).is.null;
|
|
@@ -205,7 +205,7 @@ describe('Coordinates', () => {
|
|
|
205
205
|
p2 = new Coordinates(0, 30, 15);
|
|
206
206
|
|
|
207
207
|
projection = new Coordinates(45, 5, 0).getSegmentProjection(p1, p2);
|
|
208
|
-
expect(Coordinates.
|
|
208
|
+
expect(Coordinates.equals(projection, new Coordinates(0, 5, 12.5))).true;
|
|
209
209
|
|
|
210
210
|
});
|
|
211
211
|
|
|
@@ -273,39 +273,39 @@ describe('Coordinates', () => {
|
|
|
273
273
|
let position;
|
|
274
274
|
|
|
275
275
|
position = new Coordinates(0, 0);
|
|
276
|
-
expect(Coordinates.
|
|
276
|
+
expect(Coordinates.equals(Coordinates.fromJson(position.toJson()), position)).true;
|
|
277
277
|
|
|
278
278
|
position = new Coordinates(5, -10, 2);
|
|
279
|
-
expect(Coordinates.
|
|
279
|
+
expect(Coordinates.equals(Coordinates.fromJson(position.toJson()), position)).true;
|
|
280
280
|
|
|
281
281
|
position = new Coordinates(5, -10, null, [1, 2]);
|
|
282
|
-
expect(Coordinates.
|
|
282
|
+
expect(Coordinates.equals(Coordinates.fromJson(position.toJson()), position)).true;
|
|
283
283
|
|
|
284
284
|
position = new Coordinates(5, -10, 3, [1, 2]);
|
|
285
|
-
expect(Coordinates.
|
|
285
|
+
expect(Coordinates.equals(Coordinates.fromJson(position.toJson()), position)).true;
|
|
286
286
|
|
|
287
287
|
|
|
288
|
-
expect(Coordinates.
|
|
288
|
+
expect(Coordinates.equals(
|
|
289
289
|
Coordinates.fromCompressedJson([5, -10, null, 0]),
|
|
290
290
|
new Coordinates(5, -10, null, 0))
|
|
291
291
|
).true;
|
|
292
292
|
|
|
293
|
-
expect(Coordinates.
|
|
293
|
+
expect(Coordinates.equals(
|
|
294
294
|
Coordinates.fromCompressedJson([5, -10, null, 1]),
|
|
295
295
|
new Coordinates(5, -10, null, 1))
|
|
296
296
|
).true;
|
|
297
297
|
|
|
298
|
-
expect(Coordinates.
|
|
298
|
+
expect(Coordinates.equals(
|
|
299
299
|
Coordinates.fromCompressedJson([5, -10, null, '1']),
|
|
300
300
|
new Coordinates(5, -10, null, 1))
|
|
301
301
|
).true;
|
|
302
302
|
|
|
303
|
-
expect(Coordinates.
|
|
303
|
+
expect(Coordinates.equals(
|
|
304
304
|
Coordinates.fromCompressedJson([5, -10, null, '1;2']),
|
|
305
305
|
new Coordinates(5, -10, null, [1, 2]))
|
|
306
306
|
).true;
|
|
307
307
|
|
|
308
|
-
expect(Coordinates.
|
|
308
|
+
expect(Coordinates.equals(
|
|
309
309
|
Coordinates.fromCompressedJson([5, -10, 10, '2;3']),
|
|
310
310
|
new Coordinates(5, -10, 10, [2, 3]))
|
|
311
311
|
).true;
|
package/src/coordinates/Level.js
CHANGED
|
@@ -137,7 +137,7 @@ class Level {
|
|
|
137
137
|
return null;
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
if (this.
|
|
140
|
+
if (this.equals(first, second)) {
|
|
141
141
|
return this.clone(first);
|
|
142
142
|
}
|
|
143
143
|
|
|
@@ -247,7 +247,7 @@ class Level {
|
|
|
247
247
|
* @param {null|number|[number, number]} second
|
|
248
248
|
* @returns {boolean}
|
|
249
249
|
*/
|
|
250
|
-
static
|
|
250
|
+
static equals(first, second) {
|
|
251
251
|
|
|
252
252
|
if (this.VERIFY_TYPING) {
|
|
253
253
|
this.checkType(first);
|
|
@@ -305,7 +305,7 @@ class Level {
|
|
|
305
305
|
return null;
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
-
if (Level.
|
|
308
|
+
if (Level.equals(first, second)) {
|
|
309
309
|
return 0;
|
|
310
310
|
}
|
|
311
311
|
|
|
@@ -44,12 +44,13 @@ describe('Level', () => {
|
|
|
44
44
|
|
|
45
45
|
it('fromString', () => {
|
|
46
46
|
const listOfInvalidLevel = ['toto', 'toto;toto', '1;toto', 'toto;1',
|
|
47
|
-
true, false, NaN
|
|
47
|
+
true, false, NaN];
|
|
48
48
|
|
|
49
49
|
listOfInvalidLevel.forEach(value1 => {
|
|
50
50
|
expect(() => Level.fromString(value1)).throw(Error);
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
+
expect(Level.fromString(null)).is.null;
|
|
53
54
|
expect(Level.fromString('0')).equal(0);
|
|
54
55
|
expect(Level.fromString('1')).equal(1);
|
|
55
56
|
expect(Level.fromString('-1')).equal(-1);
|
|
@@ -65,6 +66,7 @@ describe('Level', () => {
|
|
|
65
66
|
|
|
66
67
|
|
|
67
68
|
it('toString', () => {
|
|
69
|
+
expect(Level.toString(null)).is.null;
|
|
68
70
|
expect(Level.toString(0)).equals('0');
|
|
69
71
|
expect(Level.toString(1)).equals('1');
|
|
70
72
|
expect(Level.toString(-1)).equals('-1');
|
|
@@ -78,12 +80,12 @@ describe('Level', () => {
|
|
|
78
80
|
expect(Level.toString([-1.5, 1.5])).equals('-1.5;1.5');
|
|
79
81
|
});
|
|
80
82
|
|
|
81
|
-
it('
|
|
82
|
-
expect(Level.
|
|
83
|
-
expect(Level.
|
|
84
|
-
expect(Level.
|
|
85
|
-
expect(Level.
|
|
86
|
-
expect(Level.
|
|
83
|
+
it('equals', () => {
|
|
84
|
+
expect(Level.equals(1, 1)).true;
|
|
85
|
+
expect(Level.equals(-1, 1)).false;
|
|
86
|
+
expect(Level.equals(1, [0, 1])).false;
|
|
87
|
+
expect(Level.equals([0, 1], 1)).false;
|
|
88
|
+
expect(Level.equals([0, 1], [0, 1])).true;
|
|
87
89
|
});
|
|
88
90
|
|
|
89
91
|
it('clone', () => {
|
|
@@ -112,7 +112,7 @@ class RelativePosition {
|
|
|
112
112
|
* @param {RelativePosition} pos2 position 2
|
|
113
113
|
* @param {Number} eps x, y, z epsilon in meters (default: 1e-3 [= 1mm])
|
|
114
114
|
*/
|
|
115
|
-
static
|
|
115
|
+
static equals(pos1, pos2, eps = Constants.EPS_MM) {
|
|
116
116
|
|
|
117
117
|
// Handle null comparison
|
|
118
118
|
if (pos1 === null && pos1 === pos2) {
|
|
@@ -131,8 +131,8 @@ class RelativePosition {
|
|
|
131
131
|
&& pos1.bearing === pos2.bearing;
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
|
|
135
|
-
return RelativePosition.
|
|
134
|
+
equals(other) {
|
|
135
|
+
return RelativePosition.equals(this, other);
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
|
|
@@ -69,47 +69,47 @@ describe('RelativePosition', () => {
|
|
|
69
69
|
});
|
|
70
70
|
|
|
71
71
|
|
|
72
|
-
it('
|
|
72
|
+
it('equals', () => {
|
|
73
73
|
let position, position2;
|
|
74
74
|
|
|
75
|
-
expect(RelativePosition.
|
|
75
|
+
expect(RelativePosition.equals(null, null)).true;
|
|
76
76
|
|
|
77
77
|
position = new RelativePosition(1, 2, 3);
|
|
78
|
-
expect(RelativePosition.
|
|
79
|
-
expect(RelativePosition.
|
|
80
|
-
expect(RelativePosition.
|
|
78
|
+
expect(RelativePosition.equals(position, new RelativePosition(1, 2, 3))).true;
|
|
79
|
+
expect(RelativePosition.equals(position, {})).false;
|
|
80
|
+
expect(RelativePosition.equals({}, position)).false;
|
|
81
81
|
|
|
82
82
|
position = new RelativePosition(1, 2, 3, 123456, 10, Math.PI);
|
|
83
|
-
expect(RelativePosition.
|
|
83
|
+
expect(RelativePosition.equals(position,
|
|
84
84
|
new RelativePosition(1, 2, 3, 123456, 10, Math.PI)
|
|
85
85
|
)).true;
|
|
86
86
|
|
|
87
87
|
position2 = position.clone();
|
|
88
88
|
position2.x = 0;
|
|
89
|
-
expect(RelativePosition.
|
|
89
|
+
expect(RelativePosition.equals(position, position2)).false;
|
|
90
90
|
|
|
91
91
|
position2 = position.clone();
|
|
92
92
|
position2.y = 0;
|
|
93
|
-
expect(RelativePosition.
|
|
93
|
+
expect(RelativePosition.equals(position, position2)).false;
|
|
94
94
|
|
|
95
95
|
position2 = position.clone();
|
|
96
96
|
position2.z = 0;
|
|
97
|
-
expect(RelativePosition.
|
|
97
|
+
expect(RelativePosition.equals(position, position2)).false;
|
|
98
98
|
|
|
99
99
|
position2 = position.clone();
|
|
100
100
|
position2.time = 0;
|
|
101
|
-
expect(RelativePosition.
|
|
101
|
+
expect(RelativePosition.equals(position, position2)).false;
|
|
102
102
|
|
|
103
103
|
position2 = position.clone();
|
|
104
104
|
position2.accuracy = 0;
|
|
105
|
-
expect(RelativePosition.
|
|
105
|
+
expect(RelativePosition.equals(position, position2)).false;
|
|
106
106
|
|
|
107
107
|
position2 = position.clone();
|
|
108
108
|
position2.bearing = 0;
|
|
109
|
-
expect(RelativePosition.
|
|
109
|
+
expect(RelativePosition.equals(position, position2)).false;
|
|
110
110
|
|
|
111
|
-
expect(position.
|
|
112
|
-
expect(position.
|
|
111
|
+
expect(position.equals(new RelativePosition(1, 2, 3, 123456, 10, Math.PI))).true;
|
|
112
|
+
expect(position.equals(new RelativePosition(1, 2, 3, 123456, 0, Math.PI))).false;
|
|
113
113
|
});
|
|
114
114
|
|
|
115
115
|
it('json', () => {
|
|
@@ -150,13 +150,13 @@ describe('RelativePosition', () => {
|
|
|
150
150
|
});
|
|
151
151
|
|
|
152
152
|
position = new RelativePosition(1, 2, 3);
|
|
153
|
-
expect(RelativePosition.
|
|
153
|
+
expect(RelativePosition.equals(
|
|
154
154
|
RelativePosition.fromJson(position.toJson()),
|
|
155
155
|
position)
|
|
156
156
|
).true;
|
|
157
157
|
|
|
158
158
|
position = new RelativePosition(1, 2, 3, 123456, 10, Math.PI);
|
|
159
|
-
expect(RelativePosition.
|
|
159
|
+
expect(RelativePosition.equals(
|
|
160
160
|
RelativePosition.fromJson(position.toJson()),
|
|
161
161
|
position)
|
|
162
162
|
).true;
|
|
@@ -88,7 +88,7 @@ class UserPosition extends Coordinates {
|
|
|
88
88
|
* @param {Number} eps latitude and longitude epsilon in degrees (default: 1e-8 [~1mm at lat=0])
|
|
89
89
|
* @param {Number} epsAlt altitude epsilon in meters (default: 1e-3 [= 1mm])
|
|
90
90
|
*/
|
|
91
|
-
static
|
|
91
|
+
static equals(pos1, pos2, eps = Constants.EPS_DEG_MM, epsAlt = Constants.EPS_MM) {
|
|
92
92
|
|
|
93
93
|
// Handle null comparison
|
|
94
94
|
if (pos1 === null && pos1 === pos2) {
|
|
@@ -99,7 +99,7 @@ class UserPosition extends Coordinates {
|
|
|
99
99
|
return false;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
if (!super.
|
|
102
|
+
if (!super.equals(pos1, pos2, eps, epsAlt)) {
|
|
103
103
|
return false;
|
|
104
104
|
}
|
|
105
105
|
|
|
@@ -108,8 +108,8 @@ class UserPosition extends Coordinates {
|
|
|
108
108
|
&& pos1.bearing === pos2.bearing;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
return UserPosition.
|
|
111
|
+
equals(other) {
|
|
112
|
+
return UserPosition.equals(this, other);
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
|
|
@@ -47,7 +47,7 @@ describe('UserPosition', () => {
|
|
|
47
47
|
expect(position.lat).equals(45);
|
|
48
48
|
expect(position.lng).equals(5);
|
|
49
49
|
expect(position.alt).equals(0);
|
|
50
|
-
expect(Level.
|
|
50
|
+
expect(Level.equals(position.level, 2)).true;
|
|
51
51
|
expect(position.time).equals(123456);
|
|
52
52
|
expect(position.accuracy).equals(10);
|
|
53
53
|
expect(position.bearing).equals(Math.PI);
|
|
@@ -66,7 +66,7 @@ describe('UserPosition', () => {
|
|
|
66
66
|
expect(position.lat).equals(45);
|
|
67
67
|
expect(position.lng).equals(5);
|
|
68
68
|
expect(position.alt).equals(0);
|
|
69
|
-
expect(Level.
|
|
69
|
+
expect(Level.equals(position.level, 2)).true;
|
|
70
70
|
expect(position.time).equals(123456);
|
|
71
71
|
expect(position.accuracy).equals(10);
|
|
72
72
|
expect(position.bearing).equals(Math.PI);
|
|
@@ -81,7 +81,7 @@ describe('UserPosition', () => {
|
|
|
81
81
|
expect(position.lat).equals(45);
|
|
82
82
|
expect(position.lng).equals(5);
|
|
83
83
|
expect(position.alt).equals(0);
|
|
84
|
-
expect(Level.
|
|
84
|
+
expect(Level.equals(position.level, level)).true;
|
|
85
85
|
expect(position.time).is.null;
|
|
86
86
|
expect(position.accuracy).is.null;
|
|
87
87
|
expect(position.bearing).is.null;
|
|
@@ -96,7 +96,7 @@ describe('UserPosition', () => {
|
|
|
96
96
|
expect(clonePosition.lat).equals(45);
|
|
97
97
|
expect(clonePosition.lng).equals(5);
|
|
98
98
|
expect(clonePosition.alt).equals(0);
|
|
99
|
-
expect(Level.
|
|
99
|
+
expect(Level.equals(clonePosition.level, level)).true;
|
|
100
100
|
expect(clonePosition.level).not.equals(level);
|
|
101
101
|
expect(clonePosition.time).equals(123456);
|
|
102
102
|
expect(clonePosition.accuracy).equals(10);
|
|
@@ -104,52 +104,52 @@ describe('UserPosition', () => {
|
|
|
104
104
|
});
|
|
105
105
|
|
|
106
106
|
|
|
107
|
-
it('
|
|
107
|
+
it('equals', () => {
|
|
108
108
|
let position, position2;
|
|
109
109
|
|
|
110
|
-
expect(UserPosition.
|
|
110
|
+
expect(UserPosition.equals(null, null)).true;
|
|
111
111
|
|
|
112
112
|
position = new UserPosition(0, 0);
|
|
113
|
-
expect(UserPosition.
|
|
114
|
-
expect(UserPosition.
|
|
113
|
+
expect(UserPosition.equals(position, new UserPosition(0, 0))).true;
|
|
114
|
+
expect(UserPosition.equals(position, new Coordinates(0, 0))).false;
|
|
115
115
|
|
|
116
116
|
position = new UserPosition(45, 5, 0, 2, 123456, 10, Math.PI);
|
|
117
|
-
expect(UserPosition.
|
|
117
|
+
expect(UserPosition.equals(position,
|
|
118
118
|
new UserPosition(45, 5, 0, 2, 123456, 10, Math.PI)
|
|
119
119
|
)).true;
|
|
120
120
|
|
|
121
121
|
position2 = position.clone();
|
|
122
122
|
position2.lat = 0;
|
|
123
|
-
expect(UserPosition.
|
|
123
|
+
expect(UserPosition.equals(position, position2)).false;
|
|
124
124
|
|
|
125
125
|
position2 = position.clone();
|
|
126
126
|
position2.lng = 0;
|
|
127
|
-
expect(UserPosition.
|
|
127
|
+
expect(UserPosition.equals(position, position2)).false;
|
|
128
128
|
|
|
129
129
|
position2 = position.clone();
|
|
130
130
|
position2.alt = 10;
|
|
131
|
-
expect(UserPosition.
|
|
131
|
+
expect(UserPosition.equals(position, position2)).false;
|
|
132
132
|
|
|
133
133
|
position2 = position.clone();
|
|
134
134
|
position2.level = null;
|
|
135
|
-
expect(UserPosition.
|
|
135
|
+
expect(UserPosition.equals(position, position2)).false;
|
|
136
136
|
|
|
137
137
|
position2 = position.clone();
|
|
138
138
|
position2.time = 0;
|
|
139
|
-
expect(UserPosition.
|
|
139
|
+
expect(UserPosition.equals(position, position2)).false;
|
|
140
140
|
|
|
141
141
|
position2 = position.clone();
|
|
142
142
|
position2.accuracy = 0;
|
|
143
|
-
expect(UserPosition.
|
|
143
|
+
expect(UserPosition.equals(position, position2)).false;
|
|
144
144
|
|
|
145
145
|
position2 = position.clone();
|
|
146
146
|
position2.bearing = 0;
|
|
147
|
-
expect(UserPosition.
|
|
147
|
+
expect(UserPosition.equals(position, position2)).false;
|
|
148
148
|
|
|
149
|
-
expect(position.
|
|
149
|
+
expect(position.equals(
|
|
150
150
|
new UserPosition(45, 5, 0, 2, 123456, 10, Math.PI)
|
|
151
151
|
)).true;
|
|
152
|
-
expect(position.
|
|
152
|
+
expect(position.equals(
|
|
153
153
|
new UserPosition(45, 5, 0, 2, 123456, 0, Math.PI)
|
|
154
154
|
)).false;
|
|
155
155
|
});
|
|
@@ -204,13 +204,13 @@ describe('UserPosition', () => {
|
|
|
204
204
|
});
|
|
205
205
|
|
|
206
206
|
position = new UserPosition(5, -10);
|
|
207
|
-
expect(UserPosition.
|
|
207
|
+
expect(UserPosition.equals(
|
|
208
208
|
UserPosition.fromJson(position.toJson()),
|
|
209
209
|
position)
|
|
210
210
|
).true;
|
|
211
211
|
|
|
212
212
|
position = new UserPosition(45, 5, 0, 2, 123456, 10, Math.PI);
|
|
213
|
-
expect(UserPosition.
|
|
213
|
+
expect(UserPosition.equals(
|
|
214
214
|
UserPosition.fromJson(position.toJson()),
|
|
215
215
|
position)
|
|
216
216
|
).true;
|
package/src/graph/GraphEdge.js
CHANGED
|
@@ -135,7 +135,7 @@ class GraphEdge {
|
|
|
135
135
|
* @param {GraphEdge<T>} other
|
|
136
136
|
* @returns {boolean}
|
|
137
137
|
*/
|
|
138
|
-
|
|
138
|
+
equals(other) {
|
|
139
139
|
|
|
140
140
|
if (this === other) {
|
|
141
141
|
return true;
|
|
@@ -145,9 +145,9 @@ class GraphEdge {
|
|
|
145
145
|
return false;
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
return other.node1.
|
|
149
|
-
&& other.node2.
|
|
150
|
-
&& Level.
|
|
148
|
+
return other.node1.equals(this.node1)
|
|
149
|
+
&& other.node2.equals(this.node2)
|
|
150
|
+
&& Level.equals(other.level, this.level)
|
|
151
151
|
&& other.isOneway === this.isOneway
|
|
152
152
|
&& other.builtFrom === this.builtFrom;
|
|
153
153
|
}
|
|
@@ -56,34 +56,34 @@ describe('GraphEdge', () => {
|
|
|
56
56
|
expect(newEdge.length).equals(node1.distanceTo(node2));
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
-
it('
|
|
59
|
+
it('equals', () => {
|
|
60
60
|
|
|
61
61
|
const testedEdge = new GraphEdge(node1, node2);
|
|
62
62
|
|
|
63
|
-
expect(edge.
|
|
63
|
+
expect(edge.equals({})).false;
|
|
64
64
|
|
|
65
|
-
expect(edge.
|
|
66
|
-
expect(fullEdge.
|
|
65
|
+
expect(edge.equals(testedEdge)).true;
|
|
66
|
+
expect(fullEdge.equals(testedEdge)).false;
|
|
67
67
|
|
|
68
68
|
testedEdge.level = 1;
|
|
69
|
-
expect(edge.
|
|
70
|
-
expect(fullEdge.
|
|
69
|
+
expect(edge.equals(testedEdge)).false;
|
|
70
|
+
expect(fullEdge.equals(testedEdge)).false;
|
|
71
71
|
|
|
72
72
|
testedEdge.isOneway = true;
|
|
73
|
-
expect(edge.
|
|
74
|
-
expect(fullEdge.
|
|
73
|
+
expect(edge.equals(testedEdge)).false;
|
|
74
|
+
expect(fullEdge.equals(testedEdge)).false;
|
|
75
75
|
|
|
76
76
|
testedEdge.builtFrom = 'w1';
|
|
77
|
-
expect(edge.
|
|
78
|
-
expect(fullEdge.
|
|
77
|
+
expect(edge.equals(testedEdge)).false;
|
|
78
|
+
expect(fullEdge.equals(testedEdge)).true;
|
|
79
79
|
|
|
80
80
|
});
|
|
81
81
|
|
|
82
82
|
it('clone', () => {
|
|
83
83
|
let edgeBis = edge.clone();
|
|
84
|
-
expect(edgeBis.
|
|
84
|
+
expect(edgeBis.equals(edge)).true;
|
|
85
85
|
|
|
86
86
|
edgeBis = fullEdge.clone();
|
|
87
|
-
expect(edgeBis.
|
|
87
|
+
expect(edgeBis.equals(fullEdge)).true;
|
|
88
88
|
});
|
|
89
89
|
});
|
package/src/graph/GraphNode.js
CHANGED
|
@@ -41,10 +41,10 @@ describe('GraphNode', () => {
|
|
|
41
41
|
expect(node1.bearingTo(node2)).equals(pos1.bearingTo(pos2));
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
-
it('
|
|
45
|
-
expect(node1.
|
|
46
|
-
expect(node1.
|
|
47
|
-
expect(new GraphNode(pos1).
|
|
44
|
+
it('equals', () => {
|
|
45
|
+
expect(node1.equals(node2)).false;
|
|
46
|
+
expect(node1.equals(node1)).true;
|
|
47
|
+
expect(new GraphNode(pos1).equals(node1)).true;
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
it('clone', () => {
|
|
@@ -66,7 +66,7 @@ describe('GraphNode', () => {
|
|
|
66
66
|
expect(jsonNode).deep.equals([45, 5]);
|
|
67
67
|
|
|
68
68
|
const nodeBis = GraphNode.fromJson(jsonNode);
|
|
69
|
-
expect(nodeBis.coords.
|
|
69
|
+
expect(nodeBis.coords.equals(node.coords)).true;
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
// eslint-disable-next-line max-statements
|
|
@@ -91,19 +91,19 @@ describe('GraphNode', () => {
|
|
|
91
91
|
|
|
92
92
|
nodes = cleanNodesWithAdjEdges(1, 1);
|
|
93
93
|
expect(GraphNode.generateNodesLevels(nodes)).true;
|
|
94
|
-
expect(Level.
|
|
94
|
+
expect(Level.equals(nodes[0].coords.level, 1)).true;
|
|
95
95
|
|
|
96
96
|
nodes = cleanNodesWithAdjEdges(1, [1, 2]);
|
|
97
97
|
expect(GraphNode.generateNodesLevels(nodes)).true;
|
|
98
|
-
expect(Level.
|
|
98
|
+
expect(Level.equals(nodes[0].coords.level, 1)).true;
|
|
99
99
|
|
|
100
100
|
nodes = cleanNodesWithAdjEdges([0, 1], [1, 2]);
|
|
101
101
|
expect(GraphNode.generateNodesLevels(nodes)).true;
|
|
102
|
-
expect(Level.
|
|
102
|
+
expect(Level.equals(nodes[0].coords.level, 1)).true;
|
|
103
103
|
|
|
104
104
|
nodes = cleanNodesWithAdjEdges([0, 1]);
|
|
105
105
|
expect(GraphNode.generateNodesLevels(nodes)).true;
|
|
106
|
-
expect(Level.
|
|
106
|
+
expect(Level.equals(nodes[0].coords.level, [0, 1])).true;
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
109
|
* More complex cases with no adjacent edges
|
|
@@ -114,10 +114,10 @@ describe('GraphNode', () => {
|
|
|
114
114
|
new GraphEdge(nodes[1], nodes[2], [1, 2], 'e1');
|
|
115
115
|
new GraphEdge(nodes[2], nodes[3], [1, 2], 'e2');
|
|
116
116
|
expect(GraphNode.generateNodesLevels(nodes)).true;
|
|
117
|
-
expect(Level.
|
|
118
|
-
expect(Level.
|
|
119
|
-
expect(Level.
|
|
120
|
-
expect(Level.
|
|
117
|
+
expect(Level.equals(nodes[0].coords.level, 1)).true;
|
|
118
|
+
expect(Level.equals(nodes[1].coords.level, 1)).true;
|
|
119
|
+
expect(Level.equals(nodes[2].coords.level, [1, 2])).true;
|
|
120
|
+
expect(Level.equals(nodes[3].coords.level, 2)).true;
|
|
121
121
|
|
|
122
122
|
|
|
123
123
|
nodes = cleanNodes(5);
|
|
@@ -133,10 +133,10 @@ describe('GraphNode', () => {
|
|
|
133
133
|
new GraphEdge(nodes[1], nodes[2], [0, 1], 'e1');
|
|
134
134
|
new GraphEdge(nodes[2], nodes[3], [0, 1], 'e2');
|
|
135
135
|
expect(GraphNode.generateNodesLevels(nodes)).true;
|
|
136
|
-
expect(Level.
|
|
137
|
-
expect(Level.
|
|
138
|
-
expect(Level.
|
|
139
|
-
expect(Level.
|
|
136
|
+
expect(Level.equals(nodes[0].coords.level, 1)).true;
|
|
137
|
+
expect(Level.equals(nodes[1].coords.level, 1)).true;
|
|
138
|
+
expect(Level.equals(nodes[2].coords.level, [0, 1])).true;
|
|
139
|
+
expect(Level.equals(nodes[3].coords.level, 0)).true;
|
|
140
140
|
|
|
141
141
|
|
|
142
142
|
nodes = cleanNodes(4);
|
|
@@ -145,10 +145,10 @@ describe('GraphNode', () => {
|
|
|
145
145
|
new GraphEdge(nodes[2], nodes[3], [1, 2], 'e2');
|
|
146
146
|
new GraphEdge(nodes[1], nodes[3], 1, 'e3');
|
|
147
147
|
expect(GraphNode.generateNodesLevels(nodes)).true;
|
|
148
|
-
expect(Level.
|
|
149
|
-
expect(Level.
|
|
150
|
-
expect(Level.
|
|
151
|
-
expect(Level.
|
|
148
|
+
expect(Level.equals(nodes[0].coords.level, 1)).true;
|
|
149
|
+
expect(Level.equals(nodes[1].coords.level, 1)).true;
|
|
150
|
+
expect(Level.equals(nodes[2].coords.level, 2)).true;
|
|
151
|
+
expect(Level.equals(nodes[3].coords.level, 1)).true;
|
|
152
152
|
|
|
153
153
|
|
|
154
154
|
nodes = cleanNodes(4);
|
|
@@ -157,10 +157,10 @@ describe('GraphNode', () => {
|
|
|
157
157
|
new GraphEdge(nodes[2], nodes[3], [0, 1], 'e2');
|
|
158
158
|
new GraphEdge(nodes[1], nodes[3], 1, 'e3');
|
|
159
159
|
expect(GraphNode.generateNodesLevels(nodes)).true;
|
|
160
|
-
expect(Level.
|
|
161
|
-
expect(Level.
|
|
162
|
-
expect(Level.
|
|
163
|
-
expect(Level.
|
|
160
|
+
expect(Level.equals(nodes[0].coords.level, 1)).true;
|
|
161
|
+
expect(Level.equals(nodes[1].coords.level, 1)).true;
|
|
162
|
+
expect(Level.equals(nodes[2].coords.level, 0)).true;
|
|
163
|
+
expect(Level.equals(nodes[3].coords.level, 1)).true;
|
|
164
164
|
|
|
165
165
|
|
|
166
166
|
nodes = cleanNodes(6);
|
|
@@ -178,11 +178,11 @@ describe('GraphNode', () => {
|
|
|
178
178
|
new GraphEdge(nodes[2], nodes[3], [1, 2]);
|
|
179
179
|
new GraphEdge(nodes[3], nodes[4], 1);
|
|
180
180
|
expect(GraphNode.generateNodesLevels(nodes)).true;
|
|
181
|
-
expect(Level.
|
|
182
|
-
expect(Level.
|
|
183
|
-
expect(Level.
|
|
184
|
-
expect(Level.
|
|
185
|
-
expect(Level.
|
|
181
|
+
expect(Level.equals(nodes[0].coords.level, 2)).true;
|
|
182
|
+
expect(Level.equals(nodes[1].coords.level, [1, 2])).true;
|
|
183
|
+
expect(Level.equals(nodes[2].coords.level, [1, 2])).true;
|
|
184
|
+
expect(Level.equals(nodes[3].coords.level, 1)).true;
|
|
185
|
+
expect(Level.equals(nodes[4].coords.level, 1)).true;
|
|
186
186
|
|
|
187
187
|
|
|
188
188
|
nodes = cleanNodes(6);
|
|
@@ -192,12 +192,12 @@ describe('GraphNode', () => {
|
|
|
192
192
|
new GraphEdge(nodes[3], nodes[4], [0, 1], 'e3');
|
|
193
193
|
new GraphEdge(nodes[4], nodes[5], 1, 'e4');
|
|
194
194
|
expect(GraphNode.generateNodesLevels(nodes)).true;
|
|
195
|
-
expect(Level.
|
|
196
|
-
expect(Level.
|
|
197
|
-
expect(Level.
|
|
198
|
-
expect(Level.
|
|
199
|
-
expect(Level.
|
|
200
|
-
expect(Level.
|
|
195
|
+
expect(Level.equals(nodes[1].coords.level, 0)).true;
|
|
196
|
+
expect(Level.equals(nodes[1].coords.level, 0)).true;
|
|
197
|
+
expect(Level.equals(nodes[2].coords.level, [0, 1])).true;
|
|
198
|
+
expect(Level.equals(nodes[3].coords.level, [0, 1])).true;
|
|
199
|
+
expect(Level.equals(nodes[4].coords.level, 1)).true;
|
|
200
|
+
expect(Level.equals(nodes[5].coords.level, 1)).true;
|
|
201
201
|
});
|
|
202
202
|
|
|
203
203
|
});
|
package/src/graph/MapMatching.js
CHANGED
|
@@ -102,11 +102,11 @@ class MapMatching {
|
|
|
102
102
|
checkEdge = false;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
if (!Level.
|
|
105
|
+
if (!Level.equals(location.level, edge.node1.coords.level) && !(edge.node1.io && location.level === null)) {
|
|
106
106
|
checkNode1 = false;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
if (!Level.
|
|
109
|
+
if (!Level.equals(location.level, edge.node2.coords.level) && !(edge.node2.io && location.level === null)) {
|
|
110
110
|
checkNode2 = false;
|
|
111
111
|
}
|
|
112
112
|
|
|
@@ -73,7 +73,7 @@ describe('MapMatching', () => {
|
|
|
73
73
|
expect(result.nearestElement).instanceOf(GraphEdge);
|
|
74
74
|
expect(result.nearestElement.builtFrom).equal('e0');
|
|
75
75
|
expect(result.projection.distanceTo(expected)).to.below(Constants.EPS_MM);
|
|
76
|
-
expect(Level.
|
|
76
|
+
expect(Level.equals(expected.level, result.projection.level)).true;
|
|
77
77
|
|
|
78
78
|
const owNodes = [
|
|
79
79
|
new GraphNode(new Coordinates(43.6091194, 3.884099, 5)),
|
|
@@ -98,7 +98,7 @@ describe('MapMatching', () => {
|
|
|
98
98
|
expect(result.nearestElement).instanceOf(GraphEdge);
|
|
99
99
|
expect(result.nearestElement.builtFrom).equal('e1');
|
|
100
100
|
expect(result.projection.distanceTo(expected)).to.below(Constants.EPS_MM);
|
|
101
|
-
expect(Level.
|
|
101
|
+
expect(Level.equals(expected.level, result.projection.level)).true;
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
it('with epsilon', () => {
|
|
@@ -141,7 +141,7 @@ describe('MapMatching - multilevels', () => {
|
|
|
141
141
|
const result = mapMatching.getProjection(location).projection;
|
|
142
142
|
const expected = new Coordinates(43.609176387963934, 3.884122673088027, null, 2);
|
|
143
143
|
expect(result.distanceTo(expected)).to.below(Constants.EPS_MM);
|
|
144
|
-
expect(Level.
|
|
144
|
+
expect(Level.equals(expected.level, result.level)).true;
|
|
145
145
|
});
|
|
146
146
|
|
|
147
147
|
it('with bearing', () => {
|
|
@@ -150,7 +150,7 @@ describe('MapMatching - multilevels', () => {
|
|
|
150
150
|
const result = mapMatching.getProjection(location, true, true).projection;
|
|
151
151
|
const expected = new Coordinates(43.609188614172005, 3.8841275169229754, null, 2);
|
|
152
152
|
expect(result.distanceTo(expected)).to.below(Constants.EPS_MM);
|
|
153
|
-
expect(Level.
|
|
153
|
+
expect(Level.equals(expected.level, result.level)).true;
|
|
154
154
|
});
|
|
155
155
|
|
|
156
156
|
it('matching node levels', () => {
|
package/src/graph/Network.js
CHANGED
|
@@ -35,7 +35,7 @@ class Network {
|
|
|
35
35
|
* @returns {?GraphNode<T>}
|
|
36
36
|
*/
|
|
37
37
|
getNodeByCoords(coords) {
|
|
38
|
-
return this.nodes.find(node => node.coords.
|
|
38
|
+
return this.nodes.find(node => node.coords.equals(coords));
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**
|
|
@@ -162,7 +162,7 @@ class Network {
|
|
|
162
162
|
const network = new Network();
|
|
163
163
|
|
|
164
164
|
const getOrCreateNode = coords =>
|
|
165
|
-
network.nodes.find(_coords => _coords.
|
|
165
|
+
network.nodes.find(_coords => _coords.equals(coords)) || new GraphNode(coords);
|
|
166
166
|
|
|
167
167
|
|
|
168
168
|
const createEdgeFromNodes = (node1, node2) =>
|
|
@@ -76,12 +76,12 @@ describe('Network', () => {
|
|
|
76
76
|
const networkBis = Network.fromCompressedJson(networkJson);
|
|
77
77
|
|
|
78
78
|
networkBis.nodes.forEach((node, i) => {
|
|
79
|
-
expect(node.coords.
|
|
79
|
+
expect(node.coords.equals(network.nodes[i].coords)).is.true;
|
|
80
80
|
});
|
|
81
81
|
|
|
82
82
|
networkBis.edges.forEach((edge, i) => {
|
|
83
|
-
expect(edge.node1.coords.
|
|
84
|
-
expect(edge.node2.coords.
|
|
83
|
+
expect(edge.node1.coords.equals(network.edges[i].node1.coords)).is.true;
|
|
84
|
+
expect(edge.node2.coords.equals(network.edges[i].node2.coords)).is.true;
|
|
85
85
|
expect(edge.isOneway).equals(network.edges[i].isOneway);
|
|
86
86
|
});
|
|
87
87
|
});
|
|
@@ -101,7 +101,7 @@ class AbsoluteHeading {
|
|
|
101
101
|
* @param {AbsoluteHeading} heading1 heading 1
|
|
102
102
|
* @param {AbsoluteHeading} heading2 heading 2
|
|
103
103
|
*/
|
|
104
|
-
static
|
|
104
|
+
static equals(heading1, heading2) {
|
|
105
105
|
|
|
106
106
|
// Handle null comparison
|
|
107
107
|
if (heading1 === null && heading1 === heading2) {
|
|
@@ -115,8 +115,8 @@ class AbsoluteHeading {
|
|
|
115
115
|
return Math.abs(heading1.heading - heading2.heading) < 1e-8;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
|
|
119
|
-
return AbsoluteHeading.
|
|
118
|
+
equals(other) {
|
|
119
|
+
return AbsoluteHeading.equals(this, other);
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
toJson() {
|
|
@@ -68,16 +68,16 @@ describe('AbsoluteHeading', () => {
|
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
|
|
71
|
-
it('
|
|
71
|
+
it('equals', () => {
|
|
72
72
|
|
|
73
|
-
expect(AbsoluteHeading.
|
|
74
|
-
expect(AbsoluteHeading.
|
|
75
|
-
expect(AbsoluteHeading.
|
|
73
|
+
expect(AbsoluteHeading.equals(null, null)).true;
|
|
74
|
+
expect(AbsoluteHeading.equals({}, new AbsoluteHeading(Math.PI))).false;
|
|
75
|
+
expect(AbsoluteHeading.equals(new AbsoluteHeading(Math.PI), {})).false;
|
|
76
76
|
|
|
77
|
-
expect(AbsoluteHeading.
|
|
78
|
-
expect(AbsoluteHeading.
|
|
77
|
+
expect(AbsoluteHeading.equals(new AbsoluteHeading(Math.PI), new AbsoluteHeading(Math.PI))).true;
|
|
78
|
+
expect(AbsoluteHeading.equals(new AbsoluteHeading(0), new AbsoluteHeading(Math.PI))).false;
|
|
79
79
|
|
|
80
|
-
expect(new AbsoluteHeading(Math.PI).
|
|
80
|
+
expect(new AbsoluteHeading(Math.PI).equals(new AbsoluteHeading(Math.PI))).true;
|
|
81
81
|
});
|
|
82
82
|
|
|
83
83
|
|
|
@@ -87,7 +87,7 @@ describe('AbsoluteHeading', () => {
|
|
|
87
87
|
|
|
88
88
|
absoluteHeading = new AbsoluteHeading(Math.PI);
|
|
89
89
|
expect(absoluteHeading.toJson()).deep.equals({ heading: Math.PI });
|
|
90
|
-
expect(absoluteHeading.
|
|
90
|
+
expect(absoluteHeading.equals(AbsoluteHeading.fromJson(absoluteHeading.toJson()))).true;
|
|
91
91
|
|
|
92
92
|
absoluteHeading = new AbsoluteHeading(Math.PI, 123456, Math.PI / 4);
|
|
93
93
|
expect(absoluteHeading.toJson()).deep.equals({
|
|
@@ -95,14 +95,14 @@ describe('AbsoluteHeading', () => {
|
|
|
95
95
|
time: 123456,
|
|
96
96
|
accuracy: Math.PI / 4
|
|
97
97
|
});
|
|
98
|
-
expect(absoluteHeading.
|
|
98
|
+
expect(absoluteHeading.equals(AbsoluteHeading.fromJson(absoluteHeading.toJson()))).true;
|
|
99
99
|
});
|
|
100
100
|
|
|
101
101
|
|
|
102
102
|
it('toAttitude', () => {
|
|
103
|
-
expect(new AbsoluteHeading(0).toAttitude().
|
|
104
|
-
expect(new AbsoluteHeading(Math.PI / 2).toAttitude().
|
|
105
|
-
expect(new AbsoluteHeading(Math.PI).toAttitude().
|
|
106
|
-
expect(new AbsoluteHeading(3 * Math.PI / 2).toAttitude().
|
|
103
|
+
expect(new AbsoluteHeading(0).toAttitude().equals(new Attitude([1, 0, 0, 0]))).true;
|
|
104
|
+
expect(new AbsoluteHeading(Math.PI / 2).toAttitude().equals(new Attitude([Math.SQRT1_2, 0, 0, -Math.SQRT1_2]))).true;
|
|
105
|
+
expect(new AbsoluteHeading(Math.PI).toAttitude().equals(new Attitude([0, 0, 0, 1]))).true;
|
|
106
|
+
expect(new AbsoluteHeading(3 * Math.PI / 2).toAttitude().equals(new Attitude([Math.SQRT1_2, 0, 0, Math.SQRT1_2]))).true;
|
|
107
107
|
});
|
|
108
108
|
});
|
|
@@ -124,7 +124,7 @@ class Attitude {
|
|
|
124
124
|
* @param {Attitude} att1 attitude 1
|
|
125
125
|
* @param {Attitude} att2 attitude 2
|
|
126
126
|
*/
|
|
127
|
-
static
|
|
127
|
+
static equals(att1, att2) {
|
|
128
128
|
|
|
129
129
|
// Handle null comparison
|
|
130
130
|
if (att1 === null && att1 === att2) {
|
|
@@ -140,15 +140,15 @@ class Attitude {
|
|
|
140
140
|
return true;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
return Quaternion.
|
|
143
|
+
return Quaternion.equals(att1.quaternion, att2.quaternion);
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
/**
|
|
147
147
|
* @param {Attitude} other
|
|
148
148
|
* @returns {boolean}
|
|
149
149
|
*/
|
|
150
|
-
|
|
151
|
-
return Attitude.
|
|
150
|
+
equals(other) {
|
|
151
|
+
return Attitude.equals(this, other);
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
/**
|
|
@@ -131,7 +131,7 @@ describe('Attitude', () => {
|
|
|
131
131
|
|
|
132
132
|
expect(clonedAttitude).not.equal(attitude);
|
|
133
133
|
expect(clonedAttitude.quaternion).not.equal(attitude.quaternion);
|
|
134
|
-
expect(clonedAttitude.
|
|
134
|
+
expect(clonedAttitude.equals(attitude));
|
|
135
135
|
expect(clonedAttitude.time).equal(attitude.time);
|
|
136
136
|
expect(clonedAttitude.accuracy).equal(attitude.accuracy);
|
|
137
137
|
});
|
|
@@ -204,14 +204,14 @@ describe('Attitude', () => {
|
|
|
204
204
|
|
|
205
205
|
});
|
|
206
206
|
|
|
207
|
-
it('
|
|
207
|
+
it('equals', () => {
|
|
208
208
|
|
|
209
|
-
expect(Attitude.
|
|
210
|
-
expect(Attitude.
|
|
211
|
-
expect(Attitude.
|
|
212
|
-
expect(Attitude.
|
|
213
|
-
expect(new Attitude([1, 0, 0, 0]).
|
|
214
|
-
expect(new Attitude([-0.5, 0.5, 0.5, 0.5]).
|
|
209
|
+
expect(Attitude.equals(null, null)).true;
|
|
210
|
+
expect(Attitude.equals(new Attitude([-0.5, 0.5, 0.5, 0.5]), new Attitude([1, 0, 0, 0]))).false;
|
|
211
|
+
expect(Attitude.equals([-0.5, 0.5, 0.5, 0.5], new Attitude([1, 0, 0, 0]))).false;
|
|
212
|
+
expect(Attitude.equals(new Attitude([1, 0, 0, 0]), [-0.5, 0.5, 0.5, 0.5])).false;
|
|
213
|
+
expect(new Attitude([1, 0, 0, 0]).equals(new Attitude([1, 0, 0, 0]))).true;
|
|
214
|
+
expect(new Attitude([-0.5, 0.5, 0.5, 0.5]).equals(new Attitude([-0.5, 0.5, 0.5, 0.5]))).true;
|
|
215
215
|
|
|
216
216
|
});
|
|
217
217
|
|
|
@@ -222,11 +222,11 @@ describe('Attitude', () => {
|
|
|
222
222
|
|
|
223
223
|
attitude = new Attitude([1, 0, 0, 0]);
|
|
224
224
|
expect(attitude.toJson()).deep.equals([1, 0, 0, 0]);
|
|
225
|
-
expect(attitude.
|
|
225
|
+
expect(attitude.equals(Attitude.fromJson(attitude.toJson()))).true;
|
|
226
226
|
|
|
227
227
|
attitude = new Attitude([-0.5, 0.5, 0.5, 0.5]);
|
|
228
228
|
expect(attitude.toJson()).deep.equals([-0.5, 0.5, 0.5, 0.5]);
|
|
229
|
-
expect(attitude.
|
|
229
|
+
expect(attitude.equals(Attitude.fromJson(attitude.toJson()))).true;
|
|
230
230
|
});
|
|
231
231
|
|
|
232
232
|
});
|