< Summary

Information
Class: Gravitas.Queries.Physics3DHit
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/Queries/3D/Physics3DHit.cs
Line coverage
100%
Covered lines: 21
Uncovered lines: 0
Coverable lines: 21
Total lines: 109
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%
.ctor(...)100%44100%
get_Point()100%22100%
TryGetPoint(...)100%11100%

File(s)

/home/runner/work/Gravitas/Gravitas/src/Gravitas/Queries/3D/Physics3DHit.cs

#LineLine coverage
 1//=======================================================================
 2// Physics3DHit.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 3D physics query.
 18/// </summary>
 19public readonly struct Physics3DHit
 20{
 21    /// <summary>
 22    /// Creates a 3D query hit from a world-space surface witness.
 23    /// </summary>
 24    public Physics3DHit(LSCollider? collider, Vector3d point, Vector3d normal, Fixed64 distance, Vector3d direction)
 248825        : this(
 248826            collider,
 248827            ContactAnchor.FromWorldPoint(point),
 248828            normal,
 248829            distance,
 248830            direction)
 31    {
 248832    }
 33
 34    /// <summary>
 35    /// Creates a query hit with a rigid-frame surface witness.
 36    /// </summary>
 37    public Physics3DHit(
 38        LSCollider? collider,
 39        ContactAnchor anchor,
 40        Vector3d normal,
 41        Fixed64 distance,
 42        Vector3d direction)
 43    {
 1030444        if (!anchor.IsValid)
 145            throw new ArgumentException("The hit anchor must be valid.", nameof(anchor));
 46
 1030347        Collider = collider;
 1030348        Body = collider?.Body;
 1030349        Anchor = anchor;
 1030350        Normal = normal;
 1030351        Distance = distance;
 1030352        Direction = direction;
 1030353    }
 54
 55    /// <summary>
 56    /// Gets the collider reported by the query, if any.
 57    /// </summary>
 58    public LSCollider? Collider { get; }
 59
 60    /// <summary>
 61    /// Gets the collider's body, or <see langword="null"/> for a bodyless hit.
 62    /// </summary>
 63    public SolidBody? Body { get; }
 64
 65    /// <summary>
 66    /// Gets the authoritative rigid-frame query witness.
 67    /// </summary>
 68    public ContactAnchor Anchor { get; }
 69
 70    /// <summary>
 71    /// Gets the materialized world-space query witness.
 72    /// </summary>
 73    /// <exception cref="InvalidOperationException">
 74    /// The conceptual witness lies outside the representable coordinate range.
 75    /// </exception>
 76    public Vector3d Point
 77    {
 78        get
 79        {
 4580            if (TryGetPoint(out Vector3d point))
 4481                return point;
 82
 183            throw new InvalidOperationException(
 184                "Point is outside the representable coordinate range. Use TryGetPoint.");
 85        }
 86    }
 87
 88    /// <summary>
 89    /// Attempts to materialize the world-space query witness without
 90    /// saturation.
 91    /// </summary>
 92    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 5593    public bool TryGetPoint(out Vector3d point) => Anchor.TryGetWorldPoint(out point);
 94
 95    /// <summary>
 96    /// Gets the world-space surface normal.
 97    /// </summary>
 98    public Vector3d Normal { get; }
 99
 100    /// <summary>
 101    /// Gets the distance from the query origin to the hit.
 102    /// </summary>
 103    public Fixed64 Distance { get; }
 104
 105    /// <summary>
 106    /// Gets the query direction associated with the hit.
 107    /// </summary>
 108    public Vector3d Direction { get; }
 109}