Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Square {
- private int x;
- private int y;
- private int width;
- public boolean isInSquare(int x, int y) {
- int left = this.x;
- int right = this.x + width;
- int top = this.y;
- int bottom = this.y + width;
- return x >= left && x <= right &&
- y >= top && y <= bottom;
- }
- public boolean tryExpand(int x, int y, int maxSize) {
- int newWidth = Math.abs(x - this.x);
- int newHeight = Math.abs(y - this.y);
- int newSize = Math.max(newWidth, newHeight);
- if (newSize > maxSize) {
- return false;
- }
- this.width = newSize;
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement