| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Linq; |
| | | 4 | | using Itinero.IO.Osm.Restrictions.Barriers; |
| | | 5 | | using Itinero.IO.Osm.Restrictions.Turns; |
| | | 6 | | using Itinero.IO.Osm.Streams; |
| | | 7 | | using Itinero.Network; |
| | | 8 | | using Itinero.Network.Tiles.Standalone; |
| | | 9 | | using Itinero.Network.Tiles.Standalone.Global; |
| | | 10 | | using Itinero.Network.Tiles.Standalone.Writer; |
| | | 11 | | using OsmSharp; |
| | | 12 | | using OsmSharp.Streams; |
| | | 13 | | |
| | | 14 | | namespace Itinero.IO.Osm.Tiles; |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Contains extensions methods for the standalone tile writer. |
| | | 18 | | /// </summary> |
| | | 19 | | public static class StandaloneNetworkTileWriterExtensions |
| | | 20 | | { |
| | | 21 | | /// <summary> |
| | | 22 | | /// Adds tile data using the writer and the given tile data. |
| | | 23 | | /// </summary> |
| | | 24 | | /// <param name="writer">The writer.</param> |
| | | 25 | | /// <param name="tileData">The OSM data in the tile.</param> |
| | | 26 | | /// <param name="configure">The configure function.</param> |
| | | 27 | | /// <exception cref="Exception"></exception> |
| | | 28 | | public static void AddTileData(this StandaloneNetworkTileWriter writer, IEnumerable<OsmGeo> tileData, |
| | | 29 | | Action<DataProviderSettings>? configure = null) |
| | 27 | 30 | | { |
| | | 31 | | static uint ToLocalId(uint x, uint y, int zoom) |
| | 0 | 32 | | { |
| | 0 | 33 | | var xMax = 1 << zoom; |
| | 0 | 34 | | return (uint)((y * xMax) + x); |
| | 0 | 35 | | } |
| | | 36 | | |
| | | 37 | | // create settings. |
| | 27 | 38 | | var settings = new DataProviderSettings(); |
| | 27 | 39 | | configure?.Invoke(settings); |
| | | 40 | | |
| | | 41 | | // do filtering. |
| | | 42 | | // ReSharper disable once PossibleMultipleEnumeration |
| | 27 | 43 | | OsmStreamSource data = new OsmEnumerableStreamSource(tileData); |
| | | 44 | | |
| | | 45 | | // 1: complete objects. |
| | 27 | 46 | | if (settings.TagsFilter.CompleteFilter != null) |
| | 0 | 47 | | { |
| | 0 | 48 | | data = data.ApplyCompleteFilter(settings.TagsFilter.CompleteFilter); |
| | 0 | 49 | | } |
| | | 50 | | |
| | | 51 | | // 2: filter relations. |
| | 27 | 52 | | if (settings.TagsFilter.MemberFilter != null) |
| | 27 | 53 | | { |
| | 27 | 54 | | data = data.ApplyRelationMemberFilter(settings.TagsFilter.MemberFilter); |
| | 27 | 55 | | } |
| | | 56 | | |
| | | 57 | | // 3: filter tags on ways and relations. |
| | 27 | 58 | | if (settings.TagsFilter.Filter != null) |
| | 27 | 59 | | { |
| | 27 | 60 | | data = data.ApplyFilter(settings.TagsFilter.Filter); |
| | 27 | 61 | | } |
| | | 62 | | |
| | | 63 | | // setup the edge type map. |
| | 27 | 64 | | var edgeTypeMap = writer.EdgeTypeMap.func; |
| | 27 | 65 | | var emptyEdgeType = edgeTypeMap(ArraySegment<(string key, string value)>.Empty); |
| | | 66 | | |
| | | 67 | | // keep all node locations. |
| | 27 | 68 | | var nodeLocations = new Dictionary<long, (double longitude, double latitude, bool inside)>(); |
| | | 69 | | // keep a set of used nodes, all nodes inside the tile. |
| | 27 | 70 | | var usedNodes = new HashSet<long>(); |
| | | 71 | | // keep a set of core nodes, all nodes inside the tile that should be a vertex |
| | 27 | 72 | | var coreNodes = new HashSet<long>(); |
| | | 73 | | // keep a set of boundary nodes, all boundary nodes (first node outside the tile). |
| | 27 | 74 | | var boundaryNodes = new HashSet<long>(); |
| | | 75 | | // keep a set of boundary vertices. |
| | 27 | 76 | | var boundaryVertices = new HashSet<VertexId>(); |
| | | 77 | | |
| | | 78 | | // first pass to: |
| | | 79 | | // - mark nodes are core, they are to be become vertices later. |
| | | 80 | | // - parse restrictions and keep restricted edges and mark nodes as core. |
| | 27 | 81 | | using var enumerator = data.GetEnumerator(); |
| | | 82 | | |
| | 27 | 83 | | var globalRestrictions = new List<GlobalRestriction>(); |
| | 27 | 84 | | var globalRestrictionEdges = new Dictionary<GlobalEdgeId, EdgeId?>(); |
| | | 85 | | |
| | 27 | 86 | | var restrictionMembers = new Dictionary<long, Way?>(); |
| | 27 | 87 | | var restrictionParser = new OsmTurnRestrictionParser(); |
| | 27 | 88 | | var barrierNodes = new Dictionary<long, List<Way>>(); |
| | | 89 | | |
| | 27 | 90 | | var wayEdgeTypes = new Dictionary<long, (uint edgeTypeId, (string key, string value)[] attributes)>(); |
| | | 91 | | |
| | 27 | 92 | | var barrierParser = new OsmBarrierParser(); |
| | 232 | 93 | | while (enumerator.MoveNext()) |
| | 205 | 94 | | { |
| | 205 | 95 | | var current = enumerator.Current; |
| | | 96 | | |
| | 205 | 97 | | switch (current) |
| | | 98 | | { |
| | | 99 | | case Node node: |
| | 151 | 100 | | if (node.Id == null) throw new Exception("Id cannot be null"); |
| | 151 | 101 | | if (node.Longitude == null) throw new Exception("Longitude cannot be null"); |
| | 151 | 102 | | if (node.Latitude == null) throw new Exception("Latitude cannot be null"); |
| | | 103 | | |
| | 151 | 104 | | var nodeInTile = writer.IsInTile(node.Longitude.Value, node.Latitude.Value); |
| | 151 | 105 | | nodeLocations[node.Id.Value] = (node.Longitude.Value, node.Latitude.Value, |
| | 151 | 106 | | nodeInTile); |
| | | 107 | | |
| | 151 | 108 | | if (barrierParser.IsBarrier(node)) |
| | 25 | 109 | | { |
| | | 110 | | // make sure the barriers are core nodes, they need a turn cost. |
| | | 111 | | // log nodes are barriers to be able to detect their ways, |
| | | 112 | | // only take nodes in the tile to mark as barrier. |
| | 25 | 113 | | coreNodes.Add(node.Id.Value); |
| | 25 | 114 | | barrierNodes.Add(node.Id.Value, []); |
| | 25 | 115 | | } |
| | | 116 | | |
| | 151 | 117 | | break; |
| | 52 | 118 | | case Way way when way.Nodes.Length == 0: |
| | 0 | 119 | | break; |
| | | 120 | | case Way way: |
| | 52 | 121 | | { |
| | | 122 | | // calculate edge type and determine if there is relevant data. |
| | 104 | 123 | | var attributes = way.Tags?.Select(tag => (tag.Key, tag.Value)).ToArray() ?? |
| | 52 | 124 | | Array.Empty<(string key, string value)>(); |
| | 52 | 125 | | var edgeTypeId = edgeTypeMap(attributes); |
| | 52 | 126 | | if (edgeTypeId == emptyEdgeType) continue; |
| | | 127 | | |
| | | 128 | | // cache for pass 2 to avoid recomputing. |
| | 52 | 129 | | wayEdgeTypes[way.Id!.Value] = (edgeTypeId, attributes); |
| | | 130 | | |
| | | 131 | | // mark as core nodes used twice or nodes representing a boundary crossing. |
| | 52 | 132 | | bool? previousInTile = null; |
| | 456 | 133 | | for (var n = 0; n < way.Nodes.Length; n++) |
| | 176 | 134 | | { |
| | 176 | 135 | | var wayNode = way.Nodes[n]; |
| | | 136 | | |
| | | 137 | | // if the node is a barrier, at this way to the barrier nodes. |
| | 176 | 138 | | if (barrierNodes.TryGetValue(wayNode, out var barrierNodeWays)) |
| | 37 | 139 | | { |
| | 37 | 140 | | restrictionMembers[way.Id!.Value] = null; |
| | 37 | 141 | | barrierNodeWays.Add(way); |
| | 37 | 142 | | } |
| | | 143 | | |
| | | 144 | | // check if the node is in the tile or not. |
| | 176 | 145 | | if (!nodeLocations.TryGetValue(wayNode, out var value)) |
| | 0 | 146 | | { |
| | 0 | 147 | | throw new Exception( |
| | 0 | 148 | | $"Node {wayNode} as part of way {way.Id} not found in source data."); |
| | | 149 | | } |
| | 176 | 150 | | var (_, _, inTile) = value; |
| | | 151 | | |
| | | 152 | | // mark as core if used before and mark as used. |
| | 176 | 153 | | if (inTile) |
| | 118 | 154 | | { |
| | | 155 | | // only mark nodes used when in the tile. |
| | 138 | 156 | | if (usedNodes.Contains(wayNode)) coreNodes.Add(wayNode); |
| | 118 | 157 | | usedNodes.Add(wayNode); |
| | | 158 | | |
| | | 159 | | // if first or last node and inside always core. |
| | 118 | 160 | | if (n == 0 || n == way.Nodes.Length - 1) |
| | 77 | 161 | | { |
| | 77 | 162 | | coreNodes.Add(wayNode); |
| | 77 | 163 | | } |
| | 118 | 164 | | } |
| | | 165 | | |
| | | 166 | | // boundary crossing, from outside to in. |
| | 176 | 167 | | if (previousInTile is false && inTile) |
| | 9 | 168 | | { |
| | 9 | 169 | | boundaryNodes.Add(way.Nodes[n - 1]); |
| | 9 | 170 | | coreNodes.Add(way.Nodes[n]); |
| | 9 | 171 | | } |
| | | 172 | | |
| | | 173 | | // boundary crossing, from inside to out. |
| | 176 | 174 | | if (previousInTile is true && inTile == false) |
| | 8 | 175 | | { |
| | 8 | 176 | | coreNodes.Add(way.Nodes[n - 1]); |
| | 8 | 177 | | boundaryNodes.Add(way.Nodes[n]); |
| | 8 | 178 | | } |
| | | 179 | | |
| | 176 | 180 | | previousInTile = inTile; |
| | 176 | 181 | | } |
| | | 182 | | |
| | 52 | 183 | | break; |
| | | 184 | | } |
| | | 185 | | case Relation relation: |
| | 2 | 186 | | if (!restrictionParser.IsRestriction(relation, out _)) continue; |
| | 2 | 187 | | if (relation.Members == null) continue; |
| | | 188 | | |
| | | 189 | | // log ways that are members, we need to keep their edge ids ready |
| | | 190 | | // or store their global ids when the restriction crosses tile boundaries. |
| | 18 | 191 | | foreach (var relationMember in relation.Members) |
| | 6 | 192 | | { |
| | 8 | 193 | | if (relationMember.Type != OsmGeoType.Way) continue; |
| | | 194 | | |
| | 4 | 195 | | restrictionMembers[relationMember.Id] = null; |
| | 4 | 196 | | } |
| | | 197 | | |
| | 2 | 198 | | break; |
| | | 199 | | } |
| | 205 | 200 | | } |
| | | 201 | | |
| | | 202 | | // a second pass where we add all vertices, core nodes and edges. |
| | | 203 | | // we also keep an index of edges that were added and are part of a restriction. |
| | 27 | 204 | | var vertices = new Dictionary<long, VertexId>(); |
| | 27 | 205 | | enumerator.Reset(); |
| | 232 | 206 | | while (enumerator.MoveNext()) |
| | 205 | 207 | | { |
| | 205 | 208 | | var current = enumerator.Current; |
| | | 209 | | |
| | 205 | 210 | | switch (current) |
| | | 211 | | { |
| | | 212 | | case Node node: |
| | 151 | 213 | | if (node.Id == null) throw new Exception("Id cannot be null"); |
| | 151 | 214 | | if (node.Longitude == null) throw new Exception("Longitude cannot be null"); |
| | 151 | 215 | | if (node.Latitude == null) throw new Exception("Latitude cannot be null"); |
| | | 216 | | |
| | | 217 | | // add all core nodes as vertices. |
| | 151 | 218 | | if (coreNodes.Contains(node.Id.Value)) |
| | 85 | 219 | | { |
| | 93 | 220 | | if (!writer.IsInTile(node.Longitude.Value, node.Latitude.Value)) continue; |
| | 77 | 221 | | vertices[node.Id.Value] = writer.AddVertex(node.Longitude.Value, node.Latitude.Value); |
| | | 222 | | |
| | | 223 | | // a core node can be a barrier, check here. |
| | 77 | 224 | | if (barrierNodes.TryGetValue(node.Id.Value, out var barrierWays)) |
| | 17 | 225 | | { |
| | 17 | 226 | | if (!barrierParser.TryParse(node, barrierWays, out var barrier)) |
| | 0 | 227 | | throw new Exception("node in the barriers list is not a barrier"); |
| | 17 | 228 | | globalRestrictions.AddRange(barrier.ToGlobalNetworkRestrictions()); |
| | 17 | 229 | | } |
| | 77 | 230 | | } |
| | | 231 | | |
| | 143 | 232 | | break; |
| | 52 | 233 | | case Way way when way.Nodes.Length == 0: |
| | 0 | 234 | | continue; |
| | | 235 | | case Way way: |
| | 52 | 236 | | { |
| | 93 | 237 | | if (restrictionMembers.ContainsKey(way.Id.Value)) restrictionMembers[way.Id.Value] = way; |
| | | 238 | | |
| | | 239 | | // use cached values from pass 1. |
| | 52 | 240 | | if (!wayEdgeTypes.TryGetValue(way.Id!.Value, out var cached)) continue; |
| | 52 | 241 | | var (edgeTypeId, attributes) = cached; |
| | | 242 | | |
| | | 243 | | // add all boundaries, if any. |
| | 352 | 244 | | for (var n = 1; n < way.Nodes.Length; n++) |
| | 124 | 245 | | { |
| | 124 | 246 | | var tail = way.Nodes[n - 1]; |
| | 124 | 247 | | var head = way.Nodes[n]; |
| | 124 | 248 | | var globalEdgeId = way.CreateGlobalEdgeId(n - 1, n); |
| | | 249 | | |
| | 124 | 250 | | if (boundaryNodes.Contains(tail) && |
| | 124 | 251 | | vertices.TryGetValue(head, out var headVertex)) |
| | 9 | 252 | | { |
| | | 253 | | // outgoing. |
| | 9 | 254 | | writer.AddOutgoingBoundaryCrossing(globalEdgeId, headVertex, |
| | 9 | 255 | | edgeTypeId, attributes); |
| | | 256 | | |
| | 9 | 257 | | boundaryVertices.Add(headVertex); |
| | 9 | 258 | | } |
| | 115 | 259 | | else if (boundaryNodes.Contains(head) && |
| | 115 | 260 | | vertices.TryGetValue(tail, out var tailVertex)) |
| | 8 | 261 | | { |
| | | 262 | | // incoming. |
| | 8 | 263 | | writer.AddIncomingBoundaryCrossing(globalEdgeId, tailVertex, |
| | 8 | 264 | | edgeTypeId, attributes); |
| | | 265 | | |
| | 8 | 266 | | boundaryVertices.Add(tailVertex); |
| | 8 | 267 | | } |
| | 124 | 268 | | } |
| | | 269 | | |
| | | 270 | | // add regular edges, if any. |
| | 52 | 271 | | var shape = new List<(double longitude, double latitude, float? e)>(); |
| | 52 | 272 | | VertexId? previousVertex = null; |
| | 52 | 273 | | var previousVertexIdx = -1; |
| | | 274 | | |
| | 456 | 275 | | for (var n = 0; n < way.Nodes.Length; n++) |
| | 176 | 276 | | { |
| | 176 | 277 | | var wayNode = way.Nodes[n]; |
| | | 278 | | |
| | 176 | 279 | | if (boundaryNodes.Contains(wayNode)) |
| | 20 | 280 | | { |
| | 20 | 281 | | previousVertex = null; |
| | 20 | 282 | | previousVertexIdx = -1; |
| | 20 | 283 | | shape.Clear(); |
| | 20 | 284 | | continue; |
| | | 285 | | } |
| | | 286 | | |
| | 156 | 287 | | if (!vertices.TryGetValue(wayNode, out var vertexId)) |
| | 59 | 288 | | { |
| | 59 | 289 | | var (longitude, latitude, _) = nodeLocations[wayNode]; |
| | | 290 | | |
| | 59 | 291 | | shape.Add((longitude, latitude, null)); |
| | 59 | 292 | | continue; |
| | | 293 | | } |
| | | 294 | | |
| | 97 | 295 | | if (previousVertex != null) |
| | 50 | 296 | | { |
| | 50 | 297 | | var globalEdgeId = way.CreateGlobalEdgeId(previousVertexIdx, n); |
| | 50 | 298 | | var edgeId = writer.AddEdge(previousVertex.Value, vertexId, edgeTypeId, shape, |
| | 50 | 299 | | attributes, globalEdgeId); |
| | 50 | 300 | | shape.Clear(); |
| | | 301 | | |
| | 50 | 302 | | if (restrictionMembers.ContainsKey(way.Id.Value)) |
| | 41 | 303 | | globalRestrictionEdges[globalEdgeId] = edgeId; |
| | 50 | 304 | | } |
| | | 305 | | |
| | 97 | 306 | | previousVertex = vertexId; |
| | 97 | 307 | | previousVertexIdx = n; |
| | 97 | 308 | | } |
| | | 309 | | |
| | 52 | 310 | | break; |
| | | 311 | | } |
| | | 312 | | case Relation relation: |
| | 2 | 313 | | var result = restrictionParser.TryParse(relation, (wayId) => |
| | 4 | 314 | | restrictionMembers.GetValueOrDefault(wayId), |
| | 2 | 315 | | out var osmTurnRestriction); |
| | | 316 | | |
| | 2 | 317 | | if (result.IsError) continue; |
| | 2 | 318 | | if (!result.Value) continue; |
| | 2 | 319 | | if (osmTurnRestriction == null) |
| | 0 | 320 | | throw new Exception("Parsing restriction was successful but not returned"); |
| | | 321 | | |
| | 2 | 322 | | globalRestrictions.AddRange(osmTurnRestriction.ToGlobalNetworkRestrictions()); |
| | 2 | 323 | | break; |
| | | 324 | | } |
| | 197 | 325 | | } |
| | | 326 | | |
| | 27 | 327 | | var tileEnumerator = writer.GetEnumerator(); |
| | 27 | 328 | | var r = 0; |
| | 63 | 329 | | while (r < globalRestrictions.Count) |
| | 36 | 330 | | { |
| | 36 | 331 | | var globalNetworkRestriction = globalRestrictions[r]; |
| | | 332 | | |
| | | 333 | | // try to convert first, and see if all edges are there |
| | 36 | 334 | | if (!globalNetworkRestriction.TryBuildNetworkRestriction(GetEdgeForGlobalEdge, out var networkRestriction)) |
| | 14 | 335 | | { |
| | | 336 | | // one of it's edge is a boundary edge and we are working on a single tile right now. |
| | 14 | 337 | | r++; |
| | 14 | 338 | | continue; |
| | | 339 | | } |
| | | 340 | | |
| | | 341 | | // TODO: log something? |
| | | 342 | | // all the edges in the restriction are inside this tile. |
| | 22 | 343 | | if (networkRestriction!.Count < 2) |
| | 0 | 344 | | { |
| | 0 | 345 | | globalRestrictions.RemoveAt(r); |
| | 0 | 346 | | continue; |
| | | 347 | | } |
| | | 348 | | |
| | | 349 | | // get last edge and turn cost vertex. |
| | 22 | 350 | | var last = networkRestriction[^1]; |
| | 22 | 351 | | var lastEdge = writer.GetEdge(last.edge, last.forward); |
| | 22 | 352 | | var turnCostVertex = lastEdge.Tail; |
| | | 353 | | |
| | | 354 | | // only add turn costs around vertices that are in the current tile. |
| | 22 | 355 | | if (turnCostVertex.TileId != writer.TileId) |
| | 0 | 356 | | { |
| | 0 | 357 | | r++; |
| | 0 | 358 | | continue; |
| | | 359 | | } |
| | | 360 | | |
| | 22 | 361 | | var secondToLast = networkRestriction[^2]; |
| | 22 | 362 | | if (networkRestriction.IsProhibitory) |
| | 22 | 363 | | { |
| | | 364 | | // easy, we only add a single cost. |
| | 22 | 365 | | var costs = new uint[,] { { 0, 1 }, { 0, 0 } }; |
| | 22 | 366 | | writer.AddTurnCosts(turnCostVertex, networkRestriction.Attributes, |
| | 22 | 367 | | [secondToLast.edge, last.edge], costs, |
| | 22 | 368 | | networkRestriction.Take(networkRestriction.Count - 2).Select(x => x.edge)); |
| | | 369 | | |
| | | 370 | | // best case, the restriction was converted and can be removed. |
| | 22 | 371 | | globalRestrictions.RemoveAt(r); |
| | 22 | 372 | | } |
| | | 373 | | else |
| | 0 | 374 | | { |
| | | 375 | | // hard, we need to add a cost for every *other* edge than then one in the restriction. |
| | 0 | 376 | | tileEnumerator.MoveTo(secondToLast.edge, secondToLast.forward); |
| | 0 | 377 | | var to = tileEnumerator.Head; |
| | | 378 | | |
| | | 379 | | // check if the vertex of the restriction is a boundary vertex. |
| | 0 | 380 | | if (boundaryVertices.Contains(to)) |
| | 0 | 381 | | { |
| | 0 | 382 | | r++; |
| | 0 | 383 | | continue; |
| | | 384 | | } |
| | | 385 | | |
| | | 386 | | // add all the edge other than the one that is in the restriction as restricted turns. |
| | 0 | 387 | | tileEnumerator.MoveTo(to); |
| | 0 | 388 | | while (tileEnumerator.MoveNext()) |
| | 0 | 389 | | { |
| | 0 | 390 | | if (tileEnumerator.EdgeId == secondToLast.edge || |
| | 0 | 391 | | tileEnumerator.EdgeId == lastEdge.EdgeId) continue; |
| | | 392 | | |
| | | 393 | | // easy, we only add a single cost. |
| | 0 | 394 | | var costs = new uint[,] { { 0, 1 }, { 0, 0 } }; |
| | 0 | 395 | | writer.AddTurnCosts(turnCostVertex, networkRestriction.Attributes, |
| | 0 | 396 | | [secondToLast.edge, tileEnumerator.EdgeId], costs, |
| | 0 | 397 | | networkRestriction.Take(networkRestriction.Count - 2).Select(x => x.edge)); |
| | 0 | 398 | | } |
| | | 399 | | |
| | 0 | 400 | | globalRestrictions.RemoveAt(r); |
| | 0 | 401 | | } |
| | 22 | 402 | | } |
| | | 403 | | |
| | | 404 | | // add global restrictions. |
| | | 405 | | // also cache resolved edge ids per chain position for the runtime retry. |
| | 109 | 406 | | foreach (var globalNetworkRestriction in globalRestrictions) |
| | 14 | 407 | | { |
| | 14 | 408 | | var edges = new (GlobalEdgeId, EdgeId?)[globalNetworkRestriction.Count]; |
| | 84 | 409 | | for (var i = 0; i < globalNetworkRestriction.Count; i++) |
| | 28 | 410 | | { |
| | 28 | 411 | | var x = globalNetworkRestriction[i]; |
| | 28 | 412 | | var localEdge = GetEdgeForGlobalEdge(x, i == 0); |
| | 28 | 413 | | edges[i] = (x, localEdge?.edge); |
| | 28 | 414 | | } |
| | | 415 | | |
| | 14 | 416 | | writer.AddGlobalRestriction(edges, globalNetworkRestriction.IsProhibitory, |
| | 14 | 417 | | globalNetworkRestriction.Attributes); |
| | 14 | 418 | | } |
| | | 419 | | |
| | 27 | 420 | | return; |
| | | 421 | | |
| | | 422 | | // convert network restrictions to turn costs. |
| | | 423 | | (EdgeId edge, bool forward)? GetEdgeForGlobalEdge(GlobalEdgeId globalEdgeId, bool isFirst) |
| | 93 | 424 | | { |
| | 93 | 425 | | if (globalRestrictionEdges.TryGetValue(globalEdgeId, out var edgeId) && edgeId.HasValue) |
| | 21 | 426 | | { |
| | 21 | 427 | | return (edgeId.Value, true); |
| | | 428 | | } |
| | | 429 | | |
| | 72 | 430 | | if (globalRestrictionEdges.TryGetValue(globalEdgeId.GetInverted(), out edgeId) && edgeId.HasValue) |
| | 22 | 431 | | { |
| | 22 | 432 | | return (edgeId.Value, false); |
| | | 433 | | } |
| | | 434 | | |
| | 50 | 435 | | return GlobalRestrictionExtensions.WalkFromAnchor(globalEdgeId, isFirst, TryGet); |
| | | 436 | | |
| | | 437 | | bool TryGet(GlobalEdgeId geid, out EdgeId result) |
| | 145 | 438 | | { |
| | 145 | 439 | | if (globalRestrictionEdges.TryGetValue(geid, out var v) && v.HasValue) |
| | 22 | 440 | | { |
| | 22 | 441 | | result = v.Value; |
| | 22 | 442 | | return true; |
| | | 443 | | } |
| | 123 | 444 | | result = default; |
| | 123 | 445 | | return false; |
| | 145 | 446 | | } |
| | 93 | 447 | | } |
| | 27 | 448 | | } |
| | | 449 | | |
| | | 450 | | internal static IStandaloneNetworkTileEnumerator GetEnumerator(this StandaloneNetworkTileWriter writer) |
| | 27 | 451 | | { |
| | 27 | 452 | | return writer.GetResultingTile().GetEnumerator(); |
| | 27 | 453 | | } |
| | | 454 | | } |