Advertisement
Guest User

Untitled

a guest
Dec 12th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1. public class Square {
  2.  
  3.     private int x;
  4.  
  5.     private int y;
  6.  
  7.     private int width;
  8.  
  9.     public boolean isInSquare(int x, int y) {
  10.         int left = this.x;
  11.         int right = this.x + width;
  12.         int top = this.y;
  13.         int bottom = this.y + width;
  14.  
  15.         return x >= left && x <= right &&
  16.                 y >= top && y <= bottom;
  17.     }
  18.  
  19.     public boolean tryExpand(int x, int y, int maxSize) {
  20.         int newWidth = Math.abs(x - this.x);
  21.         int newHeight = Math.abs(y - this.y);
  22.         int newSize = Math.max(newWidth, newHeight);
  23.         if (newSize > maxSize) {
  24.             return false;
  25.         }
  26.         this.width = newSize;
  27.         return true;
  28.     }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement