< Summary

Information
Class: Gravitas.CollisionHandling.ContinuousCollisionCandidateOrdering
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Continuous/Candidates/ContinuousCollisionCandidateOrdering.cs
Line coverage
100%
Covered lines: 70
Uncovered lines: 0
Coverable lines: 70
Total lines: 150
Line coverage: 100%
Branch coverage
100%
Covered branches: 80
Total branches: 80
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Is2DHitFirst(...)100%11100%
ShouldReplaceHit(...)100%1212100%
ShouldReplaceHit(...)100%88100%
ShouldReplaceMixedHit(...)100%2020100%
IsIgnoredTarget(...)100%2020100%
IsIgnoredTarget(...)100%2020100%

File(s)

/home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Continuous/Candidates/ContinuousCollisionCandidateOrdering.cs

#LineLine coverage
 1//=======================================================================
 2// ContinuousCollisionCandidateOrdering.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;
 10using Gravitas.Colliders;
 11using Gravitas.Queries;
 12
 13namespace Gravitas.CollisionHandling;
 14
 15/// <summary>
 16/// Ranks CCD hits deterministically and recognizes targets excluded by body or hierarchy.
 17/// </summary>
 18internal static class ContinuousCollisionCandidateOrdering
 19{
 20    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 21    public static bool Is2DHitFirst(Fixed64 distance2D, Fixed64 distance3D) =>
 922        distance2D <= distance3D;
 23
 24    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 25    public static bool ShouldReplaceHit(
 26        Physics3DHit candidate,
 27        Fixed64 candidateClosingSpeed,
 28        bool hasCandidate,
 29        bool hasCurrent,
 30        Physics3DHit current,
 31        Fixed64 currentClosingSpeed)
 32    {
 149133        if (!hasCandidate)
 137334            return false;
 11835        if (!hasCurrent)
 9936            return true;
 37
 1938        int distance = candidate.Distance.CompareTo(current.Distance);
 1939        if (distance != 0)
 1440            return distance < 0;
 41
 542        int closing = candidateClosingSpeed.CompareTo(currentClosingSpeed);
 543        if (closing != 0)
 144            return closing > 0;
 45
 446        int candidateId = candidate.Collider?.Id ?? -1;
 447        int currentId = current.Collider?.Id ?? -1;
 448        return candidateId < currentId;
 49    }
 50
 51    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 52    public static bool ShouldReplaceHit(
 53        Physics2DHit candidate,
 54        Fixed64 candidateClosingSpeed,
 55        bool hasCandidate,
 56        bool hasCurrent,
 57        Physics2DHit current,
 58        Fixed64 currentClosingSpeed)
 59    {
 103860        if (!hasCandidate)
 94261            return false;
 9662        if (!hasCurrent)
 7963            return true;
 64
 1765        int distance = candidate.Distance.CompareTo(current.Distance);
 1766        if (distance != 0)
 1467            return distance < 0;
 68
 369        int closing = candidateClosingSpeed.CompareTo(currentClosingSpeed);
 370        if (closing != 0)
 171            return closing > 0;
 72
 273        return candidate.Collider.Id < current.Collider.Id;
 74    }
 75
 76    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 77    public static bool ShouldReplaceMixedHit(
 78        PhysicsMixedHit candidate,
 79        Fixed64 candidateClosingSpeed,
 80        bool hasCandidate,
 81        bool hasCurrent,
 82        PhysicsMixedHit current,
 83        Fixed64 currentClosingSpeed)
 84    {
 1585        if (!hasCandidate)
 186            return false;
 1487        if (!hasCurrent)
 188            return true;
 89
 1390        int distance = candidate.Distance.CompareTo(current.Distance);
 1391        if (distance != 0)
 492            return distance < 0;
 93
 994        int closing = candidateClosingSpeed.CompareTo(currentClosingSpeed);
 995        if (closing != 0)
 196            return closing > 0;
 97
 898        int reducer = candidate.ReducerKind.CompareTo(current.ReducerKind);
 899        if (reducer != 0)
 1100            return reducer < 0;
 101
 7102        int candidate3D = candidate.Collider3D?.Id ?? -1;
 7103        int current3D = current.Collider3D?.Id ?? -1;
 7104        int collider3D = candidate3D.CompareTo(current3D);
 7105        if (collider3D != 0)
 3106            return collider3D < 0;
 107
 4108        int candidate2D = candidate.Collider2D?.Id ?? -1;
 4109        int current2D = current.Collider2D?.Id ?? -1;
 4110        return candidate2D < current2D;
 111    }
 112
 113    public static bool IsIgnoredTarget(LSCollider hitCollider, LSCollider? ignored)
 114    {
 15863115        if (ignored == null)
 15567116            return false;
 117
 296118        if (ReferenceEquals(hitCollider, ignored))
 146119            return true;
 120
 150121        SolidBody? ignoredBody = ignored.Body;
 150122        if (ignoredBody != null && ReferenceEquals(hitCollider.Body, ignoredBody))
 1123            return true;
 124
 149125        LSCollider? hitTopParent = hitCollider.TopParent3D;
 149126        LSCollider? ignoredTopParent = ignored.TopParent3D;
 149127        return (hitTopParent != null && ReferenceEquals(hitTopParent, ignored))
 149128            || (ignoredTopParent != null && ReferenceEquals(hitCollider, ignoredTopParent))
 149129            || (hitTopParent != null && ignoredTopParent != null && ReferenceEquals(hitTopParent, ignoredTopParent));
 130    }
 131
 132    public static bool IsIgnoredTarget(LSCollider2D hitCollider, LSCollider2D? ignored)
 133    {
 3207134        if (ignored == null)
 2764135            return false;
 136
 443137        if (ReferenceEquals(hitCollider, ignored))
 233138            return true;
 139
 210140        SolidBody2D? ignoredBody = ignored.Body;
 210141        if (ignoredBody != null && ReferenceEquals(hitCollider.Body, ignoredBody))
 1142            return true;
 143
 209144        LSCollider2D? hitTopParent = hitCollider.TopParent2D;
 209145        LSCollider2D? ignoredTopParent = ignored.TopParent2D;
 209146        return (hitTopParent != null && ReferenceEquals(hitTopParent, ignored))
 209147            || (ignoredTopParent != null && ReferenceEquals(hitCollider, ignoredTopParent))
 209148            || (hitTopParent != null && ignoredTopParent != null && ReferenceEquals(hitTopParent, ignoredTopParent));
 149    }
 150}