HashHelper.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/Math/Vector2.h>
  10. #include <AzCore/Math/Vector3.h>
  11. #include <AzCore/Math/Vector4.h>
  12. #include <AzCore/Math/Matrix3x4.h>
  13. namespace AZStd
  14. {
  15. template<>
  16. struct hash<AZ::Vector2>
  17. {
  18. using result_type = AZStd::size_t;
  19. result_type operator()(const AZ::Vector2& value) const
  20. {
  21. result_type hash = 0;
  22. hash_combine(hash, value.GetX());
  23. hash_combine(hash, value.GetY());
  24. return hash;
  25. }
  26. };
  27. template<>
  28. struct hash<AZ::Vector3>
  29. {
  30. using result_type = AZStd::size_t;
  31. result_type operator()(const AZ::Vector3& value) const
  32. {
  33. result_type hash = 0;
  34. hash_combine(hash, value.GetX());
  35. hash_combine(hash, value.GetY());
  36. hash_combine(hash, value.GetZ());
  37. return hash;
  38. }
  39. };
  40. template<>
  41. struct hash<AZ::Vector4>
  42. {
  43. using result_type = AZStd::size_t;
  44. result_type operator()(const AZ::Vector4& value) const
  45. {
  46. result_type hash = 0;
  47. hash_combine(hash, value.GetX());
  48. hash_combine(hash, value.GetY());
  49. hash_combine(hash, value.GetZ());
  50. hash_combine(hash, value.GetW());
  51. return hash;
  52. }
  53. };
  54. template<>
  55. struct hash<AZ::Matrix3x4>
  56. {
  57. using result_type = AZStd::size_t;
  58. result_type operator()(const AZ::Matrix3x4& value) const
  59. {
  60. result_type hash = 0;
  61. AZ::Vector3 basisX;
  62. AZ::Vector3 basisY;
  63. AZ::Vector3 basisZ;
  64. AZ::Vector3 translation;
  65. value.GetBasisAndTranslation(&basisX, &basisY, &basisZ, &translation);
  66. hash_combine(hash, basisX);
  67. hash_combine(hash, basisY);
  68. hash_combine(hash, basisZ);
  69. hash_combine(hash, translation);
  70. return hash;
  71. }
  72. };
  73. }