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