< Summary

Information
Class: FixedMathSharp.Vector3dExtensions
Assembly: FixedMathSharp
File(s): /home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Numerics/Vectors/Vector3d.Extensions.cs
Line coverage
100%
Covered lines: 42
Uncovered lines: 0
Coverable lines: 42
Total lines: 127
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ClampOneInPlace(...)100%11100%
ClampMagnitude(...)100%11100%
CheckDistance(...)100%11100%
Rotate(...)100%11100%
InverseRotate(...)100%11100%
ToDegrees(...)100%11100%
ToRadians(...)100%11100%
Abs(...)100%11100%
Sign(...)100%11100%
FuzzyEqualAbsolute(...)100%44100%
FuzzyEqual(...)100%66100%

File(s)

/home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Numerics/Vectors/Vector3d.Extensions.cs

#LineLine coverage
 1using System.Runtime.CompilerServices;
 2
 3namespace FixedMathSharp;
 4
 5/// <summary>
 6/// Provides extension methods for the Vector3d type to support additional vector operations, comparisons, and conversio
 7/// </summary>
 8public static partial class Vector3dExtensions
 9{
 10    #region Vector3d Operations
 11
 12    /// <summary>
 13    /// Clamps each component of the vector to the range [-1, 1] in place and returns the modified vector.
 14    /// </summary>
 15    /// <param name="v">The vector to clamp.</param>
 16    /// <returns>The clamped vector with each component between -1 and 1.</returns>
 17    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 18    public static Vector3d ClampOneInPlace(this Vector3d v)
 119    {
 120        v.x = v.x.ClampOne();
 121        v.y = v.y.ClampOne();
 122        v.z = v.z.ClampOne();
 123        return v;
 124    }
 25
 26    /// <inheritdoc cref="Vector3d.ClampMagnitude(Vector3d, Fixed64)" />
 27    public static Vector3d ClampMagnitude(this Vector3d value, Fixed64 maxMagnitude)
 128    {
 129        return Vector3d.ClampMagnitude(value, maxMagnitude);
 130    }
 31
 32    /// <summary>
 33    /// Checks if the distance between two vectors is less than or equal to a specified factor.
 34    /// </summary>
 35    /// <param name="me">The current vector.</param>
 36    /// <param name="other">The vector to compare distance to.</param>
 37    /// <param name="factor">The maximum allowable distance.</param>
 38    /// <returns>True if the distance between the vectors is less than or equal to the factor, false otherwise.</returns
 39    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 40    public static bool CheckDistance(this Vector3d me, Vector3d other, Fixed64 factor)
 141    {
 142        var dis = Vector3d.Distance(me, other);
 143        return dis <= factor;
 144    }
 45
 46    /// <inheritdoc cref="Vector3d.Rotate(Vector3d, Vector3d, FixedQuaternion)" />
 47    public static Vector3d Rotate(this Vector3d source, Vector3d position, FixedQuaternion rotation)
 148    {
 149        return Vector3d.Rotate(source, position, rotation);
 150    }
 51
 52    /// <inheritdoc cref="Vector3d.InverseRotate(Vector3d, Vector3d, FixedQuaternion)" />
 53    public static Vector3d InverseRotate(this Vector3d source, Vector3d position, FixedQuaternion rotation)
 154    {
 155        return Vector3d.InverseRotate(source, position, rotation);
 156    }
 57
 58    #endregion
 59
 60    #region Conversion
 61
 62    /// <inheritdoc cref="Vector3d.ToDegrees(Vector3d)" />
 63    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 64    public static Vector3d ToDegrees(this Vector3d radians)
 165    {
 166        return Vector3d.ToDegrees(radians);
 167    }
 68
 69    /// <inheritdoc cref="Vector3d.ToRadians(Vector3d)" />
 70    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 71    public static Vector3d ToRadians(this Vector3d degrees)
 172    {
 173        return Vector3d.ToRadians(degrees);
 174    }
 75
 76    /// <inheritdoc cref="Vector3d.Abs(Vector3d)" />
 77    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 78    public static Vector3d Abs(this Vector3d value)
 179    {
 180        return Vector3d.Abs(value);
 181    }
 82
 83    /// <inheritdoc cref="Vector3d.Sign(Vector3d)" />
 84    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 85    public static Vector3d Sign(Vector3d value)
 186    {
 187        return Vector3d.Sign(value);
 188    }
 89
 90    #endregion
 91
 92    #region Equality
 93
 94    /// <summary>
 95    /// Compares two vectors for approximate equality, allowing a fixed absolute difference.
 96    /// </summary>
 97    /// <param name="me">The current vector.</param>
 98    /// <param name="other">The vector to compare against.</param>
 99    /// <param name="allowedDifference">The allowed absolute difference between each component.</param>
 100    /// <returns>True if the components are within the allowed difference, false otherwise.</returns>
 101    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 102    public static bool FuzzyEqualAbsolute(this Vector3d me, Vector3d other, Fixed64 allowedDifference)
 6103    {
 6104        return (me.x - other.x).Abs() <= allowedDifference &&
 6105               (me.y - other.y).Abs() <= allowedDifference &&
 6106               (me.z - other.z).Abs() <= allowedDifference;
 6107    }
 108
 109    /// <summary>
 110    /// Compares two vectors for approximate equality, allowing a fractional difference (percentage).
 111    /// Handles zero components by only using the allowed percentage difference.
 112    /// </summary>
 113    /// <param name="me">The current vector.</param>
 114    /// <param name="other">The vector to compare against.</param>
 115    /// <param name="percentage">The allowed fractional difference (percentage) for each component.</param>
 116    /// <returns>True if the components are within the allowed percentage difference, false otherwise.</returns>
 117    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 118    public static bool FuzzyEqual(this Vector3d me, Vector3d other, Fixed64? percentage = null)
 44119    {
 44120        Fixed64 p = percentage ?? Fixed64.Epsilon;
 44121        return me.x.FuzzyComponentEqual(other.x, p) &&
 44122                me.y.FuzzyComponentEqual(other.y, p) &&
 44123                me.z.FuzzyComponentEqual(other.z, p);
 44124    }
 125
 126    #endregion
 127}