@wemap/geo 3.2.17 → 4.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 +22 -22
- package/package.json +5 -4
- package/src/Utils.js +129 -115
- package/src/Utils.spec.js +17 -17
- package/src/coordinates/BoundingBox.spec.js +45 -0
- package/src/coordinates/Coordinates.js +44 -22
- package/src/coordinates/Coordinates.spec.js +5 -0
- package/src/coordinates/RelativePosition.js +3 -3
- package/src/coordinates/RelativePosition.spec.js +166 -0
- package/src/coordinates/UserPosition.spec.js +4 -0
- package/src/graph/Edge.js +235 -0
- package/src/graph/Edge.spec.js +131 -0
- package/src/graph/GraphRouter.js +269 -0
- package/src/graph/GraphRouter.spec.js +316 -0
- package/src/graph/Itinerary.js +527 -0
- package/src/graph/Itinerary.spec.js +809 -0
- package/src/graph/MapMatching.js +217 -0
- package/src/graph/MapMatching.spec.js +272 -0
- package/src/graph/Network.js +168 -0
- package/src/graph/Network.spec.js +95 -0
- package/src/graph/NoRouteFoundError.js +39 -0
- package/src/graph/Node.js +238 -0
- package/src/graph/Node.spec.js +227 -0
- package/src/graph/Step.js +88 -0
- package/src/graph/StepsGeneration.js +122 -0
- package/src/graph/Utils.js +7 -0
- package/src/rotations/AbsoluteHeading.js +12 -6
- package/src/rotations/AbsoluteHeading.spec.js +108 -0
- package/src/rotations/Attitude.js +5 -2
- package/src/rotations/Attitude.spec.js +22 -2
- package/tests/CommonTest.js +91 -0
|
@@ -0,0 +1,809 @@
|
|
|
1
|
+
/* eslint-disable max-statements */
|
|
2
|
+
import chai from 'chai';
|
|
3
|
+
|
|
4
|
+
import { diffAngle } from '@wemap/maths';
|
|
5
|
+
|
|
6
|
+
import Coordinates from '../coordinates/Coordinates.js';
|
|
7
|
+
import Level from '../coordinates/Level.js';
|
|
8
|
+
|
|
9
|
+
import Itinerary from './Itinerary.js';
|
|
10
|
+
import Edge from './Edge.js';
|
|
11
|
+
import Node from './Node.js';
|
|
12
|
+
|
|
13
|
+
import * as CommonTest from '../../tests/CommonTest.js';
|
|
14
|
+
|
|
15
|
+
const { expect } = chai;
|
|
16
|
+
|
|
17
|
+
const isReadable = itinerary => {
|
|
18
|
+
for (let i = 0; i < itinerary.nodes.length; i++) {
|
|
19
|
+
const node = itinerary.nodes[i];
|
|
20
|
+
if (i !== itinerary.nodes.length - 1) {
|
|
21
|
+
const reversed = itinerary._edgesDirectionReversed[i];
|
|
22
|
+
const firstNode = reversed ? itinerary.edges[i].node2 : itinerary.edges[i].node1;
|
|
23
|
+
const secondNode = reversed ? itinerary.edges[i].node1 : itinerary.edges[i].node2;
|
|
24
|
+
expect(firstNode).equal(node);
|
|
25
|
+
expect(secondNode).equal(itinerary.nodes[i + 1]);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const verifyNextEdgesAndNodes = itinerary => {
|
|
31
|
+
|
|
32
|
+
let currentNode, currentEdge;
|
|
33
|
+
|
|
34
|
+
// Iterate on nodes
|
|
35
|
+
currentNode = itinerary.nodes[0];
|
|
36
|
+
for (let i = 0; i < itinerary.nodes.length - 1; i++) {
|
|
37
|
+
currentEdge = itinerary.getNextEdge(currentNode);
|
|
38
|
+
expect(itinerary.edges.indexOf(currentEdge)).equal(i);
|
|
39
|
+
|
|
40
|
+
currentNode = itinerary.getNextNode(currentNode);
|
|
41
|
+
expect(itinerary.nodes.indexOf(currentNode)).equal(i + 1);
|
|
42
|
+
}
|
|
43
|
+
expect(itinerary.getNextNode(currentNode)).is.null;
|
|
44
|
+
expect(itinerary.getNextEdge(currentNode)).is.null;
|
|
45
|
+
|
|
46
|
+
// Iterate on edges
|
|
47
|
+
currentEdge = itinerary.edges[0] || null;
|
|
48
|
+
for (let i = 0; i < itinerary.edges.length - 1; i++) {
|
|
49
|
+
currentNode = itinerary.getNextNode(currentEdge);
|
|
50
|
+
expect(itinerary.nodes.indexOf(currentNode)).equal(i + 1);
|
|
51
|
+
|
|
52
|
+
currentEdge = itinerary.getNextEdge(currentEdge);
|
|
53
|
+
expect(itinerary.edges.indexOf(currentEdge)).equal(i + 1);
|
|
54
|
+
}
|
|
55
|
+
if (currentEdge !== null) {
|
|
56
|
+
const lastNode = itinerary.getNextNode(currentEdge);
|
|
57
|
+
expect(lastNode).is.not.null;
|
|
58
|
+
expect(itinerary.getNextNode(lastNode)).is.null;
|
|
59
|
+
}
|
|
60
|
+
expect(itinerary.getNextEdge(currentEdge)).is.null;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const verifySteps = itinerary => {
|
|
64
|
+
|
|
65
|
+
const {
|
|
66
|
+
steps, nodes, edges, _nextStepsIndexes
|
|
67
|
+
} = itinerary;
|
|
68
|
+
|
|
69
|
+
let previousNodeIndex = 0;
|
|
70
|
+
let previousEdgeIndex = -1;
|
|
71
|
+
steps.forEach(step => {
|
|
72
|
+
let isFirstNode = true;
|
|
73
|
+
step.nodes.forEach(node => {
|
|
74
|
+
const currentNodeIndex = nodes.indexOf(node);
|
|
75
|
+
expect(currentNodeIndex).not.equal(-1);
|
|
76
|
+
if (isFirstNode) {
|
|
77
|
+
isFirstNode = false;
|
|
78
|
+
} else {
|
|
79
|
+
previousNodeIndex++;
|
|
80
|
+
}
|
|
81
|
+
expect(currentNodeIndex).equal(previousNodeIndex);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
step.edges.forEach(edge => {
|
|
85
|
+
const currentEdgeIndex = edges.indexOf(edge);
|
|
86
|
+
expect(currentEdgeIndex).not.equal(-1);
|
|
87
|
+
expect(currentEdgeIndex).equal(previousEdgeIndex + 1);
|
|
88
|
+
previousEdgeIndex++;
|
|
89
|
+
});
|
|
90
|
+
expect(step.location).equal(step.nodes[0].coords);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
expect(_nextStepsIndexes.length).equal(nodes.length);
|
|
94
|
+
|
|
95
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
96
|
+
const node = nodes[i];
|
|
97
|
+
const nextStep = itinerary.getNextStep(node);
|
|
98
|
+
const nextStepId = itinerary.steps.indexOf(nextStep);
|
|
99
|
+
const previousStep = itinerary.getPreviousStep(node);
|
|
100
|
+
const previousStepId = itinerary.steps.indexOf(previousStep);
|
|
101
|
+
|
|
102
|
+
expect(nextStepId - previousStepId).equal(1);
|
|
103
|
+
|
|
104
|
+
if (nextStepId !== 0) {
|
|
105
|
+
const currentStep = steps[nextStepId - 1];
|
|
106
|
+
expect(currentStep.nodes).include(node);
|
|
107
|
+
} else {
|
|
108
|
+
expect(nextStep.nodes[0]).equal(node);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (previousStepId !== -1) {
|
|
112
|
+
const lastPreviousStepNode = previousStep.nodes[previousStep.nodes.length - 1];
|
|
113
|
+
expect(lastPreviousStepNode).equal(nextStep.nodes[0]);
|
|
114
|
+
} else {
|
|
115
|
+
expect(node).equal(nodes[0]);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
for (let i = 0; i < edges.length; i++) {
|
|
120
|
+
const edge = edges[i];
|
|
121
|
+
const nextStep = itinerary.getNextStep(edge);
|
|
122
|
+
const nextStepId = itinerary.steps.indexOf(nextStep);
|
|
123
|
+
const previousStep = itinerary.getPreviousStep(edge);
|
|
124
|
+
const previousStepId = itinerary.steps.indexOf(previousStep);
|
|
125
|
+
|
|
126
|
+
expect(nextStepId - previousStepId).equal(1);
|
|
127
|
+
|
|
128
|
+
if (nextStepId !== 0) {
|
|
129
|
+
const currentStep = steps[nextStepId - 1];
|
|
130
|
+
expect(currentStep.edges).include(edge);
|
|
131
|
+
} else {
|
|
132
|
+
expect(nextStep.edges[0]).equal(edge);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (previousStepId === -1) {
|
|
136
|
+
expect(edge).equal(edges[0]);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
const verifyItineraryLength = itinerary => {
|
|
143
|
+
expect(itinerary.length).equals(
|
|
144
|
+
itinerary.edges.reduce((acc, edge) => acc + edge.length, 0)
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
describe('Itinerary', () => {
|
|
149
|
+
|
|
150
|
+
const nodes = [
|
|
151
|
+
new Node(new Coordinates(43.6091194, 3.884099), 'p0'),
|
|
152
|
+
new Node(new Coordinates(43.6093629, 3.8842777), 'p1'),
|
|
153
|
+
new Node(new Coordinates(43.6092785, 3.8845052), 'p2')
|
|
154
|
+
];
|
|
155
|
+
|
|
156
|
+
const edges = [
|
|
157
|
+
new Edge(nodes[0], nodes[1], null, 'e0'),
|
|
158
|
+
new Edge(nodes[1], nodes[2], null, 'e1')
|
|
159
|
+
];
|
|
160
|
+
|
|
161
|
+
const itinerary = new Itinerary(nodes, edges);
|
|
162
|
+
itinerary.start = new Coordinates(43.6091367, 3.8839298);
|
|
163
|
+
itinerary.end = new Coordinates(43.6093154, 3.8846326);
|
|
164
|
+
|
|
165
|
+
const fakeNode = new Node(new Coordinates(0, 0));
|
|
166
|
+
const fakeEdge = new Edge(fakeNode, nodes[2]);
|
|
167
|
+
|
|
168
|
+
it('readable', () => {
|
|
169
|
+
isReadable(itinerary);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('length', () => {
|
|
173
|
+
verifyItineraryLength(itinerary);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('next edge and next node', () => {
|
|
177
|
+
verifyNextEdgesAndNodes(itinerary);
|
|
178
|
+
|
|
179
|
+
expect(itinerary.getEdgeAt(0)).equal(edges[0]);
|
|
180
|
+
expect(itinerary.getEdgeAt(10)).equal(edges[0]);
|
|
181
|
+
expect(itinerary.getEdgeAt(40)).equal(edges[1]);
|
|
182
|
+
expect(itinerary.getEdgeAt(80)).is.null;
|
|
183
|
+
|
|
184
|
+
expect(itinerary.getNextNode()).is.null;
|
|
185
|
+
expect(itinerary.getNextNode(fakeNode)).is.null;
|
|
186
|
+
expect(itinerary.getNextNode(fakeEdge)).is.null;
|
|
187
|
+
|
|
188
|
+
expect(itinerary.getNextEdge()).is.null;
|
|
189
|
+
expect(itinerary.getNextEdge(fakeNode)).is.null;
|
|
190
|
+
expect(itinerary.getNextEdge(fakeEdge)).is.null;
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('steps', () => {
|
|
194
|
+
verifySteps(itinerary);
|
|
195
|
+
|
|
196
|
+
const { steps } = itinerary;
|
|
197
|
+
expect(steps.length).equal(3);
|
|
198
|
+
expect(steps[0].nodes[0]).equal(nodes[0]);
|
|
199
|
+
expect(steps[0].node.name).equal('p0');
|
|
200
|
+
expect(steps[0].length).closeTo(30.69, 0.01);
|
|
201
|
+
expect(steps[0].nodes[1]).equal(nodes[1]);
|
|
202
|
+
expect(steps[1].nodes[0]).equal(nodes[1]);
|
|
203
|
+
expect(steps[1].nodes[1]).equal(nodes[2]);
|
|
204
|
+
expect(steps[2].nodes[0]).equal(nodes[2]);
|
|
205
|
+
|
|
206
|
+
expect(itinerary.getNextStep(null)).is.null;
|
|
207
|
+
expect(itinerary.getNextStep(fakeNode)).is.null;
|
|
208
|
+
expect(itinerary.getNextStep(fakeEdge)).is.null;
|
|
209
|
+
|
|
210
|
+
expect(itinerary.getPreviousStep(null)).is.null;
|
|
211
|
+
expect(itinerary.getPreviousStep(fakeNode)).is.null;
|
|
212
|
+
expect(itinerary.getPreviousStep(fakeEdge)).is.null;
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
it('info', () => {
|
|
217
|
+
let itineraryInfo;
|
|
218
|
+
|
|
219
|
+
expect(itinerary.getInfo()).is.null;
|
|
220
|
+
expect(itinerary.getInfo(null)).is.null;
|
|
221
|
+
expect(itinerary.getInfo({
|
|
222
|
+
lat: 0,
|
|
223
|
+
lng: 0
|
|
224
|
+
})).is.null;
|
|
225
|
+
expect(itinerary.getInfo(new Coordinates(0, 0, null, new Level(0)))).is.null;
|
|
226
|
+
|
|
227
|
+
itineraryInfo = itinerary.getInfo(new Coordinates(43.6091367, 3.8839298));
|
|
228
|
+
expect(itineraryInfo.projection).is.not.null;
|
|
229
|
+
expect(itineraryInfo.projection.nearestElement).equal(nodes[0]);
|
|
230
|
+
expect(itineraryInfo.remainingDistance).be.closeTo(51.30, 0.01);
|
|
231
|
+
expect(itineraryInfo.traveledDistance).be.closeTo(0, 0.01);
|
|
232
|
+
expect(itineraryInfo.remainingPercentage).be.closeTo(1.0, 0.01);
|
|
233
|
+
expect(itineraryInfo.traveledPercentage).be.closeTo(0.0, 0.01);
|
|
234
|
+
expect(itineraryInfo.previousStep).is.null;
|
|
235
|
+
expect(itineraryInfo.nextStep).equal(itinerary.steps[0]);
|
|
236
|
+
|
|
237
|
+
itineraryInfo = itinerary.getInfo(new Coordinates(43.6091678, 3.884182));
|
|
238
|
+
expect(itineraryInfo.projection).is.not.null;
|
|
239
|
+
expect(itineraryInfo.projection.nearestElement).equal(edges[0]);
|
|
240
|
+
expect(itineraryInfo.remainingDistance).be.closeTo(43.40, 0.01);
|
|
241
|
+
expect(itineraryInfo.traveledDistance).be.closeTo(7.90, 0.01);
|
|
242
|
+
expect(itineraryInfo.remainingPercentage).be.closeTo(0.85, 0.01);
|
|
243
|
+
expect(itineraryInfo.traveledPercentage).be.closeTo(0.15, 0.01);
|
|
244
|
+
expect(itineraryInfo.previousStep).equal(itinerary.steps[0]);
|
|
245
|
+
expect(itineraryInfo.nextStep).equal(itinerary.steps[1]);
|
|
246
|
+
|
|
247
|
+
itineraryInfo = itinerary.getInfo(new Coordinates(43.6094183, 3.8842195));
|
|
248
|
+
expect(itineraryInfo.projection).is.not.null;
|
|
249
|
+
expect(itineraryInfo.projection.nearestElement).equal(nodes[1]);
|
|
250
|
+
expect(itineraryInfo.previousStep).equal(itinerary.steps[0]);
|
|
251
|
+
expect(itineraryInfo.nextStep).equal(itinerary.steps[1]);
|
|
252
|
+
|
|
253
|
+
itineraryInfo = itinerary.getInfo(new Coordinates(43.6093795, 3.8843617));
|
|
254
|
+
expect(itineraryInfo.projection).is.not.null;
|
|
255
|
+
expect(itineraryInfo.projection.nearestElement).equal(edges[1]);
|
|
256
|
+
expect(itineraryInfo.previousStep).equal(itinerary.steps[1]);
|
|
257
|
+
expect(itineraryInfo.nextStep).equal(itinerary.steps[2]);
|
|
258
|
+
|
|
259
|
+
itineraryInfo = itinerary.getInfo(new Coordinates(43.6093154, 3.8846326));
|
|
260
|
+
expect(itineraryInfo.projection).is.not.null;
|
|
261
|
+
expect(itineraryInfo.projection.nearestElement).equal(nodes[2]);
|
|
262
|
+
expect(itineraryInfo.remainingDistance).be.closeTo(0.0, 0.01);
|
|
263
|
+
expect(itineraryInfo.traveledDistance).be.closeTo(51.30, 0.01);
|
|
264
|
+
expect(itineraryInfo.remainingPercentage).be.closeTo(0.0, 0.01);
|
|
265
|
+
expect(itineraryInfo.traveledPercentage).be.closeTo(1.0, 0.01);
|
|
266
|
+
expect(itineraryInfo.previousStep).equal(itinerary.steps[1]);
|
|
267
|
+
expect(itineraryInfo.nextStep).equal(itinerary.steps[2]);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
describe('Itinerary single line', () => {
|
|
273
|
+
|
|
274
|
+
const nodes = [
|
|
275
|
+
new Node(new Coordinates(43.6091194, 3.884099), 'p0'),
|
|
276
|
+
new Node(new Coordinates(43.6093629, 3.8842777), 'p1'),
|
|
277
|
+
new Node(new Coordinates(43.6094902, 3.8843416), 'p2')
|
|
278
|
+
];
|
|
279
|
+
|
|
280
|
+
const edges = [
|
|
281
|
+
new Edge(nodes[0], nodes[1], null, 'e0'),
|
|
282
|
+
new Edge(nodes[1], nodes[2], null, 'e1')
|
|
283
|
+
];
|
|
284
|
+
|
|
285
|
+
const itinerary = new Itinerary(nodes, edges);
|
|
286
|
+
itinerary.start = new Coordinates(43.6091367, 3.8839298);
|
|
287
|
+
itinerary.end = new Coordinates(43.6095552, 3.8844971);
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
it('common', () => {
|
|
291
|
+
isReadable(itinerary);
|
|
292
|
+
verifyItineraryLength(itinerary);
|
|
293
|
+
verifyNextEdgesAndNodes(itinerary);
|
|
294
|
+
verifySteps(itinerary);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it('specific', () => {
|
|
298
|
+
const { steps } = itinerary;
|
|
299
|
+
expect(steps.length).equal(2);
|
|
300
|
+
expect(steps[0].nodes[0]).equal(nodes[0]);
|
|
301
|
+
expect(steps[0].nodes[1]).equal(nodes[1]);
|
|
302
|
+
expect(steps[0].nodes[2]).equal(nodes[2]);
|
|
303
|
+
expect(steps[1].nodes[0]).equal(nodes[2]);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
describe('Itinerary single line - start merged', () => {
|
|
310
|
+
|
|
311
|
+
const nodes = [
|
|
312
|
+
new Node(new Coordinates(43.6091194, 3.884099), 'p0'),
|
|
313
|
+
new Node(new Coordinates(43.6093629, 3.8842777), 'p1'),
|
|
314
|
+
new Node(new Coordinates(43.6094902, 3.8843416), 'p2')
|
|
315
|
+
];
|
|
316
|
+
|
|
317
|
+
const edges = [
|
|
318
|
+
new Edge(nodes[0], nodes[1], null, 'e0'),
|
|
319
|
+
new Edge(nodes[1], nodes[2], null, 'e1')
|
|
320
|
+
];
|
|
321
|
+
|
|
322
|
+
const itinerary = new Itinerary(nodes, edges);
|
|
323
|
+
itinerary.start = new Coordinates(43.6091194, 3.884099);
|
|
324
|
+
itinerary.end = new Coordinates(43.6095552, 3.8844971);
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
it('common', () => {
|
|
328
|
+
isReadable(itinerary);
|
|
329
|
+
verifyItineraryLength(itinerary);
|
|
330
|
+
verifyNextEdgesAndNodes(itinerary);
|
|
331
|
+
verifySteps(itinerary);
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it('specific', () => {
|
|
335
|
+
const { steps } = itinerary;
|
|
336
|
+
expect(steps.length).equal(2);
|
|
337
|
+
expect(steps[0].nodes[0]).equal(nodes[0]);
|
|
338
|
+
expect(steps[0].nodes[1]).equal(nodes[1]);
|
|
339
|
+
expect(steps[0].nodes[2]).equal(nodes[2]);
|
|
340
|
+
expect(steps[1].nodes[0]).equal(nodes[2]);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
describe('Itinerary single line - end merged', () => {
|
|
346
|
+
|
|
347
|
+
const nodes = [
|
|
348
|
+
new Node(new Coordinates(43.6091194, 3.884099), 'p0'),
|
|
349
|
+
new Node(new Coordinates(43.6093629, 3.8842777), 'p1'),
|
|
350
|
+
new Node(new Coordinates(43.6094902, 3.8843416), 'p2')
|
|
351
|
+
];
|
|
352
|
+
|
|
353
|
+
const edges = [
|
|
354
|
+
new Edge(nodes[0], nodes[1], null, 'e0'),
|
|
355
|
+
new Edge(nodes[1], nodes[2], null, 'e1')
|
|
356
|
+
];
|
|
357
|
+
|
|
358
|
+
const itinerary = new Itinerary(nodes, edges);
|
|
359
|
+
itinerary.start = new Coordinates(43.6091367, 3.8839298);
|
|
360
|
+
itinerary.end = new Coordinates(43.6094902, 3.8843416);
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
it('common', () => {
|
|
364
|
+
isReadable(itinerary);
|
|
365
|
+
verifyItineraryLength(itinerary);
|
|
366
|
+
verifyNextEdgesAndNodes(itinerary);
|
|
367
|
+
verifySteps(itinerary);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it('specific', () => {
|
|
371
|
+
const { steps } = itinerary;
|
|
372
|
+
expect(steps.length).equal(2);
|
|
373
|
+
expect(steps[0].nodes[0]).equal(nodes[0]);
|
|
374
|
+
expect(steps[0].nodes[1]).equal(nodes[1]);
|
|
375
|
+
expect(steps[0].nodes[2]).equal(nodes[2]);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
describe('Itinerary single line - start and end merged', () => {
|
|
382
|
+
|
|
383
|
+
const nodes = [
|
|
384
|
+
new Node(new Coordinates(43.6091194, 3.884099), 'p0'),
|
|
385
|
+
new Node(new Coordinates(43.6093629, 3.8842777), 'p1')
|
|
386
|
+
];
|
|
387
|
+
|
|
388
|
+
const edges = [
|
|
389
|
+
new Edge(nodes[0], nodes[1], null, 'e0')
|
|
390
|
+
];
|
|
391
|
+
|
|
392
|
+
const itinerary = new Itinerary(nodes, edges);
|
|
393
|
+
itinerary.start = new Coordinates(43.6091194, 3.884099);
|
|
394
|
+
itinerary.end = new Coordinates(3.6093629, 3.8842777);
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
it('common', () => {
|
|
398
|
+
isReadable(itinerary);
|
|
399
|
+
verifyItineraryLength(itinerary);
|
|
400
|
+
verifyNextEdgesAndNodes(itinerary);
|
|
401
|
+
verifySteps(itinerary);
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
it('specific', () => {
|
|
405
|
+
const { steps } = itinerary;
|
|
406
|
+
expect(steps.length).equal(2);
|
|
407
|
+
expect(steps[0].nodes[0]).equal(nodes[0]);
|
|
408
|
+
expect(steps[0].nodes[1]).equal(nodes[1]);
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
describe('Itinerary single point', () => {
|
|
414
|
+
|
|
415
|
+
const nodes = [
|
|
416
|
+
new Node(new Coordinates(43.6092785, 3.8845052), 'p0')
|
|
417
|
+
];
|
|
418
|
+
const itinerary = new Itinerary(nodes, []);
|
|
419
|
+
itinerary.start = new Coordinates(43.6093154, 3.8846326);
|
|
420
|
+
itinerary.end = new Coordinates(43.6091901, 3.8845266);
|
|
421
|
+
|
|
422
|
+
it('common', () => {
|
|
423
|
+
isReadable(itinerary);
|
|
424
|
+
verifyItineraryLength(itinerary);
|
|
425
|
+
verifyNextEdgesAndNodes(itinerary);
|
|
426
|
+
verifySteps(itinerary);
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
it('specific', () => {
|
|
430
|
+
const { steps } = itinerary;
|
|
431
|
+
expect(steps.length).equal(1);
|
|
432
|
+
expect(steps[0].nodes[0]).equal(nodes[0]);
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
describe('Itinerary single point - start and end merged', () => {
|
|
438
|
+
|
|
439
|
+
const nodes = [
|
|
440
|
+
new Node(new Coordinates(43.6092785, 3.8845052), 'p0')
|
|
441
|
+
];
|
|
442
|
+
const itinerary = new Itinerary(nodes, []);
|
|
443
|
+
itinerary.start = new Coordinates(43.6092785, 3.8845052);
|
|
444
|
+
itinerary.end = new Coordinates(43.6092785, 3.8845052);
|
|
445
|
+
|
|
446
|
+
it('common', () => {
|
|
447
|
+
isReadable(itinerary);
|
|
448
|
+
verifyItineraryLength(itinerary);
|
|
449
|
+
verifyNextEdgesAndNodes(itinerary);
|
|
450
|
+
verifySteps(itinerary);
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
it('specific', () => {
|
|
454
|
+
const { steps } = itinerary;
|
|
455
|
+
expect(steps.length).equal(1);
|
|
456
|
+
expect(steps[0].nodes[0]).equal(nodes[0]);
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
describe('Itinerary fromOrderedPointsArray', () => {
|
|
463
|
+
|
|
464
|
+
const points = [
|
|
465
|
+
[43.6091194, 3.884099],
|
|
466
|
+
[43.6093629, 3.8842777],
|
|
467
|
+
[43.6094902, 3.8843416]
|
|
468
|
+
];
|
|
469
|
+
|
|
470
|
+
const start = [43.6091367, 3.8839298];
|
|
471
|
+
const end = [43.6094902, 3.8843416];
|
|
472
|
+
let itinerary;
|
|
473
|
+
|
|
474
|
+
it('common', () => {
|
|
475
|
+
itinerary = Itinerary.fromOrderedPointsArray(points, start, end);
|
|
476
|
+
|
|
477
|
+
isReadable(itinerary);
|
|
478
|
+
verifyItineraryLength(itinerary);
|
|
479
|
+
verifyNextEdgesAndNodes(itinerary);
|
|
480
|
+
verifySteps(itinerary);
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
it('specific', () => {
|
|
484
|
+
const { nodes } = itinerary;
|
|
485
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
486
|
+
expect(Coordinates.equalsTo(nodes[i].coords, points[i]));
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
describe('Multi - Level Itinerary (down)', () => {
|
|
494
|
+
|
|
495
|
+
const nodes = [
|
|
496
|
+
new Node(new Coordinates(43.6091194, 3.884099, null, new Level(1)), 'p0'),
|
|
497
|
+
new Node(new Coordinates(43.6093629, 3.8842777, null, new Level(1)), 'p1'),
|
|
498
|
+
new Node(new Coordinates(43.6094654, 3.8842167, null, new Level(0, 1)), 'p2'),
|
|
499
|
+
new Node(new Coordinates(43.6094902, 3.8843416, null, new Level(0)), 'p3'),
|
|
500
|
+
new Node(new Coordinates(43.6095463, 3.8843837, null, new Level(0)), 'p4')
|
|
501
|
+
];
|
|
502
|
+
|
|
503
|
+
const edges = [
|
|
504
|
+
new Edge(nodes[0], nodes[1], new Level(1), 'e0'),
|
|
505
|
+
new Edge(nodes[1], nodes[2], new Level(0, 1), 'e1'),
|
|
506
|
+
new Edge(nodes[2], nodes[3], new Level(0, 1), 'e2'),
|
|
507
|
+
new Edge(nodes[3], nodes[4], new Level(0), 'e3')
|
|
508
|
+
];
|
|
509
|
+
|
|
510
|
+
const itinerary = new Itinerary(nodes, edges);
|
|
511
|
+
itinerary.start = new Coordinates(43.6091367, 3.8839298, null, new Level(1));
|
|
512
|
+
itinerary.end = new Coordinates(43.6095552, 3.8844971, null, new Level(0));
|
|
513
|
+
|
|
514
|
+
it('common', () => {
|
|
515
|
+
isReadable(itinerary);
|
|
516
|
+
verifyItineraryLength(itinerary);
|
|
517
|
+
verifyNextEdgesAndNodes(itinerary);
|
|
518
|
+
verifySteps(itinerary);
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
it('specific', () => {
|
|
522
|
+
const { steps } = itinerary;
|
|
523
|
+
expect(steps.length).equal(4);
|
|
524
|
+
expect(steps[0].levelChange).is.null;
|
|
525
|
+
expect(steps[0].nodes[0]).equal(nodes[0]);
|
|
526
|
+
expect(steps[0].nodes[1]).equal(nodes[1]);
|
|
527
|
+
|
|
528
|
+
expect(steps[1].nodes[0]).equal(nodes[1]);
|
|
529
|
+
expect(steps[1].levelChange).is.not.null;
|
|
530
|
+
expect(steps[1].levelChange.direction).equal('down');
|
|
531
|
+
expect(steps[1].levelChange.diff).equal(-1);
|
|
532
|
+
expect(steps[1].nodes[1]).equal(nodes[2]);
|
|
533
|
+
expect(steps[1].nodes[2]).equal(nodes[3]);
|
|
534
|
+
|
|
535
|
+
expect(steps[2].levelChange).is.null;
|
|
536
|
+
expect(steps[2].nodes[0]).equal(nodes[3]);
|
|
537
|
+
expect(steps[2].nodes[1]).equal(nodes[4]);
|
|
538
|
+
expect(steps[3].nodes[0]).equal(nodes[4]);
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
describe('Multi - Level Itinerary (up)', () => {
|
|
545
|
+
|
|
546
|
+
const nodes = [
|
|
547
|
+
new Node(new Coordinates(43.6091194, 3.884099, null, new Level(0)), 'p0'),
|
|
548
|
+
new Node(new Coordinates(43.6093629, 3.8842777, null, new Level(0)), 'p1'),
|
|
549
|
+
new Node(new Coordinates(43.6094654, 3.8842167, null, new Level(0, 1)), 'p2'),
|
|
550
|
+
new Node(new Coordinates(43.6094902, 3.8843416, null, new Level(1)), 'p3'),
|
|
551
|
+
new Node(new Coordinates(43.6095463, 3.8843837, null, new Level(1)), 'p4')
|
|
552
|
+
];
|
|
553
|
+
|
|
554
|
+
const edges = [
|
|
555
|
+
new Edge(nodes[0], nodes[1], new Level(0), 'e0'),
|
|
556
|
+
new Edge(nodes[1], nodes[2], new Level(0, 1), 'e1'),
|
|
557
|
+
new Edge(nodes[2], nodes[3], new Level(0, 1), 'e2'),
|
|
558
|
+
new Edge(nodes[3], nodes[4], new Level(1), 'e3')
|
|
559
|
+
];
|
|
560
|
+
|
|
561
|
+
const itinerary = new Itinerary(nodes, edges);
|
|
562
|
+
itinerary.start = new Coordinates(43.6091367, 3.8839298, null, new Level(0));
|
|
563
|
+
itinerary.end = new Coordinates(43.6095552, 3.8844971, null, new Level(1));
|
|
564
|
+
|
|
565
|
+
it('common', () => {
|
|
566
|
+
isReadable(itinerary);
|
|
567
|
+
verifyItineraryLength(itinerary);
|
|
568
|
+
verifyNextEdgesAndNodes(itinerary);
|
|
569
|
+
verifySteps(itinerary);
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
it('specific', () => {
|
|
573
|
+
const { steps } = itinerary;
|
|
574
|
+
expect(steps.length).equal(4);
|
|
575
|
+
expect(steps[0].levelChange).is.null;
|
|
576
|
+
expect(steps[0].nodes[0]).equal(nodes[0]);
|
|
577
|
+
expect(steps[0].nodes[1]).equal(nodes[1]);
|
|
578
|
+
|
|
579
|
+
expect(steps[1].nodes[0]).equal(nodes[1]);
|
|
580
|
+
expect(steps[1].levelChange).is.not.null;
|
|
581
|
+
expect(steps[1].levelChange.direction).equal('up');
|
|
582
|
+
expect(steps[1].levelChange.diff).equal(1);
|
|
583
|
+
expect(steps[1].nodes[1]).equal(nodes[2]);
|
|
584
|
+
expect(steps[1].nodes[2]).equal(nodes[3]);
|
|
585
|
+
|
|
586
|
+
expect(steps[2].levelChange).is.null;
|
|
587
|
+
expect(steps[2].nodes[0]).equal(nodes[3]);
|
|
588
|
+
expect(steps[2].nodes[1]).equal(nodes[4]);
|
|
589
|
+
expect(steps[3].nodes[0]).equal(nodes[4]);
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
describe('Multi - Level Itinerary complex', () => {
|
|
596
|
+
|
|
597
|
+
const nodes = [
|
|
598
|
+
new Node(new Coordinates(43.6091194, 3.884099, null, new Level(0)), 'p0'),
|
|
599
|
+
new Node(new Coordinates(43.6093629, 3.8842777, null, new Level(0)), 'p1'),
|
|
600
|
+
new Node(new Coordinates(43.6094654, 3.8842167, null, new Level(0, 1)), 'p2'),
|
|
601
|
+
new Node(new Coordinates(43.6094902, 3.8843416, null, new Level(1)), 'p3'),
|
|
602
|
+
new Node(new Coordinates(43.6095463, 3.8843837, null, new Level(1)), 'p4'),
|
|
603
|
+
new Node(new Coordinates(43.6095552, 3.8844971, null, new Level(2)), 'p5'),
|
|
604
|
+
new Node(new Coordinates(43.6095908, 3.8844662, null, new Level(1)), 'p6'),
|
|
605
|
+
new Node(new Coordinates(43.6096412, 3.8844706, null, new Level(1)), 'p7')
|
|
606
|
+
];
|
|
607
|
+
|
|
608
|
+
const edges = [
|
|
609
|
+
new Edge(nodes[0], nodes[1], new Level(0), 'e0'),
|
|
610
|
+
new Edge(nodes[1], nodes[2], new Level(0), 'e1'),
|
|
611
|
+
new Edge(nodes[2], nodes[3], new Level(1), 'e2'),
|
|
612
|
+
new Edge(nodes[3], nodes[4], new Level(1), 'e3'),
|
|
613
|
+
new Edge(nodes[4], nodes[5], new Level(1, 2), 'e4'),
|
|
614
|
+
new Edge(nodes[5], nodes[6], new Level(1, 2), 'e5'),
|
|
615
|
+
new Edge(nodes[6], nodes[7], new Level(1), 'e6')
|
|
616
|
+
];
|
|
617
|
+
|
|
618
|
+
const itinerary = new Itinerary(nodes, edges);
|
|
619
|
+
itinerary.start = new Coordinates(43.6091367, 3.8839298, null, new Level(0));
|
|
620
|
+
itinerary.end = new Coordinates(43.6096683, 3.884472, null, new Level(1));
|
|
621
|
+
|
|
622
|
+
it('common', () => {
|
|
623
|
+
isReadable(itinerary);
|
|
624
|
+
verifyItineraryLength(itinerary);
|
|
625
|
+
verifyNextEdgesAndNodes(itinerary);
|
|
626
|
+
verifySteps(itinerary);
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
it('getEdgesAtLevel useMultiLevelSegments=false', () => {
|
|
630
|
+
|
|
631
|
+
const edgesAtLevel0 = itinerary.getEdgesAtLevel(new Level(0), false);
|
|
632
|
+
expect(edgesAtLevel0.length).equals(2);
|
|
633
|
+
expect(edgesAtLevel0[0].name).equals('e0');
|
|
634
|
+
expect(edgesAtLevel0[1].name).equals('e1');
|
|
635
|
+
|
|
636
|
+
const segmentsAtLevel1 = itinerary.getEdgesAtLevel(new Level(1), false);
|
|
637
|
+
expect(segmentsAtLevel1.length).equals(3);
|
|
638
|
+
expect(segmentsAtLevel1[0].name).equals('e2');
|
|
639
|
+
expect(segmentsAtLevel1[1].name).equals('e3');
|
|
640
|
+
expect(segmentsAtLevel1[2].name).equals('e6');
|
|
641
|
+
|
|
642
|
+
const segmentsAtLevel2 = itinerary.getEdgesAtLevel(new Level(2), false);
|
|
643
|
+
expect(segmentsAtLevel2.length).equals(0);
|
|
644
|
+
|
|
645
|
+
const edgesAtLevel01 = itinerary.getEdgesAtLevel(new Level(0, 1), false);
|
|
646
|
+
expect(edgesAtLevel01.length).equals(5);
|
|
647
|
+
|
|
648
|
+
const edgesAtLevel12 = itinerary.getEdgesAtLevel(new Level(1, 2), false);
|
|
649
|
+
expect(edgesAtLevel12.length).equals(5);
|
|
650
|
+
|
|
651
|
+
const edgesAtLevel02 = itinerary.getEdgesAtLevel(new Level(0, 2), false);
|
|
652
|
+
expect(edgesAtLevel02.length).equals(7);
|
|
653
|
+
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
describe('Multi - Level Itinerary elevator', () => {
|
|
660
|
+
|
|
661
|
+
const start = CommonTest.network.getNodeByName('p17');
|
|
662
|
+
const end = CommonTest.network.getNodeByName('p18');
|
|
663
|
+
const itinerary = Itinerary.fromNetworkNodes([
|
|
664
|
+
start,
|
|
665
|
+
CommonTest.network.getNodeByName('p19a'),
|
|
666
|
+
CommonTest.network.getNodeByName('p19b'),
|
|
667
|
+
end
|
|
668
|
+
], start.coords, end.coords);
|
|
669
|
+
|
|
670
|
+
it('common', () => {
|
|
671
|
+
isReadable(itinerary);
|
|
672
|
+
verifyItineraryLength(itinerary);
|
|
673
|
+
verifyNextEdgesAndNodes(itinerary);
|
|
674
|
+
verifySteps(itinerary);
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
it('Verify steps next bearing', () => {
|
|
678
|
+
|
|
679
|
+
const testEdgeBearing = (bearing, edgeId) => {
|
|
680
|
+
expect(diffAngle(
|
|
681
|
+
bearing,
|
|
682
|
+
itinerary.edges[edgeId].bearing
|
|
683
|
+
+ (itinerary._edgesDirectionReversed[edgeId] ? Math.PI : 0)
|
|
684
|
+
)).equal(0);
|
|
685
|
+
};
|
|
686
|
+
|
|
687
|
+
const steps = itinerary.steps;
|
|
688
|
+
expect(steps[0].previousBearing).equal(0);
|
|
689
|
+
testEdgeBearing(steps[0].nextBearing, 0);
|
|
690
|
+
|
|
691
|
+
testEdgeBearing(steps[1].previousBearing, 0);
|
|
692
|
+
testEdgeBearing(steps[1].nextBearing, 1);
|
|
693
|
+
|
|
694
|
+
testEdgeBearing(steps[2].previousBearing, 1);
|
|
695
|
+
testEdgeBearing(steps[2].nextBearing, 2);
|
|
696
|
+
|
|
697
|
+
testEdgeBearing(steps[3].previousBearing, 2);
|
|
698
|
+
expect(steps[3].nextBearing).is.undefined;
|
|
699
|
+
|
|
700
|
+
});
|
|
701
|
+
});
|
|
702
|
+
|
|
703
|
+
describe('Itinerary append', () => {
|
|
704
|
+
|
|
705
|
+
const points = [
|
|
706
|
+
[0, 0],
|
|
707
|
+
[1, 0],
|
|
708
|
+
[2, 0],
|
|
709
|
+
[3, 0],
|
|
710
|
+
[4, 0]
|
|
711
|
+
];
|
|
712
|
+
|
|
713
|
+
it('first it. end does not equal second it. start', () => {
|
|
714
|
+
|
|
715
|
+
const itinerary = Itinerary.fromOrderedPointsArray([
|
|
716
|
+
points[0], points[1]
|
|
717
|
+
], points[0], points[1]);
|
|
718
|
+
|
|
719
|
+
const itinerary2 = Itinerary.fromOrderedPointsArray([
|
|
720
|
+
points[2], points[3], points[4]
|
|
721
|
+
], points[2], points[4]);
|
|
722
|
+
|
|
723
|
+
expect(() => itinerary.append(itinerary2)).throw(Error);
|
|
724
|
+
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
it('first it. end node equals second it. first node', () => {
|
|
729
|
+
|
|
730
|
+
const itinerary = Itinerary.fromOrderedPointsArray([
|
|
731
|
+
points[0], points[1], points[2]
|
|
732
|
+
], points[0], points[2]);
|
|
733
|
+
|
|
734
|
+
const itinerary2 = Itinerary.fromOrderedPointsArray([
|
|
735
|
+
points[2], points[3], points[4]
|
|
736
|
+
], points[2], points[4]);
|
|
737
|
+
|
|
738
|
+
itinerary.append(itinerary2);
|
|
739
|
+
|
|
740
|
+
isReadable(itinerary);
|
|
741
|
+
verifyItineraryLength(itinerary);
|
|
742
|
+
verifyNextEdgesAndNodes(itinerary);
|
|
743
|
+
verifySteps(itinerary);
|
|
744
|
+
|
|
745
|
+
expect(itinerary.nodes.length).equals(5);
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
it('last node and end of the first it. are merged', () => {
|
|
749
|
+
|
|
750
|
+
const itinerary = Itinerary.fromOrderedPointsArray([
|
|
751
|
+
points[0], points[1], points[2]
|
|
752
|
+
], points[0], points[2]);
|
|
753
|
+
|
|
754
|
+
const itinerary2 = Itinerary.fromOrderedPointsArray([
|
|
755
|
+
points[3], points[4]
|
|
756
|
+
], points[2], points[4]);
|
|
757
|
+
|
|
758
|
+
itinerary.append(itinerary2);
|
|
759
|
+
|
|
760
|
+
isReadable(itinerary);
|
|
761
|
+
verifyItineraryLength(itinerary);
|
|
762
|
+
verifyNextEdgesAndNodes(itinerary);
|
|
763
|
+
verifySteps(itinerary);
|
|
764
|
+
|
|
765
|
+
expect(itinerary.nodes.length).equals(5);
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
it('first node and start of the second it. are merged', () => {
|
|
769
|
+
|
|
770
|
+
const itinerary = Itinerary.fromOrderedPointsArray([
|
|
771
|
+
points[0], points[1]
|
|
772
|
+
], points[0], points[2]);
|
|
773
|
+
|
|
774
|
+
const itinerary2 = Itinerary.fromOrderedPointsArray([
|
|
775
|
+
points[2], points[3], points[4]
|
|
776
|
+
], points[2], points[4]);
|
|
777
|
+
|
|
778
|
+
itinerary.append(itinerary2);
|
|
779
|
+
|
|
780
|
+
isReadable(itinerary);
|
|
781
|
+
verifyItineraryLength(itinerary);
|
|
782
|
+
verifyNextEdgesAndNodes(itinerary);
|
|
783
|
+
verifySteps(itinerary);
|
|
784
|
+
|
|
785
|
+
expect(itinerary.nodes.length).equals(5);
|
|
786
|
+
});
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
it('normal', () => {
|
|
790
|
+
|
|
791
|
+
const itinerary = Itinerary.fromOrderedPointsArray([
|
|
792
|
+
points[0], points[1]
|
|
793
|
+
], points[0], points[2]);
|
|
794
|
+
|
|
795
|
+
const itinerary2 = Itinerary.fromOrderedPointsArray([
|
|
796
|
+
points[3], points[4]
|
|
797
|
+
], points[2], points[4]);
|
|
798
|
+
|
|
799
|
+
itinerary.append(itinerary2);
|
|
800
|
+
|
|
801
|
+
isReadable(itinerary);
|
|
802
|
+
verifyItineraryLength(itinerary);
|
|
803
|
+
verifyNextEdgesAndNodes(itinerary);
|
|
804
|
+
verifySteps(itinerary);
|
|
805
|
+
|
|
806
|
+
expect(itinerary.nodes.length).equals(5);
|
|
807
|
+
});
|
|
808
|
+
|
|
809
|
+
});
|