< Summary

Class:Itinero.Routing.Costs.ProfileCostFunction
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Routing/Costs/ProfileCostFunction.cs
Covered lines:28
Uncovered lines:2
Coverable lines:30
Total lines:58
Line coverage:93.3% (28 of 30)
Covered branches:12
Total branches:16
Branch coverage:75% (12 of 16)
Tag:267_28791001112

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
Get(...)75%1692.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
 42314    public ProfileCostFunction(Profile profile)
 42315    {
 42316        _profile = profile;
 42317    }
 18
 19    public (bool canAccess, bool canStop, bool localAccess, double cost, double turnCost) Get(
 20        IEdgeEnumerator<RoutingNetwork> edgeEnumerator, bool tailToHead = true,
 21        IEnumerable<(EdgeId edgeId, byte? turn)>? previousEdges = null)
 168722    {
 168723        previousEdges ??= ArraySegment<(EdgeId edgeId, byte? turn)>.Empty;
 24
 168725        var factor = _profile.FactorInEdgeDirection(edgeEnumerator);
 168726        var length = edgeEnumerator.Length ??
 168727                     (uint)(edgeEnumerator.EdgeLength() * 100);
 168728        var directedFactor = tailToHead ? factor.ForwardFactor : factor.BackwardFactor;
 168729        var cost = directedFactor * length;
 168730        var canAccess = directedFactor > 0;
 168731        var localAccess = factor.IsLocalAccess;
 32
 33        // check for turn costs.
 168734        var totalTurnCost = 0.0;
 168735        var (_, turn) = previousEdges.FirstOrDefault();
 335736        if (turn == null) return (canAccess, factor.CanStop, localAccess, cost, totalTurnCost);
 37
 38        // there are turn costs.
 1739        var turnCosts = tailToHead
 1740            ? edgeEnumerator.GetTurnCostToTail(turn.Value)
 1741            : edgeEnumerator.GetTurnCostFromTail(turn.Value);
 6542        foreach (var (_, attributes, turnCost, prefixEdges) in turnCosts)
 1443        {
 44            // TODO: compare prefix edges with the previous edges.
 45
 1446            var turnCostFactor = _profile.TurnCostFactor(attributes);
 1447            if (turnCostFactor.IsBinary && turnCost > 0)
 1448            {
 1449                totalTurnCost = double.MaxValue;
 1450                break;
 51            }
 52
 053            totalTurnCost += turnCostFactor.CostFactor * turnCost;
 054        }
 55
 1756        return (canAccess, factor.CanStop, localAccess, cost, totalTurnCost);
 168757    }
 58}

Methods/Properties

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