< Summary

Information
Class: FixedMathSharp.Fixed64Extensions
Assembly: FixedMathSharp
File(s): /home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Numerics/Scalars/Fixed64.Extensions.cs
Line coverage
100%
Covered lines: 46
Uncovered lines: 0
Coverable lines: 46
Total lines: 253
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Sign(...)100%11100%
IsInteger(...)100%11100%
Squared(...)100%11100%
Round(...)100%11100%
RoundToPrecision(...)100%11100%
Clamp(...)100%11100%
ClampOne(...)100%11100%
Clamp01(...)100%11100%
Abs(...)100%11100%
AbsLessThan(...)100%11100%
FastAdd(...)100%11100%
FastSub(...)100%11100%
FastMul(...)100%11100%
FastDiv(...)100%11100%
FastMod(...)100%11100%
Lerp(...)100%11100%
SmoothStep(...)100%11100%
CubicInterpolate(...)100%11100%
Floor(...)100%11100%
Ceil(...)100%11100%
RoundToInt(...)100%11100%
RoundToLong(...)100%11100%
CeilToInt(...)100%11100%
CeilToLong(...)100%11100%
FloorToInt(...)100%11100%
FloorToLong(...)100%11100%
Sqrt(...)100%11100%
Pow(...)100%11100%
Pow2(...)100%11100%
Log2(...)100%11100%
Ln(...)100%11100%
Acos(...)100%11100%
Asin(...)100%11100%
Atan(...)100%11100%
Atan2(...)100%11100%
Sin(...)100%11100%
Cos(...)100%11100%
Tan(...)100%11100%
Hypot(...)100%11100%
ToRadians(...)100%11100%
ToDegrees(...)100%11100%
MoreThanEpsilon(...)100%11100%
LessThanEpsilon(...)100%11100%
FuzzyComponentEqual(...)100%22100%

File(s)

/home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Numerics/Scalars/Fixed64.Extensions.cs

#LineLine coverage
 1//=======================================================================
 2// Fixed64.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;
 9using System.Runtime.CompilerServices;
 10
 11namespace FixedMathSharp;
 12
 13/// <summary>
 14/// Provides extension methods for the Fixed64 type, enabling additional mathematical, conversion, and comparison operat
 15/// </summary>
 16public static class Fixed64Extensions
 17{
 18    #region Fixed64 Operations
 19
 20    /// <inheritdoc cref="Fixed64.Sign(Fixed64)" />
 21    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1422    public static int Sign(this Fixed64 value) => Fixed64.Sign(value);
 23
 24    /// <inheritdoc cref="Fixed64.IsInteger(Fixed64)" />
 25    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 626    public static bool IsInteger(this Fixed64 value) => Fixed64.IsInteger(value);
 27
 28    /// <inheritdoc cref="FixedMath.Squared(Fixed64)" />
 29    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 130    public static Fixed64 Squared(this Fixed64 value) => FixedMath.Squared(value);
 31
 32    /// <inheritdoc cref="FixedMath.Round(Fixed64, MidpointRounding)" />
 33    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 34    public static Fixed64 Round(this Fixed64 value, MidpointRounding mode = MidpointRounding.ToEven) =>
 235        FixedMath.Round(value, mode);
 36
 37    /// <inheritdoc cref="FixedMath.RoundToPrecision(Fixed64, int, MidpointRounding)" />
 38    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 39    public static Fixed64 RoundToPrecision(this Fixed64 value, int places, MidpointRounding mode = MidpointRounding.ToEv
 140        FixedMath.RoundToPrecision(value, places, mode);
 41
 42    /// <inheritdoc cref="FixedMath.Clamp(Fixed64, Fixed64, Fixed64)" />
 43    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 144    public static Fixed64 Clamp(this Fixed64 value, Fixed64 min, Fixed64 max) => FixedMath.Clamp(value, min, max);
 45
 46    /// <inheritdoc cref="FixedMath.ClampOne(Fixed64)" />
 47    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 148    public static Fixed64 ClampOne(this Fixed64 f1) => FixedMath.ClampOne(f1);
 49
 50    /// <inheritdoc cref="FixedMath.Clamp01(Fixed64)" />
 51    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 152    public static Fixed64 Clamp01(this Fixed64 f1) => FixedMath.Clamp01(f1);
 53
 54    /// <inheritdoc cref="FixedMath.Abs(Fixed64)" />
 55    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 364956    public static Fixed64 Abs(this Fixed64 value) => FixedMath.Abs(value);
 57
 58    /// <summary>
 59    /// Checks if the absolute value of x is less than y.
 60    /// </summary>
 61    /// <param name="x">The value to compare.</param>
 62    /// <param name="y">The comparison threshold.</param>
 63    /// <returns>True if |x| &lt; y; otherwise false.</returns>
 64    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 165    public static bool AbsLessThan(this Fixed64 x, Fixed64 y) => Abs(x) < y;
 66
 67    /// <inheritdoc cref="FixedMath.FastAdd(Fixed64, Fixed64)" />
 68    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 169    public static Fixed64 FastAdd(this Fixed64 a, Fixed64 b) => FixedMath.FastAdd(a, b);
 70
 71    /// <inheritdoc cref="FixedMath.FastSub(Fixed64, Fixed64)" />
 72    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 173    public static Fixed64 FastSub(this Fixed64 a, Fixed64 b) => FixedMath.FastSub(a, b);
 74
 75    /// <inheritdoc cref="FixedMath.FastMul(Fixed64, Fixed64)" />
 76    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 177    public static Fixed64 FastMul(this Fixed64 a, Fixed64 b) => FixedMath.FastMul(a, b);
 78
 79    /// <inheritdoc cref="FixedMath.FastDiv(Fixed64, Fixed64)" />
 80    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 181    public static Fixed64 FastDiv(this Fixed64 a, Fixed64 b) => FixedMath.FastDiv(a, b);
 82
 83    /// <inheritdoc cref="FixedMath.FastMod(Fixed64, Fixed64)" />
 84    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 185    public static Fixed64 FastMod(this Fixed64 a, Fixed64 b) => FixedMath.FastMod(a, b);
 86
 87    /// <inheritdoc cref="FixedMath.Lerp(Fixed64, Fixed64, Fixed64)" />
 88    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 189    public static Fixed64 Lerp(this Fixed64 a, Fixed64 b, Fixed64 t) => FixedMath.Lerp(a, b, t);
 90
 91    /// <inheritdoc cref="FixedMath.SmoothStep(Fixed64, Fixed64, Fixed64)" />
 92    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 193    public static Fixed64 SmoothStep(this Fixed64 a, Fixed64 b, Fixed64 t) => FixedMath.SmoothStep(a, b, t);
 94
 95    /// <inheritdoc cref="FixedMath.CubicInterpolate(Fixed64, Fixed64, Fixed64, Fixed64, Fixed64)" />
 96    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 97    public static Fixed64 CubicInterpolate(this Fixed64 p0, Fixed64 p1, Fixed64 m0, Fixed64 m1, Fixed64 t) =>
 198        FixedMath.CubicInterpolate(p0, p1, m0, m1, t);
 99
 100    /// <inheritdoc cref="FixedMath.Floor(Fixed64)" />
 101    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 39102    public static Fixed64 Floor(this Fixed64 value) => FixedMath.Floor(value);
 103
 104    /// <inheritdoc cref="FixedMath.Ceil(Fixed64)" />
 105    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1106    public static Fixed64 Ceil(this Fixed64 value) => FixedMath.Ceil(value);
 107
 108    /// <summary>
 109    /// Rounds the Fixed64 value to the nearest integer.
 110    /// </summary>
 111    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 14112    public static int RoundToInt(this Fixed64 x) => (int)FixedMath.Round(x);
 113
 114    /// <summary>
 115    /// Rounds the Fixed64 value to the nearest long.
 116    /// </summary>
 117    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1118    public static long RoundToLong(this Fixed64 x) => (long)FixedMath.Round(x);
 119
 120    /// <summary>
 121    /// Rounds up the Fixed64 value to the nearest integer.
 122    /// </summary>
 123    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 124    public static int CeilToInt(this Fixed64 x) =>
 1125        (int)(FixedMath.Ceil(x).m_rawValue >> FixedMath.SHIFT_AMOUNT_I);
 126
 127    /// <summary>
 128    /// Rounds up the Fixed64 value to the nearest long.
 129    /// </summary>
 130    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 131    public static long CeilToLong(this Fixed64 x) =>
 1132        (long)(FixedMath.Ceil(x).m_rawValue >> FixedMath.SHIFT_AMOUNT_I);
 133
 134    /// <summary>
 135    /// Rounds down the Fixed64 value to the nearest integer.
 136    /// </summary>
 137    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 138    public static int FloorToInt(this Fixed64 x) =>
 1139        (int)(FixedMath.Floor(x).m_rawValue >> FixedMath.SHIFT_AMOUNT_I);
 140
 141    /// <summary>
 142    /// Rounds down the Fixed64 value to the nearest long.
 143    /// </summary>
 144    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 145    public static long FloorToLong(this Fixed64 x) =>
 1146        (long)(FixedMath.Floor(x).m_rawValue >> FixedMath.SHIFT_AMOUNT_I);
 147
 148    #endregion
 149
 150    #region Fixed64 Trigonometry
 151
 152    /// <inheritdoc cref="FixedMath.Sqrt(Fixed64)" />
 153    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1154    public static Fixed64 Sqrt(this Fixed64 f) => FixedMath.Sqrt(f);
 155
 156    /// <inheritdoc cref="FixedMath.Pow(Fixed64, Fixed64)" />
 157    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1158    public static Fixed64 Pow(this Fixed64 f, Fixed64 exponent) => FixedMath.Pow(f, exponent);
 159
 160    /// <inheritdoc cref="FixedMath.Pow2(Fixed64)" />
 161    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1162    public static Fixed64 Pow2(this Fixed64 f) => FixedMath.Pow2(f);
 163
 164    /// <inheritdoc cref="FixedMath.Log2(Fixed64)" />
 165    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1166    public static Fixed64 Log2(this Fixed64 f) => FixedMath.Log2(f);
 167
 168    /// <inheritdoc cref="FixedMath.Ln(Fixed64)" />
 169    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1170    public static Fixed64 Ln(this Fixed64 f) => FixedMath.Ln(f);
 171
 172    /// <inheritdoc cref="FixedMath.Acos(Fixed64)" />
 173    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1174    public static Fixed64 Acos(this Fixed64 f) => FixedMath.Acos(f);
 175
 176    /// <inheritdoc cref="FixedMath.Asin(Fixed64)" />
 177    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1178    public static Fixed64 Asin(this Fixed64 f) => FixedMath.Asin(f);
 179
 180    /// <inheritdoc cref="FixedMath.Atan(Fixed64)" />
 181    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1182    public static Fixed64 Atan(this Fixed64 f) => FixedMath.Atan(f);
 183
 184    /// <inheritdoc cref="FixedMath.Atan2(Fixed64, Fixed64)" />
 185    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1186    public static Fixed64 Atan2(this Fixed64 a, Fixed64 b) => FixedMath.Atan2(a, b);
 187
 188    /// <inheritdoc cref="FixedMath.Sin(Fixed64)" />
 189    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1190    public static Fixed64 Sin(this Fixed64 f) => FixedMath.Sin(f);
 191
 192    /// <inheritdoc cref="FixedMath.Cos(Fixed64)" />
 193    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1194    public static Fixed64 Cos(this Fixed64 f) => FixedMath.Cos(f);
 195
 196    /// <inheritdoc cref="FixedMath.Tan(Fixed64)" />
 197    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1198    public static Fixed64 Tan(this Fixed64 f) => FixedMath.Tan(f);
 199
 200    /// <inheritdoc cref="FixedMath.GetHypotenuse(Fixed64, Fixed64)" />
 201    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1202    public static Fixed64 Hypot(this Fixed64 a, Fixed64 b) => FixedMath.GetHypotenuse(a, b);
 203
 204    #endregion
 205
 206    #region Conversion
 207
 208    /// <summary>
 209    /// Converts the angle in degrees to radians.
 210    /// </summary>
 211    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 2212    public static Fixed64 ToRadians(this Fixed64 angleInDegrees) => FixedMath.DegToRad(angleInDegrees);
 213
 214    /// <summary>
 215    /// Converts the angle in radians to degrees.
 216    /// </summary>
 217    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1218    public static Fixed64 ToDegrees(this Fixed64 angleInRadians) => FixedMath.RadToDeg(angleInRadians);
 219
 220    #endregion
 221
 222    #region Equality
 223
 224    /// <summary>
 225    /// Checks if the value is greater than epsilon (positive or negative).
 226    /// Useful for determining if a value is effectively non-zero with a given precision.
 227    /// </summary>
 228    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 2229    public static bool MoreThanEpsilon(this Fixed64 d) => d.Abs() > Fixed64.Epsilon;
 230
 231    /// <summary>
 232    /// Checks if the value is less than epsilon (i.e., effectively zero).
 233    /// Useful for determining if a value is close enough to zero with a given precision.
 234    /// </summary>
 235    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 677236    public static bool LessThanEpsilon(this Fixed64 d) => (d.Abs() < Fixed64.Epsilon);
 237
 238    /// <summary>
 239    /// Helper method to compare individual vector components for approximate equality, allowing a fractional difference
 240    /// Handles zero components by only using the allowed percentage difference.
 241    /// </summary>
 242    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 243    public static bool FuzzyComponentEqual(this Fixed64 a, Fixed64 b, Fixed64 percentage)
 244    {
 664245        var diff = (a - b).Abs();
 664246        var allowedErr = a.Abs() * percentage;
 247        // Compare directly to percentage if a is zero
 248        // Otherwise, use percentage of a's magnitude
 664249        return a.LessThanEpsilon() ? diff <= percentage : diff <= allowedErr;
 250    }
 251
 252    #endregion
 253}

Methods/Properties

Sign(FixedMathSharp.Fixed64)
IsInteger(FixedMathSharp.Fixed64)
Squared(FixedMathSharp.Fixed64)
Round(FixedMathSharp.Fixed64,System.MidpointRounding)
RoundToPrecision(FixedMathSharp.Fixed64,System.Int32,System.MidpointRounding)
Clamp(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
ClampOne(FixedMathSharp.Fixed64)
Clamp01(FixedMathSharp.Fixed64)
Abs(FixedMathSharp.Fixed64)
AbsLessThan(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
FastAdd(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
FastSub(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
FastMul(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
FastDiv(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
FastMod(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
Lerp(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
SmoothStep(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
CubicInterpolate(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
Floor(FixedMathSharp.Fixed64)
Ceil(FixedMathSharp.Fixed64)
RoundToInt(FixedMathSharp.Fixed64)
RoundToLong(FixedMathSharp.Fixed64)
CeilToInt(FixedMathSharp.Fixed64)
CeilToLong(FixedMathSharp.Fixed64)
FloorToInt(FixedMathSharp.Fixed64)
FloorToLong(FixedMathSharp.Fixed64)
Sqrt(FixedMathSharp.Fixed64)
Pow(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
Pow2(FixedMathSharp.Fixed64)
Log2(FixedMathSharp.Fixed64)
Ln(FixedMathSharp.Fixed64)
Acos(FixedMathSharp.Fixed64)
Asin(FixedMathSharp.Fixed64)
Atan(FixedMathSharp.Fixed64)
Atan2(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
Sin(FixedMathSharp.Fixed64)
Cos(FixedMathSharp.Fixed64)
Tan(FixedMathSharp.Fixed64)
Hypot(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
ToRadians(FixedMathSharp.Fixed64)
ToDegrees(FixedMathSharp.Fixed64)
MoreThanEpsilon(FixedMathSharp.Fixed64)
LessThanEpsilon(FixedMathSharp.Fixed64)
FuzzyComponentEqual(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)