< Summary

Information
Line coverage
100%
Covered lines: 59
Uncovered lines: 0
Coverable lines: 59
Total lines: 143
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/CollisionHandling/Continuous/Rotational/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
 14/// <summary>
 15/// Stores a moving mixed-pair search result and orders candidates by safe travel distance and contact evidence.
 16/// </summary>
 17internal readonly struct DynamicMixedIntervalHit
 18{
 19    internal DynamicMixedIntervalHit(
 20        IntervalSearchStatus status,
 21        PhysicsMixedHit exactHit,
 22        Fixed64 safeDistance,
 23        Fixed64 closingSpeed,
 24        int targetId)
 25    {
 16826        Status = status;
 16827        ExactHit = exactHit;
 16828        SafeDistance = safeDistance;
 16829        ClosingSpeed = closingSpeed;
 16830        TargetId = targetId;
 16831    }
 32
 33    internal IntervalSearchStatus Status { get; }
 34
 35    internal PhysicsMixedHit ExactHit { get; }
 36
 37    internal Fixed64 SafeDistance { get; }
 38
 39    internal Fixed64 ClosingSpeed { get; }
 40
 41    internal int TargetId { get; }
 42
 43    internal static bool ShouldReplace(
 44        DynamicMixedIntervalHit candidate,
 45        DynamicMixedIntervalHit current,
 46        bool hasCurrent)
 47    {
 12648        if (!hasCurrent)
 11749            return true;
 50
 951        int distance = candidate.SafeDistance.CompareTo(current.SafeDistance);
 952        if (distance != 0)
 553            return distance < 0;
 54
 455        bool candidateIsExact =
 456            candidate.Status == IntervalSearchStatus.ExactHit;
 457        bool currentIsExact =
 458            current.Status == IntervalSearchStatus.ExactHit;
 459        if (candidateIsExact != currentIsExact)
 260            return candidateIsExact;
 61
 262        if (candidateIsExact)
 63        {
 164            return ContinuousCollisionCandidateOrdering.ShouldReplaceMixedHit(
 165                candidate.ExactHit,
 166                candidate.ClosingSpeed,
 167                true,
 168                true,
 169                current.ExactHit,
 170                current.ClosingSpeed);
 71        }
 72
 173        return candidate.TargetId < current.TargetId;
 74    }
 75
 76    internal static DynamicMixedIntervalHit Select(
 77        DynamicMixedIntervalHit candidate,
 78        DynamicMixedIntervalHit current,
 79        ref bool hasCurrent)
 80    {
 11981        if (!ShouldReplace(candidate, current, hasCurrent))
 382            return current;
 83
 11684        hasCurrent = true;
 11685        return candidate;
 86    }
 87
 88    internal static bool ShouldReplaceStatic(
 89        DynamicMixedIntervalHit candidate,
 90        bool hasCandidate,
 91        PhysicsMixedHit current,
 92        bool hasCurrent)
 93    {
 240694        if (!hasCandidate)
 228795            return false;
 11996        if (!hasCurrent)
 11697            return true;
 398        if (candidate.SafeDistance < current.Distance)
 199            return true;
 2100        if (candidate.Status != IntervalSearchStatus.ExactHit)
 1101            return false;
 102
 1103        return ContinuousCollisionCandidateOrdering.ShouldReplaceMixedHit(
 1104            candidate.ExactHit,
 1105            candidate.ClosingSpeed,
 1106            true,
 1107            true,
 1108            current,
 1109            Fixed64.Zero);
 110    }
 111
 112    internal static bool ShouldSelect2D(
 113        bool has2D,
 114        Fixed64 distance2D,
 115        bool hasMixed,
 116        Fixed64 distanceMixed)
 117    {
 983118        if (!has2D)
 763119            return false;
 220120        if (!hasMixed)
 218121            return true;
 122
 2123        return ContinuousCollisionCandidateOrdering.Is2DHitFirst(
 2124            distance2D,
 2125            distanceMixed);
 126    }
 127
 128    internal static bool ShouldSelect3D(
 129        bool has3D,
 130        Fixed64 distance3D,
 131        bool hasMixed,
 132        Fixed64 distanceMixed)
 133    {
 1424134        if (!has3D)
 987135            return false;
 437136        if (!hasMixed)
 435137            return true;
 138
 2139        return !ContinuousCollisionCandidateOrdering.Is2DHitFirst(
 2140            distanceMixed,
 2141            distance3D);
 142    }
 143}