< Summary

Information
Class: Gravitas.CollisionHandling.ManifoldContact2D
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Contacts/2D/ManifoldContact2D.cs
Line coverage
100%
Covered lines: 46
Uncovered lines: 0
Coverable lines: 46
Total lines: 185
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
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%66100%
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/2D/ManifoldContact2D.cs

#LineLine coverage
 1//=======================================================================
 2// ManifoldContact2D.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 pure 2D narrow-phase contact point for a collision manifold.
 17/// </summary>
 18public readonly struct ManifoldContact2D
 19{
 20    /// <summary>Creates a deterministic planar contact from world-space witness points.</summary>
 21    public ManifoldContact2D(
 22        ulong contactId,
 23        Vector2d pointA,
 24        Vector2d pointB,
 25        Fixed64 depth,
 26        Vector2d normal,
 27        bool hasMaterialOverride = false,
 28        PhysicsMaterial materialA = default,
 29        PhysicsMaterial materialB = default,
 30        bool depthIsClamped = false)
 10931        : this(
 10932            contactId,
 10933            ContactAnchor2D.FromWorldPoint(pointA),
 10934            ContactAnchor2D.FromWorldPoint(pointB),
 10935            depth,
 10936            normal,
 10937            hasMaterialOverride,
 10938            materialA,
 10939            materialB,
 10940            depthIsClamped)
 10941    { }
 42
 43    /// <summary>
 44    /// Creates a deterministic planar contact from authoritative relative
 45    /// anchors.
 46    /// </summary>
 47    public ManifoldContact2D(
 48        ulong contactId,
 49        ContactAnchor2D anchorA,
 50        ContactAnchor2D anchorB,
 51        Fixed64 depth,
 52        Vector2d normal,
 53        bool hasMaterialOverride = false,
 54        PhysicsMaterial materialA = default,
 55        PhysicsMaterial materialB = default,
 56        bool depthIsClamped = false)
 11157        : this(
 11158            contactId,
 11159            anchorA,
 11160            anchorB,
 11161            depth,
 11162            normal,
 11163            hasMaterialOverride,
 11164            materialA,
 11165            materialB,
 11166            depthIsClamped,
 11167            featureNamespaceA: 0,
 11168            featureNamespaceB: 0)
 11169    { }
 70
 71    internal ManifoldContact2D(
 72        ulong contactId,
 73        ContactAnchor2D anchorA,
 74        ContactAnchor2D anchorB,
 75        Fixed64 depth,
 76        Vector2d normal,
 77        bool hasMaterialOverride,
 78        PhysicsMaterial materialA,
 79        PhysicsMaterial materialB,
 80        bool depthIsClamped,
 81        int featureNamespaceA,
 82        int featureNamespaceB)
 83    {
 1133784        ContactId = contactId;
 1133785        AnchorA = anchorA;
 1133786        AnchorB = anchorB;
 1133787        FeatureNamespaceA = featureNamespaceA;
 1133788        FeatureNamespaceB = featureNamespaceB;
 1133789        Depth = depth.Abs();
 1133790        DepthIsClamped = depthIsClamped;
 1133791        Normal = normal.MagnitudeSquared > Fixed64.Epsilon
 1133792            ? normal.Normalized
 1133793            : Vector2d.Zero;
 1133794        HasMaterialOverride = hasMaterialOverride;
 1133795        MaterialA = hasMaterialOverride ? materialA : PhysicsMaterial.Default;
 1133796        MaterialB = hasMaterialOverride ? materialB : PhysicsMaterial.Default;
 1133797    }
 98
 99    /// <summary>
 100    /// Stable identity derived from the unordered pair of pose-invariant
 101    /// canonical local feature terms.
 102    /// </summary>
 103    public ulong ContactId { get; }
 104
 105    /// <summary>
 106    /// Authoritative canonical contact anchor on collider A.
 107    /// </summary>
 108    public ContactAnchor2D AnchorA { get; }
 109
 110    /// <summary>
 111    /// Authoritative canonical contact anchor on collider B.
 112    /// </summary>
 113    public ContactAnchor2D AnchorB { get; }
 114
 115    internal int FeatureNamespaceA { get; }
 116
 117    internal int FeatureNamespaceB { get; }
 118
 119    /// <summary>
 120    /// Gets the world-space X/Z-plane contact point on collider A.
 121    /// </summary>
 122    /// <exception cref="InvalidOperationException">
 123    /// The conceptual world point is outside the scalar range.
 124    /// </exception>
 73125    public Vector2d PointA => GetRequiredWorldPoint(AnchorA, nameof(PointA));
 126
 127    /// <summary>
 128    /// Gets the world-space X/Z-plane contact point on collider B.
 129    /// </summary>
 130    /// <exception cref="InvalidOperationException">
 131    /// The conceptual world point is outside the scalar range.
 132    /// </exception>
 69133    public Vector2d PointB => GetRequiredWorldPoint(AnchorB, nameof(PointB));
 134
 135    /// <summary>
 136    /// Attempts to materialize the world-space contact point on collider A.
 137    /// </summary>
 138    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 34139    public bool TryGetPointA(out Vector2d point) => AnchorA.TryGetWorldPoint(out point);
 140
 141    /// <summary>
 142    /// Attempts to materialize the world-space contact point on collider B.
 143    /// </summary>
 144    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 137145    public bool TryGetPointB(out Vector2d point) => AnchorB.TryGetWorldPoint(out point);
 146
 147    /// <summary>
 148    /// Penetration depth along <see cref="Normal"/>.
 149    /// </summary>
 150    public Fixed64 Depth { get; }
 151
 152    /// <summary>
 153    /// Gets whether the conceptual penetration depth exceeded the scalar range.
 154    /// </summary>
 155    public bool DepthIsClamped { get; }
 156
 157    /// <summary>
 158    /// Unit normal pointing from collider A toward collider B.
 159    /// </summary>
 160    public Vector2d Normal { get; }
 161
 162    /// <summary>
 163    /// Gets whether this contact carries materials from private compound parts.
 164    /// </summary>
 165    public bool HasMaterialOverride { get; }
 166
 167    /// <summary>
 168    /// Material for collider A when <see cref="HasMaterialOverride"/> is true.
 169    /// </summary>
 170    public PhysicsMaterial MaterialA { get; }
 171
 172    /// <summary>
 173    /// Material for collider B when <see cref="HasMaterialOverride"/> is true.
 174    /// </summary>
 175    public PhysicsMaterial MaterialB { get; }
 176
 177    private static Vector2d GetRequiredWorldPoint(ContactAnchor2D anchor, string propertyName)
 178    {
 142179        if (anchor.TryGetWorldPoint(out Vector2d point))
 141180            return point;
 181
 1182        throw new InvalidOperationException(
 1183            $"{propertyName} is outside the representable coordinate range. Use the corresponding TryGet method.");
 184    }
 185}