< Summary

Information
Class: Gravitas.CollisionHandling.ManifoldContact
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Contacts/3D/ManifoldContact.cs
Line coverage
100%
Covered lines: 50
Uncovered lines: 0
Coverable lines: 50
Total lines: 189
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
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%
.ctor(...)100%11100%
.ctor(...)100%1010100%
get_PointA()100%11100%
get_PointB()100%11100%
TryGetPointA(...)100%11100%
TryGetPointB(...)100%11100%
GetRequiredWorldPoint(...)100%22100%

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// ManifoldContact.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;
 9using System.Runtime.CompilerServices;
 10using FixedMathSharp;
 11using Gravitas.Materials;
 12
 13namespace Gravitas.CollisionHandling;
 14
 15/// <summary>
 16/// A deterministic narrow-phase contact point for a collision manifold.
 17/// </summary>
 18public readonly struct ManifoldContact
 19{
 20    /// <summary>Creates a deterministic contact from world-space witness points.</summary>
 21    public ManifoldContact(
 22        ulong contactId,
 23        Vector3d pointA,
 24        Vector3d pointB,
 25        Fixed64 depth,
 26        Vector3d normal,
 27        bool hasMaterialOverride = false,
 28        PhysicsMaterial materialA = default,
 29        PhysicsMaterial materialB = default,
 30        bool depthIsClamped = false)
 30731        : this(
 30732            contactId,
 30733            ContactAnchor.FromWorldPoint(pointA),
 30734            ContactAnchor.FromWorldPoint(pointB),
 30735            depth,
 30736            normal,
 30737            hasMaterialOverride,
 30738            materialA,
 30739            materialB,
 30740            depthIsClamped)
 30741    { }
 42
 43    /// <summary>
 44    /// Creates a deterministic contact from authoritative rigid-frame anchors.
 45    /// </summary>
 46    public ManifoldContact(
 47        ulong contactId,
 48        ContactAnchor anchorA,
 49        ContactAnchor anchorB,
 50        Fixed64 depth,
 51        Vector3d normal,
 52        bool hasMaterialOverride = false,
 53        PhysicsMaterial materialA = default,
 54        PhysicsMaterial materialB = default,
 55        bool depthIsClamped = false)
 368756        : this(
 368757            contactId,
 368758            anchorA,
 368759            anchorB,
 368760            depth,
 368761            normal,
 368762            hasMaterialOverride,
 368763            materialA,
 368764            materialB,
 368765            depthIsClamped,
 368766            featureNamespaceA: 0,
 368767            featureNamespaceB: 0)
 368568    { }
 69
 70    internal ManifoldContact(
 71        ulong contactId,
 72        ContactAnchor anchorA,
 73        ContactAnchor anchorB,
 74        Fixed64 depth,
 75        Vector3d normal,
 76        bool hasMaterialOverride,
 77        PhysicsMaterial materialA,
 78        PhysicsMaterial materialB,
 79        bool depthIsClamped,
 80        int featureNamespaceA,
 81        int featureNamespaceB)
 82    {
 22856383        if (!anchorA.IsValid)
 184            throw new ArgumentException("Contact anchor A must be valid.", nameof(anchorA));
 22856285        if (!anchorB.IsValid)
 186            throw new ArgumentException("Contact anchor B must be valid.", nameof(anchorB));
 87
 22856188        ContactId = contactId;
 22856189        AnchorA = anchorA;
 22856190        AnchorB = anchorB;
 22856191        FeatureNamespaceA = featureNamespaceA;
 22856192        FeatureNamespaceB = featureNamespaceB;
 22856193        Depth = depth.Abs();
 22856194        DepthIsClamped = depthIsClamped;
 22856195        Normal = normal.MagnitudeSquared > Fixed64.Epsilon
 22856196            ? normal.Normalized
 22856197            : Vector3d.Zero;
 22856198        HasMaterialOverride = hasMaterialOverride;
 22856199        MaterialA = hasMaterialOverride ? materialA : PhysicsMaterial.Default;
 228561100        MaterialB = hasMaterialOverride ? materialB : PhysicsMaterial.Default;
 228561101    }
 102
 103    /// <summary>
 104    /// Stable identity derived from the unordered pair of pose-invariant
 105    /// canonical local feature terms.
 106    /// </summary>
 107    public ulong ContactId { get; }
 108
 109    /// <summary>
 110    /// Authoritative canonical contact anchor on collider A.
 111    /// </summary>
 112    public ContactAnchor AnchorA { get; }
 113
 114    /// <summary>
 115    /// Authoritative canonical contact anchor on collider B.
 116    /// </summary>
 117    public ContactAnchor AnchorB { get; }
 118
 119    internal int FeatureNamespaceA { get; }
 120
 121    internal int FeatureNamespaceB { get; }
 122
 123    /// <summary>
 124    /// Gets the world-space contact point on collider A.
 125    /// </summary>
 126    /// <exception cref="InvalidOperationException">
 127    /// The conceptual world point is outside the scalar range.
 128    /// </exception>
 2012129    public Vector3d PointA => GetRequiredWorldPoint(AnchorA, nameof(PointA));
 130
 131    /// <summary>
 132    /// Gets the world-space contact point on collider B.
 133    /// </summary>
 134    /// <exception cref="InvalidOperationException">
 135    /// The conceptual world point is outside the scalar range.
 136    /// </exception>
 1023137    public Vector3d PointB => GetRequiredWorldPoint(AnchorB, nameof(PointB));
 138
 139    /// <summary>
 140    /// Attempts to materialize the world-space contact point on collider A.
 141    /// </summary>
 142    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 166143    public bool TryGetPointA(out Vector3d point) => AnchorA.TryGetWorldPoint(out point);
 144
 145    /// <summary>
 146    /// Attempts to materialize the world-space contact point on collider B.
 147    /// </summary>
 148    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 166149    public bool TryGetPointB(out Vector3d point) => AnchorB.TryGetWorldPoint(out point);
 150
 151    /// <summary>
 152    /// Penetration depth along <see cref="Normal"/>.
 153    /// </summary>
 154    public Fixed64 Depth { get; }
 155
 156    /// <summary>
 157    /// Gets whether the conceptual penetration depth exceeded the scalar range.
 158    /// </summary>
 159    public bool DepthIsClamped { get; }
 160
 161    /// <summary>
 162    /// Unit normal pointing from collider A toward collider B.
 163    /// </summary>
 164    public Vector3d Normal { get; }
 165
 166    /// <summary>
 167    /// Gets whether this contact carries materials from private compound parts.
 168    /// </summary>
 169    public bool HasMaterialOverride { get; }
 170
 171    /// <summary>
 172    /// Material for collider A when <see cref="HasMaterialOverride"/> is true.
 173    /// </summary>
 174    public PhysicsMaterial MaterialA { get; }
 175
 176    /// <summary>
 177    /// Material for collider B when <see cref="HasMaterialOverride"/> is true.
 178    /// </summary>
 179    public PhysicsMaterial MaterialB { get; }
 180
 181    private static Vector3d GetRequiredWorldPoint(ContactAnchor anchor, string propertyName)
 182    {
 3035183        if (anchor.TryGetWorldPoint(out Vector3d point))
 3034184            return point;
 185
 1186        throw new InvalidOperationException(
 1187            $"{propertyName} is outside the representable coordinate range. Use the corresponding TryGet method.");
 188    }
 189}