BsRect2.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "Prerequisites/BsPrerequisitesUtil.h"
  5. namespace bs
  6. {
  7. /** @addtogroup Math
  8. * @{
  9. */
  10. /** Represents a 2D rectangle using real values. Rectangle is represented with an origin in top left and width/height. */
  11. class BS_UTILITY_EXPORT Rect2
  12. {
  13. public:
  14. Rect2();
  15. Rect2(float _x, float _y, float _width, float _height);
  16. float x, y, width, height;
  17. /** Returns true if the rectangle contains the provided point. */
  18. bool contains(const Vector2& point) const;
  19. /**
  20. * Returns true if the rectangle overlaps the provided rectangle. Also returns true if the rectangles are contained
  21. * within each other completely (no intersecting edges).
  22. */
  23. bool overlaps(const Rect2& other) const;
  24. /** Extends this rectangle so that the provided rectangle is completely contained within it. */
  25. void encapsulate(const Rect2& other);
  26. /** Clips current rectangle so that it does not overlap the provided rectangle. */
  27. void clip(const Rect2& clipRect);
  28. /**
  29. * Transforms the bounds by the given matrix. Resulting value is an axis aligned rectangle encompassing the
  30. * transformed points.
  31. *
  32. * @note Since the resulting value is an AA rectangle of the original transformed rectangle, the bounds
  33. * will be larger than needed. Oriented rectangle would provide a much tighter fit.
  34. */
  35. void transform(const Matrix4& matrix);
  36. bool operator== (const Rect2& rhs) const
  37. {
  38. return x == rhs.x && y == rhs.y && width == rhs.width && height == rhs.height;
  39. }
  40. bool operator!= (const Rect2& rhs) const
  41. {
  42. return !(*this == rhs);
  43. }
  44. static const Rect2 EMPTY;
  45. };
  46. /** @} */
  47. /** @cond SPECIALIZATIONS */
  48. BS_ALLOW_MEMCPY_SERIALIZATION(Rect2);
  49. /** @endcond */
  50. }