< Summary

Class:Itinero.Network.VertexId
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Network/VertexId.cs
Covered lines:39
Uncovered lines:6
Coverable lines:45
Total lines:126
Line coverage:86.6% (39 of 45)
Covered branches:5
Total branches:8
Branch coverage:62.5% (5 of 8)
Tag:263_26948838820

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(...)100%2100%
op_Inequality(...)100%1100%
Equals(...)50%2100%
Equals(...)50%466.66%
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)
 1739425917    {
 1739425918        this.TileId = tileId;
 1739425919        this.LocalId = localId;
 1739425920    }
 21
 22    /// <summary>
 23    /// Gets or sets the tile id.
 24    /// </summary>
 2738461625    public uint TileId { get; }
 26
 27    /// <summary>
 28    /// Gets or sets the local id.
 29    /// </summary>
 2067424630    public uint LocalId { get; }
 31
 32    /// <summary>
 33    /// Returns an empty vertex id.
 34    /// </summary>
 13642435    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()
 15781942    {
 15781943        return this.TileId == uint.MaxValue;
 15781944    }
 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)
 62436160    {
 62436161        return vertex1.LocalId == vertex2.LocalId &&
 62436162               vertex1.TileId == vertex2.TileId;
 62436163    }
 64
 65    public static bool operator !=(VertexId vertex1, VertexId vertex2)
 62206966    {
 62206967        return !(vertex1 == vertex2);
 62206968    }
 69
 70    public bool Equals(VertexId other)
 34502071    {
 34502072        return this.LocalId == other.LocalId && this.TileId == other.TileId;
 34502073    }
 74
 75    public override bool Equals(object obj)
 3876    {
 3877        if (obj is null)
 078        {
 079            return false;
 80        }
 81
 3882        return obj is VertexId other && this.Equals(other);
 3883    }
 84
 85    public override int GetHashCode()
 137671386    {
 87        unchecked
 137671388        {
 137671389            return ((int)this.TileId * 397) ^ (int)this.LocalId;
 90        }
 137671391    }
 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()
 468598    {
 468599        return ((ulong)this.TileId << 32) + this.LocalId;
 4685100    }
 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)
 113111110    {
 113111111        tileId = (uint)(encoded >> 32);
 113111112        var tileOffset = (ulong)tileId << 32;
 113111113        localId = (uint)(encoded - tileOffset);
 113111114    }
 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}