| | | 1 | | //======================================================================= |
| | | 2 | | // FiniteAxisValueRoot.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 | | |
| | | 8 | | using System; |
| | | 9 | | |
| | | 10 | | namespace FixedMathSharp.Geometry; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// One ordinal-selected root in (0,1] of a degree-at-most-eight integer value |
| | | 14 | | /// polynomial. Borrowed coefficients and cell storage outlive this view. |
| | | 15 | | /// </summary> |
| | | 16 | | internal ref struct FiniteAxisValueRoot |
| | | 17 | | { |
| | | 18 | | internal ReadOnlySpan<ulong> Coefficients; |
| | | 19 | | internal ReadOnlySpan<sbyte> Signs; |
| | | 20 | | internal Span<ulong> LowerNumerator; |
| | | 21 | | internal int DenominatorShift; |
| | | 22 | | internal int Ordinal; |
| | | 23 | | internal bool IsRational; |
| | | 24 | | |
| | | 25 | | /// <summary>Copies a root into independent storage and returns a view borrowing only the destinations.</summary> |
| | | 26 | | /// <remarks> |
| | | 27 | | /// The source must be a valid root. Destinations must be mutually disjoint |
| | | 28 | | /// and disjoint from source storage. Coefficient and sign capacities must |
| | | 29 | | /// hold the source polynomial spans; cell capacity must hold the active |
| | | 30 | | /// numerator and, for a nonrational root, its excluded upper endpoint. |
| | | 31 | | /// Polynomial destination tails are untouched; the cell tail is cleared. |
| | | 32 | | /// </remarks> |
| | | 33 | | internal static FiniteAxisValueRoot CopyTo(scoped FiniteAxisValueRoot source, |
| | | 34 | | Span<ulong> coefficients, Span<sbyte> signs, Span<ulong> cell) |
| | | 35 | | { |
| | 407 | 36 | | source.Coefficients.CopyTo(coefficients); |
| | 407 | 37 | | source.Signs.CopyTo(signs); |
| | 407 | 38 | | int words = WideArithmetic.GetActiveMagnitudeLength(source.LowerNumerator); |
| | 407 | 39 | | source.LowerNumerator[..words].CopyTo(cell); |
| | 407 | 40 | | cell[words..].Clear(); |
| | 407 | 41 | | return new FiniteAxisValueRoot |
| | 407 | 42 | | { |
| | 407 | 43 | | Coefficients = coefficients[..source.Coefficients.Length], Signs = signs[..source.Signs.Length], |
| | 407 | 44 | | LowerNumerator = cell, DenominatorShift = source.DenominatorShift, |
| | 407 | 45 | | Ordinal = source.Ordinal, IsRational = source.IsRational |
| | 407 | 46 | | }; |
| | | 47 | | } |
| | | 48 | | } |