Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. public class Rectangle {
  2. public int x;
  3. public int y;
  4. public int width;
  5. public int height;
  6.  
  7. public Rectangle() {
  8. }
  9.  
  10. public void setBounds(int x, int y, int width, int height) {
  11. this.x = x;
  12. this.y = y;
  13. this.width = width;
  14. this.height = height;
  15. }
  16.  
  17. void grow(int w, int h) {
  18. this.x -= w;
  19. this.y -= h;
  20. this.width += 2 * w;
  21. this.height += 2 * h;
  22. }
  23.  
  24. boolean intersects(Rectangle bounds) {
  25. return this.x >= bounds.x && this.x < bounds.x + bounds.width && this.y >= bounds.y && this.y < bounds.y + bounds.height;
  26. }
  27.  
  28. public boolean contains(int x, int y) {
  29. return x >= this.x && x < this.x + this.width && y >= this.y && y < this.y + this.height;
  30. }
  31.  
  32. public int getCenterX() {
  33. return (this.x + this.width) / 2;
  34. }
  35.  
  36. public int getCenterY() {
  37. return (this.y + this.height) / 2;
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement