< Summary

Class:Itinero.Network.Search.Islands.ICostFunctionExtensions
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Network/Search/Islands/ICostFunctionExtensions.cs
Covered lines:14
Uncovered lines:0
Coverable lines:14
Total lines:59
Line coverage:100% (14 of 14)
Covered branches:8
Total branches:8
Branch coverage:100% (8 of 8)
Tag:284_38118444584

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
GetIslandBuilderCost(...)100%2100%
GetIslandBuilderCost(...)100%6100%

File(s)

/home/runner/work/routing2/routing2/src/Itinero/Network/Search/Islands/ICostFunctionExtensions.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using Itinero.Network.Enumerators.Edges;
 4using Itinero.Routing.Costs;
 5using Itinero.Routing.Flavours.Dijkstra;
 6
 7namespace Itinero.Network.Search.Islands;
 8
 9internal static class ICostFunctionExtensions
 10{
 11    /// <summary>
 12    /// Gets the cost of a turn from the previous edges sequence to the given edge in the enumerator in a forward direct
 13    ///
 14    /// This does NOT include the cost of the previous edges.
 15    /// </summary>
 16    /// <param name="costFunction">The cost function.</param>
 17    /// <param name="enumerator">The edge to test.</param>
 18    /// <param name="forward">Then true, calculate the cost including turn cost from (previousEdge ->) enumerator.tail -
 19    /// <param name="previousEdges">A sequence of previously traversed edge, if any.</param>
 20    /// <returns>True if the current edge is traversable and the turn cost allows the turn.</returns>
 21    public static bool GetIslandBuilderCost(this ICostFunction costFunction,
 22        RoutingNetworkEdgeEnumerator enumerator, bool forward = true, PreviousEdgeEnumerable previousEdges = default)
 48223    {
 48224        var cost = costFunction.Get(enumerator, forward, previousEdges);
 25
 48226        return cost is { canAccess: true, turnCost: < double.MaxValue };
 48227    }
 28
 29    /// <summary>
 30    /// Gets the cost of traversing through a shared vertex from <paramref name="from"/> to
 31    /// <paramref name="to"/>, including the turn cost at the shared vertex.
 32    ///
 33    /// Both enumerators must be pre-positioned in their respective traversal directions
 34    /// such that the shared vertex is at <c>from.Head</c> and at <c>to.Tail</c>.
 35    /// </summary>
 36    /// <returns>True if <paramref name="from"/> is traversable in its direction,
 37    /// <paramref name="to"/> is traversable in its direction, AND the turn from
 38    /// <paramref name="from"/> through the shared vertex into <paramref name="to"/> is
 39    /// allowed (turn cost &lt; <see cref="double.MaxValue"/>).</returns>
 40    public static bool GetIslandBuilderCost(this ICostFunction costFunction,
 41        RoutingNetworkEdgeEnumerator from,
 42        RoutingNetworkEdgeEnumerator to)
 1190243    {
 44        // from-edge must be traversable in its current direction at all.
 45        // without this check a one-way edge whose only allowed direction goes the
 46        // OPPOSITE way of the requested traversal would still appear to enable a
 47        // turn into the to-edge.
 1190248        var fromCost = costFunction.Get(from, tailToHead: true);
 1203349        if (!fromCost.canAccess) return false;
 50
 1177151        var fromOrder = from.HeadOrder;
 1177152        var previousEdges = fromOrder.HasValue
 1177153            ? PreviousEdgeEnumerable.ForEdge(from.EdgeId, fromOrder)
 1177154            : default;
 55
 1177156        var cost = costFunction.Get(to, tailToHead: true, previousEdges);
 1177157        return cost is { canAccess: true, turnCost: < double.MaxValue };
 1190258    }
 59}