< Summary

Information
Class: Gravitas.Queries.SweepBoundsUtility
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/Queries/3D/Sweeps/SweepBoundsUtility.cs
Line coverage
100%
Covered lines: 37
Uncovered lines: 0
Coverable lines: 37
Total lines: 110
Line coverage: 100%
Branch coverage
100%
Covered branches: 30
Total branches: 30
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
TryClipSegment(...)100%88100%
CreateSweptBounds(...)100%11100%
CreateSweptSphereBounds(...)100%11100%
OverlapsInclusive(...)100%1010100%
ClipSegmentAxis(...)100%1212100%

File(s)

/home/runner/work/Gravitas/Gravitas/src/Gravitas/Queries/3D/Sweeps/SweepBoundsUtility.cs

#LineLine coverage
 1//=======================================================================
 2// SweepBoundsUtility.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.Runtime.CompilerServices;
 9using FixedMathSharp;
 10
 11namespace Gravitas.Queries;
 12
 13/// <summary>
 14/// Builds swept bounds and clips query segments to candidate bounds before narrow-phase tests.
 15/// </summary>
 16internal static class SweepBoundsUtility
 17{
 18    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 19    internal static bool TryClipSegment(
 20        Vector3d start,
 21        Vector3d direction,
 22        Fixed64 length,
 23        Vector3d min,
 24        Vector3d max,
 25        out Fixed64 entry,
 26        out Fixed64 exit)
 27    {
 45528        entry = Fixed64.Zero;
 45529        exit = length;
 45530        bool overlaps = ClipSegmentAxis(start.X, direction.X, min.X, max.X, ref entry, ref exit)
 45531            && ClipSegmentAxis(start.Y, direction.Y, min.Y, max.Y, ref entry, ref exit)
 45532            && ClipSegmentAxis(start.Z, direction.Z, min.Z, max.Z, ref entry, ref exit);
 45533        if (!overlaps)
 2134            return false;
 35
 43436        if (entry > exit)
 137            entry = exit = FixedMath.Midpoint(entry, exit);
 38
 43439        return true;
 40    }
 41
 42    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 43    internal static void CreateSweptBounds(
 44        Vector3d min,
 45        Vector3d max,
 46        Vector3d displacement,
 47        Fixed64 padding,
 48        out Vector3d sweptMin,
 49        out Vector3d sweptMax)
 50    {
 3002551        Vector3d endMin = min + displacement;
 3002552        Vector3d endMax = max + displacement;
 3002553        Vector3d extents = Vector3d.One * padding;
 3002554        sweptMin = Vector3d.Min(min, endMin) - extents;
 3002555        sweptMax = Vector3d.Max(max, endMax) + extents;
 3002556    }
 57
 58    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 59    internal static void CreateSweptSphereBounds(
 60        Vector3d start,
 61        Vector3d end,
 62        Fixed64 radius,
 63        Fixed64 padding,
 64        out Vector3d sweptMin,
 65        out Vector3d sweptMax)
 66    {
 2206267        Vector3d extents = Vector3d.One * (radius + padding);
 2206268        sweptMin = Vector3d.Min(start, end) - extents;
 2206269        sweptMax = Vector3d.Max(start, end) + extents;
 2206270    }
 71
 72    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 73    internal static bool OverlapsInclusive(
 74        Vector3d firstMin,
 75        Vector3d firstMax,
 76        Vector3d secondMin,
 77        Vector3d secondMax)
 78    {
 2969979        return firstMax.X >= secondMin.X
 2969980            && firstMin.X <= secondMax.X
 2969981            && firstMax.Y >= secondMin.Y
 2969982            && firstMin.Y <= secondMax.Y
 2969983            && firstMax.Z >= secondMin.Z
 2969984            && firstMin.Z <= secondMax.Z;
 85    }
 86
 87    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 88    private static bool ClipSegmentAxis(
 89        Fixed64 position,
 90        Fixed64 direction,
 91        Fixed64 min,
 92        Fixed64 max,
 93        ref Fixed64 entry,
 94        ref Fixed64 exit)
 95    {
 133896        if (direction == Fixed64.Zero)
 88697            return position >= min && position <= max;
 98
 45299        Fixed64 first = (min - position) / direction;
 452100        Fixed64 second = (max - position) / direction;
 452101        if (first > second)
 400102            (first, second) = (second, first);
 103
 452104        if (first > entry)
 331105            entry = first;
 452106        if (second < exit)
 58107            exit = second;
 452108        return entry <= exit || entry - exit <= Fixed64.Epsilon;
 109    }
 110}