< 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: 33
Uncovered lines: 0
Coverable lines: 33
Total lines: 172
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
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%
ClampMagnitude(...)100%11100%
CheckDistance(...)100%22100%
Distance(...)100%11100%
DistanceSquared(...)100%11100%
Dot(...)100%11100%
Cross(...)100%11100%
CrossProduct(...)100%11100%
Lerp(...)100%11100%
UnclampedLerp(...)100%11100%
Slerp(...)100%11100%
Project(...)100%11100%
ProjectOnPlane(...)100%11100%
ProjectOnPlane(...)100%11100%
Angle(...)100%11100%
Reflect(...)100%11100%
Rotate(...)100%11100%
InverseRotate(...)100%11100%
Transform(...)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
 1//=======================================================================
 2// Vector3d.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 FixedMathSharp.Bounds;
 9using System.Runtime.CompilerServices;
 10
 11namespace FixedMathSharp;
 12
 13/// <summary>
 14/// Provides extension methods for the Vector3d type to support additional vector operations, comparisons, and conversio
 15/// </summary>
 16public static partial class Vector3dExtensions
 17{
 18    #region Vector3d Operations
 19
 20    /// <inheritdoc cref="Vector3d.Clamp(Vector3d, Vector3d, Vector3d)" />
 21    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 122    public static Vector3d Clamp(this Vector3d value, Vector3d min, Vector3d max) => Vector3d.Clamp(value, min, max);
 23
 24    /// <inheritdoc cref="Vector3d.Clamp(Vector3d, Vector3d, Vector3d)" />
 25    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 126    public static Vector3d ClampOne(this Vector3d value) => Vector3d.Clamp(value, Vector3d.Negative, Vector3d.One);
 27
 28    /// <inheritdoc cref="Vector3d.ClampMagnitude(Vector3d, Fixed64)" />
 29    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 30    public static Vector3d ClampMagnitude(this Vector3d value, Fixed64 maxMagnitude) =>
 131        Vector3d.ClampMagnitude(value, maxMagnitude);
 32
 33    /// <summary>
 34    /// Checks if the distance between two vectors is less than or equal to a specified factor.
 35    /// </summary>
 36    /// <param name="me">The current vector.</param>
 37    /// <param name="other">The vector to compare distance to.</param>
 38    /// <param name="factor">The maximum allowable distance.</param>
 39    /// <returns>True if the distance between the vectors is less than or equal to the factor, false otherwise.</returns
 40    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 41    public static bool CheckDistance(this Vector3d me, Vector3d other, Fixed64 factor)
 42    {
 243        if (factor < Fixed64.Zero)
 144            return false;
 45
 146        return Vector3d.DistanceSquared(me, other) <= factor * factor;
 47    }
 48
 49    /// <inheritdoc cref="Vector3d.Distance(Vector3d, Vector3d)" />
 50    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 151    public static Fixed64 Distance(this Vector3d start, Vector3d end) => Vector3d.Distance(start, end);
 52
 53    /// <inheritdoc cref="Vector3d.DistanceSquared(Vector3d, Vector3d)" />
 54    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 155    public static Fixed64 DistanceSquared(this Vector3d start, Vector3d end) => Vector3d.DistanceSquared(start, end);
 56
 57    /// <inheritdoc cref="Vector3d.Dot(Vector3d, Vector3d)" />
 58    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 159    public static Fixed64 Dot(this Vector3d lhs, Vector3d rhs) => Vector3d.Dot(lhs, rhs);
 60
 61    /// <inheritdoc cref="Vector3d.Cross(Vector3d, Vector3d)" />
 62    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 163    public static Vector3d Cross(this Vector3d lhs, Vector3d rhs) => Vector3d.Cross(lhs, rhs);
 64
 65    /// <inheritdoc cref="Vector3d.CrossProduct(Vector3d, Vector3d)" />
 66    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 167    public static Fixed64 CrossProduct(this Vector3d lhs, Vector3d rhs) => Vector3d.CrossProduct(lhs, rhs);
 68
 69    /// <inheritdoc cref="Vector3d.Lerp(Vector3d, Vector3d, Fixed64)" />
 70    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 171    public static Vector3d Lerp(this Vector3d start, Vector3d end, Fixed64 amount) => Vector3d.Lerp(start, end, amount);
 72
 73    /// <inheritdoc cref="Vector3d.UnclampedLerp(Vector3d, Vector3d, Fixed64)" />
 74    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 75    public static Vector3d UnclampedLerp(this Vector3d start, Vector3d end, Fixed64 amount) =>
 176        Vector3d.UnclampedLerp(start, end, amount);
 77
 78    /// <inheritdoc cref="Vector3d.Slerp(Vector3d, Vector3d, Fixed64)" />
 79    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 180    public static Vector3d Slerp(this Vector3d start, Vector3d end, Fixed64 amount) => Vector3d.Slerp(start, end, amount
 81
 82    /// <inheritdoc cref="Vector3d.Project(Vector3d, Vector3d)" />
 83    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 184    public static Vector3d Project(this Vector3d vector, Vector3d onNormal) => Vector3d.Project(vector, onNormal);
 85
 86    /// <inheritdoc cref="Vector3d.ProjectOnPlane(Vector3d, Vector3d)" />
 87    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 88    public static Vector3d ProjectOnPlane(this Vector3d vector, Vector3d planeNormal) =>
 189        Vector3d.ProjectOnPlane(vector, planeNormal);
 90
 91    /// <inheritdoc cref="Vector3d.ProjectOnPlane(Vector3d, FixedPlane)" />
 92    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 193    public static Vector3d ProjectOnPlane(this Vector3d point, FixedPlane plane) => Vector3d.ProjectOnPlane(point, plane
 94
 95    /// <inheritdoc cref="Vector3d.Angle(Vector3d, Vector3d)" />
 96    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 197    public static Fixed64 Angle(this Vector3d from, Vector3d to) => Vector3d.Angle(from, to);
 98
 99    /// <inheritdoc cref="Vector3d.Reflect(Vector3d, Vector3d)" />
 100    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1101    public static Vector3d Reflect(this Vector3d vector, Vector3d normal) => Vector3d.Reflect(vector, normal);
 102
 103    /// <inheritdoc cref="Vector3d.Rotate(Vector3d, Vector3d, FixedQuaternion)" />
 104    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 105    public static Vector3d Rotate(this Vector3d source, Vector3d position, FixedQuaternion rotation) =>
 1106        Vector3d.Rotate(source, position, rotation);
 107
 108    /// <inheritdoc cref="Vector3d.InverseRotate(Vector3d, Vector3d, FixedQuaternion)" />
 109    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 110    public static Vector3d InverseRotate(this Vector3d source, Vector3d position, FixedQuaternion rotation) =>
 1111        Vector3d.InverseRotate(source, position, rotation);
 112
 113    /// <inheritdoc cref="Vector3d.Transform(Vector3d, Fixed4x4)" />
 114    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1115    public static Vector3d Transform(this Vector3d vector, Fixed4x4 matrix) => Vector3d.Transform(vector, matrix);
 116
 117    #endregion
 118
 119    #region Conversion
 120
 121    /// <inheritdoc cref="Vector3d.ToDegrees(Vector3d)" />
 122    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1123    public static Vector3d ToDegrees(this Vector3d radians) => Vector3d.ToDegrees(radians);
 124
 125    /// <inheritdoc cref="Vector3d.ToRadians(Vector3d)" />
 126    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1127    public static Vector3d ToRadians(this Vector3d degrees) => Vector3d.ToRadians(degrees);
 128
 129    /// <inheritdoc cref="Vector3d.Abs(Vector3d)" />
 130    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1131    public static Vector3d Abs(this Vector3d value) => Vector3d.Abs(value);
 132
 133    /// <inheritdoc cref="Vector3d.Sign(Vector3d)" />
 134    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1135    public static Vector3d Sign(this Vector3d value) => Vector3d.Sign(value);
 136
 137    #endregion
 138
 139    #region Equality
 140
 141    /// <summary>
 142    /// Compares two vectors for approximate equality, allowing a fixed absolute difference.
 143    /// </summary>
 144    /// <param name="me">The current vector.</param>
 145    /// <param name="other">The vector to compare against.</param>
 146    /// <param name="allowedDifference">The allowed absolute difference between each component.</param>
 147    /// <returns>True if the components are within the allowed difference, false otherwise.</returns>
 148    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 149    public static bool FuzzyEqualAbsolute(this Vector3d me, Vector3d other, Fixed64 allowedDifference) =>
 6150        (me.X - other.X).Abs() <= allowedDifference
 6151        && (me.Y - other.Y).Abs() <= allowedDifference
 6152        && (me.Z - other.Z).Abs() <= allowedDifference;
 153
 154    /// <summary>
 155    /// Compares two vectors for approximate equality, allowing a fractional difference (percentage).
 156    /// Handles zero components by only using the allowed percentage difference.
 157    /// </summary>
 158    /// <param name="me">The current vector.</param>
 159    /// <param name="other">The vector to compare against.</param>
 160    /// <param name="percentage">The allowed fractional difference (percentage) for each component.</param>
 161    /// <returns>True if the components are within the allowed percentage difference, false otherwise.</returns>
 162    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 163    public static bool FuzzyEqual(this Vector3d me, Vector3d other, Fixed64? percentage = null)
 164    {
 62165        Fixed64 p = percentage ?? Fixed64.Epsilon;
 62166        return me.X.FuzzyComponentEqual(other.X, p) &&
 62167                me.Y.FuzzyComponentEqual(other.Y, p) &&
 62168                me.Z.FuzzyComponentEqual(other.Z, p);
 169    }
 170
 171    #endregion
 172}

Methods/Properties

Clamp(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.Vector3d)
ClampOne(FixedMathSharp.Vector3d)
ClampMagnitude(FixedMathSharp.Vector3d,FixedMathSharp.Fixed64)
CheckDistance(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64)
Distance(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d)
DistanceSquared(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d)
Dot(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d)
Cross(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d)
CrossProduct(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d)
Lerp(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64)
UnclampedLerp(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64)
Slerp(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64)
Project(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d)
ProjectOnPlane(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d)
ProjectOnPlane(FixedMathSharp.Vector3d,FixedMathSharp.Bounds.FixedPlane)
Angle(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d)
Reflect(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d)
Rotate(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion)
InverseRotate(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.FixedQuaternion)
Transform(FixedMathSharp.Vector3d,FixedMathSharp.Fixed4x4)
ToDegrees(FixedMathSharp.Vector3d)
ToRadians(FixedMathSharp.Vector3d)
Abs(FixedMathSharp.Vector3d)
Sign(FixedMathSharp.Vector3d)
FuzzyEqualAbsolute(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64)
FuzzyEqual(FixedMathSharp.Vector3d,FixedMathSharp.Vector3d,System.Nullable`1<FixedMathSharp.Fixed64>)