@wemap/geo 5.0.0 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/geo"
13
13
  },
14
14
  "name": "@wemap/geo",
15
- "version": "5.0.0",
15
+ "version": "5.1.1",
16
16
  "bugs": {
17
17
  "url": "https://github.com/wemap/wemap-modules-js/issues"
18
18
  },
@@ -28,7 +28,7 @@
28
28
  "license": "ISC",
29
29
  "dependencies": {
30
30
  "@wemap/logger": "^5.0.0",
31
- "@wemap/maths": "^5.0.0"
31
+ "@wemap/maths": "^5.1.1"
32
32
  },
33
- "gitHead": "73607e294f29d3f9a41673bfc25ad9489a1da7f4"
33
+ "gitHead": "31bd3f410dc3c5beebbd2de934d393f4e8e10396"
34
34
  }
@@ -250,7 +250,7 @@ class GraphRouter {
250
250
  let endId = end.uniqueRouterId;
251
251
  while (parentVertices[endId]) {
252
252
  path.unshift(vertexNodes[endId]);
253
- edgesWeights.push(distanceMap[endId] - distanceMap[parentVertices[endId]]);
253
+ edgesWeights.unshift(distanceMap[endId] - distanceMap[parentVertices[endId]]);
254
254
  endId = parentVertices[endId];
255
255
  }
256
256
  if (path.length !== 0) {
@@ -1,4 +1,5 @@
1
1
  import chai from 'chai';
2
+ import chaiAlmost from 'chai-almost';
2
3
 
3
4
  import Coordinates from '../coordinates/Coordinates.js';
4
5
  import Level from '../coordinates/Level.js';
@@ -13,6 +14,7 @@ import NoRouteFoundError from './NoRouteFoundError.js';
13
14
  import GraphRouterOptions from './GraphRouterOptions.js';
14
15
 
15
16
  const { expect } = chai;
17
+ chai.use(chaiAlmost(1e-3));
16
18
 
17
19
  const networkDidNotChange = (networkAfter, nodesBefore, edgesBefore) => {
18
20
 
@@ -244,9 +246,22 @@ describe('GraphRouter - Itinerary one way', () => {
244
246
 
245
247
  describe('GraphRouter - Itinerary with weight', () => {
246
248
 
247
- const { edges, network } = createModel();
249
+ const { edges, network, start, end } = createModel();
248
250
  edges[1].mood = true;
249
251
 
252
+ it('Verify weight', () => {
253
+
254
+ router = new GraphRouter(network);
255
+
256
+ itinerary = getShortestPath(router, start, end, options);
257
+ expect(itinerary).is.not.undefined;
258
+ expect(getNodesNames(itinerary)).deep.equals(['p0', 'p1', 'p2']);
259
+ expect(itinerary.edges.length).equals(2);
260
+ expect(itinerary.edgesWeights.length).equals(2);
261
+ expect(itinerary.edgesWeights[0]).almost.equals(30.696);
262
+ expect(itinerary.edgesWeights[1]).almost.equals(20.604);
263
+ });
264
+
250
265
  const defaultWeighEdgeFn = new GraphRouterOptions().weightEdgeFn;
251
266
  const weightFn = edge => {
252
267
  let duration = defaultWeighEdgeFn(edge);
@@ -262,13 +277,13 @@ describe('GraphRouter - Itinerary with weight', () => {
262
277
  options = new GraphRouterOptions();
263
278
  options.weightEdgeFn = weightFn;
264
279
 
265
- itinerary = getShortestPath(router,
266
- network.nodes.find(node => node.builtFrom === 'p0'),
267
- network.nodes.find(node => node.builtFrom === 'p2'),
268
- options
269
- );
280
+ itinerary = getShortestPath(router, start, end, options);
270
281
 
271
282
  expect(itinerary).is.not.undefined;
272
283
  expect(getNodesNames(itinerary)).deep.equals(['p0', 'p1', 'p3', 'p2']);
284
+ expect(itinerary.edgesWeights[0]).almost.equals(30.696);
285
+ expect(itinerary.edgesWeights[1]).almost.equals(15.078);
286
+ expect(itinerary.edgesWeights[2]).almost.equals(27.005);
287
+
273
288
  });
274
289
  });