< 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:267_28791001112

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
 95572013    internal EdgeEnumerator(T graph)
 95572014    {
 95572015        this.Network = graph;
 16
 95572017        _tileEnumerator = new NetworkTileEnumerator();
 95572018    }
 19
 20    private (double longitude, double latitude, float? e) GetVertex(VertexId vertex)
 241616421    {
 241616422        var tile = _tileEnumerator.Tile;
 241616423        if (tile == null || tile.TileId != vertex.TileId)
 3139924        {
 3139925            tile = this.Network.GetTileForRead(vertex.TileId);
 3139926        }
 27
 241616428        if (tile == null)
 029        {
 030            throw new ArgumentOutOfRangeException(nameof(vertex), $"Vertex {vertex} not found!");
 31        }
 32
 241616433        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
 241616438        return (longitude, latitude, e);
 241616439    }
 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)
 106395647    {
 106395648        _tailLocation = null;
 106395649        _headLocation = null;
 50
 106395651        if (_tileEnumerator.TileId == vertex.TileId)
 104409052        {
 104409053            return _tileEnumerator.MoveTo(vertex);
 54        }
 55
 56        // move to the tile.
 1986657        var tile = this.Network.GetTileForRead(vertex.TileId);
 1986658        if (tile == null)
 159        {
 160            return false;
 61        }
 62
 1986563        _tileEnumerator.MoveTo(tile);
 64
 1986565        return _tileEnumerator.MoveTo(vertex);
 106395666    }
 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)
 330824974    {
 330824975        _tailLocation = null;
 330824976        _headLocation = null;
 77
 330824978        if (_tileEnumerator.TileId == edgeId.TileId)
 233988479        {
 233988480            return _tileEnumerator.MoveTo(edgeId, forward);
 81        }
 82
 83        // move to the tile.
 96836584        var tile = this.Network.GetTileForRead(edgeId.TileId);
 96836585        if (tile == null)
 086        {
 087            return false;
 88        }
 89
 96836590        _tileEnumerator.MoveTo(tile);
 91
 96836592        return _tileEnumerator.MoveTo(edgeId, forward);
 330824993    }
 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()
 4123812111    {
 4123812112        _tailLocation = null;
 4123812113        _headLocation = null;
 114
 4123812115        return _tileEnumerator.MoveNext();
 4123812116    }
 117
 118    /// <inheritdoc/>
 1019630119    public T Network { get; }
 120
 121    /// <summary>
 122    /// Returns true if the edge is from -> to, false otherwise.
 123    /// </summary>
 2127577124    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
 1268892131        {
 1268892132            _tailLocation ??= this.GetVertex(this.Tail);
 133
 1268892134            return _tailLocation.Value;
 1268892135        }
 136    }
 137
 138    /// <summary>
 139    /// Gets the source vertex.
 140    /// </summary>
 2307516141    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
 1244492148        {
 1244492149            _headLocation ??= this.GetVertex(this.Head);
 150
 1244492151            return _headLocation.Value;
 1244492152        }
 153    }
 154
 155    /// <summary>
 156    /// Gets the target vertex.
 157    /// </summary>
 2667072158    public VertexId Head => _tileEnumerator.Head;
 159
 160    /// <summary>
 161    /// Gets the edge id.
 162    /// </summary>
 3958051163    public EdgeId EdgeId => _tileEnumerator.EdgeId;
 164
 165    /// <summary>
 166    /// Gets the shape.
 167    /// </summary>
 168    /// <returns>The shape.</returns>
 1246177169    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>
 4876175    public IEnumerable<(string key, string value)> Attributes => _tileEnumerator.Attributes;
 176
 177    /// <summary>
 178    /// Gets the edge profile id.
 179    /// </summary>
 1096665180    public uint? EdgeTypeId => _tileEnumerator.EdgeTypeId;
 181
 182    /// <summary>
 183    /// Gets the length in centimeters, if any.
 184    /// </summary>
 2598530185    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>
 430138195    public byte? HeadOrder => _tileEnumerator.HeadOrder;
 196
 197    /// <summary>
 198    /// Gets the tail index.
 199    /// </summary>
 43200    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)
 19196209    {
 19196210        return _tileEnumerator.GetTurnCostToTail(sourceOrder);
 19196211    }
 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)
 17220    {
 17221        return _tileEnumerator.GetTurnCostFromTail(targetOrder);
 17222    }
 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}