< Summary

Class:Itinero.Network.VertexId
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Network/VertexId.cs
Covered lines:35
Uncovered lines:10
Coverable lines:45
Total lines:126
Line coverage:77.7% (35 of 45)
Covered branches:2
Total branches:8
Branch coverage:25% (2 of 8)
Tag:224_14471318300

Metrics

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

File(s)

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

#LineLine coverage
 1using System;
 2
 3namespace Itinero.Network;
 4
 5// TODO: the internal graph structure bleeds out via the tiled ids.
 6/// <summary>
 7/// Represents a vertex ID composed of a tile ID and a vertex ID.
 8/// </summary>
 9public readonly struct VertexId : IEquatable<VertexId>
 10{
 11    /// <summary>
 12    /// Creates a new vertex id.
 13    /// </summary>
 14    /// <param name="tileId">The tile id.</param>
 15    /// <param name="localId">The local id.</param>
 16    public VertexId(uint tileId, uint localId)
 310717    {
 310718        this.TileId = tileId;
 310719        this.LocalId = localId;
 310720    }
 21
 22    /// <summary>
 23    /// Gets or sets the tile id.
 24    /// </summary>
 760825    public uint TileId { get; }
 26
 27    /// <summary>
 28    /// Gets or sets the local id.
 29    /// </summary>
 558530    public uint LocalId { get; }
 31
 32    /// <summary>
 33    /// Returns an empty vertex id.
 34    /// </summary>
 2435    public static VertexId Empty => new(uint.MaxValue, uint.MaxValue);
 36
 37    /// <summary>
 38    /// Returns true if this vertex id is empty.
 39    /// </summary>
 40    /// <returns></returns>
 41    public bool IsEmpty()
 5842    {
 5843        return this.TileId == uint.MaxValue;
 5844    }
 45
 46    /// <summary>
 47    /// Returns a human readable description.
 48    /// </summary>
 49    /// <returns></returns>
 50    public override string ToString()
 751    {
 752        return $"{this.LocalId} @ {this.TileId}";
 753    }
 54
 55    /// <summary>
 56    /// Returns true if the two vertices represent the same id.
 57    /// </summary>
 58    /// <returns></returns>
 59    public static bool operator ==(VertexId vertex1, VertexId vertex2)
 4960    {
 4961        return vertex1.LocalId == vertex2.LocalId &&
 4962               vertex1.TileId == vertex2.TileId;
 4963    }
 64
 65    public static bool operator !=(VertexId vertex1, VertexId vertex2)
 4966    {
 4967        return !(vertex1 == vertex2);
 4968    }
 69
 70    public bool Equals(VertexId other)
 14071    {
 14072        return this.LocalId == other.LocalId && this.TileId == other.TileId;
 14073    }
 74
 75    public override bool Equals(object obj)
 076    {
 077        if (obj is null)
 078        {
 079            return false;
 80        }
 81
 082        return obj is VertexId other && this.Equals(other);
 083    }
 84
 85    public override int GetHashCode()
 25486    {
 87        unchecked
 25488        {
 25489            return ((int)this.TileId * 397) ^ (int)this.LocalId;
 90        }
 25491    }
 92
 93    /// <summary>
 94    /// Encodes the info in this vertex into one 64bit unsigned integer.
 95    /// </summary>
 96    /// <returns>An encoded version of this vertex.</returns>
 97    internal ulong Encode()
 1398    {
 1399        return ((ulong)this.TileId << 32) + this.LocalId;
 13100    }
 101
 102    /// <summary>
 103    /// Decodes the given encoded vertex id.
 104    /// </summary>
 105    /// <param name="encoded">The encoded version a vertex.</param>
 106    /// <param name="tileId">The tile id.</param>
 107    /// <param name="localId">The local id.</param>
 108    /// <returns>The decoded version of the vertex.</returns>
 109    internal static void Decode(ulong encoded, out uint tileId, out uint localId)
 14110    {
 14111        tileId = (uint)(encoded >> 32);
 14112        var tileOffset = (ulong)tileId << 32;
 14113        localId = (uint)(encoded - tileOffset);
 14114    }
 115
 116    /// <summary>
 117    /// Decodes the given encoded vertex id.
 118    /// </summary>
 119    /// <param name="encoded">The encoded version a vertex.</param>
 120    /// <returns>The decoded version of the vertex.</returns>
 121    internal static VertexId Decode(ulong encoded)
 0122    {
 0123        Decode(encoded, out var tileId, out var localId);
 0124        return new VertexId(tileId, localId);
 0125    }
 126}