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