Double3.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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(double inX, double inY, double inZ) : x(inX), y(inY), z(inZ) { }
  15. double operator [] (int inCoordinate) const
  16. {
  17. JPH_ASSERT(inCoordinate < 3);
  18. return *(&x + inCoordinate);
  19. }
  20. bool operator == (const Double3 &inRHS) const
  21. {
  22. return x == inRHS.x && y == inRHS.y && z == inRHS.z;
  23. }
  24. bool operator != (const Double3 &inRHS) const
  25. {
  26. return x != inRHS.x || y != inRHS.y || z != inRHS.z;
  27. }
  28. double x;
  29. double y;
  30. double z;
  31. };
  32. static_assert(is_trivial<Double3>(), "Is supposed to be a trivial type!");
  33. JPH_NAMESPACE_END
  34. // Create a std::hash for Double3
  35. JPH_MAKE_HASHABLE(JPH::Double3, t.x, t.y, t.z)