< 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:263_26948838820

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
 17314    public ProfileCostFunction(Profile profile)
 17315    {
 17316        _profile = profile;
 17317    }
 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)
 118722    {
 118723        previousEdges ??= ArraySegment<(EdgeId edgeId, byte? turn)>.Empty;
 24
 118725        var factor = _profile.FactorInEdgeDirection(edgeEnumerator);
 118726        var length = edgeEnumerator.Length ??
 118727                     (uint)(edgeEnumerator.EdgeLength() * 100);
 118728        var directedFactor = tailToHead ? factor.ForwardFactor : factor.BackwardFactor;
 118729        var cost = directedFactor * length;
 118730        var canAccess = directedFactor > 0;
 118731        var localAccess = factor.IsLocalAccess;
 32
 33        // check for turn costs.
 118734        var totalTurnCost = 0.0;
 118735        var (_, turn) = previousEdges.FirstOrDefault();
 235736        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);
 118757    }
 58}

Methods/Properties

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