Advertisement
Guest User

code for rect class

a guest
Apr 19th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include "stdio.h"
  2.  
  3. class Rect {
  4. /// Member variable top left (x1, y1) and bottom-right (x2, y2) points
  5. float x1, y1, x2, y2;
  6. public:
  7. /// Constructors
  8. Rect();
  9. Rect(float x1, float y1, float x2, float y2);
  10.  
  11. float getX1() const; /// Get x1
  12. float getY1() const; /// Get y1
  13. float getX2() const; /// Get x2
  14. float getY2() const; /// Get x2
  15.  
  16. void setX1(float val); /// Set x1
  17. void setY1(float val); /// Set y1
  18. void setX2(float val); /// Set x2
  19. void setY2(float val); /// Set y2
  20.  
  21. float width() const; /// Get width
  22. float height() const; /// Get height
  23. float area() const; /// Get area
  24. float aspect() const; /// Get aspect ratio: height / width
  25.  
  26. /// Check whether the rectangle overlaps with the other rectangle
  27. bool overlaps(const Rect &other) const;
  28.  
  29. /// Expand current rectangle to include the point (x, y).
  30. void include(float x, float y);
  31.  
  32. /// Expand current rectangle to include the the other rectangle.
  33. void include(const Rect &other);
  34.  
  35. /// Check if the current rectangle includes the point (x, y)
  36. bool includes(float x,float y);
  37.  
  38. /// Check if the current rectangle includes the other rectangle
  39. bool includes(const Rect &other);
  40.  
  41. /// Expand the dimensions of current rectangle by the specified values
  42. void dilate(float dx0, float dy0, float dx1, float dy1);
  43.  
  44. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement