| | | 1 | | using System.Collections.Generic; |
| | | 2 | | using Itinero.Network; |
| | | 3 | | using Itinero.Network.Enumerators.Edges; |
| | | 4 | | using Itinero.Routing.Flavours.Dijkstra; |
| | | 5 | | |
| | | 6 | | namespace Itinero.Routing.Costs; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Reports the edges of a local pocket as local-access, whatever their tags say. |
| | | 10 | | /// </summary> |
| | | 11 | | /// <remarks> |
| | | 12 | | /// An untagged segment enclosed by access=destination edges behaves as part of the pocket, so the |
| | | 13 | | /// L to L, L to N, N to N rule carries a half through it instead of stopping at it. |
| | | 14 | | /// </remarks> |
| | | 15 | | internal sealed class PocketCostFunction : ICostFunction |
| | | 16 | | { |
| | | 17 | | private readonly ICostFunction _inner; |
| | | 18 | | private readonly HashSet<EdgeId> _members; |
| | | 19 | | |
| | 3 | 20 | | public PocketCostFunction(ICostFunction inner, HashSet<EdgeId> members) |
| | 3 | 21 | | { |
| | 3 | 22 | | _inner = inner; |
| | 3 | 23 | | _members = members; |
| | 3 | 24 | | } |
| | | 25 | | |
| | | 26 | | public (bool canAccess, bool canStop, bool localAccess, double cost, double turnCost) Get( |
| | | 27 | | IEdgeEnumerator<RoutingNetwork> edgeEnumerator, bool tailToHead = true, |
| | | 28 | | PreviousEdgeEnumerable previousEdges = default) |
| | 7 | 29 | | { |
| | 7 | 30 | | var inner = _inner.Get(edgeEnumerator, tailToHead, previousEdges); |
| | 7 | 31 | | if (inner.localAccess || !_members.Contains(edgeEnumerator.EdgeId)) return inner; |
| | | 32 | | |
| | 7 | 33 | | return (inner.canAccess, inner.canStop, true, inner.cost, inner.turnCost); |
| | 7 | 34 | | } |
| | | 35 | | } |