@wemap/geo 4.0.14 → 5.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 +18 -11
- package/package.json +4 -4
- package/src/Utils.spec.js +38 -0
- package/src/graph/{Edge.js → GraphEdge.js} +33 -94
- package/src/graph/GraphEdge.spec.js +91 -0
- package/src/graph/{Node.js → GraphNode.js} +29 -67
- package/src/graph/GraphNode.spec.js +203 -0
- package/src/graph/{Projection.js → GraphProjection.js} +4 -4
- package/src/graph/GraphUtils.js +17 -0
- package/src/graph/MapMatching.js +7 -5
- package/src/graph/MapMatching.spec.js +26 -26
- package/src/graph/Network.js +85 -48
- package/src/graph/Network.spec.js +66 -15
- package/src/router/GraphItinerary.js +70 -0
- package/src/router/GraphItinerary.spec.js +18 -0
- package/src/{graph → router}/GraphRouter.js +52 -52
- package/src/{graph → router}/GraphRouter.spec.js +54 -96
- package/src/router/GraphRouterOptions.js +19 -0
- package/src/{graph → router}/NoRouteFoundError.js +1 -1
- package/tests/CommonTest.js +6 -6
- package/src/graph/Edge.spec.js +0 -131
- package/src/graph/Itinerary.js +0 -529
- package/src/graph/Itinerary.spec.js +0 -811
- package/src/graph/ItineraryInfo.js +0 -29
- package/src/graph/LevelChange.js +0 -43
- package/src/graph/Node.spec.js +0 -227
- package/src/graph/Step.js +0 -105
- package/src/graph/StepsGeneration.js +0 -123
- package/src/graph/Utils.js +0 -7
package/index.js
CHANGED
|
@@ -13,16 +13,23 @@ export { default as UserPosition } from './src/coordinates/UserPosition.js';
|
|
|
13
13
|
export { default as Attitude } from './src/rotations/Attitude.js';
|
|
14
14
|
export { default as AbsoluteHeading } from './src/rotations/AbsoluteHeading.js';
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
export { default as
|
|
18
|
-
export { default as GraphRouter } from './src/graph/GraphRouter.js';
|
|
19
|
-
export { default as Itinerary } from './src/graph/Itinerary.js';
|
|
20
|
-
export { default as ItineraryInfo } from './src/graph/ItineraryInfo.js';
|
|
21
|
-
export { default as LevelChange } from './src/graph/LevelChange.js';
|
|
16
|
+
/** Graph */
|
|
17
|
+
export { default as GraphEdge } from './src/graph/GraphEdge.js';
|
|
22
18
|
export { default as Network } from './src/graph/Network.js';
|
|
23
|
-
export { default as
|
|
19
|
+
export { default as GraphNode } from './src/graph/GraphNode.js';
|
|
24
20
|
export { default as MapMatching } from './src/graph/MapMatching.js';
|
|
25
|
-
export { default as
|
|
26
|
-
export
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
export { default as GraphProjection } from './src/graph/GraphProjection.js';
|
|
22
|
+
export * as GraphUtils from './src/graph/GraphUtils.js';
|
|
23
|
+
|
|
24
|
+
/** Router */
|
|
25
|
+
export { default as GraphItinerary } from './src/router/GraphItinerary.js';
|
|
26
|
+
export { default as GraphRouter } from './src/router/GraphRouter.js';
|
|
27
|
+
export { default as GraphRouterOptions } from './src/router/GraphRouterOptions.js';
|
|
28
|
+
export { default as NoRouteFoundError } from './src/router/NoRouteFoundError.js';
|
|
29
|
+
|
|
30
|
+
// /** Itinerary */
|
|
31
|
+
// export { default as Itinerary } from '@wemap/osm/src/routers/Itinerary';
|
|
32
|
+
// export { default as ItineraryInfo } from './src/itinerary/ItineraryInfo.js';
|
|
33
|
+
// export { default as Leg } from './src/itinerary/Leg.js';
|
|
34
|
+
// export { default as LevelChange } from './src/itinerary/LevelChange.js';
|
|
35
|
+
// export { default as Step } from './src/itinerary/Step.js';
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"directory": "packages/geo"
|
|
13
13
|
},
|
|
14
14
|
"name": "@wemap/geo",
|
|
15
|
-
"version": "
|
|
15
|
+
"version": "5.0.0",
|
|
16
16
|
"bugs": {
|
|
17
17
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
18
18
|
},
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
],
|
|
28
28
|
"license": "ISC",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@wemap/logger": "^
|
|
31
|
-
"@wemap/maths": "^
|
|
30
|
+
"@wemap/logger": "^5.0.0",
|
|
31
|
+
"@wemap/maths": "^5.0.0"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "73607e294f29d3f9a41673bfc25ad9489a1da7f4"
|
|
34
34
|
}
|
package/src/Utils.spec.js
CHANGED
|
@@ -124,6 +124,44 @@ describe('Geo Utils', () => {
|
|
|
124
124
|
expect(routeSimplified).to.include(route[4]);
|
|
125
125
|
|
|
126
126
|
|
|
127
|
+
route = [
|
|
128
|
+
new Coordinates(48.75627274161895, 2.054974197053283),
|
|
129
|
+
new Coordinates(48.756269751891594, 2.0549905921869933),
|
|
130
|
+
new Coordinates(48.756274912970845, 2.054992757591672),
|
|
131
|
+
new Coordinates(48.75628117553095, 2.0549584148199345),
|
|
132
|
+
new Coordinates(48.756276014452325, 2.054956249415256),
|
|
133
|
+
new Coordinates(48.75627274161895, 2.054974197053283)
|
|
134
|
+
];
|
|
135
|
+
|
|
136
|
+
routeSimplified = simplifyRoute(route);
|
|
137
|
+
expect(routeSimplified.length).equal(5);
|
|
138
|
+
expect(routeSimplified).to.not.include(route[0]);
|
|
139
|
+
expect(routeSimplified).to.not.include(route[5]);
|
|
140
|
+
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
it('geolocationPositionToUserPosition', () => {
|
|
145
|
+
|
|
146
|
+
let route, routeSimplified;
|
|
147
|
+
|
|
148
|
+
route = [
|
|
149
|
+
new Coordinates(48.756308386983484, 2.0549525696601694),
|
|
150
|
+
new Coordinates(48.75630194782273, 2.054987452552288),
|
|
151
|
+
new Coordinates(48.756294588780854, 2.055026521391461),
|
|
152
|
+
new Coordinates(48.7563159759933, 2.0550474511267316),
|
|
153
|
+
new Coordinates(48.756350241508265, 2.0550837293345348)
|
|
154
|
+
];
|
|
155
|
+
|
|
156
|
+
routeSimplified = simplifyRoute(route);
|
|
157
|
+
expect(routeSimplified.length).equal(3);
|
|
158
|
+
expect(routeSimplified).to.include(route[0]);
|
|
159
|
+
expect(routeSimplified).to.not.include(route[1]);
|
|
160
|
+
expect(routeSimplified).to.include(route[2]);
|
|
161
|
+
expect(routeSimplified).to.not.include(route[3]);
|
|
162
|
+
expect(routeSimplified).to.include(route[4]);
|
|
163
|
+
|
|
164
|
+
|
|
127
165
|
route = [
|
|
128
166
|
new Coordinates(48.75627274161895, 2.054974197053283),
|
|
129
167
|
new Coordinates(48.756269751891594, 2.0549905921869933),
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import Level from '../coordinates/Level.js';
|
|
2
|
-
import
|
|
2
|
+
import GraphNode from './GraphNode.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
+
* @template T
|
|
6
|
+
*
|
|
5
7
|
* An Edge is a segment composed of two Node
|
|
6
8
|
* An edge is mostly issued from an OsmWay, but this is not always the case.
|
|
7
9
|
* For example, edges created by mapmatching.
|
|
8
10
|
*/
|
|
9
|
-
class
|
|
11
|
+
class GraphEdge {
|
|
10
12
|
|
|
11
|
-
/** @type {
|
|
13
|
+
/** @type {GraphNode<T>} */
|
|
12
14
|
_node1 = null;
|
|
13
15
|
|
|
14
|
-
/** @type {
|
|
16
|
+
/** @type {GraphNode<T>} */
|
|
15
17
|
_node2 = null;
|
|
16
18
|
|
|
17
19
|
/** @type {?Level} */
|
|
@@ -24,49 +26,38 @@ class Edge {
|
|
|
24
26
|
_length;
|
|
25
27
|
|
|
26
28
|
/** @type {boolean} */
|
|
27
|
-
_computedSizeAndBearing;
|
|
29
|
+
_computedSizeAndBearing = false;
|
|
28
30
|
|
|
29
|
-
/** @type {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
/** @type {boolean} */
|
|
33
|
-
isElevator = false;
|
|
31
|
+
/** @type {?T} */
|
|
32
|
+
builtFrom = null;
|
|
34
33
|
|
|
35
34
|
/** @type {boolean} */
|
|
36
35
|
isOneway = false;
|
|
37
36
|
|
|
38
|
-
/** @type {boolean} */
|
|
39
|
-
isConveying = false;
|
|
40
|
-
|
|
41
|
-
/** @type {string} */
|
|
42
|
-
name = null;
|
|
43
|
-
|
|
44
37
|
/**
|
|
45
|
-
* @param {!
|
|
46
|
-
* @param {!
|
|
38
|
+
* @param {!GraphNode} node1
|
|
39
|
+
* @param {!GraphNode} node2
|
|
47
40
|
* @param {?Level} level
|
|
41
|
+
* @param {?T} builtFrom
|
|
48
42
|
* @param {?string} name
|
|
49
43
|
*/
|
|
50
|
-
constructor(node1, node2, level,
|
|
51
|
-
|
|
44
|
+
constructor(node1, node2, level = null, builtFrom = null) {
|
|
52
45
|
this.node1 = node1;
|
|
53
46
|
this.node2 = node2;
|
|
54
47
|
this.level = level;
|
|
55
|
-
this.
|
|
56
|
-
|
|
57
|
-
this._computedSizeAndBearing = false;
|
|
48
|
+
this.builtFrom = builtFrom;
|
|
58
49
|
}
|
|
59
50
|
|
|
60
|
-
/** @type {!
|
|
51
|
+
/** @type {!GraphNode<T>} */
|
|
61
52
|
get node1() {
|
|
62
53
|
return this._node1;
|
|
63
54
|
}
|
|
64
55
|
|
|
65
|
-
/** @type {!
|
|
56
|
+
/** @type {!GraphNode<T>} */
|
|
66
57
|
set node1(node) {
|
|
67
58
|
|
|
68
|
-
if (!(node instanceof
|
|
69
|
-
throw new TypeError('node1 is not a
|
|
59
|
+
if (!(node instanceof GraphNode)) {
|
|
60
|
+
throw new TypeError('node1 is not a GraphNode');
|
|
70
61
|
}
|
|
71
62
|
|
|
72
63
|
if (this._node1 !== null && this._node2 !== this._node1) {
|
|
@@ -79,16 +70,16 @@ class Edge {
|
|
|
79
70
|
this._computedSizeAndBearing = false;
|
|
80
71
|
}
|
|
81
72
|
|
|
82
|
-
/** @type {!
|
|
73
|
+
/** @type {!GraphNode<T>} */
|
|
83
74
|
get node2() {
|
|
84
75
|
return this._node2;
|
|
85
76
|
}
|
|
86
77
|
|
|
87
|
-
/** @type {!
|
|
78
|
+
/** @type {!GraphNode<T>} */
|
|
88
79
|
set node2(node) {
|
|
89
80
|
|
|
90
|
-
if (!(node instanceof
|
|
91
|
-
throw new TypeError('node2 is not a
|
|
81
|
+
if (!(node instanceof GraphNode)) {
|
|
82
|
+
throw new TypeError('node2 is not a GraphNode');
|
|
92
83
|
}
|
|
93
84
|
|
|
94
85
|
if (this._node2 !== null && this._node2 !== this._node1) {
|
|
@@ -147,89 +138,37 @@ class Edge {
|
|
|
147
138
|
}
|
|
148
139
|
|
|
149
140
|
/**
|
|
150
|
-
* @param {
|
|
141
|
+
* @param {GraphEdge<T>} other
|
|
151
142
|
* @returns {boolean}
|
|
152
143
|
*/
|
|
153
144
|
equalsTo(other) {
|
|
154
145
|
|
|
155
|
-
if (
|
|
146
|
+
if (this === other) {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (!(other instanceof GraphEdge)) {
|
|
156
151
|
return false;
|
|
157
152
|
}
|
|
158
153
|
|
|
159
154
|
return other.node1.equalsTo(this.node1)
|
|
160
155
|
&& other.node2.equalsTo(this.node2)
|
|
161
156
|
&& Level.equalsTo(other.level, this.level)
|
|
162
|
-
&& other.name === this.name
|
|
163
|
-
&& other.isConveying === this.isConveying
|
|
164
|
-
&& other.isElevator === this.isElevator
|
|
165
157
|
&& other.isOneway === this.isOneway
|
|
166
|
-
&& other.
|
|
158
|
+
&& other.builtFrom === this.builtFrom;
|
|
167
159
|
}
|
|
168
160
|
|
|
169
161
|
/**
|
|
170
|
-
* @returns {
|
|
162
|
+
* @returns {GraphEdge<T>}
|
|
171
163
|
*/
|
|
172
164
|
clone() {
|
|
173
|
-
const edge = new
|
|
174
|
-
edge.name = this.name;
|
|
165
|
+
const edge = new GraphEdge(this.node1, this.node2);
|
|
175
166
|
edge.level = this.level;
|
|
176
|
-
edge.isConveying = this.isConveying;
|
|
177
|
-
edge.isElevator = this.isElevator;
|
|
178
167
|
edge.isOneway = this.isOneway;
|
|
179
|
-
edge.
|
|
168
|
+
edge.builtFrom = this.builtFrom;
|
|
180
169
|
return edge;
|
|
181
170
|
}
|
|
182
171
|
|
|
183
|
-
/**
|
|
184
|
-
* @returns {object}
|
|
185
|
-
*/
|
|
186
|
-
extractProperties() {
|
|
187
|
-
const output = {};
|
|
188
|
-
if (this.level !== null) {
|
|
189
|
-
output.level = this.level.toString();
|
|
190
|
-
}
|
|
191
|
-
if (this.name !== null) {
|
|
192
|
-
output.name = this.name;
|
|
193
|
-
}
|
|
194
|
-
if (this.isConveying) {
|
|
195
|
-
output.isConveying = true;
|
|
196
|
-
}
|
|
197
|
-
if (this.isElevator) {
|
|
198
|
-
output.isElevator = true;
|
|
199
|
-
}
|
|
200
|
-
if (this.isOneway) {
|
|
201
|
-
output.isOneway = true;
|
|
202
|
-
}
|
|
203
|
-
if (this.isStairs) {
|
|
204
|
-
output.isStairs = true;
|
|
205
|
-
}
|
|
206
|
-
return output;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* @param {object} properties
|
|
211
|
-
*/
|
|
212
|
-
applyProperties(properties) {
|
|
213
|
-
if (properties.level) {
|
|
214
|
-
this.level = Level.fromString(properties.level);
|
|
215
|
-
}
|
|
216
|
-
if (properties.name) {
|
|
217
|
-
this.name = properties.name;
|
|
218
|
-
}
|
|
219
|
-
if (properties.isConveying) {
|
|
220
|
-
this.isConveying = true;
|
|
221
|
-
}
|
|
222
|
-
if (properties.isElevator) {
|
|
223
|
-
this.isElevator = true;
|
|
224
|
-
}
|
|
225
|
-
if (properties.isOneway) {
|
|
226
|
-
this.isOneway = true;
|
|
227
|
-
}
|
|
228
|
-
if (properties.isStairs) {
|
|
229
|
-
this.isStairs = true;
|
|
230
|
-
}
|
|
231
|
-
return this;
|
|
232
|
-
}
|
|
233
172
|
}
|
|
234
173
|
|
|
235
|
-
export default
|
|
174
|
+
export default GraphEdge;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import chai from 'chai';
|
|
2
|
+
|
|
3
|
+
import Logger from '@wemap/logger';
|
|
4
|
+
|
|
5
|
+
import Coordinates from '../coordinates/Coordinates.js';
|
|
6
|
+
import Level from '../coordinates/Level.js';
|
|
7
|
+
import GraphNode from './GraphNode.js';
|
|
8
|
+
import GraphEdge from './GraphEdge.js';
|
|
9
|
+
|
|
10
|
+
const { expect } = chai;
|
|
11
|
+
|
|
12
|
+
Logger.enable(false);
|
|
13
|
+
|
|
14
|
+
describe('GraphEdge', () => {
|
|
15
|
+
|
|
16
|
+
const node1 = new GraphNode(new Coordinates(45, 5), 'n1');
|
|
17
|
+
const node2 = new GraphNode(new Coordinates(46, 5), 'n2');
|
|
18
|
+
|
|
19
|
+
const edge = new GraphEdge(node1, node2);
|
|
20
|
+
|
|
21
|
+
const fullEdge = new GraphEdge(node1, node2);
|
|
22
|
+
fullEdge.level = new Level(1);
|
|
23
|
+
fullEdge.isOneway = true;
|
|
24
|
+
fullEdge.builtFrom = 'w1';
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
it('creation', () => {
|
|
28
|
+
|
|
29
|
+
expect(() => new GraphEdge()).throw(Error);
|
|
30
|
+
expect(() => new GraphEdge(
|
|
31
|
+
{
|
|
32
|
+
lat: 45,
|
|
33
|
+
lng: 5
|
|
34
|
+
}, node2)).throw(Error);
|
|
35
|
+
expect(() => new GraphEdge(node1,
|
|
36
|
+
{
|
|
37
|
+
lat: 45,
|
|
38
|
+
lng: 5
|
|
39
|
+
})).throw(Error);
|
|
40
|
+
expect(() => new GraphEdge(node1, node2)).not.throw(Error);
|
|
41
|
+
expect(() => new GraphEdge(node1, node2, null)).not.throw(Error);
|
|
42
|
+
expect(() => new GraphEdge(node1, node2, 1)).throw(Error);
|
|
43
|
+
expect(() => new GraphEdge(node1, node2, true)).throw(Error);
|
|
44
|
+
expect(() => new GraphEdge(node1, node2, false)).throw(Error);
|
|
45
|
+
expect(() => new GraphEdge(node1, node2, new Level(1))).not.throw(Error);
|
|
46
|
+
expect(() => new GraphEdge(node1, node2, new Level(1), 'foo')).not.throw(Error);
|
|
47
|
+
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
it('distanceTo / bearingTo', () => {
|
|
52
|
+
let newEdge = new GraphEdge(node1, node2);
|
|
53
|
+
expect(newEdge.length).equals(node1.distanceTo(node2));
|
|
54
|
+
expect(newEdge.bearing).equals(node1.bearingTo(node2));
|
|
55
|
+
|
|
56
|
+
newEdge = new GraphEdge(node1, node2);
|
|
57
|
+
expect(newEdge.bearing).equals(node1.bearingTo(node2));
|
|
58
|
+
expect(newEdge.length).equals(node1.distanceTo(node2));
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('equalsTo', () => {
|
|
62
|
+
|
|
63
|
+
const testedEdge = new GraphEdge(node1, node2);
|
|
64
|
+
|
|
65
|
+
expect(edge.equalsTo({})).false;
|
|
66
|
+
|
|
67
|
+
expect(edge.equalsTo(testedEdge)).true;
|
|
68
|
+
expect(fullEdge.equalsTo(testedEdge)).false;
|
|
69
|
+
|
|
70
|
+
testedEdge.level = new Level(1);
|
|
71
|
+
expect(edge.equalsTo(testedEdge)).false;
|
|
72
|
+
expect(fullEdge.equalsTo(testedEdge)).false;
|
|
73
|
+
|
|
74
|
+
testedEdge.isOneway = true;
|
|
75
|
+
expect(edge.equalsTo(testedEdge)).false;
|
|
76
|
+
expect(fullEdge.equalsTo(testedEdge)).false;
|
|
77
|
+
|
|
78
|
+
testedEdge.builtFrom = 'w1';
|
|
79
|
+
expect(edge.equalsTo(testedEdge)).false;
|
|
80
|
+
expect(fullEdge.equalsTo(testedEdge)).true;
|
|
81
|
+
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('clone', () => {
|
|
85
|
+
let edgeBis = edge.clone();
|
|
86
|
+
expect(edgeBis.equalsTo(edge)).true;
|
|
87
|
+
|
|
88
|
+
edgeBis = fullEdge.clone();
|
|
89
|
+
expect(edgeBis.equalsTo(fullEdge)).true;
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -3,32 +3,30 @@ import Logger from '@wemap/logger';
|
|
|
3
3
|
import Coordinates from '../coordinates/Coordinates.js';
|
|
4
4
|
import Level from '../coordinates/Level.js';
|
|
5
5
|
|
|
6
|
-
import Edge from './
|
|
6
|
+
import Edge from './GraphEdge.js';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* @template T
|
|
10
|
+
*/
|
|
11
|
+
class GraphNode {
|
|
9
12
|
|
|
10
13
|
/** @type {Coordinates} */
|
|
11
14
|
_coords;
|
|
12
15
|
|
|
13
|
-
/** @type {
|
|
14
|
-
name = null;
|
|
15
|
-
|
|
16
|
-
/** @type {boolean} */
|
|
17
|
-
subwayEntrance = false;
|
|
18
|
-
|
|
19
|
-
/** @type {string} */
|
|
20
|
-
subwayEntranceRef = null;
|
|
21
|
-
|
|
22
|
-
/** @type {Edge[]} */
|
|
16
|
+
/** @type {Edge<T>[]} */
|
|
23
17
|
edges = [];
|
|
24
18
|
|
|
19
|
+
/** @type {?T} */
|
|
20
|
+
builtFrom = null;
|
|
21
|
+
|
|
25
22
|
/**
|
|
26
23
|
* @param {Coordinates} coords
|
|
24
|
+
* @param {T} builtFrom
|
|
27
25
|
*/
|
|
28
|
-
constructor(coords,
|
|
26
|
+
constructor(coords, builtFrom = null) {
|
|
29
27
|
this.coords = coords;
|
|
28
|
+
this.builtFrom = builtFrom;
|
|
30
29
|
this.edges = [];
|
|
31
|
-
this.name = name || null;
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
/** @type {!Coordinates} */
|
|
@@ -45,7 +43,7 @@ class Node {
|
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
/**
|
|
48
|
-
* @param {
|
|
46
|
+
* @param {GraphNode} other
|
|
49
47
|
* @returns {number}
|
|
50
48
|
*/
|
|
51
49
|
distanceTo(other) {
|
|
@@ -53,7 +51,7 @@ class Node {
|
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
/**
|
|
56
|
-
* @param {
|
|
54
|
+
* @param {GraphNode} other
|
|
57
55
|
* @returns {number}
|
|
58
56
|
*/
|
|
59
57
|
bearingTo(other) {
|
|
@@ -61,40 +59,38 @@ class Node {
|
|
|
61
59
|
}
|
|
62
60
|
|
|
63
61
|
/**
|
|
64
|
-
* @param {
|
|
62
|
+
* @param {GraphNode} other
|
|
65
63
|
* @returns {boolean}
|
|
66
64
|
*/
|
|
67
65
|
equalsTo(other) {
|
|
68
66
|
return this.coords.equalsTo(other.coords)
|
|
69
|
-
&& this.
|
|
67
|
+
&& this.builtFrom === other.builtFrom;
|
|
70
68
|
}
|
|
71
69
|
|
|
72
70
|
/**
|
|
73
|
-
* @returns {
|
|
71
|
+
* @returns {GraphNode}
|
|
74
72
|
*/
|
|
75
73
|
clone() {
|
|
76
|
-
const node = new
|
|
77
|
-
node.
|
|
74
|
+
const node = new GraphNode(this.coords);
|
|
75
|
+
node.edges = this.edges.slice(0);
|
|
76
|
+
node.builtFrom = this.builtFrom;
|
|
78
77
|
return node;
|
|
79
78
|
}
|
|
80
79
|
|
|
81
80
|
/**
|
|
81
|
+
* Does not include "edges" and "builtFrom" properties
|
|
82
82
|
* @returns {object}
|
|
83
83
|
*/
|
|
84
84
|
toJson() {
|
|
85
|
-
return
|
|
86
|
-
{ coords: this.coords.toCompressedJson() },
|
|
87
|
-
this.extractProperties()
|
|
88
|
-
);
|
|
85
|
+
return this.coords.toCompressedJson();
|
|
89
86
|
}
|
|
90
87
|
|
|
91
88
|
/**
|
|
92
|
-
* @
|
|
89
|
+
* @template T
|
|
90
|
+
* @returns {GraphNode<T>}
|
|
93
91
|
*/
|
|
94
92
|
static fromJson(json) {
|
|
95
|
-
|
|
96
|
-
node.applyProperties(json);
|
|
97
|
-
return node;
|
|
93
|
+
return new GraphNode(Coordinates.fromCompressedJson(json));
|
|
98
94
|
}
|
|
99
95
|
|
|
100
96
|
generateLevelFromEdges() {
|
|
@@ -137,8 +133,8 @@ class Node {
|
|
|
137
133
|
/**
|
|
138
134
|
* This method looks for single level nodes recursively from a multi-level node
|
|
139
135
|
* The result of this method is an union of all single level nodes found.
|
|
140
|
-
* @param {
|
|
141
|
-
* @param {
|
|
136
|
+
* @param {GraphNode} node node to explore
|
|
137
|
+
* @param {GraphNode[]} visitedNodes list of visited nodes
|
|
142
138
|
*/
|
|
143
139
|
const lookForLevel = (node, visitedNodes) => {
|
|
144
140
|
|
|
@@ -201,7 +197,7 @@ class Node {
|
|
|
201
197
|
}
|
|
202
198
|
|
|
203
199
|
/**
|
|
204
|
-
* @param {
|
|
200
|
+
* @param {GraphNode[]} nodes
|
|
205
201
|
*/
|
|
206
202
|
static generateNodesLevels(nodes) {
|
|
207
203
|
const success = nodes.reduce((acc, node) => acc && node.generateLevelFromEdges(), true);
|
|
@@ -217,40 +213,6 @@ class Node {
|
|
|
217
213
|
&& node.inferNodeLevelByRecursion()
|
|
218
214
|
, true);
|
|
219
215
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* @returns {object}
|
|
224
|
-
*/
|
|
225
|
-
extractProperties() {
|
|
226
|
-
const output = {};
|
|
227
|
-
if (this.name !== null) {
|
|
228
|
-
output.name = this.name;
|
|
229
|
-
}
|
|
230
|
-
if (this.subwayEntrance !== null) {
|
|
231
|
-
output.subwayEntrance = this.subwayEntrance;
|
|
232
|
-
}
|
|
233
|
-
if (this.subwayEntranceRef !== null) {
|
|
234
|
-
output.subwayEntranceRef = this.subwayEntranceRef;
|
|
235
|
-
}
|
|
236
|
-
return output;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* @param {object} properties
|
|
241
|
-
*/
|
|
242
|
-
applyProperties(properties) {
|
|
243
|
-
if (properties.name) {
|
|
244
|
-
this.name = properties.name;
|
|
245
|
-
}
|
|
246
|
-
if (properties.subwayEntrance) {
|
|
247
|
-
this.subwayEntrance = properties.subwayEntrance;
|
|
248
|
-
}
|
|
249
|
-
if (properties.subwayEntranceRef) {
|
|
250
|
-
this.subwayEntranceRef = properties.subwayEntranceRef;
|
|
251
|
-
}
|
|
252
|
-
return this;
|
|
253
|
-
}
|
|
254
216
|
}
|
|
255
217
|
|
|
256
|
-
export default
|
|
218
|
+
export default GraphNode;
|