< 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:85
Line coverage:100% (42 of 42)
Covered branches:14
Total branches:16
Branch coverage:87.5% (14 of 16)
Tag:263_26948838820

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.Snapping;
 6
 7namespace Itinero.Routing.Flavours.Dijkstra;
 8
 9/// <summary>
 10/// Extensions related to snap points.
 11/// </summary>
 12public static class SnapPointExtensions
 13{
 14    /// <summary>
 15    /// Returns a factor in the range [0, 1] representing the position on the edge.
 16    /// </summary>
 17    /// <param name="snapPoint">The snap point.</param>
 18    /// <returns>The factor.</returns>
 19    public static double OffsetFactor(this SnapPoint snapPoint)
 22037520    {
 22037521        return snapPoint.Offset / (double)ushort.MaxValue;
 22037522    }
 23
 24    /// <summary>
 25    /// Calculates a single edge path using the given cost function if the two snap points are on the same edge.
 26    /// </summary>
 27    /// <param name="routingNetwork"></param>
 28    /// <param name="origin"></param>
 29    /// <param name="destination"></param>
 30    /// <param name="costFunction"></param>
 31    /// <param name="path"></param>
 32    /// <param name="cost"></param>
 33    /// <returns></returns>
 34    /// <exception cref="Exception"></exception>
 35    public static bool TrySingleHop(this RoutingNetwork routingNetwork,
 36        SnapPoint origin, SnapPoint destination, ICostFunction costFunction,
 37        out Path path, out double cost)
 8338    {
 8339        path = null;
 8340        cost = double.MaxValue;
 11341        if (origin.EdgeId != destination.EdgeId) return false;
 42
 5343        var enumerator = new CostEdgeEnumerator(routingNetwork.GetEdgeEnumerator(), costFunction);
 5344        if (!enumerator.MoveTo(origin.EdgeId, true)) throw new Exception();
 5345        var tailToHeadCost = enumerator.GetCost(true);
 5346        var headToTailCost = enumerator.GetCost(false);
 5347        if (headToTailCost.cost <= 0 && tailToHeadCost.cost <= 0) return false;
 48
 5349        if (origin.Offset == destination.Offset)
 4050        {
 4051            var tailToHead = tailToHeadCost.cost > 0;
 4052            path = new Path(routingNetwork);
 4053            path.Append(origin.EdgeId, tailToHead);
 4054            path.Offset1 = origin.Offset;
 4055            path.Offset2 = destination.Offset;
 4056            cost = 0;
 4057        }
 1358        else if (origin.Offset < destination.Offset)
 859        {
 860            var tailToHead = tailToHeadCost.cost > 0;
 961            if (!tailToHead) return false;
 62
 763            path = new Path(routingNetwork);
 764            path.Append(origin.EdgeId, true);
 765            path.Offset1 = origin.Offset;
 766            path.Offset2 = destination.Offset;
 67
 768            cost = (destination.OffsetFactor() - origin.OffsetFactor()) * tailToHeadCost.cost;
 769        }
 70        else
 571        {
 572            var headToTail = headToTailCost.cost > 0;
 673            if (!headToTail) return false;
 74
 475            path = new Path(routingNetwork);
 476            path.Append(origin.EdgeId, false);
 477            path.Offset1 = (ushort)(ushort.MaxValue - origin.Offset);
 478            path.Offset2 = (ushort)(ushort.MaxValue - destination.Offset);
 79
 480            cost = (origin.OffsetFactor() - destination.OffsetFactor()) * headToTailCost.cost;
 481        }
 82
 5183        return true;
 8384    }
 85}