< Summary

Information
Class: Gravitas.CollisionHandling.SolverContact3D
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Response/3D/SolverContact3D.cs
Line coverage
100%
Covered lines: 28
Uncovered lines: 0
Coverable lines: 28
Total lines: 107
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
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%
CreateTangent(...)100%66100%

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// SolverContact3D.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
 13
 14
 15/// <summary>
 16/// Solver-ready 3D contact data, including the deterministic tangent frame and cached impulses.
 17/// </summary>
 18internal readonly struct SolverContact3D
 19{
 20    public SolverContact3D(
 21        int groupIndex,
 22        int pointIndex,
 23        ulong contactId,
 24        ResponseBody3D bodyA,
 25        ResponseBody3D bodyB,
 26        ContactLever3D relativeA,
 27        ContactLever3D relativeB,
 28        Fixed64 depth,
 29        Vector3d normal,
 30        PhysicsMaterial materialA,
 31        PhysicsMaterial materialB,
 32        Fixed64 cachedNormalImpulse,
 33        Fixed64 cachedTangentImpulse,
 34        Fixed64 cachedSecondaryTangentImpulse)
 35    {
 71443236        GroupIndex = groupIndex;
 71443237        PointIndex = pointIndex;
 71443238        ContactId = contactId;
 71443239        A = bodyA;
 71443240        B = bodyB;
 71443241        RelativeA = relativeA;
 71443242        RelativeB = relativeB;
 71443243        Depth = depth;
 71443244        Normal = normal;
 71443245        MaterialA = materialA;
 71443246        MaterialB = materialB;
 71443247        PhysicsMaterial.CombineFriction(materialA, materialB, out Fixed64 staticFriction, out Fixed64 dynamicFriction);
 71443248        StaticFriction = staticFriction;
 71443249        DynamicFriction = dynamicFriction;
 71443250        Restitution = PhysicsMaterial.CombineRestitution(materialA, materialB);
 71443251        Tangent = CreateTangent(normal);
 71443252        SecondaryTangent = Vector3d.Cross(normal, Tangent).Normalized;
 71443253        CachedNormalImpulse = cachedNormalImpulse;
 71443254        CachedTangentImpulse = cachedTangentImpulse;
 71443255        CachedSecondaryTangentImpulse = cachedSecondaryTangentImpulse;
 71443256    }
 57
 58    internal int GroupIndex { get; }
 59
 60    internal int PointIndex { get; }
 61
 62    public ulong ContactId { get; }
 63
 64    public ResponseBody3D A { get; }
 65
 66    public ResponseBody3D B { get; }
 67
 68    public ContactLever3D RelativeA { get; }
 69
 70    public ContactLever3D RelativeB { get; }
 71
 72    public Fixed64 Depth { get; }
 73
 74    public Vector3d Normal { get; }
 75
 76    public PhysicsMaterial MaterialA { get; }
 77
 78    public PhysicsMaterial MaterialB { get; }
 79
 80    public Fixed64 StaticFriction { get; }
 81
 82    public Fixed64 DynamicFriction { get; }
 83
 84    public Fixed64 Restitution { get; }
 85
 86    public Vector3d Tangent { get; }
 87
 88    public Vector3d SecondaryTangent { get; }
 89
 90    public Fixed64 CachedNormalImpulse { get; }
 91
 92    public Fixed64 CachedTangentImpulse { get; }
 93
 94    public Fixed64 CachedSecondaryTangentImpulse { get; }
 95
 96    internal static Vector3d CreateTangent(Vector3d normal)
 97    {
 71471298        Vector3d absolute = Vector3d.Abs(normal);
 71471299        Vector3d reference = absolute.X <= absolute.Y && absolute.X <= absolute.Z
 714712100            ? Vector3d.Right
 714712101            : absolute.Y <= absolute.Z
 714712102                ? Vector3d.Up
 714712103                : Vector3d.Forward;
 104
 714712105        return Vector3d.Cross(reference, normal).Normalized;
 106    }
 107}