< Summary

Information
Class: Gravitas.Queries.Physics3DHit
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/Queries/3D/Hits/Physics3DHit.cs
Line coverage
100%
Covered lines: 21
Uncovered lines: 0
Coverable lines: 21
Total lines: 114
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/Hits/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 System;
 9using System.Runtime.CompilerServices;
 10using FixedMathSharp;
 11using Gravitas.Colliders;
 12using Gravitas.CollisionHandling;
 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)
 400025        : this(
 400026            collider,
 400027            ContactAnchor.FromWorldPoint(point),
 400028            normal,
 400029            distance,
 400030            direction)
 31    {
 400032    }
 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    {
 2207944        if (!anchor.IsValid)
 145            throw new ArgumentException("The hit anchor must be valid.", nameof(anchor));
 46
 2207847        Collider = collider;
 2207848        Body = collider?.Body;
 2207849        Anchor = anchor;
 2207850        Normal = normal;
 2207851        Distance = distance;
 2207852        Direction = direction;
 2207853    }
 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        {
 56180            if (TryGetPoint(out Vector3d point))
 56081                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)]
 81893    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 query-specific distance used to rank this hit.
 102    /// </summary>
 103    /// <remarks>
 104    /// Rays and sweeps report query travel; cone volumes report axial distance.
 105    /// Projected overlaps use their overlap ranking distance, which can be zero
 106    /// for a contained origin. This need not equal origin-to-witness distance.
 107    /// </remarks>
 108    public Fixed64 Distance { get; }
 109
 110    /// <summary>
 111    /// Gets the query direction associated with the hit.
 112    /// </summary>
 113    public Vector3d Direction { get; }
 114}