< Summary

Class:Itinero.Routing.Costs.ProfileCostFunction
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Routing/Costs/ProfileCostFunction.cs
Covered lines:27
Uncovered lines:2
Coverable lines:29
Total lines:59
Line coverage:93.1% (27 of 29)
Covered branches:12
Total branches:16
Branch coverage:75% (12 of 16)
Tag:284_38118444584

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
Get(...)75%1692%

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
 8using Itinero.Routing.Flavours.Dijkstra;
 9
 10namespace Itinero.Routing.Costs;
 11
 12internal class ProfileCostFunction : ICostFunction
 13{
 14    private readonly Profile _profile;
 15
 51916    public ProfileCostFunction(Profile profile)
 51917    {
 51918        _profile = profile;
 51919    }
 20
 21    public (bool canAccess, bool canStop, bool localAccess, double cost, double turnCost) Get(
 22        IEdgeEnumerator<RoutingNetwork> edgeEnumerator, bool tailToHead = true,
 23        PreviousEdgeEnumerable previousEdges = default)
 1620424    {
 25
 1620426        var factor = _profile.FactorInEdgeDirection(edgeEnumerator);
 1620427        var length = edgeEnumerator.Length ??
 1620428                     (uint)(edgeEnumerator.EdgeLength() * 100);
 1620429        var directedFactor = tailToHead ? factor.ForwardFactor : factor.BackwardFactor;
 1620430        var cost = directedFactor * length;
 1620431        var canAccess = directedFactor > 0;
 1620432        var localAccess = factor.IsLocalAccess;
 33
 34        // check for turn costs.
 1620435        var totalTurnCost = 0.0;
 1620436        var turn = previousEdges.First?.turn;
 3239137        if (turn == null) return (canAccess, factor.CanStop, localAccess, cost, totalTurnCost);
 38
 39        // there are turn costs.
 1740        var turnCosts = tailToHead
 1741            ? edgeEnumerator.GetTurnCostToTail(turn.Value)
 1742            : edgeEnumerator.GetTurnCostFromTail(turn.Value);
 6543        foreach (var (_, attributes, turnCost, prefixEdges) in turnCosts)
 1444        {
 45            // TODO: compare prefix edges with the previous edges.
 46
 1447            var turnCostFactor = _profile.TurnCostFactor(attributes);
 1448            if (turnCostFactor.IsBinary && turnCost > 0)
 1449            {
 1450                totalTurnCost = double.MaxValue;
 1451                break;
 52            }
 53
 054            totalTurnCost += turnCostFactor.CostFactor * turnCost;
 055        }
 56
 1757        return (canAccess, factor.CanStop, localAccess, cost, totalTurnCost);
 1620458    }
 59}

Methods/Properties

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