| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using Itinero.Network.Tiles; |
| | 4 | |
|
| | 5 | | namespace Itinero.Network.Enumerators.Vertices; |
| | 6 | |
|
| | 7 | | internal class TilesVertexEnumerator : IEnumerator<VertexId> |
| | 8 | | { |
| | 9 | | private readonly RoutingNetwork _routingNetwork; |
| | 10 | | private readonly IEnumerator<(uint x, uint y)> _tiles; |
| | 11 | |
|
| 30 | 12 | | public TilesVertexEnumerator(RoutingNetwork routingNetwork, IEnumerable<(uint x, uint y)> tiles) |
| 30 | 13 | | { |
| 30 | 14 | | _routingNetwork = routingNetwork; |
| 30 | 15 | | _tiles = tiles.GetEnumerator(); |
| 30 | 16 | | } |
| | 17 | |
|
| | 18 | | public void Reset() |
| 0 | 19 | | { |
| 0 | 20 | | _tiles.Reset(); |
| 0 | 21 | | _currentTile = uint.MaxValue; |
| 0 | 22 | | } |
| | 23 | |
|
| 0 | 24 | | object IEnumerator.Current => this.Current; |
| | 25 | |
|
| 30 | 26 | | private uint _currentTile = uint.MaxValue; |
| 30 | 27 | | private uint _currentVertex = uint.MaxValue; |
| | 28 | | private double _currentLatitude; |
| | 29 | | private double _currentLongitude; |
| | 30 | | private float? _currentElevation; |
| | 31 | |
|
| | 32 | | public bool MoveNext() |
| 80 | 33 | | { |
| 80 | 34 | | if (_currentTile == uint.MaxValue) |
| 30 | 35 | | { |
| 50 | 36 | | while (_tiles.MoveNext()) |
| 50 | 37 | | { |
| 50 | 38 | | _currentTile = TileStatic.ToLocalId(_tiles.Current.x, _tiles.Current.y, _routingNetwork.Zoom); |
| 50 | 39 | | _currentVertex = 0; |
| | 40 | |
|
| 50 | 41 | | if (_routingNetwork.TryGetVertex(new VertexId(_currentTile, _currentVertex), |
| 50 | 42 | | out _currentLongitude, out _currentLatitude, out _currentElevation)) |
| 30 | 43 | | { |
| 30 | 44 | | return true; |
| | 45 | | } |
| 20 | 46 | | } |
| | 47 | |
|
| 0 | 48 | | return false; |
| | 49 | | } |
| | 50 | |
|
| 53 | 51 | | while (true) |
| 53 | 52 | | { |
| 53 | 53 | | _currentVertex++; |
| 53 | 54 | | if (_routingNetwork.TryGetVertex(new VertexId(_currentTile, _currentVertex), |
| 53 | 55 | | out _currentLongitude, out _currentLatitude, out _currentElevation)) |
| 40 | 56 | | { |
| 40 | 57 | | return true; |
| | 58 | | } |
| | 59 | | else |
| 13 | 60 | | { |
| 13 | 61 | | if (!_tiles.MoveNext()) |
| 10 | 62 | | { |
| 10 | 63 | | break; |
| | 64 | | } |
| | 65 | |
|
| 3 | 66 | | _currentTile = TileStatic.ToLocalId(_tiles.Current.x, _tiles.Current.y, _routingNetwork.Zoom); |
| 3 | 67 | | _currentVertex = 0; |
| 3 | 68 | | if (_routingNetwork.TryGetVertex(new VertexId(_currentTile, _currentVertex), |
| 3 | 69 | | out _currentLongitude, out _currentLatitude, out _currentElevation)) |
| 0 | 70 | | { |
| 0 | 71 | | return true; |
| | 72 | | } |
| 3 | 73 | | } |
| 3 | 74 | | } |
| | 75 | |
|
| 10 | 76 | | return false; |
| 80 | 77 | | } |
| | 78 | |
|
| 63 | 79 | | public VertexId Current => new(_currentTile, _currentVertex); |
| | 80 | |
|
| | 81 | | public (double longitude, double latitude, float? e) Location => |
| 70 | 82 | | (_currentLongitude, _currentLatitude, _currentElevation); |
| | 83 | |
|
| | 84 | | public void Dispose() |
| 0 | 85 | | { |
| 0 | 86 | | _tiles.Dispose(); |
| 0 | 87 | | } |
| | 88 | | } |