Rename `points` array to `nodes` in segments
This commit is contained in:
		
							parent
							
								
									51ec5f5d40
								
							
						
					
					
						commit
						314625f4ef
					
				|  | @ -206,14 +206,14 @@ ${name} is one-way and cannot be used in reverse.`); | ||||||
|                 const end = elements[lineStops[stopIdx + 1]].tags.ref; |                 const end = elements[lineStops[stopIdx + 1]].tags.ref; | ||||||
| 
 | 
 | ||||||
|                 const id = `${begin}-${end}`; |                 const id = `${begin}-${end}`; | ||||||
|                 const nodes = path.slice( |                 const nodesIds = path.slice( | ||||||
|                     path.indexOf(lineStops[stopIdx]), |                     path.indexOf(lineStops[stopIdx]), | ||||||
|                     path.indexOf(lineStops[stopIdx + 1]) + 1, |                     path.indexOf(lineStops[stopIdx + 1]) + 1, | ||||||
|                 ); |                 ); | ||||||
| 
 | 
 | ||||||
|                 if (id in segments) |                 if (id in segments) | ||||||
|                 { |                 { | ||||||
|                     if (!util.arraysEqual(nodes, segments[id].nodes)) |                     if (!util.arraysEqual(nodesIds, segments[id].nodesIds)) | ||||||
|                     { |                     { | ||||||
|                         throw new Error(`Segment ${id} is defined as a
 |                         throw new Error(`Segment ${id} is defined as a
 | ||||||
| different sequence of nodes in two or more lines.`);
 | different sequence of nodes in two or more lines.`);
 | ||||||
|  | @ -223,31 +223,30 @@ different sequence of nodes in two or more lines.`); | ||||||
|                 } |                 } | ||||||
|                 else |                 else | ||||||
|                 { |                 { | ||||||
|                     const points = nodes.map(id => ({ |                     const nodes = nodesIds.map(id => ({ | ||||||
|                         lat: elements[id].lat, |                         lat: elements[id].lat, | ||||||
|                         lon: elements[id].lon |                         lon: elements[id].lon | ||||||
|                     })); |                     })); | ||||||
| 
 | 
 | ||||||
|                     if (points.length) |                     if (nodes.length) | ||||||
|                     { |                     { | ||||||
|                         // Augment each point with the distance to the start
 |                         // Augment each node with the distance to the start
 | ||||||
|                         points[0].distance = 0; |                         nodes[0].distance = 0; | ||||||
| 
 | 
 | ||||||
|                         for (let i = 1; i < points.length; ++i) |                         for (let i = 1; i < nodes.length; ++i) | ||||||
|                         { |                         { | ||||||
|                             points[i].distance = geolib.getPreciseDistance( |                             nodes[i].distance = geolib.getPreciseDistance( | ||||||
|                                 points[i - 1], |                                 nodes[i - 1], | ||||||
|                                 points[i], |                                 nodes[i], | ||||||
|                             ) + points[i - 1].distance; |                             ) + nodes[i - 1].distance; | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
| 
 | 
 | ||||||
|                     segments[id] = { |                     segments[id] = { | ||||||
|                         // Keep track of the original sequence of nodes to
 |                         // Keep track of the original sequence of nodes to
 | ||||||
|                         // compare with duplicates
 |                         // compare with duplicates
 | ||||||
|  |                         nodesIds, | ||||||
|                         nodes, |                         nodes, | ||||||
| 
 |  | ||||||
|                         points, |  | ||||||
|                         routes: [[lineRef, routeRef]], |                         routes: [[lineRef, routeRef]], | ||||||
|                     }; |                     }; | ||||||
|                 } |                 } | ||||||
|  | @ -269,7 +268,7 @@ different sequence of nodes in two or more lines.`); | ||||||
|     // Remove OSM nodes from segments that were only used for checking validity
 |     // Remove OSM nodes from segments that were only used for checking validity
 | ||||||
|     for (let segment of Object.values(segments)) |     for (let segment of Object.values(segments)) | ||||||
|     { |     { | ||||||
|         delete segment.nodes; |         delete segment.nodesIds; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return {stops, lines, segments}; |     return {stops, lines, segments}; | ||||||
|  |  | ||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							|  | @ -147,7 +147,7 @@ class Course | ||||||
|             const delta = this.speed * time; |             const delta = this.speed * time; | ||||||
| 
 | 
 | ||||||
|             const segment = this.currentSegment; |             const segment = this.currentSegment; | ||||||
|             const length = segment.points[segment.points.length - 1].distance; |             const length = segment.nodes[segment.nodes.length - 1].distance; | ||||||
|             this.traveledDistance += delta; |             this.traveledDistance += delta; | ||||||
| 
 | 
 | ||||||
|             if (this.traveledDistance >= length) |             if (this.traveledDistance >= length) | ||||||
|  | @ -159,7 +159,7 @@ class Course | ||||||
|             // Recompute updated position
 |             // Recompute updated position
 | ||||||
|             const departureStop = network.stops[this.departureStop]; |             const departureStop = network.stops[this.departureStop]; | ||||||
|             const arrivalStop = network.stops[this.arrivalStop]; |             const arrivalStop = network.stops[this.arrivalStop]; | ||||||
|             const nextNodeIndex = segment.points.findIndex( |             const nextNodeIndex = segment.nodes.findIndex( | ||||||
|                 ({distance}) => distance >= this.traveledDistance); |                 ({distance}) => distance >= this.traveledDistance); | ||||||
| 
 | 
 | ||||||
|             if (nextNodeIndex === 0) |             if (nextNodeIndex === 0) | ||||||
|  | @ -171,8 +171,8 @@ class Course | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|                 const previousNode = segment.points[nextNodeIndex - 1]; |                 const previousNode = segment.nodes[nextNodeIndex - 1]; | ||||||
|                 const nextNode = segment.points[nextNodeIndex]; |                 const nextNode = segment.nodes[nextNodeIndex]; | ||||||
| 
 | 
 | ||||||
|                 const previousPoint = turf.toMercator([ |                 const previousPoint = turf.toMercator([ | ||||||
|                     previousNode.lon, |                     previousNode.lon, | ||||||
|  | @ -271,7 +271,7 @@ with initial speed ${this.computeTheoreticalSpeed() * 3600} km/h`); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         const segment = this.currentSegment; |         const segment = this.currentSegment; | ||||||
|         const length = segment.points[segment.points.length - 1].distance; |         const length = segment.nodes[segment.nodes.length - 1].distance; | ||||||
| 
 | 
 | ||||||
|         const remainingTime = this.arrivalTime - Date.now(); |         const remainingTime = this.arrivalTime - Date.now(); | ||||||
|         const remainingDistance = length - this.traveledDistance; |         const remainingDistance = length - this.traveledDistance; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue