< Summary

Class:Itinero.Routing.Costs.ProfileCostFunction
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Routing/Costs/ProfileCostFunction.cs
Covered lines:16
Uncovered lines:13
Coverable lines:29
Total lines:57
Line coverage:55.1% (16 of 29)
Covered branches:6
Total branches:16
Branch coverage:37.5% (6 of 16)
Tag:251_23667616543

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
Get(...)37.5%1648%

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
 5214    public ProfileCostFunction(Profile profile)
 5215    {
 5216        _profile = profile;
 5217    }
 18
 19    public (bool canAccess, bool canStop, double cost, double turnCost) Get(
 20        IEdgeEnumerator<RoutingNetwork> edgeEnumerator, bool tailToHead = true,
 21        IEnumerable<(EdgeId edgeId, byte? turn)>? previousEdges = null)
 28222    {
 28223        previousEdges ??= ArraySegment<(EdgeId edgeId, byte? turn)>.Empty;
 24
 28225        var factor = _profile.FactorInEdgeDirection(edgeEnumerator);
 28226        var length = edgeEnumerator.Length ??
 28227                     (uint)(edgeEnumerator.EdgeLength() * 100);
 28228        var directedFactor = tailToHead ? factor.ForwardFactor : factor.BackwardFactor;
 28229        var cost = directedFactor * length;
 28230        var canAccess = directedFactor > 0;
 31
 32        // check for turn costs.
 28233        var totalTurnCost = 0.0;
 28234        var (_, turn) = previousEdges.FirstOrDefault();
 56435        if (turn == null) return (canAccess, factor.CanStop, cost, totalTurnCost);
 36
 37        // there are turn costs.
 038        var turnCosts = tailToHead
 039            ? edgeEnumerator.GetTurnCostToTail(turn.Value)
 040            : edgeEnumerator.GetTurnCostFromTail(turn.Value);
 041        foreach (var (_, attributes, turnCost, prefixEdges) in turnCosts)
 042        {
 43            // TODO: compare prefix edges with the previous edges.
 44
 045            var turnCostFactor = _profile.TurnCostFactor(attributes);
 046            if (turnCostFactor.IsBinary && turnCost > 0)
 047            {
 048                totalTurnCost = double.MaxValue;
 049                break;
 50            }
 51
 052            totalTurnCost += turnCostFactor.CostFactor * turnCost;
 053        }
 54
 055        return (canAccess, factor.CanStop, cost, totalTurnCost);
 28256    }
 57}

Methods/Properties

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