< 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: 103
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
 13internal readonly struct ColliderHierarchyKey : IEquatable<ColliderHierarchyKey>
 14{
 15    private const byte NoneDimension = 0;
 16    private const byte ThreeDDimension = 1;
 17    private const byte TwoDDimension = 2;
 18
 119    public static readonly ColliderHierarchyKey None = new(NoneDimension, -1);
 20
 21    private readonly byte _dimension;
 22    private readonly int _id;
 23
 24    private ColliderHierarchyKey(byte dimension, int id)
 25    {
 23813126        _dimension = dimension;
 23813127        _id = id;
 23813128    }
 29
 30    public byte Dimension
 31    {
 32        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 305333        get => _dimension;
 34    }
 35
 36    public int Id
 37    {
 38        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 308339        get => _id;
 40    }
 41
 42    public ulong Packed
 43    {
 44        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 13245        get => IsValid ? ((ulong)_dimension << 32) | (uint)_id : 0UL;
 46    }
 47
 48    public bool IsValid
 49    {
 50        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 35558451        get => _dimension != NoneDimension && _id >= 0;
 52    }
 53
 54    public bool Is3D
 55    {
 56        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 227457        get => _dimension == ThreeDDimension;
 58    }
 59
 60    public bool Is2D
 61    {
 62        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 80763        get => _dimension == TwoDDimension;
 64    }
 65
 66    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 67    public static ColliderHierarchyKey Create3D(int id)
 68    {
 21352169        SwiftThrowHelper.ThrowIfNegative(id, nameof(id));
 21352070        return new ColliderHierarchyKey(ThreeDDimension, id);
 71    }
 72
 73    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 74    public static ColliderHierarchyKey Create2D(int id)
 75    {
 2460676        SwiftThrowHelper.ThrowIfNegative(id, nameof(id));
 2460577        return new ColliderHierarchyKey(TwoDDimension, id);
 78    }
 79
 80    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 81    public static ColliderHierarchyKey FromPacked(ulong packed)
 82    {
 683        if (packed == 0UL)
 184            return None;
 85
 586        return new ColliderHierarchyKey((byte)(packed >> 32), (int)(uint)packed);
 87    }
 88
 89    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 33908590    public bool Equals(ColliderHierarchyKey other) => _dimension == other._dimension && _id == other._id;
 91
 92    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1693    public override bool Equals(object? obj) => obj is ColliderHierarchyKey other && Equals(other);
 94
 95    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 296    public override int GetHashCode() => Packed.GetHashCode();
 97
 98    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 33900799    public static bool operator ==(ColliderHierarchyKey left, ColliderHierarchyKey right) => left.Equals(right);
 100
 101    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 64102    public static bool operator !=(ColliderHierarchyKey left, ColliderHierarchyKey right) => !left.Equals(right);
 103}