BsRect2.h 1.7 KB

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