< Summary

Information
Class: FixedMathSharp.Vector2dExtensions
Assembly: FixedMathSharp
File(s): /home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Numerics/Vectors/Vector2d.Extensions.cs
Line coverage
100%
Covered lines: 32
Uncovered lines: 0
Coverable lines: 32
Total lines: 111
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
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%
CheckDistance(...)100%11100%
Rotate(...)100%11100%
Abs(...)100%11100%
Sign(...)100%11100%
ToDegrees(...)100%11100%
ToRadians(...)100%11100%
FuzzyEqualAbsolute(...)100%22100%
FuzzyEqual(...)100%44100%

File(s)

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

#LineLine coverage
 1using System.Runtime.CompilerServices;
 2
 3namespace FixedMathSharp;
 4
 5/// <summary>
 6/// Provides extension methods for the Vector2d type to support additional vector operations, comparisons, and conversio
 7/// </summary>
 8public static partial class Vector2dExtensions
 9{
 10    #region Vector2d 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 Vector2d ClampOneInPlace(this Vector2d v)
 119    {
 120        v.x = v.x.ClampOne();
 121        v.y = v.y.ClampOne();
 122        return v;
 123    }
 24
 25    /// <summary>
 26    /// Checks if the distance between two vectors is less than or equal to a specified factor.
 27    /// </summary>
 28    /// <param name="me">The current vector.</param>
 29    /// <param name="other">The vector to compare distance to.</param>
 30    /// <param name="factor">The maximum allowable distance.</param>
 31    /// <returns>True if the distance between the vectors is less than or equal to the factor, false otherwise.</returns
 32    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 33    public static bool CheckDistance(this Vector2d me, Vector2d other, Fixed64 factor)
 134    {
 135        var dis = Vector2d.Distance(me, other);
 136        return dis <= factor;
 137    }
 38
 39    /// <inheritdoc cref="Vector2d.Rotate(Vector2d, Fixed64)" />
 40    public static Vector2d Rotate(this Vector2d vec, Fixed64 angleInRadians)
 141    {
 142        return Vector2d.Rotate(vec, angleInRadians);
 143    }
 44
 45    /// <inheritdoc cref="Vector2d.Abs(Vector2d)" />
 46    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 47    public static Vector2d Abs(this Vector2d value)
 148    {
 149        return Vector2d.Abs(value);
 150    }
 51
 52    /// <inheritdoc cref="Vector2d.Sign(Vector2d)" />
 53    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 54    public static Vector2d Sign(this Vector2d value)
 155    {
 156        return Vector2d.Sign(value);
 157    }
 58
 59    #endregion
 60
 61    #region Conversion
 62
 63    /// <inheritdoc cref="Vector2d.ToDegrees(Vector2d)" />
 64    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 65    public static Vector2d ToDegrees(this Vector2d radians)
 166    {
 167        return Vector2d.ToDegrees(radians);
 168    }
 69
 70    /// <inheritdoc cref="Vector2d.ToRadians(Vector2d)" />
 71    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 72    public static Vector2d ToRadians(this Vector2d degrees)
 173    {
 174        return Vector2d.ToRadians(degrees);
 175    }
 76
 77    #endregion
 78
 79    #region Equality
 80
 81    /// <summary>
 82    /// Compares two vectors for approximate equality, allowing a fixed absolute difference.
 83    /// </summary>
 84    /// <param name="me">The current vector.</param>
 85    /// <param name="other">The vector to compare against.</param>
 86    /// <param name="allowedDifference">The allowed absolute difference between each component.</param>
 87    /// <returns>True if the components are within the allowed difference, false otherwise.</returns>
 88    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 89    public static bool FuzzyEqualAbsolute(this Vector2d me, Vector2d other, Fixed64 allowedDifference)
 390    {
 391        return (me.x - other.x).Abs() <= allowedDifference &&
 392               (me.y - other.y).Abs() <= allowedDifference;
 393    }
 94
 95    /// <summary>
 96    /// Compares two vectors for approximate equality, allowing a fractional difference (percentage).
 97    /// Handles zero components by only using the allowed percentage difference.
 98    /// </summary>
 99    /// <param name="me">The current vector.</param>
 100    /// <param name="other">The vector to compare against.</param>
 101    /// <param name="percentage">The allowed fractional difference (percentage) for each component.</param>
 102    /// <returns>True if the components are within the allowed percentage difference, false otherwise.</returns>
 103    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 104    public static bool FuzzyEqual(this Vector2d me, Vector2d other, Fixed64? percentage = null)
 13105    {
 13106        Fixed64 p = percentage ?? Fixed64.Epsilon;
 13107        return me.x.FuzzyComponentEqual(other.x, p) && me.y.FuzzyComponentEqual(other.y, p);
 13108    }
 109
 110    #endregion
 111}