3
0

Aabb2i.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #include <TerrainRenderer/Aabb2i.h>
  9. #include <AzCore/Math/MathUtils.h>
  10. namespace Terrain
  11. {
  12. Aabb2i::Aabb2i(const Vector2i& min, const Vector2i& max)
  13. : m_min(min)
  14. , m_max(max)
  15. {}
  16. Aabb2i Aabb2i::operator+(const Vector2i& rhs) const
  17. {
  18. Aabb2i returnValue = *this;
  19. returnValue += rhs;
  20. return returnValue;
  21. }
  22. Aabb2i& Aabb2i::operator+=(const Vector2i& rhs)
  23. {
  24. m_min += rhs;
  25. m_max += rhs;
  26. return *this;
  27. }
  28. Aabb2i Aabb2i::operator-(const Vector2i& rhs) const
  29. {
  30. Aabb2i returnValue = *this;
  31. returnValue -= rhs;
  32. return returnValue;
  33. }
  34. Aabb2i& Aabb2i::operator-=(const Vector2i& rhs)
  35. {
  36. m_min -= rhs;
  37. m_max -= rhs;
  38. return *this;
  39. }
  40. bool Aabb2i::operator==(const Aabb2i& other) const
  41. {
  42. return m_min == other.m_min && m_max == other.m_max;
  43. }
  44. bool Aabb2i::operator!=(const Aabb2i& other) const
  45. {
  46. return !(*this == other);
  47. }
  48. Aabb2i Aabb2i::GetClamped(Aabb2i rhs) const
  49. {
  50. Aabb2i ret;
  51. ret.m_min.m_x = AZ::GetMax(m_min.m_x, rhs.m_min.m_x);
  52. ret.m_min.m_y = AZ::GetMax(m_min.m_y, rhs.m_min.m_y);
  53. ret.m_max.m_x = AZ::GetMin(m_max.m_x, rhs.m_max.m_x);
  54. ret.m_max.m_y = AZ::GetMin(m_max.m_y, rhs.m_max.m_y);
  55. return ret;
  56. }
  57. bool Aabb2i::IsValid() const
  58. {
  59. // Intentionally strict, equal min/max not valid.
  60. return m_min.m_x < m_max.m_x && m_min.m_y < m_max.m_y;
  61. }
  62. }