| | | 1 | | //======================================================================= |
| | | 2 | | // Vector4d.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 | | |
| | | 8 | | using System.Runtime.CompilerServices; |
| | | 9 | | |
| | | 10 | | namespace FixedMathSharp; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Provides extension methods for the Vector4d type to support additional vector operations and comparisons. |
| | | 14 | | /// </summary> |
| | | 15 | | public static partial class Vector4dExtensions |
| | | 16 | | { |
| | | 17 | | #region Vector4d Operations |
| | | 18 | | |
| | | 19 | | /// <inheritdoc cref="Vector4d.Clamp(Vector4d, Vector4d, Vector4d)" /> |
| | | 20 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 21 | | public static Vector4d Clamp(this Vector4d value, Vector4d min, Vector4d max) => Vector4d.Clamp(value, min, max); |
| | | 22 | | |
| | | 23 | | /// <inheritdoc cref="Vector4d.Clamp(Vector4d, Vector4d, Vector4d)" /> |
| | | 24 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 25 | | public static Vector4d ClampOne(this Vector4d value) => Vector4d.Clamp(value, Vector4d.Negative, Vector4d.One); |
| | | 26 | | |
| | | 27 | | /// <inheritdoc cref="Vector4d.Lerp(Vector4d, Vector4d, Fixed64)" /> |
| | | 28 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 29 | | public static Vector4d Lerp(this Vector4d start, Vector4d end, Fixed64 amount) => Vector4d.Lerp(start, end, amount); |
| | | 30 | | |
| | | 31 | | /// <inheritdoc cref="Vector4d.UnclampedLerp(Vector4d, Vector4d, Fixed64)" /> |
| | | 32 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 33 | | public static Vector4d UnclampedLerp(this Vector4d start, Vector4d end, Fixed64 amount) => |
| | 1 | 34 | | Vector4d.UnclampedLerp(start, end, amount); |
| | | 35 | | |
| | | 36 | | /// <inheritdoc cref="Vector4d.Midpoint(Vector4d, Vector4d)" /> |
| | | 37 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 38 | | public static Vector4d Midpoint(this Vector4d value, Vector4d other) => Vector4d.Midpoint(value, other); |
| | | 39 | | |
| | | 40 | | /// <inheritdoc cref="Vector4d.Max(Vector4d, Vector4d)" /> |
| | | 41 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 42 | | public static Vector4d Max(this Vector4d value, Vector4d other) => Vector4d.Max(value, other); |
| | | 43 | | |
| | | 44 | | /// <inheritdoc cref="Vector4d.Min(Vector4d, Vector4d)" /> |
| | | 45 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 46 | | public static Vector4d Min(this Vector4d value, Vector4d other) => Vector4d.Min(value, other); |
| | | 47 | | |
| | | 48 | | /// <inheritdoc cref="Vector4d.Transform(Fixed4x4, Vector4d)" /> |
| | | 49 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 50 | | public static Vector4d Transform(this Vector4d vector, Fixed4x4 matrix) => Vector4d.Transform(matrix, vector); |
| | | 51 | | |
| | | 52 | | #endregion |
| | | 53 | | |
| | | 54 | | #region Conversion |
| | | 55 | | |
| | | 56 | | /// <inheritdoc cref="Vector4d.Abs(Vector4d)" /> |
| | | 57 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 58 | | public static Vector4d Abs(this Vector4d value) => Vector4d.Abs(value); |
| | | 59 | | |
| | | 60 | | /// <inheritdoc cref="Vector4d.Sign(Vector4d)" /> |
| | | 61 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1 | 62 | | public static Vector4d Sign(this Vector4d value) => Vector4d.Sign(value); |
| | | 63 | | |
| | | 64 | | #endregion |
| | | 65 | | |
| | | 66 | | #region Equality |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// Compares two vectors for approximate equality, allowing a fixed absolute difference. |
| | | 70 | | /// </summary> |
| | | 71 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 72 | | public static bool FuzzyEqualAbsolute(this Vector4d me, Vector4d other, Fixed64 allowedDifference) => |
| | 5 | 73 | | (me.X - other.X).Abs() <= allowedDifference && |
| | 5 | 74 | | (me.Y - other.Y).Abs() <= allowedDifference && |
| | 5 | 75 | | (me.Z - other.Z).Abs() <= allowedDifference && |
| | 5 | 76 | | (me.W - other.W).Abs() <= allowedDifference; |
| | | 77 | | |
| | | 78 | | /// <summary> |
| | | 79 | | /// Compares two vectors for approximate equality, allowing a fractional difference. |
| | | 80 | | /// </summary> |
| | | 81 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 82 | | public static bool FuzzyEqual(this Vector4d me, Vector4d other, Fixed64? percentage = null) |
| | | 83 | | { |
| | 7 | 84 | | Fixed64 p = percentage ?? Fixed64.Epsilon; |
| | 7 | 85 | | return me.X.FuzzyComponentEqual(other.X, p) && |
| | 7 | 86 | | me.Y.FuzzyComponentEqual(other.Y, p) && |
| | 7 | 87 | | me.Z.FuzzyComponentEqual(other.Z, p) && |
| | 7 | 88 | | me.W.FuzzyComponentEqual(other.W, p); |
| | | 89 | | } |
| | | 90 | | |
| | | 91 | | #endregion |
| | | 92 | | } |