BsRect2I.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #pragma once
  2. #include "BsPrerequisitesUtil.h"
  3. namespace BansheeEngine
  4. {
  5. /** @addtogroup Math
  6. * @{
  7. */
  8. /** Represents a 2D rectangle using integer values. Rectangle is represented with an origin in top left and width/height. */
  9. class BS_UTILITY_EXPORT Rect2I
  10. {
  11. public:
  12. Rect2I();
  13. Rect2I(int _x, int _y, int _width, int _height);
  14. int x, y, width, height;
  15. /** Returns true if the rectangle contains the provided point. */
  16. bool contains(const Vector2I& 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 Rect2I& other) const;
  22. /** Extends this rectangle so that the provided rectangle is completely contained within it. */
  23. void encapsulate(const Rect2I& other);
  24. /** Clips current rectangle so that it does not overlap the provided rectangle. */
  25. void clip(const Rect2I& clipRect);
  26. /**
  27. * Cuts the current rectangle with the provided rectangle and outputs the pieces. The pieces will contain all area
  28. * of the current rectangle without including the cut rectangle area.
  29. */
  30. void cut(const Rect2I& cutRect, Vector<Rect2I>& pieces);
  31. /**
  32. * Cuts the current rectangle with the provided rectangles and outputs the pieces. The pieces will contain all area
  33. * of the current rectangle without including the cut rectangles area.
  34. */
  35. void cut(const Vector<Rect2I>& cutRects, Vector<Rect2I>& pieces);
  36. /**
  37. * Transforms the bounds by the given matrix. Resulting value is an axis aligned rectangle encompassing the
  38. * transformed points.
  39. *
  40. * @note
  41. * Since the resulting value is an AA rectangle of the original transformed rectangle, the bounds will be larger
  42. * than needed. Oriented rectangle would provide a much tighter fit.
  43. */
  44. void transform(const Matrix4& matrix);
  45. inline bool operator== (const Rect2I& rhs) const
  46. {
  47. return x == rhs.x && y == rhs.y && width == rhs.width && height == rhs.height;
  48. }
  49. inline bool operator!= (const Rect2I& rhs) const
  50. {
  51. return !(*this == rhs);
  52. }
  53. static const Rect2I EMPTY;
  54. };
  55. /** @} */
  56. }