< Summary

Class:Itinero.Profiles.ProfileCached
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Profiles/ProfileCached.cs
Covered lines:26
Uncovered lines:3
Coverable lines:29
Total lines:60
Line coverage:89.6% (26 of 29)
Covered branches:5
Total branches:6
Branch coverage:83.3% (5 of 6)
Tag:263_26948838820

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
Factor(...)83.33%686.95%

File(s)

/home/runner/work/routing2/routing2/src/Itinero/Profiles/ProfileCached.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using Itinero.Network.Enumerators.Edges;
 3using Itinero.Routing.Costs.Caches;
 4
 5namespace Itinero.Profiles;
 6
 7/// <summary>
 8/// A cached version of a profile.
 9/// </summary>
 10public class ProfileCached
 11{
 12    private readonly Profile _profile;
 13    private readonly EdgeFactorCache _edgeFactorCache;
 14    private readonly TurnCostFactorCache _turnCostFactorCache;
 15
 5416    internal ProfileCached(Profile profile, EdgeFactorCache edgeFactorCache, TurnCostFactorCache turnCostFactorCache)
 5417    {
 5418        _profile = profile;
 5419        _edgeFactorCache = edgeFactorCache;
 5420        _turnCostFactorCache = turnCostFactorCache;
 5421    }
 22
 23    /// <summary>
 24    /// Gets an edge factor for the current edge.
 25    /// </summary>
 26    /// <param name="edgeEnumerator">The enumerator with the current edge.</param>
 27    /// <returns>The edge factor.</returns>
 28    public EdgeFactor Factor(RoutingNetworkEdgeEnumerator edgeEnumerator)
 62329    {
 30        // get edge factor and length.
 31        EdgeFactor factor;
 62332        var edgeTypeId = edgeEnumerator.EdgeTypeId;
 62333        if (edgeTypeId == null)
 034        {
 035            factor = _profile.FactorInEdgeDirection(edgeEnumerator);
 036        }
 37        else
 62338        {
 62339            var edgeFactor = _edgeFactorCache.Get(edgeTypeId.Value);
 62340            if (edgeFactor == null)
 2641            {
 42                // no cached value, cache forward value.
 2643                factor = _profile.Factor(edgeEnumerator.Attributes);
 2644                _edgeFactorCache.Set(edgeTypeId.Value, factor);
 2645            }
 46            else
 59747            {
 59748                factor = edgeFactor.Value;
 59749            }
 50
 51            // cached value is always forward.
 62352            if (!edgeEnumerator.Forward)
 15853            {
 15854                factor = factor.Reverse;
 15855            }
 62356        }
 57
 62358        return factor;
 62359    }
 60}

Methods/Properties

.ctor(...)
Factor(...)