< Summary

Information
Class: FixedMathSharp.Geometry.WideRationalBasis3d
Assembly: FixedMathSharp
File(s): /home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Geometry/Wide/Common/WideRationalBasis3d.cs
Line coverage
100%
Covered lines: 142
Uncovered lines: 0
Coverable lines: 142
Total lines: 211
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%
.ctor(...)100%11100%
CreateRelative(...)100%11100%
GetAxis(...)100%44100%
GetComposedScaledCoordinateNumerator(...)100%11100%
Double(...)100%11100%

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// WideRationalBasis3d.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.Runtime.CompilerServices;
 9
 10namespace FixedMathSharp.Geometry;
 11
 12/// <summary>
 13/// Preserves a quaternion-derived rotation basis as exact rational
 14/// numerators over one shared denominator.
 15/// </summary>
 16internal readonly struct WideRationalBasis3d
 17{
 18    internal readonly Signed192 Denominator;
 19    internal readonly Signed192 Xx;
 20    internal readonly Signed192 Xy;
 21    internal readonly Signed192 Xz;
 22    internal readonly Signed192 Yx;
 23    internal readonly Signed192 Yy;
 24    internal readonly Signed192 Yz;
 25    internal readonly Signed192 Zx;
 26    internal readonly Signed192 Zy;
 27    internal readonly Signed192 Zz;
 28
 29    internal WideRationalBasis3d(FixedQuaternion orientation)
 30    {
 3603331        Signed192 xx = Fixed64.GetExactRawProduct(
 3603332            orientation.X,
 3603333            orientation.X);
 3603334        Signed192 yy = Fixed64.GetExactRawProduct(
 3603335            orientation.Y,
 3603336            orientation.Y);
 3603337        Signed192 zz = Fixed64.GetExactRawProduct(
 3603338            orientation.Z,
 3603339            orientation.Z);
 3603340        Signed192 ww = Fixed64.GetExactRawProduct(
 3603341            orientation.W,
 3603342            orientation.W);
 3603343        Signed192 xy = Fixed64.GetExactRawProduct(
 3603344            orientation.X,
 3603345            orientation.Y);
 3603346        Signed192 xz = Fixed64.GetExactRawProduct(
 3603347            orientation.X,
 3603348            orientation.Z);
 3603349        Signed192 xw = Fixed64.GetExactRawProduct(
 3603350            orientation.X,
 3603351            orientation.W);
 3603352        Signed192 yz = Fixed64.GetExactRawProduct(
 3603353            orientation.Y,
 3603354            orientation.Z);
 3603355        Signed192 yw = Fixed64.GetExactRawProduct(
 3603356            orientation.Y,
 3603357            orientation.W);
 3603358        Signed192 zw = Fixed64.GetExactRawProduct(
 3603359            orientation.Z,
 3603360            orientation.W);
 3603361        Denominator = WideArithmetic.AddSigned192(
 3603362            WideArithmetic.AddSigned192(xx, yy),
 3603363            WideArithmetic.AddSigned192(zz, ww));
 64
 3603365        Xx = WideArithmetic.AddSigned192(
 3603366            WideArithmetic.SubtractSigned192(
 3603367                WideArithmetic.SubtractSigned192(xx, yy),
 3603368                zz),
 3603369            ww);
 3603370        Xy = Double(WideArithmetic.AddSigned192(xy, zw));
 3603371        Xz = Double(WideArithmetic.SubtractSigned192(xz, yw));
 3603372        Yx = Double(WideArithmetic.SubtractSigned192(xy, zw));
 3603373        Yy = WideArithmetic.AddSigned192(
 3603374            WideArithmetic.SubtractSigned192(
 3603375                WideArithmetic.SubtractSigned192(yy, xx),
 3603376                zz),
 3603377            ww);
 3603378        Yz = Double(WideArithmetic.AddSigned192(yz, xw));
 3603379        Zx = Double(WideArithmetic.AddSigned192(xz, yw));
 3603380        Zy = Double(WideArithmetic.SubtractSigned192(yz, xw));
 3603381        Zz = WideArithmetic.AddSigned192(
 3603382            WideArithmetic.SubtractSigned192(
 3603383                WideArithmetic.SubtractSigned192(zz, xx),
 3603384                yy),
 3603385            ww);
 3603386    }
 87
 88    private WideRationalBasis3d(
 89        Signed192 denominator,
 90        Signed192 xx,
 91        Signed192 xy,
 92        Signed192 xz,
 93        Signed192 yx,
 94        Signed192 yy,
 95        Signed192 yz,
 96        Signed192 zx,
 97        Signed192 zy,
 98        Signed192 zz)
 99    {
 1334100        Denominator = denominator;
 1334101        Xx = xx;
 1334102        Xy = xy;
 1334103        Xz = xz;
 1334104        Yx = yx;
 1334105        Yy = yy;
 1334106        Yz = yz;
 1334107        Zx = zx;
 1334108        Zy = zy;
 1334109        Zz = zz;
 1334110    }
 111
 112    internal static WideRationalBasis3d CreateRelative(
 113        in WideRationalBasis3d target,
 114        in WideRationalBasis3d source) =>
 115        // Normalized quaternion-basis products and their three-term sums fit
 116        // Signed192, including the unreduced shared denominator.
 1334117        new(
 1334118            Signed192.NarrowProven(
 1334119                WideArithmetic.MultiplySigned192(
 1334120                    target.Denominator,
 1334121                    source.Denominator)),
 1334122            Signed192.NarrowProven(WideArithmetic.GetDotProduct3D(
 1334123                target.Xx, target.Xy, target.Xz,
 1334124                source.Xx, source.Xy, source.Xz)),
 1334125            Signed192.NarrowProven(WideArithmetic.GetDotProduct3D(
 1334126                target.Yx, target.Yy, target.Yz,
 1334127                source.Xx, source.Xy, source.Xz)),
 1334128            Signed192.NarrowProven(WideArithmetic.GetDotProduct3D(
 1334129                target.Zx, target.Zy, target.Zz,
 1334130                source.Xx, source.Xy, source.Xz)),
 1334131            Signed192.NarrowProven(WideArithmetic.GetDotProduct3D(
 1334132                target.Xx, target.Xy, target.Xz,
 1334133                source.Yx, source.Yy, source.Yz)),
 1334134            Signed192.NarrowProven(WideArithmetic.GetDotProduct3D(
 1334135                target.Yx, target.Yy, target.Yz,
 1334136                source.Yx, source.Yy, source.Yz)),
 1334137            Signed192.NarrowProven(WideArithmetic.GetDotProduct3D(
 1334138                target.Zx, target.Zy, target.Zz,
 1334139                source.Yx, source.Yy, source.Yz)),
 1334140            Signed192.NarrowProven(WideArithmetic.GetDotProduct3D(
 1334141                target.Xx, target.Xy, target.Xz,
 1334142                source.Zx, source.Zy, source.Zz)),
 1334143            Signed192.NarrowProven(WideArithmetic.GetDotProduct3D(
 1334144                target.Yx, target.Yy, target.Yz,
 1334145                source.Zx, source.Zy, source.Zz)),
 1334146            Signed192.NarrowProven(WideArithmetic.GetDotProduct3D(
 1334147                target.Zx, target.Zy, target.Zz,
 1334148                source.Zx, source.Zy, source.Zz)));
 149
 150    internal WideAxis3 GetAxis(int index) =>
 5142151        index switch
 5142152        {
 2058153            0 => new WideAxis3(
 2058154                Signed320.ExtendValue(Xx),
 2058155                Signed320.ExtendValue(Xy),
 2058156                Signed320.ExtendValue(Xz)),
 2048157            1 => new WideAxis3(
 2048158                Signed320.ExtendValue(Yx),
 2048159                Signed320.ExtendValue(Yy),
 2048160                Signed320.ExtendValue(Yz)),
 1036161            _ => new WideAxis3(
 1036162                Signed320.ExtendValue(Zx),
 1036163                Signed320.ExtendValue(Zy),
 1036164                Signed320.ExtendValue(Zz)),
 5142165        };
 166
 167    internal static Signed576 GetComposedScaledCoordinateNumerator(
 168        Fixed64 outerLocalPoint,
 169        Fixed64 outerScale,
 170        Signed192 axisX,
 171        Signed192 axisY,
 172        Signed192 axisZ,
 173        Signed192 rotationDenominator,
 174        Fixed64 innerFrameOffset,
 175        Fixed64 innerFrameScale,
 176        Vector3d innerLocalDisplacement)
 177    {
 201178        Signed576 outerScaled = WideArithmetic.MultiplySigned320(
 201179            WideArithmetic.MultiplySigned192(
 201180                Signed192.Raw(outerLocalPoint),
 201181                Signed192.Raw(outerScale)),
 201182            Signed320.ExtendValue(rotationDenominator));
 201183        Signed576 innerScaled = WideArithmetic.MultiplySigned320(
 201184            WideArithmetic.MultiplySigned192(
 201185                Signed192.Raw(innerFrameOffset),
 201186                Signed192.Raw(innerFrameScale)),
 201187            Signed320.ExtendValue(rotationDenominator));
 201188        Signed320 displacement = WideArithmetic.AddSigned320(
 201189            WideArithmetic.AddSigned320(
 201190                WideArithmetic.MultiplySigned192(
 201191                    Signed192.Raw(innerLocalDisplacement.X),
 201192                    axisX),
 201193                WideArithmetic.MultiplySigned192(
 201194                    Signed192.Raw(innerLocalDisplacement.Y),
 201195                    axisY)),
 201196            WideArithmetic.MultiplySigned192(
 201197                Signed192.Raw(innerLocalDisplacement.Z),
 201198                axisZ));
 201199        return WideArithmetic.AddSigned576(
 201200            WideArithmetic.AddSigned576(
 201201                outerScaled,
 201202                innerScaled),
 201203            WideArithmetic.MultiplySigned320(
 201204                displacement,
 201205                Signed320.ExtendValue(Signed192.One)));
 206    }
 207
 208    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 209    private static Signed192 Double(Signed192 value) =>
 216198210        WideArithmetic.AddSigned192(value, value);
 211}