< Summary

Class:Itinero.Routing.Costs.ProfileCostFunction
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Routing/Costs/ProfileCostFunction.cs
Covered lines:25
Uncovered lines:2
Coverable lines:27
Total lines:55
Line coverage:92.5% (25 of 27)
Covered branches:12
Total branches:14
Branch coverage:85.7% (12 of 14)
Tag:224_14471318300

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
Get(...)85.71%1491.3%

File(s)

/home/runner/work/routing2/routing2/src/Itinero/Routing/Costs/ProfileCostFunction.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using Itinero.Network;
 5using Itinero.Network.Enumerators.Edges;
 6using Itinero.Profiles;
 7
 8namespace Itinero.Routing.Costs;
 9
 10internal class ProfileCostFunction : ICostFunction
 11{
 12    private readonly Profile _profile;
 13
 3014    public ProfileCostFunction(Profile profile)
 3015    {
 3016        _profile = profile;
 3017    }
 18
 19    public (bool canAccess, bool canStop, double cost, double turnCost) Get(
 20        IEdgeEnumerator<RoutingNetwork> edgeEnumerator, bool forward = true,
 21        IEnumerable<(EdgeId edgeId, byte? turn)>? previousEdges = null)
 19122    {
 19123        previousEdges ??= ArraySegment<(EdgeId edgeId, byte? turn)>.Empty;
 24
 19125        var factor = _profile.FactorInEdgeDirection(edgeEnumerator);
 19126        var length = edgeEnumerator.Length ??
 19127                     (uint)(edgeEnumerator.EdgeLength() * 100);
 19128        var directedFactor = forward ? factor.ForwardFactor : factor.BackwardFactor;
 19129        var cost = directedFactor * length;
 19130        var canAccess = directedFactor > 0;
 31
 32        // check for turn costs.
 19133        var totalTurnCost = 0.0;
 19134        var (_, turn) = previousEdges.FirstOrDefault();
 37835        if (turn == null) return (canAccess, factor.CanStop, cost, totalTurnCost);
 36
 37        // there are turn costs.
 438        var turnCosts = edgeEnumerator.GetTurnCostToTail(turn.Value);
 1639        foreach (var (_, attributes, turnCost, prefixEdges) in turnCosts)
 440        {
 41            // TODO: compare prefix edges with the previous edges.
 42
 443            var turnCostFactor = _profile.TurnCostFactor(attributes);
 444            if (turnCostFactor.IsBinary && turnCost > 0)
 445            {
 446                totalTurnCost = double.MaxValue;
 447                break;
 48            }
 49
 050            totalTurnCost += turnCostFactor.CostFactor * turnCost;
 051        }
 52
 453        return (canAccess, factor.CanStop, cost, totalTurnCost);
 19154    }
 55}

Methods/Properties

.ctor(...)
Get(...)