< Summary

Information
Class: FixedMathSharp.Geometry.WideDirection3d
Assembly: FixedMathSharp
File(s): /home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Geometry/Wide/Common/WideDirection3d.cs
Line coverage
100%
Covered lines: 50
Uncovered lines: 0
Coverable lines: 50
Total lines: 91
Line coverage: 100%
Branch coverage
100%
Covered branches: 14
Total branches: 14
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%
.ctor(...)100%11100%
get_IsZero()100%44100%
get_SquaredLength()100%11100%
GetNormal(...)100%66100%
Cross(...)100%11100%
Dot(...)100%11100%
Dot(...)100%11100%
AreParallel(...)100%44100%
ProjectPerpendicular(...)100%11100%
DifferenceScaled(...)100%11100%
op_UnaryNegation(...)100%11100%
DifferenceProduct(...)100%11100%
GetLocalEdge(...)100%11100%
Transform(...)100%11100%
TransformComponent(...)100%11100%

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// WideDirection3d.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>An exact scaled-hull SAT direction; its magnitude is deliberately arbitrary.</summary>
 11internal readonly struct WideDirection3d
 12{
 13    internal readonly Signed576 X, Y, Z;
 676413614    internal WideDirection3d(Signed576 x, Signed576 y, Signed576 z) { X = x; Y = y; Z = z; }
 15    internal WideDirection3d(Signed320 x, Signed320 y, Signed320 z)
 81646416        : this(Signed576.ExtendValue(x), Signed576.ExtendValue(y), Signed576.ExtendValue(z)) { }
 17    internal WideDirection3d(in WideAxis3 value)
 4907018        : this(Signed576.ExtendValue(value.X), Signed576.ExtendValue(value.Y), Signed576.ExtendValue(value.Z)) { }
 61984319    internal bool IsZero => X.IsZero && Y.IsZero && Z.IsZero;
 5781120    internal Signed832 SquaredLength => WideArithmetic.AddSigned832(WideArithmetic.AddSigned832(
 5781121        WideArithmetic.MultiplySigned576ToSigned832(X, X), WideArithmetic.MultiplySigned576ToSigned832(Y, Y)),
 5781122        WideArithmetic.MultiplySigned576ToSigned832(Z, Z));
 16423    internal Vector3d GetNormal(bool negate) => WideNormalization.GetNormalized(
 16424        negate ? WideArithmetic.SubtractSigned576(default, X) : X,
 16425        negate ? WideArithmetic.SubtractSigned576(default, Y) : Y,
 16426        negate ? WideArithmetic.SubtractSigned576(default, Z) : Z);
 27
 5403628    internal static WideDirection3d Cross(in WideDirection3d a, in WideDirection3d b) => new(
 5403629        DifferenceProduct(a.Y, b.Z, a.Z, b.Y), DifferenceProduct(a.Z, b.X, a.X, b.Z),
 5403630        DifferenceProduct(a.X, b.Y, a.Y, b.X));
 31    internal static Signed832 Dot(in WideDirection3d axis, in WideAxis3 point) =>
 3452032        WideArithmetic.AddSigned832(WideArithmetic.AddSigned832(
 3452033            WideArithmetic.MultiplySigned576ToSigned832(axis.X, point.X),
 3452034            WideArithmetic.MultiplySigned576ToSigned832(axis.Y, point.Y)),
 3452035            WideArithmetic.MultiplySigned576ToSigned832(axis.Z, point.Z));
 36    internal static Signed832 Dot(in WideDirection3d first, in WideDirection3d second) =>
 51513137        WideArithmetic.AddSigned832(WideArithmetic.AddSigned832(
 51513138            WideArithmetic.MultiplySigned576ToSigned832(first.X, second.X),
 51513139            WideArithmetic.MultiplySigned576ToSigned832(first.Y, second.Y)),
 51513140            WideArithmetic.MultiplySigned576ToSigned832(first.Z, second.Z));
 41    internal static bool AreParallel(in WideDirection3d first, in WideDirection3d second) =>
 288742        WideArithmetic.SubtractSigned832(WideArithmetic.MultiplySigned576ToSigned832(first.Y, second.Z),
 288743            WideArithmetic.MultiplySigned576ToSigned832(first.Z, second.Y)).IsZero
 288744        && WideArithmetic.SubtractSigned832(WideArithmetic.MultiplySigned576ToSigned832(first.Z, second.X),
 288745            WideArithmetic.MultiplySigned576ToSigned832(first.X, second.Z)).IsZero
 288746        && WideArithmetic.SubtractSigned832(WideArithmetic.MultiplySigned576ToSigned832(first.X, second.Y),
 288747            WideArithmetic.MultiplySigned576ToSigned832(first.Y, second.X)).IsZero;
 48    /// <summary>
 49    /// Returns axis squared times value minus (axis dot value) times axis.
 50    /// The caller proves the squared norm, dot and result fit 576 bits, and
 51    /// every complete product/difference fits 832 bits.
 52    /// </summary>
 53    internal static WideDirection3d ProjectPerpendicular(in WideDirection3d axis, in WideDirection3d value)
 54    {
 842955        Signed576 squaredAxis = Signed576.NarrowValue(axis.SquaredLength);
 842956        Signed576 projection = Signed576.NarrowValue(Dot(axis, value));
 842957        return DifferenceScaled(value, squaredAxis, axis, projection);
 58    }
 59
 60    /// <summary>
 61    /// Returns firstScale times first minus secondScale times second.
 62    /// Complete products/differences must fit 832 bits and result components 576.
 63    /// </summary>
 64    internal static WideDirection3d DifferenceScaled(in WideDirection3d first, Signed576 firstScale,
 986965        in WideDirection3d second, Signed576 secondScale) => new(
 986966        DifferenceProduct(first.X, firstScale, second.X, secondScale),
 986967        DifferenceProduct(first.Y, firstScale, second.Y, secondScale),
 986968        DifferenceProduct(first.Z, firstScale, second.Z, secondScale));
 69
 7805570    public static WideDirection3d operator -(WideDirection3d value) => new(
 7805571        WideArithmetic.SubtractSigned576(default, value.X), WideArithmetic.SubtractSigned576(default, value.Y),
 7805572        WideArithmetic.SubtractSigned576(default, value.Z));
 73    private static Signed576 DifferenceProduct(Signed576 a, Signed576 b, Signed576 c, Signed576 d) =>
 19171574        Signed576.NarrowValue(WideArithmetic.SubtractSigned832(WideArithmetic.MultiplySigned576ToSigned832(a, b),
 19171575            WideArithmetic.MultiplySigned576ToSigned832(c, d)));
 76
 77    internal static WideDirection3d GetLocalEdge(in ScaledRigidFrame3d frame, Vector3d a, Vector3d b)
 78    {
 3998979        frame.GetScaledLocalPointNumerators(a, out Signed192 ax, out Signed192 ay, out Signed192 az);
 3998980        frame.GetScaledLocalPointNumerators(b, out Signed192 bx, out Signed192 by, out Signed192 bz);
 3998981        return new WideDirection3d(Signed576.ExtendValue(Signed320.ExtendValue(WideArithmetic.SubtractSigned192(bx, ax))
 3998982            Signed576.ExtendValue(Signed320.ExtendValue(WideArithmetic.SubtractSigned192(by, ay))),
 3998983            Signed576.ExtendValue(Signed320.ExtendValue(WideArithmetic.SubtractSigned192(bz, az))));
 84    }
 3639685    internal WideDirection3d Transform(in WideRationalBasis3d basis) => new(
 3639686        TransformComponent(basis.Xx, basis.Yx, basis.Zx), TransformComponent(basis.Xy, basis.Yy, basis.Zy),
 3639687        TransformComponent(basis.Xz, basis.Yz, basis.Zz));
 88    private Signed576 TransformComponent(Signed192 x, Signed192 y, Signed192 z) =>
 10918889        WideArithmetic.AddSigned576(WideArithmetic.AddSigned576(WideArithmetic.MultiplySigned576(X, x),
 10918890            WideArithmetic.MultiplySigned576(Y, y)), WideArithmetic.MultiplySigned576(Z, z));
 91}