< Summary

Class:Itinero.Routing.Flavours.Dijkstra.SnapPointExtensions
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Routing/Flavours/Dijkstra/SnapPointExtensions.cs
Covered lines:42
Uncovered lines:0
Coverable lines:42
Total lines:86
Line coverage:100% (42 of 42)
Covered branches:14
Total branches:16
Branch coverage:87.5% (14 of 16)
Tag:251_23667616543

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
OffsetFactor(...)100%1100%
TrySingleHop(...)87.5%16100%

File(s)

/home/runner/work/routing2/routing2/src/Itinero/Routing/Flavours/Dijkstra/SnapPointExtensions.cs

#LineLine coverage
 1using System;
 2using Itinero.Network;
 3using Itinero.Routes.Paths;
 4using Itinero.Routing.Costs;
 5using Itinero.Routing.Flavours.Dijkstra.Bidirectional;
 6using Itinero.Snapping;
 7
 8namespace Itinero.Routing.Flavours.Dijkstra;
 9
 10/// <summary>
 11/// Extensions related to snap points.
 12/// </summary>
 13public static class SnapPointExtensions
 14{
 15    /// <summary>
 16    /// Returns a factor in the range [0, 1] representing the position on the edge.
 17    /// </summary>
 18    /// <param name="snapPoint">The snap point.</param>
 19    /// <returns>The factor.</returns>
 20    public static double OffsetFactor(this SnapPoint snapPoint)
 21760921    {
 21760922        return snapPoint.Offset / (double)ushort.MaxValue;
 21760923    }
 24
 25    /// <summary>
 26    /// Calculates a single edge path using the given cost function if the two snap points are on the same edge.
 27    /// </summary>
 28    /// <param name="routingNetwork"></param>
 29    /// <param name="origin"></param>
 30    /// <param name="destination"></param>
 31    /// <param name="costFunction"></param>
 32    /// <param name="path"></param>
 33    /// <param name="cost"></param>
 34    /// <returns></returns>
 35    /// <exception cref="Exception"></exception>
 36    public static bool TrySingleHop(this RoutingNetwork routingNetwork,
 37        SnapPoint origin, SnapPoint destination, ICostFunction costFunction,
 38        out Path path, out double cost)
 6539    {
 6540        path = null;
 6541        cost = double.MaxValue;
 7842        if (origin.EdgeId != destination.EdgeId) return false;
 43
 5244        var enumerator = new CostEdgeEnumerator(routingNetwork.GetEdgeEnumerator(), costFunction);
 5245        if (!enumerator.MoveTo(origin.EdgeId, true)) throw new Exception();
 5246        var tailToHeadCost = enumerator.GetCost(true);
 5247        var headToTailCost = enumerator.GetCost(false);
 5248        if (headToTailCost.cost <= 0 && tailToHeadCost.cost <= 0) return false;
 49
 5250        if (origin.Offset == destination.Offset)
 3951        {
 3952            var tailToHead = tailToHeadCost.cost > 0;
 3953            path = new Path(routingNetwork);
 3954            path.Append(origin.EdgeId, tailToHead);
 3955            path.Offset1 = origin.Offset;
 3956            path.Offset2 = destination.Offset;
 3957            cost = 0;
 3958        }
 1359        else if (origin.Offset < destination.Offset)
 860        {
 861            var tailToHead = tailToHeadCost.cost > 0;
 962            if (!tailToHead) return false;
 63
 764            path = new Path(routingNetwork);
 765            path.Append(origin.EdgeId, true);
 766            path.Offset1 = origin.Offset;
 767            path.Offset2 = destination.Offset;
 68
 769            cost = (destination.OffsetFactor() - origin.OffsetFactor()) * tailToHeadCost.cost;
 770        }
 71        else
 572        {
 573            var headToTail = headToTailCost.cost > 0;
 674            if (!headToTail) return false;
 75
 476            path = new Path(routingNetwork);
 477            path.Append(origin.EdgeId, false);
 478            path.Offset1 = (ushort)(ushort.MaxValue - origin.Offset);
 479            path.Offset2 = (ushort)(ushort.MaxValue - destination.Offset);
 80
 481            cost = (origin.OffsetFactor() - destination.OffsetFactor()) * headToTailCost.cost;
 482        }
 83
 5084        return true;
 6585    }
 86}