< Summary

Class:Itinero.Network.Enumerators.Edges.EdgeEnumerator`1
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Network/Enumerators/Edges/EdgeEnumerator.cs
Covered lines:69
Uncovered lines:18
Coverable lines:87
Total lines:245
Line coverage:79.3% (69 of 87)
Covered branches:16
Total branches:20
Branch coverage:80% (16 of 20)
Tag:251_23667616543

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
GetVertex(...)62.5%871.42%
MoveTo(...)100%4100%
MoveTo(...)75%484.61%
Reset()100%10%
MoveNext()100%1100%
get_Network()100%1100%
get_Forward()100%1100%
get_TailLocation()100%2100%
get_Tail()100%1100%
get_HeadLocation()100%2100%
get_Head()100%1100%
get_EdgeId()100%1100%
get_Shape()100%1100%
get_Attributes()100%1100%
get_EdgeTypeId()100%1100%
get_Length()100%1100%
get_GlobalEdgeId()100%10%
get_HeadOrder()100%1100%
get_TailOrder()100%1100%
GetTurnCostToTail(...)100%1100%
GetTurnCostFromTail(...)100%1100%
GetTurnCostToHead(...)100%10%
GetTurnCostFromHead(...)100%10%

File(s)

/home/runner/work/routing2/routing2/src/Itinero/Network/Enumerators/Edges/EdgeEnumerator.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using Itinero.Network.Tiles;
 4using Itinero.Network.Tiles.Standalone.Global;
 5
 6namespace Itinero.Network.Enumerators.Edges;
 7
 8public abstract class EdgeEnumerator<T> :
 9    IEdgeEnumerator<T> where T : IEdgeEnumerable
 10{
 11    private readonly NetworkTileEnumerator _tileEnumerator;
 12
 93347513    internal EdgeEnumerator(T graph)
 93347514    {
 93347515        this.Network = graph;
 16
 93347517        _tileEnumerator = new NetworkTileEnumerator();
 93347518    }
 19
 20    private (double longitude, double latitude, float? e) GetVertex(VertexId vertex)
 261172921    {
 261172922        var tile = _tileEnumerator.Tile;
 261172923        if (tile == null || tile.TileId != vertex.TileId)
 3246224        {
 3246225            tile = this.Network.GetTileForRead(vertex.TileId);
 3246226        }
 27
 261172928        if (tile == null)
 029        {
 030            throw new ArgumentOutOfRangeException(nameof(vertex), $"Vertex {vertex} not found!");
 31        }
 32
 261172933        if (!tile.TryGetVertex(vertex, out var longitude, out var latitude, out var e))
 034        {
 035            throw new ArgumentOutOfRangeException(nameof(vertex), $"Vertex {vertex} not found!");
 36        }
 37
 261172938        return (longitude, latitude, e);
 261172939    }
 40
 41    /// <summary>
 42    /// Moves the enumerator to the first edge of the given vertex.
 43    /// </summary>
 44    /// <param name="vertex">The vertex.</param>
 45    /// <returns>True if the vertex exists.</returns>
 46    public bool MoveTo(VertexId vertex)
 114074847    {
 114074848        _tailLocation = null;
 114074849        _headLocation = null;
 50
 114074851        if (_tileEnumerator.TileId == vertex.TileId)
 112455552        {
 112455553            return _tileEnumerator.MoveTo(vertex);
 54        }
 55
 56        // move to the tile.
 1619357        var tile = this.Network.GetTileForRead(vertex.TileId);
 1619358        if (tile == null)
 159        {
 160            return false;
 61        }
 62
 1619263        _tileEnumerator.MoveTo(tile);
 64
 1619265        return _tileEnumerator.MoveTo(vertex);
 114074866    }
 67
 68    /// <summary>
 69    /// Moves the enumerator to the given edge.
 70    /// </summary>
 71    /// <param name="edgeId">The edge id.</param>
 72    /// <param name="forward">The forward flag, when false the enumerator is in a state as it was enumerated to the edge
 73    public bool MoveTo(EdgeId edgeId, bool forward = true)
 326365574    {
 326365575        _tailLocation = null;
 326365576        _headLocation = null;
 77
 326365578        if (_tileEnumerator.TileId == edgeId.TileId)
 231392079        {
 231392080            return _tileEnumerator.MoveTo(edgeId, forward);
 81        }
 82
 83        // move to the tile.
 94973584        var tile = this.Network.GetTileForRead(edgeId.TileId);
 94973585        if (tile == null)
 086        {
 087            return false;
 88        }
 89
 94973590        _tileEnumerator.MoveTo(tile);
 91
 94973592        return _tileEnumerator.MoveTo(edgeId, forward);
 326365593    }
 94
 95    /// <summary>
 96    /// Resets this enumerator.
 97    /// </summary>
 98    public void Reset()
 099    {
 0100        _tailLocation = null;
 0101        _headLocation = null;
 102
 0103        _tileEnumerator.Reset();
 0104    }
 105
 106    /// <summary>
 107    /// Moves this enumerator to the next edge.
 108    /// </summary>
 109    /// <returns>True if there is data available.</returns>
 110    public bool MoveNext()
 4408217111    {
 4408217112        _tailLocation = null;
 4408217113        _headLocation = null;
 114
 4408217115        return _tileEnumerator.MoveNext();
 4408217116    }
 117
 118    /// <inheritdoc/>
 998390119    public T Network { get; }
 120
 121    /// <summary>
 122    /// Returns true if the edge is from -> to, false otherwise.
 123    /// </summary>
 2084821124    public bool Forward => _tileEnumerator.Forward;
 125
 126    private (double longitude, double latitude, float? e)? _tailLocation;
 127
 128    public (double longitude, double latitude, float? e) TailLocation
 129    {
 130        get
 1318057131        {
 1318057132            _tailLocation ??= this.GetVertex(this.Tail);
 133
 1318057134            return _tailLocation.Value;
 1318057135        }
 136    }
 137
 138    /// <summary>
 139    /// Gets the source vertex.
 140    /// </summary>
 2400853141    public VertexId Tail => _tileEnumerator.Tail;
 142
 143    private (double longitude, double latitude, float? e)? _headLocation;
 144
 145    public (double longitude, double latitude, float? e) HeadLocation
 146    {
 147        get
 1293682148        {
 1293682149            _headLocation ??= this.GetVertex(this.Head);
 150
 1293682151            return _headLocation.Value;
 1293682152        }
 153    }
 154
 155    /// <summary>
 156    /// Gets the target vertex.
 157    /// </summary>
 2732355158    public VertexId Head => _tileEnumerator.Head;
 159
 160    /// <summary>
 161    /// Gets the edge id.
 162    /// </summary>
 4153727163    public EdgeId EdgeId => _tileEnumerator.EdgeId;
 164
 165    /// <summary>
 166    /// Gets the shape.
 167    /// </summary>
 168    /// <returns>The shape.</returns>
 1295362169    public IEnumerable<(double longitude, double latitude, float? e)> Shape => _tileEnumerator.Shape;
 170
 171    /// <summary>
 172    /// Gets the attributes.
 173    /// </summary>
 174    /// <returns>The attributes.</returns>
 3399175    public IEnumerable<(string key, string value)> Attributes => _tileEnumerator.Attributes;
 176
 177    /// <summary>
 178    /// Gets the edge profile id.
 179    /// </summary>
 1071011180    public uint? EdgeTypeId => _tileEnumerator.EdgeTypeId;
 181
 182    /// <summary>
 183    /// Gets the length in centimeters, if any.
 184    /// </summary>
 2558569185    public uint? Length => _tileEnumerator.Length;
 186
 187    /// <summary>
 188    /// Gets the global edge id, if any.
 189    /// </summary>
 0190    public GlobalEdgeId? GlobalEdgeId => _tileEnumerator.GlobalEdgeId;
 191
 192    /// <summary>
 193    /// Gets the head index.
 194    /// </summary>
 410336195    public byte? HeadOrder => _tileEnumerator.HeadOrder;
 196
 197    /// <summary>
 198    /// Gets the tail index.
 199    /// </summary>
 2200    public byte? TailOrder => _tileEnumerator.TailOrder;
 201
 202    /// <summary>
 203    /// Gets the turn cost at the tail turn (source -> [tail -> head]).
 204    /// </summary>
 205    /// <param name="sourceOrder">The order of the source edge.</param>
 206    /// <returns>The turn costs if any.</returns>
 207    public IEnumerable<(uint turnCostType, IEnumerable<(string key, string value)> attributes, uint cost, IEnumerable<Ed
 208        byte sourceOrder)
 2033209    {
 2033210        return _tileEnumerator.GetTurnCostToTail(sourceOrder);
 2033211    }
 212
 213    /// <summary>
 214    /// Gets the turn cost at the tail turn ([head -> tail] -> target).
 215    /// </summary>
 216    /// <param name="targetOrder">The order of the target edge.</param>
 217    /// <returns>The turn costs if any.</returns>
 218    public IEnumerable<(uint turnCostType, IEnumerable<(string key, string value)> attributes, uint cost, IEnumerable<Ed
 219        byte targetOrder)
 8220    {
 8221        return _tileEnumerator.GetTurnCostFromTail(targetOrder);
 8222    }
 223
 224    /// <summary>
 225    /// Gets the turn cost at the tail turn (source -> [head -> tail]).
 226    /// </summary>
 227    /// <param name="sourceOrder">The order of the source edge.</param>
 228    /// <returns>The turn costs if any.</returns>
 229    public IEnumerable<(uint turnCostType, IEnumerable<(string key, string value)> attributes, uint cost, IEnumerable<Ed
 230        byte sourceOrder)
 0231    {
 0232        return _tileEnumerator.GetTurnCostToHead(sourceOrder);
 0233    }
 234
 235    /// <summary>
 236    /// Gets the turn cost at the tail turn ([tail -> head] -> target).
 237    /// </summary>
 238    /// <param name="targetOrder">The order of the target edge.</param>
 239    /// <returns>The turn costs if any.</returns>
 240    public IEnumerable<(uint turnCostType, IEnumerable<(string key, string value)> attributes, uint cost, IEnumerable<Ed
 241        byte targetOrder)
 0242    {
 0243        return _tileEnumerator.GetTurnCostFromHead(targetOrder);
 0244    }
 245}