BsRect2.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #include "BsPrerequisitesUtil.h"
  3. namespace BansheeEngine
  4. {
  5. /**
  6. * @brief Represents a 2D rectangle using real values.
  7. * Rectangle is represented with an origin in top left and width/height.
  8. */
  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. /**
  16. * @brief Returns true if the rectangle contains the provided point.
  17. */
  18. bool contains(const Vector2& 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 Rect2& other) const;
  25. /**
  26. * @brief Extends this rectangle so that the provided rectangle is
  27. * completely contained within it.
  28. */
  29. void encapsulate(const Rect2& other);
  30. /**
  31. * @brief Clips current rectangle so that it does not overlap
  32. * the provided rectangle.
  33. */
  34. void clip(const Rect2& clipRect);
  35. /**
  36. * @brief Transforms the bounds by the given matrix.
  37. * Resulting value is an axis aligned rectangle encompassing the transformed points.
  38. *
  39. * @note Since the resulting value is an AA rectangle of the original transformed rectangle, the bounds
  40. * will be larger than needed. Oriented rectangle would provide a much tighter fit.
  41. */
  42. void transform(const Matrix4& matrix);
  43. inline bool operator== (const Rect2& rhs) const
  44. {
  45. return x == rhs.x && y == rhs.y && width == rhs.width && height == rhs.height;
  46. }
  47. inline bool operator!= (const Rect2& rhs) const
  48. {
  49. return !(*this == rhs);
  50. }
  51. static const Rect2 EMPTY;
  52. };
  53. BS_ALLOW_MEMCPY_SERIALIZATION(Rect2);
  54. }