Rename `points` array to `nodes` in segments

This commit is contained in:
Mattéo Delabre 2020-07-25 01:02:07 +02:00
parent 51ec5f5d40
commit 314625f4ef
Signed by: matteo
GPG Key ID: AE3FBD02DC583ABB
3 changed files with 214 additions and 215 deletions

View File

@ -206,14 +206,14 @@ ${name} is one-way and cannot be used in reverse.`);
const end = elements[lineStops[stopIdx + 1]].tags.ref;
const id = `${begin}-${end}`;
const nodes = path.slice(
const nodesIds = path.slice(
path.indexOf(lineStops[stopIdx]),
path.indexOf(lineStops[stopIdx + 1]) + 1,
);
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
different sequence of nodes in two or more lines.`);
@ -223,31 +223,30 @@ different sequence of nodes in two or more lines.`);
}
else
{
const points = nodes.map(id => ({
const nodes = nodesIds.map(id => ({
lat: elements[id].lat,
lon: elements[id].lon
}));
if (points.length)
if (nodes.length)
{
// Augment each point with the distance to the start
points[0].distance = 0;
// Augment each node with the distance to the start
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(
points[i - 1],
points[i],
) + points[i - 1].distance;
nodes[i].distance = geolib.getPreciseDistance(
nodes[i - 1],
nodes[i],
) + nodes[i - 1].distance;
}
}
segments[id] = {
// Keep track of the original sequence of nodes to
// compare with duplicates
nodesIds,
nodes,
points,
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
for (let segment of Object.values(segments))
{
delete segment.nodes;
delete segment.nodesIds;
}
return {stops, lines, segments};

File diff suppressed because it is too large Load Diff

View File

@ -147,7 +147,7 @@ class Course
const delta = this.speed * time;
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;
if (this.traveledDistance >= length)
@ -159,7 +159,7 @@ class Course
// Recompute updated position
const departureStop = network.stops[this.departureStop];
const arrivalStop = network.stops[this.arrivalStop];
const nextNodeIndex = segment.points.findIndex(
const nextNodeIndex = segment.nodes.findIndex(
({distance}) => distance >= this.traveledDistance);
if (nextNodeIndex === 0)
@ -171,8 +171,8 @@ class Course
}
else
{
const previousNode = segment.points[nextNodeIndex - 1];
const nextNode = segment.points[nextNodeIndex];
const previousNode = segment.nodes[nextNodeIndex - 1];
const nextNode = segment.nodes[nextNodeIndex];
const previousPoint = turf.toMercator([
previousNode.lon,
@ -271,7 +271,7 @@ with initial speed ${this.computeTheoreticalSpeed() * 3600} km/h`);
}
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 remainingDistance = length - this.traveledDistance;