< Summary

Information
Class: Gravitas.CollisionHandling.ContactGroupKey
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Contacts/3D/ContactGroupKey.cs
Line coverage
100%
Covered lines: 27
Uncovered lines: 0
Coverable lines: 27
Total lines: 58
Line coverage: 100%
Branch coverage
100%
Covered branches: 24
Total branches: 24
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_SourceIdA()100%11100%
get_SourceIdB()100%11100%
CompareTo(...)100%1212100%
Remap(...)100%1212100%

File(s)

/home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Contacts/3D/ContactGroupKey.cs

#LineLine coverage
 1//=======================================================================
 2// ContactGroupKey.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
 8namespace Gravitas.CollisionHandling;
 9
 10/// <summary>Collision-free local provenance for one admitted surface region.</summary>
 11internal readonly struct ContactGroupKey
 12{
 13    internal ContactGroupKey(int namespaceA, int namespaceB, int surfaceA = 0,
 14        int surfaceB = 0, int region = 0, int sourceIdA = 0, int sourceIdB = 0,
 15        int sourceOrderA = 0, int sourceOrderB = 0)
 16    {
 37636817        NamespaceA = namespaceA;
 37636818        NamespaceB = namespaceB;
 37636819        SurfaceA = surfaceA;
 37636820        SurfaceB = surfaceB;
 37636821        Region = region;
 37636822        _orderedSourceA = ((ulong)(uint)sourceOrderA << 32) | (uint)sourceIdA;
 37636823        _orderedSourceB = ((ulong)(uint)sourceOrderB << 32) | (uint)sourceIdB;
 37636824    }
 25
 26    internal readonly int NamespaceA, NamespaceB, SurfaceA, SurfaceB, Region;
 27    // Compound namespaces identify leaves. Supplier registry IDs plus one are
 28    // normalized to replay ordinals only when hashing; zero means no supplier.
 27882429    internal int SourceIdA => (int)(uint)_orderedSourceA;
 27630030    internal int SourceIdB => (int)(uint)_orderedSourceB;
 31    // Joined suppliers sort by live logical registration, independently of recycled
 32    // registry slots. Keep the actual ID as the low-word uniqueness/lookup key;
 33    // ordinary groups retain their existing order and two source comparisons.
 34    private readonly ulong _orderedSourceA, _orderedSourceB;
 35
 36    internal int CompareTo(in ContactGroupKey other)
 37    {
 255471938        int order = NamespaceA.CompareTo(other.NamespaceA);
 255848939        if (order != 0) return order;
 255094940        order = NamespaceB.CompareTo(other.NamespaceB);
 255313141        if (order != 0) return order;
 254876742        order = SurfaceA.CompareTo(other.SurfaceA);
 257737343        if (order != 0) return order;
 252016144        order = SurfaceB.CompareTo(other.SurfaceB);
 272857345        if (order != 0) return order;
 231174946        order = Region.CompareTo(other.Region);
 235337947        if (order != 0) return order;
 227011948        order = _orderedSourceA.CompareTo(other._orderedSourceA);
 227011949        return order != 0 ? order : _orderedSourceB.CompareTo(other._orderedSourceB);
 50    }
 51
 52    internal ContactGroupKey Remap(int namespaceA, int namespaceB, bool reverse) =>
 25461253        new(namespaceA, namespaceB, reverse ? SurfaceB : SurfaceA,
 25461254            reverse ? SurfaceA : SurfaceB, Region,
 25461255            reverse ? SourceIdB : SourceIdA, reverse ? SourceIdA : SourceIdB,
 25461256            (int)((reverse ? _orderedSourceB : _orderedSourceA) >> 32),
 25461257            (int)((reverse ? _orderedSourceA : _orderedSourceB) >> 32));
 58}