< Summary

Information
Class: Gravitas.CollisionHandling.ContinuousCollisionSweepRange
Assembly: Gravitas
File(s): /home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Continuous/ContinuousCollisionSweepRange.cs
Line coverage
100%
Covered lines: 24
Uncovered lines: 0
Coverable lines: 24
Total lines: 103
Line coverage: 100%
Branch coverage
100%
Covered branches: 20
Total branches: 20
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ValidateEndpoint(...)100%44100%
ValidateEndpoint(...)100%44100%
ValidateEndpoint(...)100%22100%
ValidateEndpoint(...)100%22100%
ValidateRelativeDisplacement(...)100%44100%
ValidateRelativeDisplacement(...)100%44100%

File(s)

/home/runner/work/Gravitas/Gravitas/src/Gravitas/CollisionHandling/Continuous/ContinuousCollisionSweepRange.cs

#LineLine coverage
 1//=======================================================================
 2// ContinuousCollisionSweepRange.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;
 10using System.Runtime.CompilerServices;
 11
 12namespace Gravitas.CollisionHandling;
 13
 14/// <summary>
 15/// Validates the scalar-distance contract required by continuous sweep queries.
 16/// </summary>
 17internal static class ContinuousCollisionSweepRange
 18{
 19    private const string RangeMessage =
 20        "Continuous collision motion must have a component-exact difference and a representable Euclidean length.";
 21
 22    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 23    public static Vector2d ValidateEndpoint(Vector2d start, Vector2d end, out Fixed64 length)
 24    {
 143225        if (!Vector2d.TrySubtract(end, start, out Vector2d displacement)
 143226            || !Vector2d.TryGetMagnitude(displacement, out length))
 27        {
 428            throw new ArgumentOutOfRangeException(nameof(end), RangeMessage);
 29        }
 30
 142831        return displacement;
 32    }
 33
 34    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 35    public static Vector3d ValidateEndpoint(Vector3d start, Vector3d end, out Fixed64 length)
 36    {
 2006637        if (!Vector3d.TrySubtract(end, start, out Vector3d displacement)
 2006638            || !Vector3d.TryGetMagnitude(displacement, out length))
 39        {
 440            throw new ArgumentOutOfRangeException(nameof(end), RangeMessage);
 41        }
 42
 2006243        return displacement;
 44    }
 45
 46    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 47    public static Vector2d ValidateEndpoint(
 48        Vector2d start,
 49        Vector2d end,
 50        Vector2d requestedDisplacement,
 51        out Fixed64 length)
 52    {
 58153        Vector2d displacement = ValidateEndpoint(start, end, out length);
 57954        if (displacement != requestedDisplacement)
 155            throw new ArgumentOutOfRangeException(nameof(end), RangeMessage);
 56
 57857        return displacement;
 58    }
 59
 60    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 61    public static Vector3d ValidateEndpoint(
 62        Vector3d start,
 63        Vector3d end,
 64        Vector3d requestedDisplacement,
 65        out Fixed64 length)
 66    {
 80167        Vector3d displacement = ValidateEndpoint(start, end, out length);
 80068        if (displacement != requestedDisplacement)
 169            throw new ArgumentOutOfRangeException(nameof(end), RangeMessage);
 70
 79971        return displacement;
 72    }
 73
 74    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 75    public static Vector2d ValidateRelativeDisplacement(
 76        Vector2d sourceDisplacement,
 77        Vector2d targetDisplacement,
 78        out Fixed64 length)
 79    {
 31380        if (!Vector2d.TrySubtract(sourceDisplacement, targetDisplacement, out Vector2d relativeDisplacement)
 31381            || !Vector2d.TryGetMagnitude(relativeDisplacement, out length))
 82        {
 383            throw new ArgumentOutOfRangeException(nameof(sourceDisplacement), RangeMessage);
 84        }
 85
 31086        return relativeDisplacement;
 87    }
 88
 89    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 90    public static Vector3d ValidateRelativeDisplacement(
 91        Vector3d sourceDisplacement,
 92        Vector3d targetDisplacement,
 93        out Fixed64 length)
 94    {
 32895        if (!Vector3d.TrySubtract(sourceDisplacement, targetDisplacement, out Vector3d relativeDisplacement)
 32896            || !Vector3d.TryGetMagnitude(relativeDisplacement, out length))
 97        {
 398            throw new ArgumentOutOfRangeException(nameof(sourceDisplacement), RangeMessage);
 99        }
 100
 325101        return relativeDisplacement;
 102    }
 103}