| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Diagnostics.CodeAnalysis; |
| | | 4 | | |
| | | 5 | | namespace Itinero.Network.Tiles.Standalone.Global; |
| | | 6 | | |
| | | 7 | | public static class GlobalRestrictionExtensions |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Tries to build a network restriction from a global restriction. |
| | | 11 | | /// </summary> |
| | | 12 | | /// <remarks> |
| | | 13 | | /// Should always succeed if all edges are available but can fail if the data available is a tile and does not conta |
| | | 14 | | /// </remarks> |
| | | 15 | | /// <param name="globalNetworkRestriction">The global network.</param> |
| | | 16 | | /// <param name="getEdge">The function to get an edge.</param> |
| | | 17 | | /// <param name="networkRestriction">The resulting network restriction, if any.</param> |
| | | 18 | | /// <returns>True if success, false otherwise.</returns> |
| | | 19 | | public static bool TryBuildNetworkRestriction(this GlobalRestriction globalNetworkRestriction, Func<GlobalEdgeId, (E |
| | | 20 | | [MaybeNullWhen(false)] out NetworkRestriction? networkRestriction) |
| | 4752 | 21 | | { |
| | 4752 | 22 | | networkRestriction = null; |
| | | 23 | | |
| | 4752 | 24 | | var edges = new List<(EdgeId edge, bool forward)>(); |
| | 24928 | 25 | | foreach (var globalId in globalNetworkRestriction) |
| | 7196 | 26 | | { |
| | 7196 | 27 | | var e = getEdge(globalId); |
| | 10916 | 28 | | if (e == null) return false; |
| | | 29 | | |
| | 3476 | 30 | | edges.Add(e.Value); |
| | 3476 | 31 | | } |
| | | 32 | | |
| | 1032 | 33 | | networkRestriction = new NetworkRestriction(edges, globalNetworkRestriction.IsProhibitory, |
| | 1032 | 34 | | globalNetworkRestriction.Attributes); |
| | 1032 | 35 | | return true; |
| | 4752 | 36 | | } |
| | | 37 | | } |