using FishNet.Documenting;
using UnityEngine;
namespace FishNet.Utility.Extension
{
[APIExclude]
public static class QuaternionFN
{
///
/// Returns if two quaternions match.
///
/// True to use a custom implementation with no error tolerance. False to use Unity's implementation which may return a match even when not true due to error tolerance.
///
public static bool Matches(this Quaternion a, Quaternion b, bool precise = false)
{
if (precise)
return (a.w == b.w && a.x == b.x && a.y == b.y && a.z == b.z);
else
return (a == b);
}
///
/// Returns the angle between two quaterions.
///
/// True to use a custom implementation with no error tolerance. False to use Unity's implementation which may return 0f due to error tolerance, even while there is a difference.
///
public static float Angle(this Quaternion a, Quaternion b, bool precise = false)
{
if (precise)
{
//This is run Unitys implementation without the error tolerance.
float dot = (a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w);
return (Mathf.Acos(Mathf.Min(Mathf.Abs(dot), 1f)) * 2f * 57.29578f);
}
else
{
return Quaternion.Angle(a, b);
}
}
}
}