< 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: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 101
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
Clamp(...)100%11100%
ClampOne(...)100%11100%
CheckDistance(...)100%22100%
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
 1//=======================================================================
 2// Vector2d.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 Vector2d type to support additional vector operations, comparisons, and conversio
 14/// </summary>
 15public static partial class Vector2dExtensions
 16{
 17    #region Vector2d Operations
 18
 19    /// <inheritdoc cref="Vector2d.Clamp(Vector2d, Vector2d, Vector2d)" />
 20    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 121    public static Vector2d Clamp(this Vector2d value, Vector2d min, Vector2d max) => Vector2d.Clamp(value, min, max);
 22
 23    /// <inheritdoc cref="Vector2d.Clamp(Vector2d, Vector2d, Vector2d)" />
 24    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 125    public static Vector2d ClampOne(this Vector2d value) => Vector2d.Clamp(value, Vector2d.Negative, Vector2d.One);
 26
 27    /// <summary>
 28    /// Checks if the distance between two vectors is less than or equal to a specified factor.
 29    /// </summary>
 30    /// <param name="me">The current vector.</param>
 31    /// <param name="other">The vector to compare distance to.</param>
 32    /// <param name="factor">The maximum allowable distance.</param>
 33    /// <returns>True if the distance between the vectors is less than or equal to the factor, false otherwise.</returns
 34    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 35    public static bool CheckDistance(this Vector2d me, Vector2d other, Fixed64 factor)
 36    {
 237        if (factor < Fixed64.Zero)
 138            return false;
 39
 140        return Vector2d.DistanceSquared(me, other) <= factor * factor;
 41    }
 42
 43    /// <inheritdoc cref="Vector2d.Rotate(Vector2d, Fixed64)" />
 44    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 145    public static Vector2d Rotate(this Vector2d vec, Fixed64 angleInRadians) => Vector2d.Rotate(vec, angleInRadians);
 46
 47    /// <inheritdoc cref="Vector2d.Abs(Vector2d)" />
 48    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 149    public static Vector2d Abs(this Vector2d value) => Vector2d.Abs(value);
 50
 51    /// <inheritdoc cref="Vector2d.Sign(Vector2d)" />
 52    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 153    public static Vector2d Sign(this Vector2d value) => Vector2d.Sign(value);
 54
 55    #endregion
 56
 57    #region Conversion
 58
 59    /// <inheritdoc cref="Vector2d.ToDegrees(Vector2d)" />
 60    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 161    public static Vector2d ToDegrees(this Vector2d radians) => Vector2d.ToDegrees(radians);
 62
 63    /// <inheritdoc cref="Vector2d.ToRadians(Vector2d)" />
 64    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 165    public static Vector2d ToRadians(this Vector2d degrees) => Vector2d.ToRadians(degrees);
 66
 67    #endregion
 68
 69    #region Equality
 70
 71    /// <summary>
 72    /// Compares two vectors for approximate equality, allowing a fixed absolute difference.
 73    /// </summary>
 74    /// <param name="me">The current vector.</param>
 75    /// <param name="other">The vector to compare against.</param>
 76    /// <param name="allowedDifference">The allowed absolute difference between each component.</param>
 77    /// <returns>True if the components are within the allowed difference, false otherwise.</returns>
 78    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 79    public static bool FuzzyEqualAbsolute(this Vector2d me, Vector2d other, Fixed64 allowedDifference)
 80    {
 381        return (me.X - other.X).Abs() <= allowedDifference &&
 382               (me.Y - other.Y).Abs() <= allowedDifference;
 83    }
 84
 85    /// <summary>
 86    /// Compares two vectors for approximate equality, allowing a fractional difference (percentage).
 87    /// Handles zero components by only using the allowed percentage difference.
 88    /// </summary>
 89    /// <param name="me">The current vector.</param>
 90    /// <param name="other">The vector to compare against.</param>
 91    /// <param name="percentage">The allowed fractional difference (percentage) for each component.</param>
 92    /// <returns>True if the components are within the allowed percentage difference, false otherwise.</returns>
 93    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 94    public static bool FuzzyEqual(this Vector2d me, Vector2d other, Fixed64? percentage = null)
 95    {
 1396        Fixed64 p = percentage ?? Fixed64.Epsilon;
 1397        return me.X.FuzzyComponentEqual(other.X, p) && me.Y.FuzzyComponentEqual(other.Y, p);
 98    }
 99
 100    #endregion
 101}