private void UpdateCurrentPositions() { if (this.currentPositions == null) { System.Diagnostics.Debug.Assert(NextManeuver != null); var nextPosition = NextManeuver.StartingPoint.Position; this.currentPositionIndex = 0; this.currentPositions = this.remainingPositions.TakeWhile(position => !position.Equals(nextPosition)).ToList(); this.remainingPositions = this.remainingPositions.SkipWhile(position => !position.Equals(nextPosition)).ToList(); this.currentSegmentPositionIndex = 0; this.currentSegmentPositions = this.currentPositions.Count >= 2 ? this.currentPositions.GetRange(this.currentPositionIndex, 2) : this.currentPositions; } else if (this.currentSegmentPositionIndex + 1 < this.currentSegmentPositions.Count) { this.currentSegmentPositionIndex++; return; } else if (this.currentPositionIndex + 1 < this.currentPositions.Count) { this.currentPositionIndex++; if (this.currentPositionIndex + 1 == this.currentPositions.Count) { var nextPosition = (this.lastLegManeuverIndex + 1 < this.lastLeg.Maneuvers.Count) ? NextManeuver.StartingPoint.Position : this.route.Path.Positions.Last(); this.currentSegmentPositionIndex = 0; this.currentSegmentPositions = new List <BasicGeoposition>() { this.currentPositions.Last(), nextPosition }; } else { this.currentSegmentPositionIndex = 0; this.currentSegmentPositions = this.currentPositions.GetRange(this.currentPositionIndex, 2); } } else if (this.lastLegManeuverIndex + 1 < this.lastLeg.Maneuvers.Count) { //System.Diagnostics.Debug.Assert(this.remainingPositions.Count > 0); this.lastLegManeuverIndex++; var nextPosition = (this.lastLegManeuverIndex + 1 < this.lastLeg.Maneuvers.Count) ? NextManeuver.StartingPoint.Position : this.route.Path.Positions.Last(); this.currentPositionIndex = 0; this.currentPositions = this.remainingPositions.TakeWhile(position => !position.Equals(nextPosition)).ToList(); this.remainingPositions = this.remainingPositions.SkipWhile(position => !position.Equals(nextPosition)).ToList(); this.currentSegmentPositionIndex = 0; this.currentSegmentPositions = this.currentPositions.Count >= 2 ? this.currentPositions.GetRange(this.currentPositionIndex, 2) : this.currentPositions; } else if (this.lastLegIndex + 1 < this.route.Legs.Count) { this.lastLegIndex++; this.lastLegManeuverIndex = 0; this.currentPositionIndex = 0; this.currentSegmentPositionIndex = 0; } if (this.currentSegmentPositions.Count >= 2) { var t = Spatial.DistanceInMeters(currentSegmentPositions.First(), currentSegmentPositions.Last()) / Speed; var n = (int)(t * UpdatesPerSecond / currentSegmentPositions.Count) - 2; if (n > 0) { this.currentSegmentPositions = Spatial.CalculateGeodesic(currentSegmentPositions, n); } } }