Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Rect {
- private double left, top, right, bottom;
- private static final double DEFAULT_SIZE = 0.5;
- public Rect() {
- left = -DEFAULT_SIZE;
- top = DEFAULT_SIZE;
- right = DEFAULT_SIZE;
- bottom = -DEFAULT_SIZE;
- }
- public Rect(double left, double top, double right, double bottom) {
- this.left = left;
- this.top = top;
- this.right = right;
- this.bottom = bottom;
- }
- public void translateRect(double vx, double vy) {
- left += vx;
- top += vy;
- right += vx;
- bottom += vy;
- }
- public void rotateRect90graus() {
- double halfWidth = this.getWidth() / 2;
- double halfHeight = this.getHeight() / 2;
- double cx = this.getXCenter();
- double cy = this.getYCenter();
- left = cx - halfHeight;
- top = cy + halfWidth;
- right = cx + halfHeight;
- bottom = cy - halfWidth;
- }
- /*
- * public void rotateRect90graus() { left = this.getXCenter() -
- * (this.getHeight()/2); top = this.getYCenter() + (this.getWidth()/2);
- * right = this.getXCenter() + (this.getHeight()/2); bottom =
- * this.getYCenter() - (this.getWidth()/2); }
- */
- public double getLeft() {
- return left;
- }
- public double getRight() {
- return right;
- }
- public double getTop() {
- return top;
- }
- public double getBottom() {
- return bottom;
- }
- public double getHeight() {
- return top - bottom;
- }
- public double getWidth() {
- return right - left;
- }
- public double getPerimeter() {
- double width = getWidth();
- double height = getHeight();
- return (2 * width) + (2 * height);
- }
- public double getArea() {
- return this.getWidth() * this.getHeight();
- }
- public double getXCenter() {
- return left + (this.getWidth() / 2);
- }
- public double getYCenter() {
- return bottom + (this.getHeight() / 2);
- }
- public boolean ptInRect(double x, double y) {
- return x >= left && x <= right && y <= top && y >= bottom;
- }
- public boolean rectInRect(Rect b) {
- return b.getLeft() >= left && b.getRight() <= right && b.getTop() <= top && b.getBottom() >= bottom;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement