Rect.pkg 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. $#include "Rect.h"
  2. /// Two-dimensional bounding rectangle.
  3. class Rect
  4. {
  5. public:
  6. /// Construct an undefined rect.
  7. Rect();
  8. /// Copy-construct from another rect.
  9. Rect(const Rect& rect);
  10. /// Construct from minimum and maximum vectors.
  11. Rect(const Vector2& min, const Vector2& max);
  12. /// Construct from coordinates.
  13. Rect(float left, float top, float right, float bottom);
  14. /// Construct from a Vector4.
  15. Rect(const Vector4& vector);
  16. /// Test for equality with another rect.
  17. bool operator == (const Rect& rhs) const;
  18. /// Define from another rect.
  19. void Define(const Rect& rect);
  20. /// Define from minimum and maximum vectors.
  21. void Define(const Vector2& min, const Vector2& max);
  22. /// Define from a point.
  23. void Define(const Vector2& point);
  24. /// Merge a point.
  25. void Merge(const Vector2& point);
  26. /// Merge a rect.
  27. void Merge(const Rect& rect);
  28. /// Clear to undefined state.
  29. void Clear();
  30. /// Clip with another rect.
  31. void Clip(const Rect& rect);
  32. /// Return center.
  33. Vector2 Center() const;
  34. /// Return size.
  35. Vector2 Size() const;
  36. /// Return half-size.
  37. Vector2 HalfSize() const;
  38. /// Test for equality with another rect with epsilon.
  39. bool Equals(const Rect& rhs) const;
  40. /// Return as a vector.
  41. Vector4 ToVector4() const;
  42. /// Minimum vector.
  43. Vector2 min_ @ min;
  44. /// Maximum vector.
  45. Vector2 max_ @ max;
  46. /// Rect in the range (-1, -1) - (1, 1)
  47. static const Rect FULL;
  48. /// Rect in the range (0, 0) - (1, 1)
  49. static const Rect POSITIVE;
  50. /// Zero-sized rect.
  51. static const Rect ZERO;
  52. };
  53. /// Two-dimensional bounding rectangle with integer values.
  54. class IntRect
  55. {
  56. public:
  57. /// Construct an undefined rect.
  58. IntRect();
  59. /// Construct from coordinates.
  60. IntRect(int left, int top, int right, int bottom);
  61. /// Test for equality with another rect.
  62. bool operator == (const IntRect& rhs) const;
  63. /// Return size.
  64. IntVector2 Size() const;
  65. /// Return width.
  66. int Width() const;
  67. /// Return height.
  68. int Height() const;
  69. /// Left coordinate.
  70. int left_ @ left;
  71. /// Top coordinate.
  72. int top_ @ top;
  73. /// Right coordinate.
  74. int right_ @ right;
  75. /// Bottom coordinate.
  76. int bottom_ @ bottom;
  77. /// Zero-sized rect.
  78. static const IntRect ZERO;
  79. };