< Summary

Information
Class: Gravitas.Queries.Physics2DHit
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/Queries/2D/Physics2DHit.cs
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 97
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_Point()100%22100%
TryGetPoint(...)100%11100%

File(s)

/home/runner/work/Gravitas/Gravitas/src/Gravitas/Queries/2D/Physics2DHit.cs

#LineLine coverage
 1//=======================================================================
 2// Physics2DHit.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.Colliders;
 10using Gravitas.CollisionHandling;
 11using System;
 12using System.Runtime.CompilerServices;
 13
 14namespace Gravitas.Queries;
 15
 16/// <summary>
 17/// Result from a pure 2D query.
 18/// </summary>
 19public readonly struct Physics2DHit
 20{
 21    /// <summary>
 22    /// Creates a 2D query hit from a world-space surface witness.
 23    /// </summary>
 24    public Physics2DHit(LSCollider2D collider, Vector2d point, Vector2d normal, Fixed64 distance)
 64725        : this(
 64726            collider,
 64727            ContactAnchor2D.FromWorldPoint(point),
 64728            normal,
 64729            distance)
 30    {
 64731    }
 32
 33    /// <summary>
 34    /// Creates a 2D query hit with a rigid-frame surface witness.
 35    /// </summary>
 36    public Physics2DHit(
 37        LSCollider2D collider,
 38        ContactAnchor2D anchor,
 39        Vector2d normal,
 40        Fixed64 distance)
 41    {
 4584542        Collider = collider;
 4584543        Body = collider.Body;
 4584544        Anchor = anchor;
 4584545        Normal = normal;
 4584546        Distance = distance;
 4584547    }
 48
 49    /// <summary>
 50    /// Gets the collider reported by the query.
 51    /// </summary>
 52    public LSCollider2D Collider { get; }
 53
 54    /// <summary>
 55    /// Gets the collider's body, or <see langword="null"/> for a bodyless collider.
 56    /// </summary>
 57    public SolidBody2D? Body { get; }
 58
 59    /// <summary>
 60    /// Gets the rigid-frame query witness.
 61    /// </summary>
 62    public ContactAnchor2D Anchor { get; }
 63
 64    /// <summary>
 65    /// Gets the materialized world-space query witness.
 66    /// </summary>
 67    /// <exception cref="InvalidOperationException">
 68    /// The conceptual witness lies outside the representable coordinate range.
 69    /// </exception>
 70    public Vector2d Point
 71    {
 72        get
 73        {
 11774            if (TryGetPoint(out Vector2d point))
 11675                return point;
 76
 177            throw new InvalidOperationException(
 178                "Point is outside the representable coordinate range. Use TryGetPoint.");
 79        }
 80    }
 81
 82    /// <summary>
 83    /// Attempts to materialize the world-space query witness without saturation.
 84    /// </summary>
 85    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 16286    public bool TryGetPoint(out Vector2d point) => Anchor.TryGetWorldPoint(out point);
 87
 88    /// <summary>
 89    /// Gets the world-space surface normal.
 90    /// </summary>
 91    public Vector2d Normal { get; }
 92
 93    /// <summary>
 94    /// Gets the distance from the query origin to the hit.
 95    /// </summary>
 96    public Fixed64 Distance { get; }
 97}