BsRect2I.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 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(INT32 x, INT32 y, UINT32 width, UINT32 height);
  16. INT32 x, y;
  17. UINT32 width, height;
  18. /** Returns true if the rectangle contains the provided point. */
  19. bool contains(const Vector2I& point) const;
  20. /**
  21. * Returns true if the rectangle overlaps the provided rectangle. Also returns true if the rectangles are contained
  22. * within each other completely (no intersecting edges).
  23. */
  24. bool overlaps(const Rect2I& other) const;
  25. /** Extends this rectangle so that the provided rectangle is completely contained within it. */
  26. void encapsulate(const Rect2I& other);
  27. /** Clips current rectangle so that it does not overlap the provided rectangle. */
  28. void clip(const Rect2I& clipRect);
  29. /**
  30. * Cuts the current rectangle with the provided rectangle and outputs the pieces. The pieces will contain all area
  31. * of the current rectangle without including the cut rectangle area.
  32. */
  33. void cut(const Rect2I& cutRect, Vector<Rect2I>& pieces);
  34. /**
  35. * Cuts the current rectangle with the provided rectangles and outputs the pieces. The pieces will contain all area
  36. * of the current rectangle without including the cut rectangles area.
  37. */
  38. void cut(const Vector<Rect2I>& cutRects, Vector<Rect2I>& pieces);
  39. /**
  40. * Transforms the bounds by the given matrix. Resulting value is an axis aligned rectangle encompassing the
  41. * transformed points.
  42. *
  43. * @note
  44. * Since the resulting value is an AA rectangle of the original transformed rectangle, the bounds will be larger
  45. * than needed. Oriented rectangle would provide a much tighter fit.
  46. */
  47. void transform(const Matrix4& matrix);
  48. bool operator== (const Rect2I& rhs) const
  49. {
  50. return x == rhs.x && y == rhs.y && width == rhs.width && height == rhs.height;
  51. }
  52. bool operator!= (const Rect2I& rhs) const
  53. {
  54. return !(*this == rhs);
  55. }
  56. static const Rect2I EMPTY;
  57. };
  58. /** @} */
  59. }