| | | 1 | | using System; |
| | | 2 | | using Itinero.Network.Tiles.Standalone.Global; |
| | | 3 | | using OsmSharp; |
| | | 4 | | |
| | | 5 | | namespace Itinero.IO.Osm.Tiles; |
| | | 6 | | |
| | | 7 | | internal static class GlobalEdgeIdExtensions |
| | | 8 | | { |
| | | 9 | | public static (Guid guid, bool forward) GenerateGlobalEdgeIdAndDirection(this Way way, int node1Idx, int node2Idx) |
| | 0 | 10 | | { |
| | 0 | 11 | | var forward = node1Idx < node2Idx; |
| | 0 | 12 | | return forward ? (way.GenerateGlobalEdgeId(node1Idx, node2Idx), true) : (way.GenerateGlobalEdgeId(node2Idx, node |
| | 0 | 13 | | } |
| | | 14 | | |
| | | 15 | | public static (Guid guid, bool forward) GenerateGlobalEdgeIdAndDirection(long wayId, int node1Idx, int node2Idx) |
| | 0 | 16 | | { |
| | 0 | 17 | | var forward = node1Idx < node2Idx; |
| | 0 | 18 | | return forward ? (GenerateGlobalEdgeId(wayId, node1Idx, node2Idx), true) : (GenerateGlobalEdgeId(wayId, node2Idx |
| | 0 | 19 | | } |
| | | 20 | | |
| | | 21 | | public static Guid GenerateGlobalEdgeId(this Way way, int node1Idx, int node2Idx) |
| | 0 | 22 | | { |
| | 0 | 23 | | return GenerateGlobalEdgeId(way.Id.Value, node1Idx, node2Idx); |
| | 0 | 24 | | } |
| | | 25 | | |
| | | 26 | | public static GlobalEdgeId CreateGlobalEdgeId(this Way way, int node1Idx, int node2Idx) |
| | 5965 | 27 | | { |
| | 5965 | 28 | | return GlobalEdgeId.Create(way.Id!.Value, node1Idx, node2Idx); |
| | 5965 | 29 | | } |
| | | 30 | | |
| | | 31 | | public static Guid GenerateGlobalEdgeId(long wayId, int node1Idx, int node2Idx) |
| | 0 | 32 | | { |
| | 0 | 33 | | if (node1Idx >= node2Idx) throw new ArgumentException("edge is not given in forward direction"); |
| | | 34 | | |
| | 0 | 35 | | var data = new byte[16]; |
| | 0 | 36 | | BitConverter.GetBytes(wayId).CopyTo(data.AsSpan()); |
| | 0 | 37 | | BitConverter.GetBytes(node1Idx).CopyTo(data.AsSpan(8)); |
| | 0 | 38 | | BitConverter.GetBytes(node2Idx).CopyTo(data.AsSpan(12)); |
| | | 39 | | |
| | 0 | 40 | | return new Guid(data); |
| | 0 | 41 | | } |
| | | 42 | | |
| | | 43 | | public static void ParseGlobalId(this Guid guid, out long wayId, out int node1Idx, out int node2Idx) |
| | 0 | 44 | | { |
| | 0 | 45 | | var bytes = guid.ToByteArray(); |
| | 0 | 46 | | wayId = BitConverter.ToInt64(bytes, 0); |
| | 0 | 47 | | node1Idx = BitConverter.ToInt32(bytes, 8); |
| | 0 | 48 | | node2Idx = BitConverter.ToInt32(bytes, 12); |
| | 0 | 49 | | } |
| | | 50 | | } |