< 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:224_14471318300

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
 2116    internal ProfileCached(Profile profile, EdgeFactorCache edgeFactorCache, TurnCostFactorCache turnCostFactorCache)
 2117    {
 2118        _profile = profile;
 2119        _edgeFactorCache = edgeFactorCache;
 2120        _turnCostFactorCache = turnCostFactorCache;
 2121    }
 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)
 3029    {
 30        // get edge factor and length.
 31        EdgeFactor factor;
 3032        var edgeTypeId = edgeEnumerator.EdgeTypeId;
 3033        if (edgeTypeId == null)
 034        {
 035            factor = _profile.FactorInEdgeDirection(edgeEnumerator);
 036        }
 37        else
 3038        {
 3039            var edgeFactor = _edgeFactorCache.Get(edgeTypeId.Value);
 3040            if (edgeFactor == null)
 2141            {
 42                // no cached value, cache forward value.
 2143                factor = _profile.Factor(edgeEnumerator.Attributes);
 2144                _edgeFactorCache.Set(edgeTypeId.Value, factor);
 2145            }
 46            else
 947            {
 948                factor = edgeFactor.Value;
 949            }
 50
 51            // cached value is always forward.
 3052            if (!edgeEnumerator.Forward)
 1153            {
 1154                factor = factor.Reverse;
 1155            }
 3056        }
 57
 3058        return factor;
 3059    }
 60}

Methods/Properties

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