BsRect2I.h 2.2 KB

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