| | | 1 | | using System.Runtime.CompilerServices; |
| | | 2 | | |
| | | 3 | | namespace FixedMathSharp; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Provides extension methods for the Vector4d type to support additional vector operations and comparisons. |
| | | 7 | | /// </summary> |
| | | 8 | | public static partial class Vector4dExtensions |
| | | 9 | | { |
| | | 10 | | #region Vector4d Operations |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Clamps each component of the vector to the range [-1, 1] and returns the clamped vector. |
| | | 14 | | /// </summary> |
| | | 15 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 16 | | public static Vector4d ClampOneInPlace(this Vector4d v) |
| | 1 | 17 | | { |
| | 1 | 18 | | v.x = v.x.ClampOne(); |
| | 1 | 19 | | v.y = v.y.ClampOne(); |
| | 1 | 20 | | v.z = v.z.ClampOne(); |
| | 1 | 21 | | v.w = v.w.ClampOne(); |
| | 1 | 22 | | return v; |
| | 1 | 23 | | } |
| | | 24 | | |
| | | 25 | | #endregion |
| | | 26 | | |
| | | 27 | | #region Conversion |
| | | 28 | | |
| | | 29 | | /// <inheritdoc cref="Vector4d.Abs(Vector4d)" /> |
| | | 30 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 31 | | public static Vector4d Abs(this Vector4d value) |
| | 1 | 32 | | { |
| | 1 | 33 | | return Vector4d.Abs(value); |
| | 1 | 34 | | } |
| | | 35 | | |
| | | 36 | | /// <inheritdoc cref="Vector4d.Sign(Vector4d)" /> |
| | | 37 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 38 | | public static Vector4d Sign(this Vector4d value) |
| | 1 | 39 | | { |
| | 1 | 40 | | return Vector4d.Sign(value); |
| | 1 | 41 | | } |
| | | 42 | | |
| | | 43 | | #endregion |
| | | 44 | | |
| | | 45 | | #region Equality |
| | | 46 | | |
| | | 47 | | /// <summary> |
| | | 48 | | /// Compares two vectors for approximate equality, allowing a fixed absolute difference. |
| | | 49 | | /// </summary> |
| | | 50 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 51 | | public static bool FuzzyEqualAbsolute(this Vector4d me, Vector4d other, Fixed64 allowedDifference) |
| | 5 | 52 | | { |
| | 5 | 53 | | return (me.x - other.x).Abs() <= allowedDifference && |
| | 5 | 54 | | (me.y - other.y).Abs() <= allowedDifference && |
| | 5 | 55 | | (me.z - other.z).Abs() <= allowedDifference && |
| | 5 | 56 | | (me.w - other.w).Abs() <= allowedDifference; |
| | 5 | 57 | | } |
| | | 58 | | |
| | | 59 | | /// <summary> |
| | | 60 | | /// Compares two vectors for approximate equality, allowing a fractional difference. |
| | | 61 | | /// </summary> |
| | | 62 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 63 | | public static bool FuzzyEqual(this Vector4d me, Vector4d other, Fixed64? percentage = null) |
| | 7 | 64 | | { |
| | 7 | 65 | | Fixed64 p = percentage ?? Fixed64.Epsilon; |
| | 7 | 66 | | return me.x.FuzzyComponentEqual(other.x, p) && |
| | 7 | 67 | | me.y.FuzzyComponentEqual(other.y, p) && |
| | 7 | 68 | | me.z.FuzzyComponentEqual(other.z, p) && |
| | 7 | 69 | | me.w.FuzzyComponentEqual(other.w, p); |
| | 7 | 70 | | } |
| | | 71 | | |
| | | 72 | | #endregion |
| | | 73 | | } |