< Summary

Class:Itinero.Network.RoutingNetworkSnapshotExtensions
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Network/RoutingNetworkExtensions.cs
Covered lines:40
Uncovered lines:8
Coverable lines:48
Total lines:124
Line coverage:83.3% (40 of 48)
Covered branches:13
Total branches:26
Branch coverage:50% (13 of 26)
Tag:224_14471318300

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
GetVertex(...)50%266.66%
GetVertices()100%2100%
GetEdges()87.5%887.5%
GetCachedProfile(...)16.66%683.33%
GetCostFunctionFor(...)16.66%683.33%
GetAttributes(...)50%271.42%

File(s)

/home/runner/work/routing2/routing2/src/Itinero/Network/RoutingNetworkExtensions.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Runtime.CompilerServices;
 5using Itinero.Network.Enumerators.Edges;
 6using Itinero.Network.Search;
 7using Itinero.Profiles;
 8using Itinero.Routing.Costs;
 9using Itinero.Routing.Costs.Caches;
 10
 11[assembly: InternalsVisibleTo("Itinero.Geo")]
 12
 13namespace Itinero.Network;
 14
 15/// <summary>
 16/// Extensions methods for routing networks.
 17/// </summary>
 18public static class RoutingNetworkSnapshotExtensions
 19{
 20    /// <summary>
 21    /// Gets the location of the given vertex.
 22    /// </summary>
 23    /// <param name="routingNetwork">The network</param>
 24    /// <param name="vertex">The vertex.</param>
 25    /// <returns>The location.</returns>
 26    /// <exception cref="ArgumentOutOfRangeException">When the vertex doesn't exist.</exception>
 27    public static (double longitude, double latitude, float? e) GetVertex(this RoutingNetwork routingNetwork,
 28        VertexId vertex)
 929    {
 930        if (!routingNetwork.TryGetVertex(vertex, out var longitude, out var latitude, out var e))
 031        {
 032            throw new ArgumentOutOfRangeException(nameof(vertex));
 33        }
 34
 935        return (longitude, latitude, e);
 936    }
 37
 38    /// <summary>
 39    /// Gets an enumerable with all vertices.
 40    /// </summary>
 41    /// <param name="routingNetwork">The routing network.</param>
 42    /// <param name="box">The bounding box, if any.</param>
 43    /// <returns>An enumerable with all vertices.</returns>
 44    public static IEnumerable<VertexId> GetVertices(this RoutingNetwork routingNetwork)
 845    {
 846        var enumerator = routingNetwork.GetVertexEnumerator();
 2047        while (enumerator.MoveNext())
 1248        {
 1249            yield return enumerator.Current;
 1250        }
 851    }
 52
 53    /// <summary>
 54    /// Gets an enumerable with all edges.
 55    /// </summary>
 56    /// <param name="routingNetwork">The routing network.</param>
 57    /// <param name="box">The bounding box, if any.</param>
 58    /// <returns>An enumerable with all edges.</returns>
 59    public static IEnumerable<EdgeId> GetEdges(this RoutingNetwork routingNetwork)
 160    {
 161        var edgeEnumerator = routingNetwork.GetEdgeEnumerator();
 762        foreach (var vertex in routingNetwork.GetVertices())
 263        {
 264            if (!edgeEnumerator.MoveTo(vertex))
 065            {
 066                continue;
 67            }
 68
 469            while (edgeEnumerator.MoveNext())
 270            {
 271                if (!edgeEnumerator.Forward)
 172                {
 173                    continue;
 74                }
 75
 176                yield return edgeEnumerator.EdgeId;
 177            }
 278        }
 179    }
 80
 81    /// <summary>
 82    /// Gets a cached version of the given profile.
 83    /// </summary>
 84    /// <param name="network">The network.</param>
 85    /// <param name="profile">The profile.</param>
 86    /// <returns>The cached profile.</returns>
 87    public static ProfileCached GetCachedProfile(this RoutingNetwork network, Profile profile)
 2188    {
 2189        if (!network.RouterDb.ProfileConfiguration.TryGetProfileHandlerEdgeTypesCache(profile.Name, out var cache, out v
 2190        {
 2191            return new ProfileCached(profile, new EdgeFactorCache(), new TurnCostFactorCache());
 92        }
 93
 094        return new ProfileCached(profile, cache ?? new EdgeFactorCache(), turnCostFactorCache ?? new TurnCostFactorCache
 2195    }
 96
 97    /// <summary>
 98    /// Gets the cost function for the given profile.
 99    /// </summary>
 100    /// <param name="network">The network.</param>
 101    /// <param name="profile">The profile.</param>
 102    /// <returns>The cost function.</returns>
 103    public static ICostFunction GetCostFunctionFor(this RoutingNetwork network, Profile profile)
 26104    {
 26105        if (!network.RouterDb.ProfileConfiguration.TryGetProfileHandlerEdgeTypesCache(profile.Name, out var cache, out v
 26106        {
 26107            return new ProfileCostFunction(profile);
 108        }
 109
 0110        return new ProfileCostFunctionCached(profile, cache ?? new EdgeFactorCache(), turnCostFactorCache ?? new TurnCos
 26111    }
 112
 113    internal static IEnumerable<(string key, string value)>
 114        GetAttributes(this RoutingNetwork routerDb, EdgeId edge)
 1115    {
 1116        var enumerator = routerDb.GetEdgeEnumerator();
 1117        if (!enumerator.MoveTo(edge))
 0118        {
 0119            return Enumerable.Empty<(string key, string value)>();
 120        }
 121
 1122        return enumerator.Attributes;
 1123    }
 124}