fork download
  1. #ifndef FURROVINEBOUNDINGRECTANGLE_H
  2. #define FURROVINEBOUNDINGRECTANGLE_H
  3.  
  4. #include <Furrovine++/Vector2.h>
  5.  
  6. namespace Furrovine {
  7.  
  8. struct BoundingRectangle {
  9. public:
  10. Vector2 Min;
  11. Vector2 Max;
  12.  
  13. BoundingRectangle () : Min(0), Max(1) {
  14. }
  15.  
  16. BoundingRectangle (float X, float Y = 0, float width = 1, float height = 1) : Min(X, Y), Max(X + width, Y + height) {
  17. }
  18.  
  19. BoundingRectangle (const Vector2& min, const Vector2& max) : Min(min), Max(max) {
  20. }
  21.  
  22. BoundingRectangle (const Vector2& location, const Size2<float>& size) : Min(location.x, location.y), Max(location.x + size.Width, location.y + size.Height) {
  23. }
  24.  
  25. BoundingRectangle (const BoundingRectangle& obj) : Min(obj.Min), Max(obj.Max) {
  26. }
  27.  
  28. float Bottom () {
  29. return Max.y;
  30. }
  31.  
  32. float Right () {
  33. return Max.x;
  34. }
  35.  
  36. float CenterX () {
  37. return Min.x + ((Max.x - Min.x) * 0.5f);
  38. }
  39.  
  40. float CenterY () {
  41. return Min.y + ((Max.y - Min.y) * 0.5f);
  42. }
  43.  
  44. float Width () {
  45. return Max.x - Min.x;
  46. }
  47.  
  48. float Height () {
  49. return Max.y - Min.y;
  50. }
  51.  
  52. float Width () const {
  53. return Max.x - Min.x;
  54. }
  55.  
  56. float Height () const {
  57. return Max.y - Min.y;
  58. }
  59.  
  60. Vector2 Center () {
  61. return Vector2(Min.x + ((Max.x - Min.x) * 0.5f), Min.y + ((Max.y - Min.y) * 0.5f));
  62. }
  63.  
  64. Vector2 Location () {
  65. return Min;
  66. }
  67.  
  68. void Location (const float& X, const float& Y) {
  69. float diffx = Min.x - X;
  70. float diffy = Min.y - Y;
  71. Min.x = X;
  72. Min.y = Y;
  73. Max.x += diffx;
  74. Max.y += diffy;
  75. }
  76.  
  77. void Location (const Vector2& p) {
  78. float diffx = Min.x - p.x;
  79. float diffy = Min.y - p.y;
  80. Min.x = p.x;
  81. Min.y = p.y;
  82. Max.x += diffx;
  83. Max.y += diffy;
  84. }
  85.  
  86. void Size (const float& width, const float& height) {
  87. Max.x = Min.x + Mathema<float>::Abs(width);
  88. Max.y = Min.y + Mathema<float>::Abs(height);
  89. }
  90.  
  91. Size2f Size () {
  92. return Size2f(Width(), Height());
  93. }
  94.  
  95. float WidthOverHeight () {
  96. return Width() / Height();
  97. }
  98.  
  99. float HeightOverWidth () {
  100. return Height() / Width();
  101. }
  102.  
  103. BoundingRectangle Shift (const float& X, const float& Y) {
  104. BoundingRectangle rect(Min.x + X, Min.y + Y, Width(), Height());
  105. return rect;
  106. }
  107.  
  108. BoundingRectangle Scale (const float& xscale, const float& yscale) {
  109. BoundingRectangle rect(Min.x, Min.y, Width() * xscale, Height() * yscale);
  110. return rect;
  111. }
  112.  
  113. bool Contains (const Vector2& p) {
  114. return p.x > Min.x && p.y > Min.y && p.x < Max.x && p.y < Max.y;
  115. }
  116.  
  117. bool Contains (const float& X, const float& Y) {
  118. return X > Min.x && Y > Min.y && X < Max.x && Y < Max.y;
  119. }
  120. };
  121. }
  122. #endif // FURROVINEBOUNDINGRECTANGLE_H
  123.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty