< Summary

Information
Class: FixedMathSharp.Geometry.FixedPointAnchorTerm3d
Assembly: FixedMathSharp
File(s): /home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Geometry/Anchors/FixedPointAnchorTerm3d.cs
Line coverage
100%
Covered lines: 47
Uncovered lines: 0
Coverable lines: 47
Total lines: 118
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
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%
get_IsZero()100%44100%
CreateCenteredAxisSupport(...)100%11100%
CreateRadialSupport(...)100%11100%
LiftPlanarXZ(...)100%11100%
GetResidual(...)100%11100%
get_Denominator()100%11100%
Equals(...)100%44100%
GetHashCode()100%11100%

File(s)

/home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Geometry/Anchors/FixedPointAnchorTerm3d.cs

#LineLine coverage
 1//=======================================================================
 2// FixedPointAnchorTerm3d.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/// Retains the residual between rounded local feature components and their
 14/// exact centered-axis construction over the shared 2*Q32.32 denominator.
 15/// </summary>
 16internal readonly struct FixedPointAnchorTerm3d : IEquatable<FixedPointAnchorTerm3d>
 17{
 18    internal readonly long X;
 19    internal readonly long Y;
 20    internal readonly long Z;
 21
 22    internal FixedPointAnchorTerm3d(
 23        long x,
 24        long y,
 25        long z)
 26    {
 855027        X = x;
 855028        Y = y;
 855029        Z = z;
 855030    }
 31
 2740932    internal bool IsZero => X == 0L && Y == 0L && Z == 0L;
 33
 34    internal static FixedPointAnchorTerm3d CreateCenteredAxisSupport(
 35        Vector3d localAxis,
 36        Fixed64 signedAxisLength,
 37        Vector3d localRadialDirection,
 38        Fixed64 radius,
 39        Vector3d roundedAxialOffset,
 40        Vector3d roundedRadialOffset) =>
 853041        new(
 853042            GetResidual(
 853043                localAxis.X,
 853044                signedAxisLength,
 853045                localRadialDirection.X,
 853046                radius,
 853047                roundedAxialOffset.X,
 853048                roundedRadialOffset.X),
 853049            GetResidual(
 853050                localAxis.Y,
 853051                signedAxisLength,
 853052                localRadialDirection.Y,
 853053                radius,
 853054                roundedAxialOffset.Y,
 853055                roundedRadialOffset.Y),
 853056            GetResidual(
 853057                localAxis.Z,
 853058                signedAxisLength,
 853059                localRadialDirection.Z,
 853060                radius,
 853061                roundedAxialOffset.Z,
 853062                roundedRadialOffset.Z));
 63
 64    internal static FixedPointAnchorTerm3d CreateRadialSupport(
 65        Vector3d localRadialDirection,
 66        Fixed64 radius,
 67        Vector3d roundedRadialOffset) =>
 42168        CreateCenteredAxisSupport(
 42169            Vector3d.Zero,
 42170            Fixed64.Zero,
 42171            localRadialDirection,
 42172            radius,
 42173            Vector3d.Zero,
 42174            roundedRadialOffset);
 75
 76    internal static FixedPointAnchorTerm3d LiftPlanarXZ(
 77        FixedPointAnchorTerm2d planarTerm) =>
 578        new(planarTerm.X, 0L, planarTerm.Y);
 79
 80    internal static long GetResidual(
 81        Fixed64 localAxis,
 82        Fixed64 signedAxisLength,
 83        Fixed64 localRadialDirection,
 84        Fixed64 radius,
 85        Fixed64 roundedAxialOffset,
 86        Fixed64 roundedRadialOffset)
 87    {
 88        // Retain the rounding residual of the local feature construction.
 89        // The axial term can include two rounding steps (length/2, then
 90        // multiplication by the axis), not just a single half-raw error.
 91        // Only the low word is retained. Unchecked raw arithmetic preserves
 92        // that word through cancellation even when intermediate products or
 93        // the rounded-offset sum overflow; Fixed64 operators would not.
 2689594        return unchecked(
 2689595            localAxis.m_rawValue * signedAxisLength.m_rawValue
 2689596            + 2L * localRadialDirection.m_rawValue * radius.m_rawValue
 2689597            - Fixed64.Two.m_rawValue
 2689598                * (roundedAxialOffset.m_rawValue + roundedRadialOffset.m_rawValue));
 99    }
 100
 101    internal static Signed192 Denominator =>
 5371102        Signed192.Signed(Fixed64.Two.m_rawValue);
 103
 104    public bool Equals(FixedPointAnchorTerm3d other) =>
 825105        X == other.X && Y == other.Y && Z == other.Z;
 106
 107    public override int GetHashCode()
 108    {
 109        unchecked
 110        {
 2111            int hash = 17;
 2112            hash = (hash * 31) + X.GetHashCode();
 2113            hash = (hash * 31) + Y.GetHashCode();
 2114            hash = (hash * 31) + Z.GetHashCode();
 2115            return hash;
 116        }
 117    }
 118}