Double3.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Jolt/Core/HashCombine.h>
  6. JPH_NAMESPACE_BEGIN
  7. /// Class that holds 3 doubles. Used as a storage class. Convert to DVec3 for calculations.
  8. class [[nodiscard]] Double3
  9. {
  10. public:
  11. JPH_OVERRIDE_NEW_DELETE
  12. Double3() = default; ///< Intentionally not initialized for performance reasons
  13. Double3(const Double3 &inRHS) = default;
  14. Double3 & operator = (const Double3 &inRHS) = default;
  15. Double3(double inX, double inY, double inZ) : x(inX), y(inY), z(inZ) { }
  16. double operator [] (int inCoordinate) const
  17. {
  18. JPH_ASSERT(inCoordinate < 3);
  19. return *(&x + inCoordinate);
  20. }
  21. bool operator == (const Double3 &inRHS) const
  22. {
  23. return x == inRHS.x && y == inRHS.y && z == inRHS.z;
  24. }
  25. bool operator != (const Double3 &inRHS) const
  26. {
  27. return x != inRHS.x || y != inRHS.y || z != inRHS.z;
  28. }
  29. double x;
  30. double y;
  31. double z;
  32. };
  33. static_assert(is_trivial<Double3>(), "Is supposed to be a trivial type!");
  34. JPH_NAMESPACE_END
  35. // Create a std::hash for Double3
  36. JPH_MAKE_HASHABLE(JPH::Double3, t.x, t.y, t.z)