< Summary

Information
Class: Gravitas.CollisionHandling.Contact2D
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Contacts/2D/Contact2D.cs
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 75
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
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%
get_PointA()100%11100%
get_PointB()100%11100%
GetRequiredWorldPoint(...)100%22100%

File(s)

/home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Contacts/2D/Contact2D.cs

#LineLine coverage
 1//=======================================================================
 2// Contact2D.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;
 10
 11namespace Gravitas.CollisionHandling;
 12
 13/// <summary>
 14/// Deterministic pure 2D contact data generated by the 2D narrow phase.
 15/// </summary>
 16internal readonly struct Contact2D
 17{
 18    public Contact2D(
 19        Vector2d pointA,
 20        Vector2d pointB,
 21        Vector2d normal,
 22        Fixed64 depth,
 23        bool depthIsClamped = false)
 524        : this(
 525            ContactAnchor2D.FromWorldPoint(pointA),
 526            ContactAnchor2D.FromWorldPoint(pointB),
 527            normal,
 528            depth,
 529            depthIsClamped)
 530    { }
 31
 32    public Contact2D(
 33        ContactAnchor2D anchorA,
 34        ContactAnchor2D anchorB,
 35        Vector2d normal,
 36        Fixed64 depth,
 37        bool depthIsClamped = false)
 38    {
 153839        AnchorA = anchorA;
 153840        AnchorB = anchorB;
 153841        Normal = normal;
 153842        Depth = depth;
 153843        DepthIsClamped = depthIsClamped;
 153844        HasContact = true;
 153845    }
 46
 47    public bool HasContact { get; }
 48
 49    public ContactAnchor2D AnchorA { get; }
 50
 51    public ContactAnchor2D AnchorB { get; }
 52
 1253    public Vector2d PointA => GetRequiredWorldPoint(AnchorA, nameof(PointA));
 54
 1155    public Vector2d PointB => GetRequiredWorldPoint(AnchorB, nameof(PointB));
 56
 57    /// <summary>
 58    /// Contact normal pointing from collider A toward collider B.
 59    /// </summary>
 60    public Vector2d Normal { get; }
 61
 62    public Fixed64 Depth { get; }
 63
 64    public bool DepthIsClamped { get; }
 65
 66    private static Vector2d GetRequiredWorldPoint(ContactAnchor2D anchor, string propertyName)
 67    {
 2368        if (anchor.TryGetWorldPoint(out Vector2d point))
 2269            return point;
 70
 171        throw new InvalidOperationException(
 172            $"{propertyName} is outside the representable coordinate range.");
 73    }
 74
 75}