< Summary

Information
Class: Gravitas.CollisionHandling.ContactWarmStartGroup2D
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Contacts/2D/ContactWarmStartGroup2D.cs
Line coverage
100%
Covered lines: 45
Uncovered lines: 0
Coverable lines: 45
Total lines: 120
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
Set(...)100%66100%
TryGet(...)100%44100%
Remove(...)100%66100%
GetContactId(...)100%22100%
GetImpulseUnchecked(...)100%22100%
SetContactIdUnchecked(...)100%22100%
SetImpulseUnchecked(...)100%22100%

File(s)

/home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Contacts/2D/ContactWarmStartGroup2D.cs

#LineLine coverage
 1//=======================================================================
 2// ContactWarmStartGroup2D.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.Runtime.CompilerServices;
 9using FixedMathSharp;
 10
 11namespace Gravitas.CollisionHandling;
 12
 13/// <summary>
 14/// Two inline warm-start rows belonging to one planar surface region.
 15/// </summary>
 16internal struct ContactWarmStartGroup2D
 17{
 18    internal ContactGroupKey Key;
 19    private ulong _contactId0;
 20    private ulong _contactId1;
 21    private ContactWarmStartImpulse _impulse0;
 22    private ContactWarmStartImpulse _impulse1;
 23
 24    public int Count { get; private set; }
 25
 26    public void Set(ulong contactId, Fixed64 normalImpulse, Fixed64 tangentImpulse)
 27    {
 1679928        ContactWarmStartImpulse impulse = new(normalImpulse, tangentImpulse);
 4319229        for (int i = 0; i < Count; i++)
 30        {
 1781031            if (GetContactId(i) != contactId)
 32                continue;
 33
 1301334            SetImpulseUnchecked(i, impulse);
 1301335            return;
 36        }
 37
 378638        if (Count < ContactManifold2D.MaxContactsPerGroup)
 39        {
 378540            SetContactIdUnchecked(Count, contactId);
 378541            SetImpulseUnchecked(Count, impulse);
 378542            Count++;
 378543            return;
 44        }
 45
 146        SetContactIdUnchecked(ContactManifold2D.MaxContactsPerGroup - 1, contactId);
 147        SetImpulseUnchecked(ContactManifold2D.MaxContactsPerGroup - 1, impulse);
 148    }
 49
 50    public bool TryGet(ulong contactId, out ContactWarmStartImpulse impulse)
 51    {
 3636452        for (int i = 0; i < Count; i++)
 53        {
 1817554            if (GetContactId(i) != contactId)
 55                continue;
 56
 1354657            impulse = GetImpulseUnchecked(i);
 1354658            return true;
 59        }
 60
 761        impulse = default;
 762        return false;
 63    }
 64
 65    public bool Remove(ulong contactId)
 66    {
 622667        for (int i = 0; i < Count; i++)
 68        {
 311269            if (GetContactId(i) != contactId)
 70                continue;
 71
 298972            Count--;
 598473            for (int shift = i; shift < Count; shift++)
 74            {
 375                SetContactIdUnchecked(
 376                    shift,
 377                    GetContactId(shift + 1));
 378                SetImpulseUnchecked(
 379                    shift,
 380                    GetImpulseUnchecked(shift + 1));
 81            }
 82
 298983            SetContactIdUnchecked(Count, 0UL);
 298984            SetImpulseUnchecked(Count, default);
 298985            return true;
 86        }
 87
 188        return false;
 89    }
 90
 91    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 5284892    internal ulong GetContactId(int index) => index == 0 ? _contactId0 : _contactId1;
 93
 94    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1372895    internal ContactWarmStartImpulse GetImpulseUnchecked(int index) => index == 0 ? _impulse0 : _impulse1;
 96
 97    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 98    private void SetContactIdUnchecked(int index, ulong contactId)
 99    {
 6778100        if (index == 0)
 101        {
 6465102            _contactId0 = contactId;
 6465103            return;
 104        }
 105
 313106        _contactId1 = contactId;
 313107    }
 108
 109    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 110    private void SetImpulseUnchecked(int index, ContactWarmStartImpulse impulse)
 111    {
 19791112        if (index == 0)
 113        {
 14870114            _impulse0 = impulse;
 14870115            return;
 116        }
 117
 4921118        _impulse1 = impulse;
 4921119    }
 120}