Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Rectangle {
- public int x;
- public int y;
- public int width;
- public int height;
- public Rectangle() {
- }
- public void setBounds(int x, int y, int width, int height) {
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- }
- void grow(int w, int h) {
- this.x -= w;
- this.y -= h;
- this.width += 2 * w;
- this.height += 2 * h;
- }
- boolean intersects(Rectangle bounds) {
- return this.x >= bounds.x && this.x < bounds.x + bounds.width && this.y >= bounds.y && this.y < bounds.y + bounds.height;
- }
- public boolean contains(int x, int y) {
- return x >= this.x && x < this.x + this.width && y >= this.y && y < this.y + this.height;
- }
- public int getCenterX() {
- return (this.x + this.width) / 2;
- }
- public int getCenterY() {
- return (this.y + this.height) / 2;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement