| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | namespace Itinero.Network.Tiles.Standalone.Global; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// A global edge id. |
| | | 7 | | /// </summary> |
| | | 8 | | public readonly struct GlobalEdgeId : IEquatable<GlobalEdgeId> |
| | | 9 | | { |
| | | 10 | | |
| | | 11 | | private GlobalEdgeId(long edgeId, ushort tail, ushort head) |
| | 29989 | 12 | | { |
| | 29989 | 13 | | this.EdgeId = edgeId; |
| | 29989 | 14 | | this.Tail = tail; |
| | 29989 | 15 | | this.Head = head; |
| | 29989 | 16 | | } |
| | | 17 | | |
| | | 18 | | public static GlobalEdgeId Create(long edgeId, uint tail, uint head) |
| | 0 | 19 | | { |
| | 0 | 20 | | if (tail > ushort.MaxValue) throw new ArgumentOutOfRangeException(nameof(tail)); |
| | 0 | 21 | | if (head > ushort.MaxValue) throw new ArgumentOutOfRangeException(nameof(head)); |
| | | 22 | | |
| | 0 | 23 | | return new GlobalEdgeId(edgeId, (ushort)tail, (ushort)head); |
| | 0 | 24 | | } |
| | | 25 | | |
| | | 26 | | public static GlobalEdgeId Create(long edgeId, int tail, int head) |
| | 19853 | 27 | | { |
| | 19853 | 28 | | if (tail > ushort.MaxValue) throw new ArgumentOutOfRangeException(nameof(tail)); |
| | 19853 | 29 | | if (head > ushort.MaxValue) throw new ArgumentOutOfRangeException(nameof(head)); |
| | | 30 | | |
| | 19853 | 31 | | return new GlobalEdgeId(edgeId, (ushort)tail, (ushort)head); |
| | 19853 | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// The edge id, the way id when using OSM. |
| | | 36 | | /// </summary> |
| | 54179 | 37 | | public long EdgeId { get; } |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// The tail, the index of first node in the way representing the segment when using OSM. |
| | | 41 | | /// </summary> |
| | 48631 | 42 | | public ushort Tail { get; } |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// The tail, the index of last node in the way representing the segment when using OSM. |
| | | 46 | | /// </summary> |
| | 44767 | 47 | | public ushort Head { get; } |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// Gets the inverted edge, tail and head switched. |
| | | 51 | | /// </summary> |
| | | 52 | | /// <returns></returns> |
| | | 53 | | public GlobalEdgeId GetInverted() |
| | 10136 | 54 | | { |
| | 10136 | 55 | | return new GlobalEdgeId(this.EdgeId, this.Head, this.Tail); |
| | 10136 | 56 | | } |
| | | 57 | | |
| | | 58 | | /// <inheritdoc /> |
| | | 59 | | public override string ToString() |
| | 0 | 60 | | { |
| | 0 | 61 | | return $"{this.EdgeId}_{this.Tail}->{this.Head}"; |
| | 0 | 62 | | } |
| | | 63 | | |
| | | 64 | | public bool Equals(GlobalEdgeId other) |
| | 12726 | 65 | | { |
| | 12726 | 66 | | return this.EdgeId == other.EdgeId && this.Tail == other.Tail && this.Head == other.Head; |
| | 12726 | 67 | | } |
| | | 68 | | |
| | | 69 | | public override bool Equals(object? obj) |
| | 0 | 70 | | { |
| | 0 | 71 | | return obj is GlobalEdgeId other && this.Equals(other); |
| | 0 | 72 | | } |
| | | 73 | | |
| | | 74 | | public override int GetHashCode() |
| | 18591 | 75 | | { |
| | 18591 | 76 | | return HashCode.Combine(this.EdgeId, this.Tail, this.Head); |
| | 18591 | 77 | | } |
| | | 78 | | |
| | | 79 | | public static bool operator ==(GlobalEdgeId left, GlobalEdgeId right) |
| | 9229 | 80 | | { |
| | 9229 | 81 | | return left.Equals(right); |
| | 9229 | 82 | | } |
| | | 83 | | |
| | | 84 | | public static bool operator !=(GlobalEdgeId left, GlobalEdgeId right) |
| | 0 | 85 | | { |
| | 0 | 86 | | return !left.Equals(right); |
| | 0 | 87 | | } |
| | | 88 | | } |