< Summary

Information
Class: Gravitas.DynamicMixedIntervalHit
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/Core/DynamicMixedIntervalHit.cs
Line coverage
100%
Covered lines: 59
Uncovered lines: 0
Coverable lines: 59
Total lines: 140
Line coverage: 100%
Branch coverage
100%
Covered branches: 26
Total branches: 26
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%
ShouldReplace(...)100%88100%
Select(...)100%22100%
ShouldReplaceStatic(...)100%88100%
ShouldSelect2D(...)100%44100%
ShouldSelect3D(...)100%44100%

File(s)

/home/runner/work/Gravitas/Gravitas/src/Gravitas/Core/DynamicMixedIntervalHit.cs

#LineLine coverage
 1//=======================================================================
 2// DynamicMixedIntervalHit.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.CollisionHandling;
 10using Gravitas.Queries;
 11
 12namespace Gravitas;
 13
 14internal readonly struct DynamicMixedIntervalHit
 15{
 16    internal DynamicMixedIntervalHit(
 17        ContinuousCollisionMath.IntervalSearchStatus status,
 18        PhysicsMixedHit exactHit,
 19        Fixed64 safeDistance,
 20        Fixed64 closingSpeed,
 21        int targetId)
 22    {
 10523        Status = status;
 10524        ExactHit = exactHit;
 10525        SafeDistance = safeDistance;
 10526        ClosingSpeed = closingSpeed;
 10527        TargetId = targetId;
 10528    }
 29
 30    internal ContinuousCollisionMath.IntervalSearchStatus Status { get; }
 31
 32    internal PhysicsMixedHit ExactHit { get; }
 33
 34    internal Fixed64 SafeDistance { get; }
 35
 36    internal Fixed64 ClosingSpeed { get; }
 37
 38    internal int TargetId { get; }
 39
 40    internal static bool ShouldReplace(
 41        DynamicMixedIntervalHit candidate,
 42        DynamicMixedIntervalHit current,
 43        bool hasCurrent)
 44    {
 6945        if (!hasCurrent)
 6046            return true;
 47
 948        int distance = candidate.SafeDistance.CompareTo(current.SafeDistance);
 949        if (distance != 0)
 550            return distance < 0;
 51
 452        bool candidateIsExact =
 453            candidate.Status == ContinuousCollisionMath.IntervalSearchStatus.ExactHit;
 454        bool currentIsExact =
 455            current.Status == ContinuousCollisionMath.IntervalSearchStatus.ExactHit;
 456        if (candidateIsExact != currentIsExact)
 257            return candidateIsExact;
 58
 259        if (candidateIsExact)
 60        {
 161            return ContinuousCollisionCandidateOrdering.ShouldReplaceMixedHit(
 162                candidate.ExactHit,
 163                candidate.ClosingSpeed,
 164                true,
 165                true,
 166                current.ExactHit,
 167                current.ClosingSpeed);
 68        }
 69
 170        return candidate.TargetId < current.TargetId;
 71    }
 72
 73    internal static DynamicMixedIntervalHit Select(
 74        DynamicMixedIntervalHit candidate,
 75        DynamicMixedIntervalHit current,
 76        ref bool hasCurrent)
 77    {
 6278        if (!ShouldReplace(candidate, current, hasCurrent))
 379            return current;
 80
 5981        hasCurrent = true;
 5982        return candidate;
 83    }
 84
 85    internal static bool ShouldReplaceStatic(
 86        DynamicMixedIntervalHit candidate,
 87        bool hasCandidate,
 88        PhysicsMixedHit current,
 89        bool hasCurrent)
 90    {
 75791        if (!hasCandidate)
 69592            return false;
 6293        if (!hasCurrent)
 5994            return true;
 395        if (candidate.SafeDistance < current.Distance)
 196            return true;
 297        if (candidate.Status != ContinuousCollisionMath.IntervalSearchStatus.ExactHit)
 198            return false;
 99
 1100        return ContinuousCollisionCandidateOrdering.ShouldReplaceMixedHit(
 1101            candidate.ExactHit,
 1102            candidate.ClosingSpeed,
 1103            true,
 1104            true,
 1105            current,
 1106            Fixed64.Zero);
 107    }
 108
 109    internal static bool ShouldSelect2D(
 110        bool has2D,
 111        Fixed64 distance2D,
 112        bool hasMixed,
 113        Fixed64 distanceMixed)
 114    {
 324115        if (!has2D)
 205116            return false;
 119117        if (!hasMixed)
 117118            return true;
 119
 2120        return ContinuousCollisionCandidateOrdering.Is2DHitFirst(
 2121            distance2D,
 2122            distanceMixed);
 123    }
 124
 125    internal static bool ShouldSelect3D(
 126        bool has3D,
 127        Fixed64 distance3D,
 128        bool hasMixed,
 129        Fixed64 distanceMixed)
 130    {
 434131        if (!has3D)
 300132            return false;
 134133        if (!hasMixed)
 132134            return true;
 135
 2136        return !ContinuousCollisionCandidateOrdering.Is2DHitFirst(
 2137            distanceMixed,
 2138            distance3D);
 139    }
 140}