@wemap/geo 0.2.1 → 0.3.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.
@@ -1,72 +1,128 @@
1
- import chai from 'chai';
2
- import chaiAlmost from 'chai-almost';
1
+ import { expect } from 'chai';
3
2
 
4
3
  import {
5
4
  WGS84, WGS84UserPosition
6
5
  } from '@wemap/geo';
7
6
 
8
- import Edge from './Edge';
9
- import Node from './Node';
10
- import Network from './Network';
11
7
  import MapMatching from './MapMatching';
12
8
 
13
- const expect = chai.expect;
14
- chai.use(chaiAlmost());
15
-
16
-
17
- function edgeFromTwoNodes(node1, node2) {
18
- if (!(node1 instanceof Node)) {
19
- throw new TypeError('node1 is not an instance of Node');
20
- }
21
-
22
- if (!(node2 instanceof Node)) {
23
- throw new TypeError('node2 is not an instance of Node');
24
- }
25
- const edge = new Edge(node1, node2);
26
- node1.edges.push(edge);
27
- node2.edges.push(edge);
28
- return edge;
29
- }
30
-
31
- function createNetworkFromEdgesAndNodes(edges, nodes) {
32
- const network = new Network();
33
- network.edges = edges;
34
- network.nodes = nodes;
35
- return network;
36
- }
37
-
38
- describe('matching', () => {
39
- it('Should return the good value', () => {
40
-
41
- const n1 = new Node(new WGS84(43.6091883, 3.8841242));
42
- const n2 = new Node(new WGS84(43.6091709, 3.8842382));
43
- const n3 = new Node(new WGS84(43.6091288, 3.884226));
44
- const n4 = new Node(new WGS84(43.6091461, 3.884112));
45
- const e1 = edgeFromTwoNodes(n1, n2);
46
- const e2 = edgeFromTwoNodes(n2, n3);
47
- const e3 = edgeFromTwoNodes(n3, n4);
48
- const e4 = edgeFromTwoNodes(n4, n1);
49
- const network = createNetworkFromEdgesAndNodes([e1, e2, e3, e4], [n1, n2, n3, n4]);
50
-
51
- const mapMatching = new MapMatching(network);
52
- mapMatching.maxAngleBearing = 30;
9
+ import { network } from '../../tests/CommonTest';
10
+ import Level from '../coordinates/Level';
11
+
12
+ describe('MapMatching', () => {
13
+
14
+ const mapMatching = new MapMatching(network);
15
+
16
+ const location = new WGS84UserPosition(43.6091762, 3.8841239, null, new Level(2));
53
17
 
54
- const location = new WGS84UserPosition(43.6091762, 3.8841239);
18
+ it('without bearing', () => {
19
+ const result = mapMatching.getProjection(location, true, false).projection;
20
+ const expected = new WGS84(43.609176389330685, 3.8841226728537976, null, new Level(2));
21
+ expect(result.distanceTo(expected)).to.below(0.01);
22
+ expect(Level.equalsTo(expected.level, result.level)).true;
23
+ });
55
24
 
25
+ it('with bearing', () => {
26
+ mapMatching.maxAngleBearing = 30;
56
27
  location.bearing = 101.9;
57
- const projection1 = mapMatching.getProjection(location);
58
- const result1 = projection1.projection;
59
- const expected1 = new WGS84(43.609187832342556, 3.884127262759803);
60
- const distance1 = result1.distanceTo(expected1);
61
- expect(distance1).to.below(0.01);
28
+ const result = mapMatching.getProjection(location).projection;
29
+ const expected = new WGS84(43.60918861773314, 3.8841274925288447, null, new Level(2));
30
+ expect(result.distanceTo(expected)).to.below(0.01);
31
+ expect(Level.equalsTo(expected.level, result.level)).true;
32
+ });
33
+
34
+ it('matching node levels', () => {
35
+ let currentPosition, projection;
36
+
37
+ /**
38
+ * Projection on Nodes
39
+ */
40
+
41
+ currentPosition = new WGS84(43.6091773, 3.8842584, null, null);
42
+ projection = mapMatching.getProjection(currentPosition);
43
+ expect(projection).is.null;
44
+
45
+ currentPosition = new WGS84(43.6091773, 3.8842584, null, new Level(1));
46
+ projection = mapMatching.getProjection(currentPosition, true, false);
47
+ expect(projection).is.not.null;
48
+ expect(projection.projection.level.isInside(1)).true;
49
+
50
+ currentPosition = new WGS84(43.6091773, 3.8842584, null, new Level(2));
51
+ projection = mapMatching.getProjection(currentPosition, true, false);
52
+ expect(projection).is.not.null;
53
+ expect(projection.projection.level.isInside(2)).true;
54
+
55
+ });
56
+
57
+ it('matching edge levels', () => {
58
+ let currentPosition, projection;
59
+
60
+ /**
61
+ * Projection on Edges
62
+ */
62
63
 
64
+ currentPosition = new WGS84(43.6092811, 3.8842406, null, null);
65
+ projection = mapMatching.getProjection(currentPosition);
66
+ expect(projection).is.null;
63
67
 
64
- location.bearing = 11.9;
65
- const projection2 = mapMatching.getProjection(location);
66
- const result2 = projection2.projection;
67
- const expected2 = new WGS84(43.609176667533255, 3.8841208369745965);
68
- const distance2 = result2.distanceTo(expected2);
69
- expect(distance2).to.below(0.01);
68
+ currentPosition = new WGS84(43.6092811, 3.8842406, null, new Level(1));
69
+ projection = mapMatching.getProjection(currentPosition, true, false);
70
+ expect(projection).is.not.null;
71
+ expect(projection.nearestElement.level.isInside(1)).true;
72
+
73
+ currentPosition = new WGS84(43.6092811, 3.8842406, null, new Level(2));
74
+ projection = mapMatching.getProjection(currentPosition, true, false);
75
+ expect(projection).is.not.null;
76
+ expect(projection.nearestElement.level.isInside(2)).true;
77
+
78
+ });
79
+
80
+ it('matching stairs nodes levels', () => {
81
+ let currentPosition, projection;
82
+
83
+ /**
84
+ * Projection on Edges
85
+ */
86
+
87
+ currentPosition = new WGS84(43.6093691, 3.8842057, null, null);
88
+ projection = mapMatching.getProjection(currentPosition);
89
+ expect(projection).is.null;
90
+
91
+ currentPosition = new WGS84(43.6093691, 3.8842057, null, new Level(1));
92
+ projection = mapMatching.getProjection(currentPosition, true, false);
93
+ expect(projection).is.not.null;
94
+ expect(projection.projection.level.isInside(1)).true;
95
+
96
+ currentPosition = new WGS84(43.6093691, 3.8842057, null, new Level(2));
97
+ projection = mapMatching.getProjection(currentPosition, true, false);
98
+ expect(projection).is.not.null;
99
+ expect(projection.projection.level.isInside(2)).true;
70
100
 
71
101
  });
102
+
103
+ it('matching stairs edge levels', () => {
104
+ let currentPosition, projection;
105
+
106
+ /**
107
+ * Projection on Edges
108
+ */
109
+
110
+ currentPosition = new WGS84(43.6093476, 3.8841978, null, null);
111
+ projection = mapMatching.getProjection(currentPosition);
112
+ expect(projection).is.null;
113
+
114
+ currentPosition = new WGS84(43.6093476, 3.8841978, null, new Level(1));
115
+ projection = mapMatching.getProjection(currentPosition, true, false);
116
+ expect(projection).is.not.null;
117
+ expect(projection.projection.level.isInside(1)).true;
118
+ expect(projection.nearestElement.level.isInside(1)).true;
119
+
120
+ currentPosition = new WGS84(43.6093476, 3.8841978, null, new Level(2));
121
+ projection = mapMatching.getProjection(currentPosition, true, false);
122
+ expect(projection).is.not.null;
123
+ expect(projection.projection.level.isInside(2)).true;
124
+ expect(projection.nearestElement.level.isInside(2)).true;
125
+
126
+ });
127
+
72
128
  });
@@ -0,0 +1,54 @@
1
+ import Itinerary from './Itinerary';
2
+
3
+ class Step {
4
+
5
+ nodes = [];
6
+ edges = [];
7
+ angle;
8
+ _length = 0;
9
+ previousBearing;
10
+ nextBearing;
11
+
12
+ get node() {
13
+ return this.nodes[0];
14
+ }
15
+
16
+ get nodeData() {
17
+ return this.nodes[0].data;
18
+ }
19
+
20
+ get nextEdgeData() {
21
+ if (this.edges.length === 0) {
22
+ return null;
23
+ }
24
+ return this.edges[0].data;
25
+ }
26
+
27
+ /**
28
+ * Get route length
29
+ */
30
+ get length() {
31
+ if (!this._length) {
32
+ this._length = this.edges.reduce((acc, edge) => acc + edge.length, 0);
33
+ }
34
+ return this._length;
35
+ }
36
+
37
+ /**
38
+ * Get route duration with default speed
39
+ */
40
+ get duration() {
41
+ return this.getDuration();
42
+ }
43
+
44
+ /**
45
+ * Get route duration
46
+ * @param {Number} speed in km/h
47
+ */
48
+ getDuration(speed) {
49
+ return Itinerary.getDurationFromLength(this.length, speed);
50
+ }
51
+
52
+ }
53
+
54
+ export default Step;
@@ -0,0 +1,57 @@
1
+ import {
2
+ WGS84, Level
3
+ } from '@wemap/geo';
4
+
5
+ import Edge from '../src/graph/Edge';
6
+ import Node from '../src/graph/Node';
7
+ import Network from '../src/graph/Network';
8
+
9
+ const nodes = [
10
+ new Node(new WGS84(43.6092404, 3.884099), { name: 'p0' }),
11
+ new Node(new WGS84(43.6091965, 3.8841285), { name: 'p1' }),
12
+ new Node(new WGS84(43.6091888, 3.8841263), { name: 'p2' }),
13
+ new Node(new WGS84(43.6091361, 3.8841109), { name: 'p3' }),
14
+ new Node(new WGS84(43.6091194, 3.8842202), { name: 'p4' }),
15
+ new Node(new WGS84(43.6091722, 3.8842355), { name: 'p5' }),
16
+ new Node(new WGS84(43.6091749, 3.8842173), { name: 'p6' }),
17
+ new Node(new WGS84(43.609276, 3.8842467), { name: 'p7' }),
18
+ new Node(new WGS84(43.6092935, 3.8842518), { name: 'p8' }),
19
+ new Node(new WGS84(43.6093022, 3.8842702), { name: 'p9' }),
20
+ new Node(new WGS84(43.6093123, 3.8842731), { name: 'p10' }),
21
+ new Node(new WGS84(43.6093234, 3.8842009), { name: 'p11' }),
22
+ new Node(new WGS84(43.6093629, 3.8842127), { name: 'p12' }),
23
+ new Node(new WGS84(43.6093597, 3.8842336), { name: 'p13' }),
24
+ new Node(new WGS84(43.6093202, 3.8842218), { name: 'p14' }),
25
+ new Node(new WGS84(43.6093123, 3.8842731), { name: 'p15' }),
26
+ new Node(new WGS84(43.6092681, 3.8842604), { name: 'p16' })
27
+ ];
28
+
29
+ const edges = [
30
+ new Edge(nodes[1], nodes[2], { name: 'e0' }, new Level(2)),
31
+ new Edge(nodes[2], nodes[3], { name: 'e1' }, new Level(2)),
32
+ new Edge(nodes[3], nodes[4], { name: 'e2' }, new Level(2)),
33
+ new Edge(nodes[4], nodes[5], { name: 'e3' }, new Level(2)),
34
+ new Edge(nodes[5], nodes[6], { name: 'e4' }, new Level(2)),
35
+ new Edge(nodes[6], nodes[2], { name: 'e5' }, new Level(2)),
36
+ new Edge(nodes[6], nodes[7], { name: 'e6' }, new Level(2)),
37
+ new Edge(nodes[7], nodes[8], { name: 'e7' }, new Level(2)),
38
+ new Edge(nodes[8], nodes[9], { name: 'e8' }, new Level(2)),
39
+ new Edge(nodes[9], nodes[10], { name: 'e9' }, new Level(2)),
40
+ new Edge(nodes[10], nodes[11], { name: 'e10' }, new Level(2)),
41
+ new Edge(nodes[11], nodes[12], { name: 'e11', stairs: true }, new Level(1, 2)),
42
+ new Edge(nodes[12], nodes[13], { name: 'e12', stairs: true }, new Level(1, 2)),
43
+ new Edge(nodes[13], nodes[14], { name: 'e13', stairs: true }, new Level(1, 2)),
44
+ new Edge(nodes[14], nodes[15], { name: 'e14' }, new Level(1)),
45
+ new Edge(nodes[15], nodes[16], { name: 'e15' }, new Level(1))
46
+ ];
47
+
48
+ const network = new Network();
49
+ network.edges = edges;
50
+ network.nodes = nodes;
51
+
52
+ const itineraryStart = new WGS84(43.6092754, 3.8842306, null, new Level(2));
53
+ const itineraryEnd = new WGS84(43.6092602, 3.8842669, null, new Level(1));
54
+
55
+ export {
56
+ nodes, edges, network, itineraryStart, itineraryEnd
57
+ };