< 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:66
Uncovered lines:20
Coverable lines:86
Total lines:239
Line coverage:76.7% (66 of 86)
Covered branches:16
Total branches:20
Branch coverage:80% (16 of 20)
Tag:224_14471318300

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_HeadOrder()100%1100%
get_TailOrder()100%1100%
GetTurnCostToTail(...)100%1100%
GetTurnCostFromTail(...)100%10%
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;
 4
 5namespace Itinero.Network.Enumerators.Edges;
 6
 7public abstract class EdgeEnumerator<T> :
 8    IEdgeEnumerator<T> where T : IEdgeEnumerable
 9{
 10    private readonly NetworkTileEnumerator _tileEnumerator;
 11
 38812    internal EdgeEnumerator(T graph)
 38813    {
 38814        this.Network = graph;
 15
 38816        _tileEnumerator = new NetworkTileEnumerator();
 38817    }
 18
 19    private (double longitude, double latitude, float? e) GetVertex(VertexId vertex)
 52220    {
 52221        var tile = _tileEnumerator.Tile;
 52222        if (tile == null || tile.TileId != vertex.TileId)
 123        {
 124            tile = this.Network.GetTileForRead(vertex.TileId);
 125        }
 26
 52227        if (tile == null)
 028        {
 029            throw new ArgumentOutOfRangeException(nameof(vertex), $"Vertex {vertex} not found!");
 30        }
 31
 52232        if (!tile.TryGetVertex(vertex, out var longitude, out var latitude, out var e))
 033        {
 034            throw new ArgumentOutOfRangeException(nameof(vertex), $"Vertex {vertex} not found!");
 35        }
 36
 52237        return (longitude, latitude, e);
 52238    }
 39
 40    /// <summary>
 41    /// Moves the enumerator to the first edge of the given vertex.
 42    /// </summary>
 43    /// <param name="vertex">The vertex.</param>
 44    /// <returns>True if the vertex exists.</returns>
 45    public bool MoveTo(VertexId vertex)
 32146    {
 32147        _tailLocation = null;
 32148        _headLocation = null;
 49
 32150        if (_tileEnumerator.TileId == vertex.TileId)
 21751        {
 21752            return _tileEnumerator.MoveTo(vertex);
 53        }
 54
 55        // move to the tile.
 10456        var tile = this.Network.GetTileForRead(vertex.TileId);
 10457        if (tile == null)
 158        {
 159            return false;
 60        }
 61
 10362        _tileEnumerator.MoveTo(tile);
 63
 10364        return _tileEnumerator.MoveTo(vertex);
 32165    }
 66
 67    /// <summary>
 68    /// Moves the enumerator to the given edge.
 69    /// </summary>
 70    /// <param name="edgeId">The edge id.</param>
 71    /// <param name="forward">The forward flag, when false the enumerator is in a state as it was enumerated to the edge
 72    public bool MoveTo(EdgeId edgeId, bool forward = true)
 59473    {
 59474        _tailLocation = null;
 59475        _headLocation = null;
 76
 59477        if (_tileEnumerator.TileId == edgeId.TileId)
 33478        {
 33479            return _tileEnumerator.MoveTo(edgeId, forward);
 80        }
 81
 82        // move to the tile.
 26083        var tile = this.Network.GetTileForRead(edgeId.TileId);
 26084        if (tile == null)
 085        {
 086            return false;
 87        }
 88
 26089        _tileEnumerator.MoveTo(tile);
 90
 26091        return _tileEnumerator.MoveTo(edgeId, forward);
 59492    }
 93
 94    /// <summary>
 95    /// Resets this enumerator.
 96    /// </summary>
 97    public void Reset()
 098    {
 099        _tailLocation = null;
 0100        _headLocation = null;
 101
 0102        _tileEnumerator.Reset();
 0103    }
 104
 105    /// <summary>
 106    /// Moves this enumerator to the next edge.
 107    /// </summary>
 108    /// <returns>True if there is data available.</returns>
 109    public bool MoveNext()
 643110    {
 643111        _tailLocation = null;
 643112        _headLocation = null;
 113
 643114        return _tileEnumerator.MoveNext();
 643115    }
 116
 117    /// <inheritdoc/>
 365118    public T Network { get; }
 119
 120    /// <summary>
 121    /// Returns true if the edge is from -> to, false otherwise.
 122    /// </summary>
 474123    public bool Forward => _tileEnumerator.Forward;
 124
 125    private (double longitude, double latitude, float? e)? _tailLocation;
 126
 127    public (double longitude, double latitude, float? e) TailLocation
 128    {
 129        get
 342130        {
 342131            _tailLocation ??= this.GetVertex(this.Tail);
 132
 342133            return _tailLocation.Value;
 342134        }
 135    }
 136
 137    /// <summary>
 138    /// Gets the source vertex.
 139    /// </summary>
 507140    public VertexId Tail => _tileEnumerator.Tail;
 141
 142    private (double longitude, double latitude, float? e)? _headLocation;
 143
 144    public (double longitude, double latitude, float? e) HeadLocation
 145    {
 146        get
 342147        {
 342148            _headLocation ??= this.GetVertex(this.Head);
 149
 342150            return _headLocation.Value;
 342151        }
 152    }
 153
 154    /// <summary>
 155    /// Gets the target vertex.
 156    /// </summary>
 526157    public VertexId Head => _tileEnumerator.Head;
 158
 159    /// <summary>
 160    /// Gets the edge id.
 161    /// </summary>
 684162    public EdgeId EdgeId => _tileEnumerator.EdgeId;
 163
 164    /// <summary>
 165    /// Gets the shape.
 166    /// </summary>
 167    /// <returns>The shape.</returns>
 349168    public IEnumerable<(double longitude, double latitude, float? e)> Shape => _tileEnumerator.Shape;
 169
 170    /// <summary>
 171    /// Gets the attributes.
 172    /// </summary>
 173    /// <returns>The attributes.</returns>
 257174    public IEnumerable<(string key, string value)> Attributes => _tileEnumerator.Attributes;
 175
 176    /// <summary>
 177    /// Gets the edge profile id.
 178    /// </summary>
 35179    public uint? EdgeTypeId => _tileEnumerator.EdgeTypeId;
 180
 181    /// <summary>
 182    /// Gets the length in centimeters, if any.
 183    /// </summary>
 428184    public uint? Length => _tileEnumerator.Length;
 185
 186    /// <summary>
 187    /// Gets the head index.
 188    /// </summary>
 123189    public byte? HeadOrder => _tileEnumerator.HeadOrder;
 190
 191    /// <summary>
 192    /// Gets the tail index.
 193    /// </summary>
 30194    public byte? TailOrder => _tileEnumerator.TailOrder;
 195
 196    /// <summary>
 197    /// Gets the turn cost at the tail turn (source -> [tail -> head]).
 198    /// </summary>
 199    /// <param name="sourceOrder">The order of the source edge.</param>
 200    /// <returns>The turn costs if any.</returns>
 201    public IEnumerable<(uint turnCostType, IEnumerable<(string key, string value)> attributes, uint cost, IEnumerable<Ed
 202        byte sourceOrder)
 13203    {
 13204        return _tileEnumerator.GetTurnCostToTail(sourceOrder);
 13205    }
 206
 207    /// <summary>
 208    /// Gets the turn cost at the tail turn ([head -> tail] -> target).
 209    /// </summary>
 210    /// <param name="targetOrder">The order of the target edge.</param>
 211    /// <returns>The turn costs if any.</returns>
 212    public IEnumerable<(uint turnCostType, IEnumerable<(string key, string value)> attributes, uint cost, IEnumerable<Ed
 213        byte targetOrder)
 0214    {
 0215        return _tileEnumerator.GetTurnCostFromTail(targetOrder);
 0216    }
 217
 218    /// <summary>
 219    /// Gets the turn cost at the tail turn (source -> [head -> tail]).
 220    /// </summary>
 221    /// <param name="sourceOrder">The order of the source edge.</param>
 222    /// <returns>The turn costs if any.</returns>
 223    public IEnumerable<(uint turnCostType, IEnumerable<(string key, string value)> attributes, uint cost, IEnumerable<Ed
 224        byte sourceOrder)
 0225    {
 0226        return _tileEnumerator.GetTurnCostToHead(sourceOrder);
 0227    }
 228
 229    /// <summary>
 230    /// Gets the turn cost at the tail turn ([tail -> head] -> target).
 231    /// </summary>
 232    /// <param name="targetOrder">The order of the target edge.</param>
 233    /// <returns>The turn costs if any.</returns>
 234    public IEnumerable<(uint turnCostType, IEnumerable<(string key, string value)> attributes, uint cost, IEnumerable<Ed
 235        byte targetOrder)
 0236    {
 0237        return _tileEnumerator.GetTurnCostFromHead(targetOrder);
 0238    }
 239}