BsRect2I.h 2.4 KB

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