QuaternionEqualityComparer.cs 931 B

12345678910111213141516171819202122232425262728293031
  1. using System.Collections.Generic;
  2. namespace UnityEngine.TestTools.Utils
  3. {
  4. public class QuaternionEqualityComparer : IEqualityComparer<Quaternion>
  5. {
  6. private const float k_DefaultError = 0.00001f;
  7. private readonly float AllowedError;
  8. private static readonly QuaternionEqualityComparer m_Instance = new QuaternionEqualityComparer();
  9. public static QuaternionEqualityComparer Instance { get { return m_Instance; } }
  10. private QuaternionEqualityComparer() : this(k_DefaultError) {}
  11. public QuaternionEqualityComparer(float allowedError)
  12. {
  13. AllowedError = allowedError;
  14. }
  15. public bool Equals(Quaternion expected, Quaternion actual)
  16. {
  17. return Mathf.Abs(Quaternion.Dot(expected, actual)) > (1.0f - AllowedError);
  18. }
  19. public int GetHashCode(Quaternion quaternion)
  20. {
  21. return 0;
  22. }
  23. }
  24. }