45 lines
855 B
Java
Raw Normal View History

2015-05-08 20:35:47 +03:00
package com.iluwatar;
2015-05-09 19:26:35 +03:00
/**
*
* Rectangle has coordinates and can be checked for overlap against
* other Rectangles.
*
*/
2015-05-08 20:35:47 +03:00
public class Rectangle {
private int left;
private int top;
private int right;
private int bottom;
public Rectangle(int left, int top, int right, int bottom) {
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
public int getLeft() {
return left;
}
public int getTop() {
return top;
}
public int getRight() {
return right;
}
public int getBottom() {
return bottom;
}
boolean intersectsWith(Rectangle r) {
return !(r.getLeft() > getRight() || r.getRight() < getLeft() || r.getTop() > getBottom() || r.getBottom() < getTop());
}
2015-05-08 21:01:06 +03:00
@Override
public String toString() {
return String.format("[%d,%d,%d,%d]", getLeft(), getTop(), getRight(), getBottom());
}
2015-05-08 20:35:47 +03:00
}