Created
May 7, 2015 05:21
-
-
Save SwipeX/0eaaae4b78b1c88c27b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Tim Dekker | |
* @since 5/7/15 | |
*/ | |
public class Rectangle { | |
int x1; | |
int y1; | |
int x2; | |
int y2; | |
public Rectangle(int x1, int y1, int x2, int y2) { | |
this.x1 = x1; | |
this.y1 = y1; | |
this.x2 = x2; | |
this.y2 = y2; | |
} | |
public Rectangle(String s, String s1, String s2, String s3) { | |
this(Integer.parseInt(s), Integer.parseInt(s1), Integer.parseInt(s2), Integer.parseInt(s3)); | |
} | |
public int getX1() { | |
return x1; | |
} | |
public int getY1() { | |
return y1; | |
} | |
public int getX2() { | |
return x2; | |
} | |
public int getY2() { | |
return y2; | |
} | |
public int getWidth() { | |
return x1 - x2; | |
} | |
public int getHeight() { | |
return y1 - y2; | |
} | |
public boolean contains(Rectangle rectangle) { | |
return (x1 <= rectangle.x1 && y1 <= rectangle.y1) && | |
(x2 >= rectangle.x2 && y2 >= rectangle.y2); | |
} | |
public String toString() { | |
return String.format("(%s,%s,%s,%s)", x1, y1, x2, y2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment