| | | 1 | | using System.Runtime.CompilerServices; |
| | | 2 | | |
| | | 3 | | namespace FixedMathSharp |
| | | 4 | | { |
| | | 5 | | public static partial class FixedQuaternionExtensions |
| | | 6 | | { |
| | | 7 | | /// <inheritdoc cref="FixedQuaternion.ToAngularVelocity" /> |
| | | 8 | | public static Vector3d ToAngularVelocity( |
| | | 9 | | this FixedQuaternion currentRotation, |
| | | 10 | | FixedQuaternion previousRotation, |
| | | 11 | | Fixed64 deltaTime) |
| | 1 | 12 | | { |
| | 1 | 13 | | return FixedQuaternion.ToAngularVelocity(currentRotation, previousRotation, deltaTime); |
| | 1 | 14 | | } |
| | | 15 | | |
| | | 16 | | #region Equality |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Compares two quaternions for approximate equality, allowing a fixed absolute difference between components. |
| | | 20 | | /// </summary> |
| | | 21 | | /// <param name="q1">The current quaternion.</param> |
| | | 22 | | /// <param name="q2">The quaternion to compare against.</param> |
| | | 23 | | /// <param name="allowedDifference">The allowed absolute difference between each component.</param> |
| | | 24 | | /// <returns>True if the components are within the allowed difference, false otherwise.</returns> |
| | | 25 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 26 | | public static bool FuzzyEqualAbsolute(this FixedQuaternion q1, FixedQuaternion q2, Fixed64 allowedDifference) |
| | 2 | 27 | | { |
| | 2 | 28 | | return (q1.x - q2.x).Abs() <= allowedDifference && |
| | 2 | 29 | | (q1.y - q2.y).Abs() <= allowedDifference && |
| | 2 | 30 | | (q1.z - q2.z).Abs() <= allowedDifference && |
| | 2 | 31 | | (q1.w - q2.w).Abs() <= allowedDifference; |
| | 2 | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Compares two quaternions for approximate equality, allowing a fractional percentage (defaults to ~1%) differ |
| | | 36 | | /// </summary> |
| | | 37 | | /// <param name="q1">The current quaternion.</param> |
| | | 38 | | /// <param name="q2">The quaternion to compare against.</param> |
| | | 39 | | /// <param name="percentage">The allowed fractional difference (percentage) for each component.</param> |
| | | 40 | | /// <returns>True if the components are within the allowed percentage difference, false otherwise.</returns> |
| | | 41 | | public static bool FuzzyEqual(this FixedQuaternion q1, FixedQuaternion q2, Fixed64? percentage = null) |
| | 31 | 42 | | { |
| | 31 | 43 | | Fixed64 p = percentage ?? Fixed64.Epsilon; |
| | 31 | 44 | | return q1.x.FuzzyComponentEqual(q2.x, p) && |
| | 31 | 45 | | q1.y.FuzzyComponentEqual(q2.y, p) && |
| | 31 | 46 | | q1.z.FuzzyComponentEqual(q2.z, p) && |
| | 31 | 47 | | q1.w.FuzzyComponentEqual(q2.w, p); |
| | 31 | 48 | | } |
| | | 49 | | |
| | | 50 | | #endregion |
| | | 51 | | } |
| | | 52 | | } |