< Summary

Information
Class: FixedMathSharp.Geometry.WideRadialGeometry
Assembly: FixedMathSharp
File(s): /home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Geometry/Wide/Common/WideRadialGeometry.cs
Line coverage
100%
Covered lines: 30
Uncovered lines: 0
Coverable lines: 30
Total lines: 67
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
TryGetSphereSlabCrossSectionRadius(...)100%66100%
TryGetCircleCrossSectionRadius(...)100%44100%

File(s)

/home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Geometry/Wide/Common/WideRadialGeometry.cs

#LineLine coverage
 1//=======================================================================
 2// WideRadialGeometry.cs
 3//=======================================================================
 4// MIT License, Copyright (c) 2024–present David Oravsky (mrdav30)
 5// See LICENSE file in the project root for full license information.
 6//=======================================================================
 7
 8namespace FixedMathSharp.Geometry;
 9
 10/// <summary>
 11/// Owns exact scalar reductions used by radial geometry.
 12/// </summary>
 13internal static class WideRadialGeometry
 14{
 15    internal static bool TryGetSphereSlabCrossSectionRadius(
 16        Fixed64 sphereCenter,
 17        Fixed64 sphereRadius,
 18        Fixed64 slabCenter,
 19        Fixed64 slabHalfThickness,
 20        out Fixed64 crossSectionRadius)
 21    {
 522        ulong centerDistance = sphereCenter.m_rawValue >= slabCenter.m_rawValue
 523            ? unchecked((ulong)sphereCenter.m_rawValue - (ulong)slabCenter.m_rawValue)
 524            : unchecked((ulong)slabCenter.m_rawValue - (ulong)sphereCenter.m_rawValue);
 525        ulong halfThickness = (ulong)slabHalfThickness.m_rawValue;
 526        ulong offset = centerDistance > halfThickness
 527            ? centerDistance - halfThickness
 528            : 0UL;
 529        if (offset > (ulong)sphereRadius.m_rawValue)
 30        {
 131            crossSectionRadius = Fixed64.Zero;
 132            return false;
 33        }
 34
 435        return TryGetCircleCrossSectionRadius(
 436            sphereRadius,
 437            Fixed64.FromRaw((long)offset),
 438            out crossSectionRadius);
 39    }
 40
 41    internal static bool TryGetCircleCrossSectionRadius(
 42        Fixed64 radius,
 43        Fixed64 offset,
 44        out Fixed64 crossSectionRadius)
 45    {
 1146        Signed192 radiusRaw = Signed192.Signed(radius.m_rawValue);
 1147        Signed192 offsetRaw = Signed192.Signed(offset.m_rawValue);
 1148        Signed320 squaredRadius = WideArithmetic.MultiplySigned192(radiusRaw, radiusRaw);
 1149        Signed320 squaredOffset = WideArithmetic.MultiplySigned192(offsetRaw, offsetRaw);
 1150        Signed320 squaredCrossSection = WideArithmetic.SubtractSigned320(squaredRadius, squaredOffset);
 1151        if (squaredCrossSection.Sign < 0)
 52        {
 253            crossSectionRadius = Fixed64.Zero;
 254            return false;
 55        }
 56
 957        Signed192 root = WideArithmetic.GetFloorSquareRoot(
 958            squaredCrossSection,
 959            out Signed192 remainder);
 960        WideArithmetic.GetMagnitude(root, out _, out _, out ulong rawRadius);
 961        if (WideArithmetic.CompareMagnitude(remainder, root) > 0)
 162            rawRadius++;
 63
 964        crossSectionRadius = Fixed64.FromRaw((long)rawRadius);
 965        return true;
 66    }
 67}