< Summary

Class:Itinero.Network.EdgeId
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Network/EdgeId.cs
Covered lines:24
Uncovered lines:20
Coverable lines:44
Total lines:145
Line coverage:54.5% (24 of 44)
Covered branches:4
Total branches:8
Branch coverage:50% (4 of 8)
Tag:224_14471318300

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
CrossEdgeId(...)100%1100%
get_TileId()100%1100%
get_LocalId()100%1100%
.cctor()100%1100%
IsEmpty()100%10%
ToString()0%20%
op_Equality(...)100%2100%
op_Inequality(...)100%1100%
Equals(...)100%2100%
Equals(...)0%20%
GetHashCode()100%1100%
Encode()100%10%
Decode(...)100%10%

File(s)

/home/runner/work/routing2/routing2/src/Itinero/Network/EdgeId.cs

#LineLine coverage
 1using System;
 2
 3namespace Itinero.Network;
 4
 5/// <summary>
 6/// Represents a edge id composed of a tile id and a local id.
 7/// </summary>
 8public readonly struct EdgeId : IEquatable<EdgeId>
 9{
 10    /// <summary>
 11    /// The minimum id for edges crossing tile boundaries.
 12    /// </summary>
 13    internal const uint MinCrossId = MaxLocalId + 1;
 14
 15    /// <summary>
 16    /// The maximum number of internal edges in one tile.
 17    /// </summary>
 18    internal const uint MaxLocalId = (uint.MaxValue / 2) - 1;
 19
 20    /// <summary>
 21    /// Creates a new edge id.
 22    /// </summary>
 23    /// <param name="tileId">The tile id.</param>
 24    /// <param name="localId">The local id.</param>
 25    public EdgeId(uint tileId, uint localId)
 98726    {
 98727        this.TileId = tileId;
 98728        this.LocalId = localId;
 98729    }
 30
 31    /// <summary>
 32    /// Creates a new cross edge id.
 33    /// </summary>
 34    /// <param name="tileId">The tile id.</param>
 35    /// <param name="localId">The local id.</param>
 36    /// <returns>An edge id represented as a id crossing tiles.</returns>
 37    public static EdgeId CrossEdgeId(uint tileId, uint localId)
 1138    {
 1139        return new EdgeId(tileId, EdgeId.MinCrossId + localId);
 1140    }
 41
 42    /// <summary>
 43    /// Gets or sets the tile id.
 44    /// </summary>
 325445    public uint TileId { get; }
 46
 47    /// <summary>
 48    /// Gets or sets the local id.
 49    /// </summary>
 343650    public uint LocalId { get; }
 51
 52    /// <summary>
 53    /// Returns an empty edge id.
 54    /// </summary>
 155    public static readonly EdgeId Empty = new(uint.MaxValue, uint.MaxValue);
 56
 57    /// <summary>
 58    /// Returns true if this edge id is empty.
 59    /// </summary>
 60    /// <returns></returns>
 61    public bool IsEmpty()
 062    {
 063        return this.TileId == uint.MaxValue;
 064    }
 65
 66    /// <summary>
 67    /// Returns a human readable description.
 68    /// </summary>
 69    /// <returns></returns>
 70    public override string ToString()
 071    {
 072        if (this.LocalId >= MinCrossId)
 073        {
 074            return $"{this.LocalId} (X {this.LocalId - MinCrossId}) @ {this.TileId} ";
 75        }
 76
 077        return $"{this.LocalId} @ {this.TileId}";
 078    }
 79
 80    /// <summary>
 81    /// Returns true if the two edges represent the same id.
 82    /// </summary>
 83    /// <returns></returns>
 84    public static bool operator ==(EdgeId vertex1, EdgeId vertex2)
 41285    {
 41286        return vertex1.LocalId == vertex2.LocalId &&
 41287               vertex1.TileId == vertex2.TileId;
 41288    }
 89
 90    /// <summary>
 91    /// Returns true if the two edges don't represent the same id.
 92    /// </summary>
 93    /// <returns></returns>
 94    public static bool operator !=(EdgeId vertex1, EdgeId vertex2)
 7495    {
 7496        return !(vertex1 == vertex2);
 7497    }
 98
 99    /// <summary>
 100    /// Returns true if the given edge represent the same id.
 101    /// </summary>
 102    /// <param name="other"></param>
 103    /// <returns></returns>
 104    public bool Equals(EdgeId other)
 405105    {
 405106        return this.LocalId == other.LocalId && this.TileId == other.TileId;
 405107    }
 108
 109    /// <inheritdoc/>
 110    public override bool Equals(object obj)
 0111    {
 0112        return obj is EdgeId other && this.Equals(other);
 0113    }
 114
 115    /// <inheritdoc/>
 116    public override int GetHashCode()
 467117    {
 118        unchecked
 467119        {
 467120            return ((int)this.TileId * 397) ^ (int)this.LocalId;
 121        }
 467122    }
 123
 124    /// <summary>
 125    /// Encodes the info in this edge into one 64bit unsigned integer.
 126    /// </summary>
 127    /// <returns>An encoded version of this edge.</returns>
 128    internal ulong Encode()
 0129    {
 0130        return ((ulong)this.TileId << 32) + this.LocalId;
 0131    }
 132
 133    /// <summary>
 134    /// Decodes the given encoded edge id.
 135    /// </summary>
 136    /// <param name="encoded">The encoded version an edge.</param>
 137    /// <returns>The decoded version of edge.</returns>
 138    internal static EdgeId Decode(ulong encoded)
 0139    {
 0140        var tileId = (uint)(encoded >> 32);
 0141        var localId = (uint)(encoded - ((ulong)tileId << 32));
 142
 0143        return new EdgeId(tileId, localId);
 0144    }
 145}