< Summary

Information
Class: Gravitas.CollisionHandling.SolverContact2D
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Response/2D/SolverContact2D.cs
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 109
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%

File(s)

/home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Response/2D/SolverContact2D.cs

#LineLine coverage
 1//=======================================================================
 2// SolverContact2D.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 Gravitas.Materials;
 10
 11namespace Gravitas.CollisionHandling;
 12
 13internal readonly struct ContactLever2D
 14{
 15    private ContactLever2D(Vector2d vector, bool isExact)
 16    {
 17        Vector = vector;
 18        IsExact = isExact;
 19    }
 20
 21    internal bool IsExact { get; }
 22
 23    internal Vector2d Vector { get; }
 24
 25    internal static ContactLever2D Zero =>
 26        new(Vector2d.Zero, isExact: false);
 27
 28    internal static ContactLever2D Create(
 29        in ContactAnchor2D point,
 30        in ContactAnchor2D origin)
 31    {
 32        if (point.TryGetOffsetFrom(origin, out Vector2d vector))
 33            return new ContactLever2D(vector, isExact: false);
 34
 35        return new ContactLever2D(default, isExact: true);
 36    }
 37}
 38
 39/// <summary>
 40/// Solver-ready scalar pure 2D contact data.
 41/// </summary>
 42internal readonly struct SolverContact2D
 43{
 44    public SolverContact2D(
 45        int manifoldIndex,
 46        ulong contactId,
 47        ResponseBody2D bodyA,
 48        ResponseBody2D bodyB,
 49        ContactLever2D relativeA,
 50        ContactLever2D relativeB,
 51        Fixed64 depth,
 52        Vector2d normal,
 53        PhysicsMaterial materialA,
 54        PhysicsMaterial materialB,
 55        Fixed64 cachedNormalImpulse,
 56        Fixed64 cachedTangentImpulse)
 57    {
 101158        ManifoldIndex = manifoldIndex;
 101159        ContactId = contactId;
 101160        A = bodyA;
 101161        B = bodyB;
 101162        RelativeA = relativeA;
 101163        RelativeB = relativeB;
 101164        Depth = depth;
 101165        Normal = normal;
 101166        MaterialA = materialA;
 101167        MaterialB = materialB;
 101168        PhysicsMaterial.CombineFriction(materialA, materialB, out Fixed64 staticFriction, out Fixed64 dynamicFriction);
 101169        StaticFriction = staticFriction;
 101170        DynamicFriction = dynamicFriction;
 101171        Restitution = PhysicsMaterial.CombineRestitution(materialA, materialB);
 101172        Tangent = normal.RightHandNormal;
 101173        CachedNormalImpulse = cachedNormalImpulse;
 101174        CachedTangentImpulse = cachedTangentImpulse;
 101175    }
 76
 77    public int ManifoldIndex { get; }
 78
 79    public ulong ContactId { get; }
 80
 81    public ResponseBody2D A { get; }
 82
 83    public ResponseBody2D B { get; }
 84
 85    public ContactLever2D RelativeA { get; }
 86
 87    public ContactLever2D RelativeB { get; }
 88
 89    public Fixed64 Depth { get; }
 90
 91    public Vector2d Normal { get; }
 92
 93    public PhysicsMaterial MaterialA { get; }
 94
 95    public PhysicsMaterial MaterialB { get; }
 96
 97    public Fixed64 StaticFriction { get; }
 98
 99    public Fixed64 DynamicFriction { get; }
 100
 101    public Fixed64 Restitution { get; }
 102
 103    public Vector2d Tangent { get; }
 104
 105    public Fixed64 CachedNormalImpulse { get; }
 106
 107    public Fixed64 CachedTangentImpulse { get; }
 108
 109}