< 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: 107
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 FixedMathSharp;
 9using System.Runtime.CompilerServices;
 10
 11namespace Gravitas.Queries;
 12
 13internal static class SweepBoundsUtility
 14{
 15    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 16    internal static bool TryClipSegment(
 17        Vector3d start,
 18        Vector3d direction,
 19        Fixed64 length,
 20        Vector3d min,
 21        Vector3d max,
 22        out Fixed64 entry,
 23        out Fixed64 exit)
 24    {
 12425        entry = Fixed64.Zero;
 12426        exit = length;
 12427        bool overlaps = ClipSegmentAxis(start.X, direction.X, min.X, max.X, ref entry, ref exit)
 12428            && ClipSegmentAxis(start.Y, direction.Y, min.Y, max.Y, ref entry, ref exit)
 12429            && ClipSegmentAxis(start.Z, direction.Z, min.Z, max.Z, ref entry, ref exit);
 12430        if (!overlaps)
 1631            return false;
 32
 10833        if (entry > exit)
 134            entry = exit = FixedMath.Midpoint(entry, exit);
 35
 10836        return true;
 37    }
 38
 39    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 40    internal static void CreateSweptBounds(
 41        Vector3d min,
 42        Vector3d max,
 43        Vector3d displacement,
 44        Fixed64 padding,
 45        out Vector3d sweptMin,
 46        out Vector3d sweptMax)
 47    {
 1484948        Vector3d endMin = min + displacement;
 1484949        Vector3d endMax = max + displacement;
 1484950        Vector3d extents = Vector3d.One * padding;
 1484951        sweptMin = Vector3d.Min(min, endMin) - extents;
 1484952        sweptMax = Vector3d.Max(max, endMax) + extents;
 1484953    }
 54
 55    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 56    internal static void CreateSweptSphereBounds(
 57        Vector3d start,
 58        Vector3d end,
 59        Fixed64 radius,
 60        Fixed64 padding,
 61        out Vector3d sweptMin,
 62        out Vector3d sweptMax)
 63    {
 1447964        Vector3d extents = Vector3d.One * (radius + padding);
 1447965        sweptMin = Vector3d.Min(start, end) - extents;
 1447966        sweptMax = Vector3d.Max(start, end) + extents;
 1447967    }
 68
 69    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 70    internal static bool OverlapsInclusive(
 71        Vector3d firstMin,
 72        Vector3d firstMax,
 73        Vector3d secondMin,
 74        Vector3d secondMax)
 75    {
 1002776        return firstMax.X >= secondMin.X
 1002777            && firstMin.X <= secondMax.X
 1002778            && firstMax.Y >= secondMin.Y
 1002779            && firstMin.Y <= secondMax.Y
 1002780            && firstMax.Z >= secondMin.Z
 1002781            && firstMin.Z <= secondMax.Z;
 82    }
 83
 84    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 85    private static bool ClipSegmentAxis(
 86        Fixed64 position,
 87        Fixed64 direction,
 88        Fixed64 min,
 89        Fixed64 max,
 90        ref Fixed64 entry,
 91        ref Fixed64 exit)
 92    {
 34593        if (direction == Fixed64.Zero)
 22494            return position >= min && position <= max;
 95
 12196        Fixed64 first = (min - position) / direction;
 12197        Fixed64 second = (max - position) / direction;
 12198        if (first > second)
 10199            (first, second) = (second, first);
 100
 121101        if (first > entry)
 32102            entry = first;
 121103        if (second < exit)
 16104            exit = second;
 121105        return entry <= exit || entry - exit <= Fixed64.Epsilon;
 106    }
 107}