| | | 1 | | using System.Collections.Generic; |
| | | 2 | | using Itinero.Network; |
| | | 3 | | using Itinero.Network.Enumerators.Edges; |
| | | 4 | | |
| | | 5 | | namespace Itinero.Routing.Costs; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Decorator that masks off local-access edges. Wraps an inner cost function and |
| | | 9 | | /// reports <c>canAccess = false</c> (and cost 0, turn cost <see cref="double.MaxValue"/>) |
| | | 10 | | /// for any edge the inner cost function flagged as <c>localAccess = true</c>. |
| | | 11 | | /// |
| | | 12 | | /// Used by the N-only island classification (<c>IslandKind.NonLocal</c>): feeding this |
| | | 13 | | /// into <see cref="Itinero.Network.Search.Islands.IslandClassifier"/> produces a |
| | | 14 | | /// reachability classification over the subgraph that excludes <c>access=destination</c> |
| | | 15 | | /// edges, i.e. the "main routable network" used by the access-aware routing rule. |
| | | 16 | | /// </summary> |
| | | 17 | | internal sealed class NonLocalCostFunction : ICostFunction |
| | | 18 | | { |
| | | 19 | | private readonly ICostFunction _inner; |
| | | 20 | | |
| | 1049 | 21 | | public NonLocalCostFunction(ICostFunction inner) |
| | 1049 | 22 | | { |
| | 1049 | 23 | | _inner = inner; |
| | 1049 | 24 | | } |
| | | 25 | | |
| | | 26 | | public (bool canAccess, bool canStop, bool localAccess, double cost, double turnCost) Get( |
| | | 27 | | IEdgeEnumerator<RoutingNetwork> edgeEnumerator, bool tailToHead = true, |
| | | 28 | | IEnumerable<(EdgeId edgeId, byte? turn)>? previousEdges = null) |
| | 23091 | 29 | | { |
| | 23091 | 30 | | var inner = _inner.Get(edgeEnumerator, tailToHead, previousEdges); |
| | 23091 | 31 | | if (inner.localAccess) |
| | 26 | 32 | | { |
| | | 33 | | // Mask off: the island classifier checks `canAccess && turnCost < MaxValue`. |
| | | 34 | | // Returning either failing condition is enough; we set both for clarity. |
| | 26 | 35 | | return (false, false, true, 0.0, double.MaxValue); |
| | | 36 | | } |
| | 23065 | 37 | | return inner; |
| | 23091 | 38 | | } |
| | | 39 | | } |