| | | 1 | | using System.Runtime.CompilerServices; |
| | | 2 | | |
| | | 3 | | namespace FixedMathSharp; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Provides extension methods for the Fixed3x3 structure, enabling additional transformation and comparison operations. |
| | | 7 | | /// </summary> |
| | | 8 | | public static class Fixed3x3Extensions |
| | | 9 | | { |
| | | 10 | | #region Transformations |
| | | 11 | | |
| | | 12 | | /// <inheritdoc cref="Fixed3x3.ExtractScale(Fixed3x3)" /> |
| | | 13 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 14 | | public static Vector3d ExtractScale(this Fixed3x3 matrix) |
| | 1 | 15 | | { |
| | 1 | 16 | | return Fixed3x3.ExtractScale(matrix); |
| | 1 | 17 | | } |
| | | 18 | | |
| | | 19 | | /// <inheritdoc cref="Fixed3x3.SetScale(Fixed3x3, Vector3d)" /> |
| | | 20 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 21 | | public static Fixed3x3 SetScale(this ref Fixed3x3 matrix, Vector3d localScale) |
| | 4 | 22 | | { |
| | 4 | 23 | | return matrix = Fixed3x3.SetScale(matrix, localScale); |
| | 4 | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <inheritdoc cref="Fixed3x3.SetGlobalScale(Fixed3x3, Vector3d)" /> |
| | | 27 | | public static Fixed3x3 SetGlobalScale(this ref Fixed3x3 matrix, Vector3d globalScale) |
| | 2 | 28 | | { |
| | 2 | 29 | | return matrix = Fixed3x3.SetGlobalScale(matrix, globalScale); |
| | 2 | 30 | | } |
| | | 31 | | |
| | | 32 | | #endregion |
| | | 33 | | |
| | | 34 | | #region Equality |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// Compares two Fixed3x3 for approximate equality, allowing a fixed absolute difference between components. |
| | | 38 | | /// </summary> |
| | | 39 | | /// <param name="f1">The current Fixed3x3.</param> |
| | | 40 | | /// <param name="f2">The Fixed3x3 to compare against.</param> |
| | | 41 | | /// <param name="allowedDifference">The allowed absolute difference between each component.</param> |
| | | 42 | | /// <returns>True if the components are within the allowed difference, false otherwise.</returns> |
| | | 43 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 44 | | public static bool FuzzyEqualAbsolute(this Fixed3x3 f1, Fixed3x3 f2, Fixed64 allowedDifference) |
| | 11 | 45 | | { |
| | 11 | 46 | | return (f1.m00 - f2.m00).Abs() <= allowedDifference && |
| | 11 | 47 | | (f1.m01 - f2.m01).Abs() <= allowedDifference && |
| | 11 | 48 | | (f1.m02 - f2.m02).Abs() <= allowedDifference && |
| | 11 | 49 | | (f1.m10 - f2.m10).Abs() <= allowedDifference && |
| | 11 | 50 | | (f1.m11 - f2.m11).Abs() <= allowedDifference && |
| | 11 | 51 | | (f1.m12 - f2.m12).Abs() <= allowedDifference && |
| | 11 | 52 | | (f1.m20 - f2.m20).Abs() <= allowedDifference && |
| | 11 | 53 | | (f1.m21 - f2.m21).Abs() <= allowedDifference && |
| | 11 | 54 | | (f1.m22 - f2.m22).Abs() <= allowedDifference; |
| | 11 | 55 | | } |
| | | 56 | | |
| | | 57 | | /// <summary> |
| | | 58 | | /// Compares two Fixed3x3 for approximate equality, allowing a fractional percentage (defaults to ~1%) difference be |
| | | 59 | | /// </summary> |
| | | 60 | | /// <param name="f1">The current Fixed3x3.</param> |
| | | 61 | | /// <param name="f2">The Fixed3x3 to compare against.</param> |
| | | 62 | | /// <param name="percentage">The allowed fractional difference (percentage) for each component.</param> |
| | | 63 | | /// <returns>True if the components are within the allowed percentage difference, false otherwise.</returns> |
| | | 64 | | public static bool FuzzyEqual(this Fixed3x3 f1, Fixed3x3 f2, Fixed64? percentage = null) |
| | 12 | 65 | | { |
| | 12 | 66 | | Fixed64 p = percentage ?? Fixed64.Epsilon; |
| | 12 | 67 | | return f1.m00.FuzzyComponentEqual(f2.m00, p) && |
| | 12 | 68 | | f1.m01.FuzzyComponentEqual(f2.m01, p) && |
| | 12 | 69 | | f1.m02.FuzzyComponentEqual(f2.m02, p) && |
| | 12 | 70 | | f1.m10.FuzzyComponentEqual(f2.m10, p) && |
| | 12 | 71 | | f1.m11.FuzzyComponentEqual(f2.m11, p) && |
| | 12 | 72 | | f1.m12.FuzzyComponentEqual(f2.m12, p) && |
| | 12 | 73 | | f1.m20.FuzzyComponentEqual(f2.m20, p) && |
| | 12 | 74 | | f1.m21.FuzzyComponentEqual(f2.m21, p) && |
| | 12 | 75 | | f1.m22.FuzzyComponentEqual(f2.m22, p); |
| | 12 | 76 | | } |
| | | 77 | | |
| | | 78 | | #endregion |
| | | 79 | | } |