< Summary

Information
Class: FixedMathSharp.Vector3dExtensions
Assembly: FixedMathSharp
File(s): /home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Numerics/Extensions/Vector3d.Extensions.cs
Line coverage
100%
Covered lines: 42
Uncovered lines: 0
Coverable lines: 42
Total lines: 124
Line coverage: 100%
Branch coverage
60%
Covered branches: 6
Total branches: 10
Branch coverage: 60%
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(...)50%44100%
FuzzyEqual(...)66.66%66100%

File(s)

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

#LineLine coverage
 1using System.Runtime.CompilerServices;
 2
 3namespace FixedMathSharp
 4{
 5    public static partial class Vector3dExtensions
 6    {
 7        #region Vector3d 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 Vector3d ClampOneInPlace(this Vector3d v)
 116        {
 117            v.x = v.x.ClampOne();
 118            v.y = v.y.ClampOne();
 119            v.z = v.z.ClampOne();
 120            return v;
 121        }
 22
 23        public static Vector3d ClampMagnitude(this Vector3d value, Fixed64 maxMagnitude)
 124        {
 125            return Vector3d.ClampMagnitude(value, maxMagnitude);
 126        }
 27
 28        /// <summary>
 29        /// Checks if the distance between two vectors is less than or equal to a specified factor.
 30        /// </summary>
 31        /// <param name="me">The current vector.</param>
 32        /// <param name="other">The vector to compare distance to.</param>
 33        /// <param name="factor">The maximum allowable distance.</param>
 34        /// <returns>True if the distance between the vectors is less than or equal to the factor, false otherwise.</ret
 35        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 36        public static bool CheckDistance(this Vector3d me, Vector3d other, Fixed64 factor)
 137        {
 138            var dis = Vector3d.Distance(me, other);
 139            return dis <= factor;
 140        }
 41
 42        /// <inheritdoc cref="Vector3d.Rotate(Vector3d, Vector3d, FixedQuaternion)" />
 43        public static Vector3d Rotate(this Vector3d source, Vector3d position, FixedQuaternion rotation)
 144        {
 145            return Vector3d.Rotate(source, position, rotation);
 146        }
 47
 48        /// <inheritdoc cref="Vector3d.InverseRotate(Vector3d, Vector3d, FixedQuaternion)" />
 49        public static Vector3d InverseRotate(this Vector3d source, Vector3d position, FixedQuaternion rotation)
 150        {
 151            return Vector3d.InverseRotate(source, position, rotation);
 152        }
 53
 54        #endregion
 55
 56        #region Conversion
 57
 58        /// <inheritdoc cref="Vector3d.ToDegrees(Vector3d)" />
 59        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 60        public static Vector3d ToDegrees(this Vector3d radians)
 161        {
 162            return Vector3d.ToDegrees(radians);
 163        }
 64
 65        /// <inheritdoc cref="Vector3d.ToRadians(Vector3d)" />
 66        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 67        public static Vector3d ToRadians(this Vector3d degrees)
 168        {
 169            return Vector3d.ToRadians(degrees);
 170        }
 71
 72        /// <inheritdoc cref="Vector3d.Abs(Vector3d)" />
 73        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 74        public static Vector3d Abs(this Vector3d value)
 175        {
 176            return Vector3d.Abs(value);
 177        }
 78
 79        /// <inheritdoc cref="Vector3d.Sign(Vector3d)" />
 80        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 81        public static Vector3d Sign(Vector3d value)
 182        {
 183            return Vector3d.Sign(value);
 184        }
 85
 86        #endregion
 87
 88        #region Equality
 89
 90        /// <summary>
 91        /// Compares two vectors for approximate equality, allowing a fixed absolute difference.
 92        /// </summary>
 93        /// <param name="me">The current vector.</param>
 94        /// <param name="other">The vector to compare against.</param>
 95        /// <param name="allowedDifference">The allowed absolute difference between each component.</param>
 96        /// <returns>True if the components are within the allowed difference, false otherwise.</returns>
 97        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 98        public static bool FuzzyEqualAbsolute(this Vector3d me, Vector3d other, Fixed64 allowedDifference)
 399        {
 3100            return (me.x - other.x).Abs() <= allowedDifference &&
 3101                   (me.y - other.y).Abs() <= allowedDifference &&
 3102                   (me.z - other.z).Abs() <= allowedDifference;
 3103        }
 104
 105        /// <summary>
 106        /// Compares two vectors for approximate equality, allowing a fractional difference (percentage).
 107        /// Handles zero components by only using the allowed percentage difference.
 108        /// </summary>
 109        /// <param name="me">The current vector.</param>
 110        /// <param name="other">The vector 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        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 114        public static bool FuzzyEqual(this Vector3d me, Vector3d other, Fixed64? percentage = null)
 25115        {
 25116            Fixed64 p = percentage ?? Fixed64.Epsilon;
 25117            return me.x.FuzzyComponentEqual(other.x, p) &&
 25118                    me.y.FuzzyComponentEqual(other.y, p) &&
 25119                    me.z.FuzzyComponentEqual(other.z, p);
 25120        }
 121
 122        #endregion
 123    }
 124}