< Summary

Information
Class: Gravitas.Colliders.ColliderHierarchyKey
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/Colliders/Hierarchy/ColliderHierarchyKey.cs
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 106
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
.ctor(...)100%11100%
get_Dimension()100%11100%
get_Id()100%11100%
get_Packed()100%22100%
get_IsValid()100%22100%
get_Is3D()100%11100%
get_Is2D()100%11100%
Create3D(...)100%11100%
Create2D(...)100%11100%
FromPacked(...)100%22100%
Equals(...)100%22100%
Equals(...)100%22100%
GetHashCode()100%11100%
op_Equality(...)100%11100%
op_Inequality(...)100%11100%

File(s)

/home/runner/work/Gravitas/Gravitas/src/Gravitas/Colliders/Hierarchy/ColliderHierarchyKey.cs

#LineLine coverage
 1//=======================================================================
 2// ColliderHierarchyKey.cs
 3//=======================================================================
 4// MIT License, Copyright (c) 2026-present David Oravsky (mrdav30)
 5// See LICENSE file in the project root for full license information.
 6//=======================================================================
 7
 8using System;
 9using System.Runtime.CompilerServices;
 10
 11namespace Gravitas.Colliders;
 12
 13/// <summary>
 14/// Identifies a collider within its dimension for hierarchy links.
 15/// </summary>
 16internal readonly struct ColliderHierarchyKey : IEquatable<ColliderHierarchyKey>
 17{
 18    private const byte NoneDimension = 0;
 19    private const byte ThreeDDimension = 1;
 20    private const byte TwoDDimension = 2;
 21
 122    public static readonly ColliderHierarchyKey None = new(NoneDimension, -1);
 23
 24    private readonly byte _dimension;
 25    private readonly int _id;
 26
 27    private ColliderHierarchyKey(byte dimension, int id)
 28    {
 578381829        _dimension = dimension;
 578381830        _id = id;
 578381831    }
 32
 33    public byte Dimension
 34    {
 35        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1679636        get => _dimension;
 37    }
 38
 39    public int Id
 40    {
 41        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1683142        get => _id;
 43    }
 44
 45    public ulong Packed
 46    {
 47        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 14348        get => IsValid ? ((ulong)_dimension << 32) | (uint)_id : 0UL;
 49    }
 50
 51    public bool IsValid
 52    {
 53        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 869505354        get => _dimension != NoneDimension && _id >= 0;
 55    }
 56
 57    public bool Is3D
 58    {
 59        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1112360        get => _dimension == ThreeDDimension;
 61    }
 62
 63    public bool Is2D
 64    {
 65        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 570966        get => _dimension == TwoDDimension;
 67    }
 68
 69    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 70    public static ColliderHierarchyKey Create3D(int id)
 71    {
 535309872        ChronicleGuard.ThrowIfNegative(id, nameof(id));
 535309773        return new ColliderHierarchyKey(ThreeDDimension, id);
 74    }
 75
 76    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 77    public static ColliderHierarchyKey Create2D(int id)
 78    {
 43071179        ChronicleGuard.ThrowIfNegative(id, nameof(id));
 43071080        return new ColliderHierarchyKey(TwoDDimension, id);
 81    }
 82
 83    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 84    public static ColliderHierarchyKey FromPacked(ulong packed)
 85    {
 1186        if (packed == 0UL)
 187            return None;
 88
 1089        return new ColliderHierarchyKey((byte)(packed >> 32), (int)(uint)packed);
 90    }
 91
 92    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 863477693    public bool Equals(ColliderHierarchyKey other) => _dimension == other._dimension && _id == other._id;
 94
 95    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1696    public override bool Equals(object? obj) => obj is ColliderHierarchyKey other && Equals(other);
 97
 98    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 299    public override int GetHashCode() => Packed.GetHashCode();
 100
 101    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 8634683102    public static bool operator ==(ColliderHierarchyKey left, ColliderHierarchyKey right) => left.Equals(right);
 103
 104    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 79105    public static bool operator !=(ColliderHierarchyKey left, ColliderHierarchyKey right) => !left.Equals(right);
 106}