< Summary

Information
Class: Gravitas.CollisionHandling.ContinuousCollisionCandidateOrdering
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Continuous/ContinuousCollisionCandidateOrdering.cs
Line coverage
100%
Covered lines: 70
Uncovered lines: 0
Coverable lines: 70
Total lines: 147
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/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 FixedMathSharp;
 9using Gravitas.Colliders;
 10using Gravitas.Queries;
 11using System.Runtime.CompilerServices;
 12
 13namespace Gravitas.CollisionHandling;
 14
 15internal static class ContinuousCollisionCandidateOrdering
 16{
 17    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 18    public static bool Is2DHitFirst(Fixed64 distance2D, Fixed64 distance3D) =>
 919        distance2D <= distance3D;
 20
 21    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 22    public static bool ShouldReplaceHit(
 23        Physics3DHit candidate,
 24        Fixed64 candidateClosingSpeed,
 25        bool hasCandidate,
 26        bool hasCurrent,
 27        Physics3DHit current,
 28        Fixed64 currentClosingSpeed)
 29    {
 49830        if (!hasCandidate)
 38531            return false;
 11332        if (!hasCurrent)
 9533            return true;
 34
 1835        int distance = candidate.Distance.CompareTo(current.Distance);
 1836        if (distance != 0)
 1337            return distance < 0;
 38
 539        int closing = candidateClosingSpeed.CompareTo(currentClosingSpeed);
 540        if (closing != 0)
 141            return closing > 0;
 42
 443        int candidateId = candidate.Collider?.Id ?? -1;
 444        int currentId = current.Collider?.Id ?? -1;
 445        return candidateId < currentId;
 46    }
 47
 48    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 49    public static bool ShouldReplaceHit(
 50        Physics2DHit candidate,
 51        Fixed64 candidateClosingSpeed,
 52        bool hasCandidate,
 53        bool hasCurrent,
 54        Physics2DHit current,
 55        Fixed64 currentClosingSpeed)
 56    {
 37557        if (!hasCandidate)
 28658            return false;
 8959        if (!hasCurrent)
 7360            return true;
 61
 1662        int distance = candidate.Distance.CompareTo(current.Distance);
 1663        if (distance != 0)
 1364            return distance < 0;
 65
 366        int closing = candidateClosingSpeed.CompareTo(currentClosingSpeed);
 367        if (closing != 0)
 168            return closing > 0;
 69
 270        return candidate.Collider.Id < current.Collider.Id;
 71    }
 72
 73    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 74    public static bool ShouldReplaceMixedHit(
 75        PhysicsMixedHit candidate,
 76        Fixed64 candidateClosingSpeed,
 77        bool hasCandidate,
 78        bool hasCurrent,
 79        PhysicsMixedHit current,
 80        Fixed64 currentClosingSpeed)
 81    {
 1582        if (!hasCandidate)
 183            return false;
 1484        if (!hasCurrent)
 185            return true;
 86
 1387        int distance = candidate.Distance.CompareTo(current.Distance);
 1388        if (distance != 0)
 489            return distance < 0;
 90
 991        int closing = candidateClosingSpeed.CompareTo(currentClosingSpeed);
 992        if (closing != 0)
 193            return closing > 0;
 94
 895        int reducer = candidate.ReducerKind.CompareTo(current.ReducerKind);
 896        if (reducer != 0)
 197            return reducer < 0;
 98
 799        int candidate3D = candidate.Collider3D?.Id ?? -1;
 7100        int current3D = current.Collider3D?.Id ?? -1;
 7101        int collider3D = candidate3D.CompareTo(current3D);
 7102        if (collider3D != 0)
 3103            return collider3D < 0;
 104
 4105        int candidate2D = candidate.Collider2D?.Id ?? -1;
 4106        int current2D = current.Collider2D?.Id ?? -1;
 4107        return candidate2D < current2D;
 108    }
 109
 110    public static bool IsIgnoredTarget(LSCollider hitCollider, LSCollider? ignored)
 111    {
 13661112        if (ignored == null)
 13406113            return false;
 114
 255115        if (ReferenceEquals(hitCollider, ignored))
 124116            return true;
 117
 131118        SolidBody? ignoredBody = ignored.Body;
 131119        if (ignoredBody != null && ReferenceEquals(hitCollider.Body, ignoredBody))
 1120            return true;
 121
 130122        LSCollider? hitTopParent = hitCollider.TopParent3D;
 130123        LSCollider? ignoredTopParent = ignored.TopParent3D;
 130124        return (hitTopParent != null && ReferenceEquals(hitTopParent, ignored))
 130125            || (ignoredTopParent != null && ReferenceEquals(hitCollider, ignoredTopParent))
 130126            || (hitTopParent != null && ignoredTopParent != null && ReferenceEquals(hitTopParent, ignoredTopParent));
 127    }
 128
 129    public static bool IsIgnoredTarget(LSCollider2D hitCollider, LSCollider2D? ignored)
 130    {
 1523131        if (ignored == null)
 1280132            return false;
 133
 243134        if (ReferenceEquals(hitCollider, ignored))
 149135            return true;
 136
 94137        SolidBody2D? ignoredBody = ignored.Body;
 94138        if (ignoredBody != null && ReferenceEquals(hitCollider.Body, ignoredBody))
 1139            return true;
 140
 93141        LSCollider2D? hitTopParent = hitCollider.TopParent2D;
 93142        LSCollider2D? ignoredTopParent = ignored.TopParent2D;
 93143        return (hitTopParent != null && ReferenceEquals(hitTopParent, ignored))
 93144            || (ignoredTopParent != null && ReferenceEquals(hitCollider, ignoredTopParent))
 93145            || (hitTopParent != null && ignoredTopParent != null && ReferenceEquals(hitTopParent, ignoredTopParent));
 146    }
 147}