< Summary

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

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetRoot(...)100%44100%

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// FiniteAxisValueRoots.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>
 13/// Authoritative distinct-root count and optional compact cells for one fixed
 14/// polynomial on (0,1]. A failed compact batch still owns the complete count;
 15/// its partial cells are never consumed. Storage is borrowed and not mutated.
 16/// </summary>
 17internal readonly ref struct FiniteAxisValueRoots
 18{
 19    private readonly ReadOnlySpan<ulong> _cells;
 20    private readonly ReadOnlySpan<int> _shifts;
 21    private readonly int _rationalMask;
 22    internal int Count { get; }
 23    internal bool HasCompactCells { get; }
 24    internal bool HasRepeatedRoots { get; }
 25
 26    internal FiniteAxisValueRoots(ReadOnlySpan<ulong> cells, ReadOnlySpan<int> shifts,
 27        int count, int rationalMask, bool compact, bool repeated)
 28    {
 2925729        _cells = cells;
 2925730        _shifts = shifts;
 2925731        _rationalMask = rationalMask;
 2925732        Count = count;
 2925733        HasCompactCells = compact;
 2925734        HasRepeatedRoots = repeated;
 2925735    }
 36
 37    /// <summary>
 38    /// Materializes ordinal in [0,Count) for the unchanged polynomial used to
 39    /// create this view. The result borrows only the explicit polynomial and
 40    /// destination spans, not the compact cache. Fallback requires the full
 41    /// GetFiniteValueRootCellWords capacity; compact copying needs its active
 42    /// numerator words plus capacity for the nonrational upper endpoint.
 43    /// </summary>
 44    internal static FiniteAxisValueRoot GetRoot(scoped FiniteAxisValueRoots roots,
 45        int ordinal, ReadOnlySpan<ulong> coefficients,
 46        ReadOnlySpan<sbyte> signs, Span<ulong> cell)
 47    {
 48        System.Diagnostics.Debug.Assert(ordinal >= 0 && ordinal < roots.Count);
 2489249        int words = coefficients.Length / signs.Length;
 2489250        int degree = signs.Length - 1;
 51        // A valid ordinal proves that this unchanged polynomial has a root,
 52        // so trimming cannot reach a constant or zero polynomial.
 2592753        while (signs[degree] == 0)
 103554            degree--;
 2489255        coefficients = coefficients[..((degree + 1) * words)];
 2489256        signs = signs[..(degree + 1)];
 2489257        if (!roots.HasCompactCells)
 1858            return WideFiniteAxisIntersection.GetKnownFiniteValueRoot(coefficients, signs, ordinal, roots.Count, cell);
 2487459        int cellWords = roots._cells.Length / 8;
 2487460        ReadOnlySpan<ulong> source = roots._cells.Slice(ordinal * cellWords, cellWords);
 2487461        cell.Clear();
 2487462        source[..WideArithmetic.GetActiveMagnitudeLength(source)].CopyTo(cell);
 2487463        return new FiniteAxisValueRoot
 2487464        {
 2487465            Coefficients = coefficients, Signs = signs, LowerNumerator = cell,
 2487466            DenominatorShift = roots._shifts[ordinal], Ordinal = ordinal,
 2487467            IsRational = (roots._rationalMask & (1 << ordinal)) != 0
 2487468        };
 69    }
 70}