< Summary

Information
Class: FixedMathSharp.Vector2dExtensions
Assembly: FixedMathSharp
File(s): /home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Numerics/Extensions/Vector2d.Extensions.cs
Line coverage
100%
Covered lines: 32
Uncovered lines: 0
Coverable lines: 32
Total lines: 109
Line coverage: 100%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
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(...)50%22100%
FuzzyEqual(...)100%44100%

File(s)

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

#LineLine coverage
 1using System.Runtime.CompilerServices;
 2
 3namespace FixedMathSharp
 4{
 5    public static partial class Vector2dExtensions
 6    {
 7        #region Vector2d Operations
 8
 9        /// <summary>
 10        /// Clamps each component of the vector to the range [-1, 1] in place and returns the modified vector.
 11        /// </summary>
 12        /// <param name="v">The vector to clamp.</param>
 13        /// <returns>The clamped vector with each component between -1 and 1.</returns>
 14        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 15        public static Vector2d ClampOneInPlace(this Vector2d v)
 116        {
 117            v.x = v.x.ClampOne();
 118            v.y = v.y.ClampOne();
 119            return v;
 120        }
 21
 22        /// <summary>
 23        /// Checks if the distance between two vectors is less than or equal to a specified factor.
 24        /// </summary>
 25        /// <param name="me">The current vector.</param>
 26        /// <param name="other">The vector to compare distance to.</param>
 27        /// <param name="factor">The maximum allowable distance.</param>
 28        /// <returns>True if the distance between the vectors is less than or equal to the factor, false otherwise.</ret
 29        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 30        public static bool CheckDistance(this Vector2d me, Vector2d other, Fixed64 factor)
 131        {
 132            var dis = Vector2d.Distance(me, other);
 133            return dis <= factor;
 134        }
 35
 36        /// <inheritdoc cref="Vector2d.Rotate(Vector2d, Fixed64)" />
 37        public static Vector2d Rotate(this Vector2d vec, Fixed64 angleInRadians)
 138        {
 139            return Vector2d.Rotate(vec, angleInRadians);
 140        }
 41
 42        /// <inheritdoc cref="Vector2d.Abs(Vector2d)" />
 43        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 44        public static Vector2d Abs(this Vector2d value)
 145        {
 146            return Vector2d.Abs(value);
 147        }
 48
 49        /// <inheritdoc cref="Vector2d.Sign(Vector2d)" />
 50        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 51        public static Vector2d Sign(this Vector2d value)
 152        {
 153            return Vector2d.Sign(value);
 154        }
 55
 56        #endregion
 57
 58        #region Conversion
 59
 60        /// <inheritdoc cref="Vector2d.ToDegrees(Vector2d)" />
 61        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 62        public static Vector2d ToDegrees(this Vector2d radians)
 163        {
 164            return Vector2d.ToDegrees(radians);
 165        }
 66
 67        /// <inheritdoc cref="Vector2d.ToRadians(Vector2d)" />
 68        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 69        public static Vector2d ToRadians(this Vector2d degrees)
 170        {
 171            return Vector2d.ToRadians(degrees);
 172        }
 73
 74        #endregion
 75
 76        #region Equality
 77
 78        /// <summary>
 79        /// Compares two vectors for approximate equality, allowing a fixed absolute difference.
 80        /// </summary>
 81        /// <param name="me">The current vector.</param>
 82        /// <param name="other">The vector to compare against.</param>
 83        /// <param name="allowedDifference">The allowed absolute difference between each component.</param>
 84        /// <returns>True if the components are within the allowed difference, false otherwise.</returns>
 85        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 86        public static bool FuzzyEqualAbsolute(this Vector2d me, Vector2d other, Fixed64 allowedDifference)
 187        {
 188            return (me.x - other.x).Abs() <= allowedDifference &&
 189                   (me.y - other.y).Abs() <= allowedDifference;
 190        }
 91
 92        /// <summary>
 93        /// Compares two vectors for approximate equality, allowing a fractional difference (percentage).
 94        /// Handles zero components by only using the allowed percentage difference.
 95        /// </summary>
 96        /// <param name="me">The current vector.</param>
 97        /// <param name="other">The vector to compare against.</param>
 98        /// <param name="percentage">The allowed fractional difference (percentage) for each component.</param>
 99        /// <returns>True if the components are within the allowed percentage difference, false otherwise.</returns>
 100        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 101        public static bool FuzzyEqual(this Vector2d me, Vector2d other, Fixed64? percentage = null)
 13102        {
 13103            Fixed64 p = percentage ?? Fixed64.Epsilon;
 13104            return me.x.FuzzyComponentEqual(other.x, p) && me.y.FuzzyComponentEqual(other.y, p);
 13105        }
 106
 107        #endregion
 108    }
 109}