< Summary

Information
Class: FixedMathSharp.Fixed4x4Extensions
Assembly: FixedMathSharp
File(s): /home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Numerics/Matrices/Fixed4x4.Extensions.cs
Line coverage
100%
Covered lines: 56
Uncovered lines: 0
Coverable lines: 56
Total lines: 179
Line coverage: 100%
Branch coverage
100%
Covered branches: 62
Total branches: 62
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ExtractLossyScale(...)100%11100%
ExtractScale(...)100%11100%
ExtractTranslation(...)100%11100%
ExtractRotation(...)100%11100%
Decompose(...)100%11100%
SetGlobalScale(...)100%11100%
SetScale(...)100%11100%
SetTranslation(...)100%11100%
SetRotation(...)100%11100%
NormalizeRotationMatrix(...)100%11100%
Lerp(...)100%11100%
Transpose(...)100%11100%
TransformPoint(...)100%11100%
Transform(...)100%11100%
InverseTransformPoint(...)100%11100%
FuzzyEqualAbsolute(...)100%66100%
FuzzyEqual(...)100%88100%
FuzzyEqualAbsoluteRow1(...)100%66100%
FuzzyEqualAbsoluteRow2(...)100%66100%
FuzzyEqualAbsoluteRow3(...)100%66100%
FuzzyEqualAbsoluteRow4(...)100%66100%
FuzzyEqualRow1(...)100%66100%
FuzzyEqualRow2(...)100%66100%
FuzzyEqualRow3(...)100%66100%
FuzzyEqualRow4(...)100%66100%

File(s)

/home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Numerics/Matrices/Fixed4x4.Extensions.cs

#LineLine coverage
 1//=======================================================================
 2// Fixed4x4.Extensions.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;
 11
 12/// <summary>
 13/// Provides extension methods for the Fixed4x4 structure to simplify common matrix operations
 14/// such as extracting scale, setting transformation components, and transforming points.
 15/// </summary>
 16public static class Fixed4x4Extensions
 17{
 18    #region Extraction, and Setters
 19
 20    /// <inheritdoc cref="Fixed4x4.ExtractLossyScale(Fixed4x4)" />
 21    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 222    public static Vector3d ExtractLossyScale(this Fixed4x4 matrix) => Fixed4x4.ExtractLossyScale(matrix);
 23
 24    /// <inheritdoc cref="Fixed4x4.ExtractScale(Fixed4x4)" />
 25    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 126    public static Vector3d ExtractScale(this Fixed4x4 matrix) => Fixed4x4.ExtractScale(matrix);
 27
 28    /// <inheritdoc cref="Fixed4x4.ExtractTranslation(Fixed4x4)" />
 29    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 130    public static Vector3d ExtractTranslation(this Fixed4x4 matrix) => Fixed4x4.ExtractTranslation(matrix);
 31
 32    /// <inheritdoc cref="Fixed4x4.ExtractRotation(Fixed4x4)" />
 33    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 134    public static FixedQuaternion ExtractRotation(this Fixed4x4 matrix) => Fixed4x4.ExtractRotation(matrix);
 35
 36    /// <inheritdoc cref="Fixed4x4.Decompose(Fixed4x4, out Vector3d, out FixedQuaternion, out Vector3d)" />
 37    public static bool Decompose(
 38        this Fixed4x4 matrix,
 39        out Vector3d translation,
 40        out FixedQuaternion rotation,
 141        out Vector3d scale) => Fixed4x4.Decompose(matrix, out translation, out rotation, out scale);
 42
 43    /// <inheritdoc cref="Fixed4x4.SetGlobalScale(Fixed4x4, Vector3d)" />
 44    public static Fixed4x4 SetGlobalScale(this ref Fixed4x4 matrix, Vector3d globalScale) =>
 345        matrix = Fixed4x4.SetGlobalScale(matrix, globalScale);
 46
 47    /// <inheritdoc cref="Fixed4x4.SetScale(Fixed4x4, Vector3d)" />
 48    public static Fixed4x4 SetScale(this ref Fixed4x4 matrix, Vector3d scale) =>
 149        matrix = Fixed4x4.SetScale(matrix, scale);
 50
 51    /// <inheritdoc cref="Fixed4x4.SetTranslation(Fixed4x4, Vector3d)" />
 52    public static Fixed4x4 SetTranslation(this ref Fixed4x4 matrix, Vector3d position) =>
 253        matrix = Fixed4x4.SetTranslation(matrix, position);
 54
 55    /// <inheritdoc cref="Fixed4x4.SetRotation(Fixed4x4, FixedQuaternion)" />
 56    public static Fixed4x4 SetRotation(this ref Fixed4x4 matrix, FixedQuaternion rotation) =>
 357        matrix = Fixed4x4.SetRotation(matrix, rotation);
 58
 59    /// <inheritdoc cref="Fixed4x4.NormalizeRotationMatrix(Fixed4x4)" />
 60    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 61    public static Fixed4x4 NormalizeRotationMatrix(this ref Fixed4x4 matrix) =>
 162        matrix = Fixed4x4.NormalizeRotationMatrix(matrix);
 63
 64    /// <inheritdoc cref="Fixed4x4.Lerp(Fixed4x4, Fixed4x4, Fixed64)" />
 65    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 66    public static Fixed4x4 Lerp(this Fixed4x4 matrix, Fixed4x4 target, Fixed64 amount) =>
 167        Fixed4x4.Lerp(matrix, target, amount);
 68
 69    /// <inheritdoc cref="Fixed4x4.Transpose(Fixed4x4)" />
 70    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 171    public static Fixed4x4 Transpose(this Fixed4x4 matrix) => Fixed4x4.Transpose(matrix);
 72
 73    /// <inheritdoc cref="Fixed4x4.TransformPoint(Fixed4x4, Vector3d)" />
 74    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 75    public static Vector3d TransformPoint(this Fixed4x4 matrix, Vector3d point) =>
 176        Fixed4x4.TransformPoint(matrix, point);
 77
 78    /// <inheritdoc cref="Fixed4x4.Transform(Fixed4x4, Vector4d)" />
 79    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 80    public static Vector4d Transform(this Fixed4x4 matrix, Vector4d vector) =>
 181        Fixed4x4.Transform(matrix, vector);
 82
 83    /// <inheritdoc cref="Fixed4x4.InverseTransformPoint(Fixed4x4, Vector3d)" />
 84    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 85    public static Vector3d InverseTransformPoint(this Fixed4x4 matrix, Vector3d point) =>
 186        Fixed4x4.InverseTransformPoint(matrix, point);
 87
 88    #endregion
 89
 90    #region Equality
 91
 92    /// <summary>
 93    /// Compares two Fixed4x4 for approximate equality, allowing a fixed absolute difference between components.
 94    /// </summary>
 95    /// <param name="f1">The current Fixed4x4.</param>
 96    /// <param name="f2">The Fixed4x4 to compare against.</param>
 97    /// <param name="allowedDifference">The allowed absolute difference between each component.</param>
 98    /// <returns>True if the components are within the allowed difference, false otherwise.</returns>
 99    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 100    public static bool FuzzyEqualAbsolute(this Fixed4x4 f1, Fixed4x4 f2, Fixed64 allowedDifference) =>
 18101        FuzzyEqualAbsoluteRow1(f1, f2, allowedDifference) &&
 18102        FuzzyEqualAbsoluteRow2(f1, f2, allowedDifference) &&
 18103        FuzzyEqualAbsoluteRow3(f1, f2, allowedDifference) &&
 18104        FuzzyEqualAbsoluteRow4(f1, f2, allowedDifference);
 105
 106    /// <summary>
 107    /// Compares two Fixed4x4 for approximate equality, allowing a fractional percentage (defaults to ~1%) difference be
 108    /// </summary>
 109    /// <param name="f1">The current Fixed4x4.</param>
 110    /// <param name="f2">The Fixed4x4 to compare against.</param>
 111    /// <param name="percentage">The allowed fractional difference (percentage) for each component.</param>
 112    /// <returns>True if the components are within the allowed percentage difference, false otherwise.</returns>
 113    public static bool FuzzyEqual(this Fixed4x4 f1, Fixed4x4 f2, Fixed64? percentage = null)
 114    {
 18115        Fixed64 p = percentage ?? Fixed64.Epsilon;
 18116        return FuzzyEqualRow1(f1, f2, p) &&
 18117               FuzzyEqualRow2(f1, f2, p) &&
 18118               FuzzyEqualRow3(f1, f2, p) &&
 18119               FuzzyEqualRow4(f1, f2, p);
 120    }
 121
 122    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 123    private static bool FuzzyEqualAbsoluteRow1(Fixed4x4 f1, Fixed4x4 f2, Fixed64 allowedDifference) =>
 18124        (f1.M11 - f2.M11).Abs() <= allowedDifference &&
 18125        (f1.M12 - f2.M12).Abs() <= allowedDifference &&
 18126        (f1.M13 - f2.M13).Abs() <= allowedDifference &&
 18127        (f1.M14 - f2.M14).Abs() <= allowedDifference;
 128
 129    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 130    private static bool FuzzyEqualAbsoluteRow2(Fixed4x4 f1, Fixed4x4 f2, Fixed64 allowedDifference) =>
 14131        (f1.M21 - f2.M21).Abs() <= allowedDifference &&
 14132        (f1.M22 - f2.M22).Abs() <= allowedDifference &&
 14133        (f1.M23 - f2.M23).Abs() <= allowedDifference &&
 14134        (f1.M24 - f2.M24).Abs() <= allowedDifference;
 135
 136    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 137    private static bool FuzzyEqualAbsoluteRow3(Fixed4x4 f1, Fixed4x4 f2, Fixed64 allowedDifference) =>
 10138        (f1.M31 - f2.M31).Abs() <= allowedDifference &&
 10139        (f1.M32 - f2.M32).Abs() <= allowedDifference &&
 10140        (f1.M33 - f2.M33).Abs() <= allowedDifference &&
 10141        (f1.M34 - f2.M34).Abs() <= allowedDifference;
 142
 143    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 144    private static bool FuzzyEqualAbsoluteRow4(Fixed4x4 f1, Fixed4x4 f2, Fixed64 allowedDifference) =>
 6145        (f1.M41 - f2.M41).Abs() <= allowedDifference &&
 6146        (f1.M42 - f2.M42).Abs() <= allowedDifference &&
 6147        (f1.M43 - f2.M43).Abs() <= allowedDifference &&
 6148        (f1.M44 - f2.M44).Abs() <= allowedDifference;
 149
 150    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 151    private static bool FuzzyEqualRow1(Fixed4x4 f1, Fixed4x4 f2, Fixed64 percentage) =>
 18152        f1.M11.FuzzyComponentEqual(f2.M11, percentage) &&
 18153        f1.M12.FuzzyComponentEqual(f2.M12, percentage) &&
 18154        f1.M13.FuzzyComponentEqual(f2.M13, percentage) &&
 18155        f1.M14.FuzzyComponentEqual(f2.M14, percentage);
 156
 157    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 158    private static bool FuzzyEqualRow2(Fixed4x4 f1, Fixed4x4 f2, Fixed64 percentage) =>
 14159        f1.M21.FuzzyComponentEqual(f2.M21, percentage) &&
 14160        f1.M22.FuzzyComponentEqual(f2.M22, percentage) &&
 14161        f1.M23.FuzzyComponentEqual(f2.M23, percentage) &&
 14162        f1.M24.FuzzyComponentEqual(f2.M24, percentage);
 163
 164    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 165    private static bool FuzzyEqualRow3(Fixed4x4 f1, Fixed4x4 f2, Fixed64 percentage) =>
 10166        f1.M31.FuzzyComponentEqual(f2.M31, percentage) &&
 10167        f1.M32.FuzzyComponentEqual(f2.M32, percentage) &&
 10168        f1.M33.FuzzyComponentEqual(f2.M33, percentage) &&
 10169        f1.M34.FuzzyComponentEqual(f2.M34, percentage);
 170
 171    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 172    private static bool FuzzyEqualRow4(Fixed4x4 f1, Fixed4x4 f2, Fixed64 percentage) =>
 6173        f1.M41.FuzzyComponentEqual(f2.M41, percentage) &&
 6174        f1.M42.FuzzyComponentEqual(f2.M42, percentage) &&
 6175        f1.M43.FuzzyComponentEqual(f2.M43, percentage) &&
 6176        f1.M44.FuzzyComponentEqual(f2.M44, percentage);
 177
 178    #endregion
 179}

Methods/Properties

ExtractLossyScale(FixedMathSharp.Fixed4x4)
ExtractScale(FixedMathSharp.Fixed4x4)
ExtractTranslation(FixedMathSharp.Fixed4x4)
ExtractRotation(FixedMathSharp.Fixed4x4)
Decompose(FixedMathSharp.Fixed4x4,FixedMathSharp.Vector3d&,FixedMathSharp.FixedQuaternion&,FixedMathSharp.Vector3d&)
SetGlobalScale(FixedMathSharp.Fixed4x4&,FixedMathSharp.Vector3d)
SetScale(FixedMathSharp.Fixed4x4&,FixedMathSharp.Vector3d)
SetTranslation(FixedMathSharp.Fixed4x4&,FixedMathSharp.Vector3d)
SetRotation(FixedMathSharp.Fixed4x4&,FixedMathSharp.FixedQuaternion)
NormalizeRotationMatrix(FixedMathSharp.Fixed4x4&)
Lerp(FixedMathSharp.Fixed4x4,FixedMathSharp.Fixed4x4,FixedMathSharp.Fixed64)
Transpose(FixedMathSharp.Fixed4x4)
TransformPoint(FixedMathSharp.Fixed4x4,FixedMathSharp.Vector3d)
Transform(FixedMathSharp.Fixed4x4,FixedMathSharp.Vector4d)
InverseTransformPoint(FixedMathSharp.Fixed4x4,FixedMathSharp.Vector3d)
FuzzyEqualAbsolute(FixedMathSharp.Fixed4x4,FixedMathSharp.Fixed4x4,FixedMathSharp.Fixed64)
FuzzyEqual(FixedMathSharp.Fixed4x4,FixedMathSharp.Fixed4x4,System.Nullable`1<FixedMathSharp.Fixed64>)
FuzzyEqualAbsoluteRow1(FixedMathSharp.Fixed4x4,FixedMathSharp.Fixed4x4,FixedMathSharp.Fixed64)
FuzzyEqualAbsoluteRow2(FixedMathSharp.Fixed4x4,FixedMathSharp.Fixed4x4,FixedMathSharp.Fixed64)
FuzzyEqualAbsoluteRow3(FixedMathSharp.Fixed4x4,FixedMathSharp.Fixed4x4,FixedMathSharp.Fixed64)
FuzzyEqualAbsoluteRow4(FixedMathSharp.Fixed4x4,FixedMathSharp.Fixed4x4,FixedMathSharp.Fixed64)
FuzzyEqualRow1(FixedMathSharp.Fixed4x4,FixedMathSharp.Fixed4x4,FixedMathSharp.Fixed64)
FuzzyEqualRow2(FixedMathSharp.Fixed4x4,FixedMathSharp.Fixed4x4,FixedMathSharp.Fixed64)
FuzzyEqualRow3(FixedMathSharp.Fixed4x4,FixedMathSharp.Fixed4x4,FixedMathSharp.Fixed64)
FuzzyEqualRow4(FixedMathSharp.Fixed4x4,FixedMathSharp.Fixed4x4,FixedMathSharp.Fixed64)