| | | 1 | | using System.Collections.Generic; |
| | | 2 | | using Itinero.Network; |
| | | 3 | | using Itinero.Network.Enumerators.Edges; |
| | | 4 | | using Itinero.Routing.Costs; |
| | | 5 | | |
| | | 6 | | namespace Itinero.Routing.Flavours.Dijkstra.Bidirectional; |
| | | 7 | | |
| | | 8 | | internal static class ICostFunctionExtensions |
| | | 9 | | { |
| | | 10 | | public static (double cost, double turnCost) GetCost(this ICostFunction costFunction, |
| | | 11 | | RoutingNetworkEdgeEnumerator edgeEnumerator, bool tailToHead, PreviousEdgeEnumerable previousEdges) |
| | 1437 | 12 | | { |
| | | 13 | | // fast path: when there are no previous edges at all, pass null to avoid boxing. |
| | 1437 | 14 | | if (previousEdges.IsEmpty) |
| | 0 | 15 | | { |
| | 0 | 16 | | var (_, _, c, _) = costFunction.Get(edgeEnumerator, tailToHead, null); |
| | 0 | 17 | | return (c, 0.0); |
| | | 18 | | } |
| | | 19 | | |
| | | 20 | | // box the struct for ICostFunction. |
| | 1437 | 21 | | var (_, _, cost, turnCost) = costFunction.Get(edgeEnumerator, tailToHead, previousEdges); |
| | 1437 | 22 | | return (cost, turnCost); |
| | 1437 | 23 | | } |
| | | 24 | | |
| | | 25 | | public static (double cost, double turnCost) GetCost(this ICostFunction costFunction, |
| | | 26 | | RoutingNetworkEdgeEnumerator edgeEnumerator, bool tailToHead, IEnumerable<(EdgeId edgeId, byte? turn)>? previous |
| | 354 | 27 | | { |
| | 354 | 28 | | var (_, _, cost, turnCost) = costFunction.Get(edgeEnumerator, tailToHead, previousEdges); |
| | 354 | 29 | | return (cost, turnCost); |
| | 354 | 30 | | } |
| | | 31 | | |
| | | 32 | | public static (double cost, double turnCost) MoveToAndGetCost(this ICostFunction costFunction, |
| | | 33 | | RoutingNetworkEdgeEnumerator edgeEnumerator, EdgeId edgeId, bool forward, bool tailToHead, IEnumerable<(EdgeId e |
| | 0 | 34 | | { |
| | 0 | 35 | | var (_, _, cost, turnCost) = costFunction.Get(edgeEnumerator, tailToHead, previousEdges); |
| | 0 | 36 | | return (cost, turnCost); |
| | 0 | 37 | | } |
| | | 38 | | } |