< Summary

Information
Class: Gravitas.CollisionHandling.SolverContactBuffer
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Response/3D/SolverContactBuffer.cs
Line coverage
100%
Covered lines: 69
Uncovered lines: 0
Coverable lines: 69
Total lines: 160
Line coverage: 100%
Branch coverage
100%
Covered branches: 32
Total branches: 32
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Add(...)100%44100%
GetContact(...)100%44100%
GetNormalImpulse(...)100%44100%
GetNormalResult(...)100%44100%
GetTangentImpulse(...)100%44100%
GetSecondaryTangentImpulse(...)100%44100%
SetNormalImpulse(...)100%44100%
SetTangentImpulse(...)100%44100%

File(s)

/home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Response/3D/SolverContactBuffer.cs

#LineLine coverage
 1//=======================================================================
 2// SolverContactBuffer.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 FixedMathSharp;
 9using System.Runtime.CompilerServices;
 10
 11namespace Gravitas.CollisionHandling;
 12
 13/// <summary>
 14/// A buffer for storing contact points and their associated impulses and velocities during collision resolution.
 15/// </summary>
 16internal struct SolverContactBuffer
 17{
 18    private SolverContact _contact0;
 19    private SolverContact _contact1;
 20    private SolverContact _contact2;
 21    private SolverContact _contact3;
 22    private Fixed64 _normalImpulse0;
 23    private Fixed64 _normalImpulse1;
 24    private Fixed64 _normalImpulse2;
 25    private Fixed64 _normalImpulse3;
 26    private Fixed64 _tangentImpulse0;
 27    private Fixed64 _tangentImpulse1;
 28    private Fixed64 _tangentImpulse2;
 29    private Fixed64 _tangentImpulse3;
 30    private Fixed64 _secondaryTangentImpulse0;
 31    private Fixed64 _secondaryTangentImpulse1;
 32    private Fixed64 _secondaryTangentImpulse2;
 33    private Fixed64 _secondaryTangentImpulse3;
 34    private ContactNormalImpulseResult3D _normalResult0;
 35    private ContactNormalImpulseResult3D _normalResult1;
 36    private ContactNormalImpulseResult3D _normalResult2;
 37    private ContactNormalImpulseResult3D _normalResult3;
 38
 39    public int Count { get; private set; }
 40
 41    public void Add(SolverContact contact)
 42    {
 908443        switch (Count)
 44        {
 45            case 0:
 884446                _contact0 = contact;
 884447                break;
 48            case 1:
 8249                _contact1 = contact;
 8250                break;
 51            case 2:
 7952                _contact2 = contact;
 7953                break;
 54            default:
 7955                _contact3 = contact;
 56                break;
 57        }
 58
 908459        Count++;
 908460    }
 61
 62    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 63    public SolverContact GetContact(int index) =>
 3824764        index switch
 3824765        {
 3710766            0 => _contact0,
 39267            1 => _contact1,
 37468            2 => _contact2,
 37469            _ => _contact3
 3824770        };
 71
 72    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 73    public Fixed64 GetNormalImpulse(int index) =>
 1814774        index switch
 1814775        {
 1766776            0 => _normalImpulse0,
 16477            1 => _normalImpulse1,
 15878            2 => _normalImpulse2,
 15879            _ => _normalImpulse3
 1814780        };
 81
 82    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 83    public ContactNormalImpulseResult3D GetNormalResult(int index) =>
 907584        index switch
 907585        {
 883586            0 => _normalResult0,
 8287            1 => _normalResult1,
 7988            2 => _normalResult2,
 7989            _ => _normalResult3
 907590        };
 91
 92    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 93    public Fixed64 GetTangentImpulse(int index) =>
 907394        index switch
 907395        {
 883396            0 => _tangentImpulse0,
 8297            1 => _tangentImpulse1,
 7998            2 => _tangentImpulse2,
 7999            _ => _tangentImpulse3
 9073100        };
 101
 102    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 103    public Fixed64 GetSecondaryTangentImpulse(int index) =>
 9073104        index switch
 9073105        {
 8833106            0 => _secondaryTangentImpulse0,
 82107            1 => _secondaryTangentImpulse1,
 79108            2 => _secondaryTangentImpulse2,
 79109            _ => _secondaryTangentImpulse3
 9073110        };
 111
 112    public void SetNormalImpulse(
 113        int index,
 114        Fixed64 impulse,
 115        ContactNormalImpulseResult3D normalResult)
 116    {
 117        switch (index)
 118        {
 119            case 0:
 8835120                _normalImpulse0 = impulse;
 8835121                _normalResult0 = normalResult;
 8835122                break;
 123            case 1:
 82124                _normalImpulse1 = impulse;
 82125                _normalResult1 = normalResult;
 82126                break;
 127            case 2:
 79128                _normalImpulse2 = impulse;
 79129                _normalResult2 = normalResult;
 79130                break;
 131            default:
 79132                _normalImpulse3 = impulse;
 79133                _normalResult3 = normalResult;
 134                break;
 135        }
 79136    }
 137
 138    public void SetTangentImpulse(int index, Fixed64 impulse, Fixed64 secondaryImpulse)
 139    {
 140        switch (index)
 141        {
 142            case 0:
 8833143                _tangentImpulse0 = impulse;
 8833144                _secondaryTangentImpulse0 = secondaryImpulse;
 8833145                break;
 146            case 1:
 82147                _tangentImpulse1 = impulse;
 82148                _secondaryTangentImpulse1 = secondaryImpulse;
 82149                break;
 150            case 2:
 79151                _tangentImpulse2 = impulse;
 79152                _secondaryTangentImpulse2 = secondaryImpulse;
 79153                break;
 154            default:
 79155                _tangentImpulse3 = impulse;
 79156                _secondaryTangentImpulse3 = secondaryImpulse;
 157                break;
 158        }
 79159    }
 160}