< 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:232_15462506344

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)
 14721    {
 14722        return snapPoint.Offset / (double)ushort.MaxValue;
 14723    }
 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)
 1539    {
 1540        path = null;
 1541        cost = double.MaxValue;
 1842        if (origin.EdgeId != destination.EdgeId) return false;
 43
 1244        var enumerator = new CostEdgeEnumerator(routingNetwork.GetEdgeEnumerator(), costFunction);
 1245        if (!enumerator.MoveTo(origin.EdgeId, true)) throw new Exception();
 1246        var tailToHeadCost = enumerator.GetCost(true);
 1247        var headToTailCost = enumerator.GetCost(false);
 1248        if (headToTailCost.cost <= 0 && tailToHeadCost.cost <= 0) return false;
 49
 1250        if (origin.Offset == destination.Offset)
 151        {
 152            var tailToHead = tailToHeadCost.cost > 0;
 153            path = new Path(routingNetwork);
 154            path.Append(origin.EdgeId, tailToHead);
 155            path.Offset1 = origin.Offset;
 156            path.Offset2 = destination.Offset;
 157            cost = 0;
 158        }
 1159        else if (origin.Offset < destination.Offset)
 660        {
 661            var tailToHead = tailToHeadCost.cost > 0;
 762            if (!tailToHead) return false;
 63
 564            path = new Path(routingNetwork);
 565            path.Append(origin.EdgeId, true);
 566            path.Offset1 = origin.Offset;
 567            path.Offset2 = destination.Offset;
 68
 569            cost = (destination.OffsetFactor() - origin.OffsetFactor()) * tailToHeadCost.cost;
 570        }
 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
 1084        return true;
 1585    }
 86}