< Summary

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

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_BankWords()100%11100%
get_X()100%11100%
get_Y()100%11100%
get_Z()100%11100%
get_Denominator()100%11100%
.ctor(...)100%44100%
CopyTo(...)100%11100%
CopyTo(...)100%11100%
CompareTo(...)100%1212100%
CompareTo(...)100%1414100%
Set(...)100%11100%
Set(...)100%11100%

File(s)

/home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Geometry/Wide/FiniteAxis/ConePlaneRayPoint.cs

#LineLine coverage
 1//=======================================================================
 2// ConePlaneRayPoint.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
 8using System;
 9
 10namespace FixedMathSharp.Geometry;
 11
 12/// <summary>Borrowed homogeneous coordinates in one exact quadratic field.</summary>
 13internal readonly ref struct ConePlaneRayPoint
 14{
 15    internal const int FieldWords = ConePlaneRaySelection.FieldWords;
 16    internal const int StorageWords = 8 * FieldWords;
 17    internal const int SignCount = 8;
 18    private readonly Span<ulong> values;
 19    private readonly Span<int> signs;
 20    private readonly int _fieldWords;
 457421    internal int BankWords => _fieldWords;
 14385622    internal ContactQuadratic X => ContactQuadratic.At(values, signs, 0, _fieldWords);
 16262823    internal ContactQuadratic Y => ContactQuadratic.At(values, signs, 1, _fieldWords);
 14008224    internal ContactQuadratic Z => ContactQuadratic.At(values, signs, 2, _fieldWords);
 13756025    internal ContactQuadratic Denominator => ContactQuadratic.At(values, signs, 3, _fieldWords);
 26
 27    internal ConePlaneRayPoint(Span<ulong> values, Span<int> signs, int fieldWords = FieldWords)
 28    {
 5168129        if (values.Length < 8 * fieldWords || signs.Length < SignCount)
 230            throw new ArgumentException("The plane-ray point storage is too small.");
 10335831        this.values = values[..(8 * fieldWords)]; this.signs = signs[..SignCount];
 5167932        _fieldWords = fieldWords;
 5167933    }
 34
 35    internal void CopyTo(scoped ConePlaneRayPoint target)
 36    {
 6759637        X.CopyTo(target.X); Y.CopyTo(target.Y); Z.CopyTo(target.Z); Denominator.CopyTo(target.Denominator);
 1689938    }
 39
 40    /// <summary>Changes only the native scale of coordinates in the same physical cone frame.</summary>
 41    internal void CopyTo(scoped ConePlaneRayPoint target, Signed320 sourceScale, Signed320 targetScale)
 42    {
 43        // Coordinates carry 2D native scale. Cross multiplication adds fewer
 44        // than 132 bits to certified point fields below 3072 bits.
 2945        Signed576 scale = Signed576.ExtendValue(targetScale);
 2946        ContactQuadratic.Scale(X, scale, target.X);
 2947        ContactQuadratic.Scale(Y, scale, target.Y);
 2948        ContactQuadratic.Scale(Z, scale, target.Z);
 2949        ContactQuadratic.Scale(Denominator, Signed576.ExtendValue(sourceScale), target.Denominator);
 2950    }
 51
 52    internal int CompareTo(scoped ConePlaneRayPoint other, scoped ReadOnlySpan<ulong> root, scoped ReadOnlySpan<ulong> o
 53    {
 1340454        for (int axis = 0; axis < 3; axis++)
 55        {
 549856            int order = ContactQuadratic.CompareRatios(axis == 0 ? X : axis == 1 ? Y : Z, Denominator, root,
 549857                axis == 0 ? other.X : axis == 1 ? other.Y : other.Z, other.Denominator, otherRoot);
 720758            if (order != 0) return order;
 59        }
 120460        return 0;
 61    }
 62
 63    /// <summary>Orders physical cone-frame points across independently scaled authored frames of the same cone.</summar
 64    /// <remarks>Both points have positive homogeneous denominators and the frames describe the same physical cone.</rem
 65    internal int CompareTo(scoped ConePlaneRayPoint other, scoped ReadOnlySpan<ulong> root,
 66        scoped ReadOnlySpan<ulong> otherRoot, in ConePlaneRayFrame frame, in ConePlaneRayFrame otherFrame)
 67    {
 2468        Signed320 scale = frame.Finite.ShapeFrame.CoordinateDenominator;
 2469        Signed320 otherScale = otherFrame.Finite.ShapeFrame.CoordinateDenominator;
 4070        if (scale.Equals(otherScale)) return CompareTo(other, root, otherRoot);
 71        // Each native coordinate is 2D times the physical coordinate. Carry
 72        // D in the homogeneous denominator; at most three extra limbs keep
 73        // the comparison exact even when Q32.32 witnesses coincide.
 874        int words = Math.Max(ContactQuadratic.ActiveWords(Denominator), ContactQuadratic.ActiveWords(other.Denominator))
 1675        Span<ulong> values = stackalloc ulong[4 * words]; Span<int> signs = stackalloc int[4];
 876        ContactQuadratic denominator = ContactQuadratic.At(values, signs, 0, words);
 877        ContactQuadratic otherDenominator = ContactQuadratic.At(values, signs, 1, words);
 878        ContactQuadratic.Scale(Denominator, Signed576.ExtendValue(scale), denominator);
 879        ContactQuadratic.Scale(other.Denominator, Signed576.ExtendValue(otherScale), otherDenominator);
 4080        for (int axis = 0; axis < 3; axis++)
 81        {
 1882            int order = ContactQuadratic.CompareRatios(axis == 0 ? X : axis == 1 ? Y : Z, denominator, root,
 1883                axis == 0 ? other.X : axis == 1 ? other.Y : other.Z, otherDenominator, otherRoot);
 2484            if (order != 0) return order;
 85        }
 286        return 0;
 87    }
 88
 89    internal void Set(WideAxis3 point)
 90    {
 108091        X.Set(Signed576.ExtendValue(point.X)); Y.Set(Signed576.ExtendValue(point.Y));
 54092        Z.Set(Signed576.ExtendValue(point.Z));
 93        // Signed*.One is Q32 raw unity; a homogeneous denominator needs
 94        // integer unity instead of the physical fixed-point scale.
 54095        Denominator.Set(Signed576.ExtendValue(Signed320.ExtendValue(Signed192.Signed(1))));
 54096    }
 97
 98    internal void Set(WideDirection3d direction)
 99    {
 20112100        X.Set(direction.X); Y.Set(direction.Y); Z.Set(direction.Z);
 6704101        Denominator.Set(Signed576.ExtendValue(Signed320.ExtendValue(Signed192.Signed(1))));
 6704102    }
 103}