-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle.java
More file actions
86 lines (80 loc) · 1.88 KB
/
Copy pathRectangle.java
File metadata and controls
86 lines (80 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package Packing;
import java.awt.Point;
public class Rectangle implements Comparable<Rectangle>{
private int width;
private int height;
private int area;
private Point[] point = new Point[4];
public Rectangle(){
for (int i = 0; i < point.length; i++) {
point[i] = new Point();
}
}
public Rectangle(int width, int height){
this.width = width;
this.height = height;
area = width*height;
for (int i = 0; i < point.length; i++) {
point[i] = new Point();
}
}
public int getWidth(){
return width;
}
public int getHeight(){
return height;
}
public int getArea(){
return area;
}
public void setWidth(int width){
this.width = width;
setArea(this.width, this.height);
}
public void setHeight(int height){
this.height = height;
setArea(this.width, this.height);
}
public void setArea(int width, int height){
area = width * height;
}
public void rotate(){
int temp = width;
width = height;
height = temp;
}
public void randomRotate(){
int rNum = (int)(2*Math.random());
if(rNum == 1) rotate();
}
public Rectangle getRotRect(){
int height = this.width;
int width = this.height;
return new Rectangle(width, height);
}
public void setLeftBottomPoint(int x, int y){
point[0].setLocation(x, y);
point[1].setLocation(x, y+height);
point[2].setLocation(x+width, y+height);
point[3].setLocation(x+width, y);
}
public Point getLeftBottomPoint(){
return point[0].getLocation();
}
public Point getLeftTopPoint(){
return point[1].getLocation();
}
public Point getRightTopPoint(){
return point[2].getLocation();
}
public Point getRightBottomPoint(){
return point[3].getLocation();
}
@Override
public int compareTo(Rectangle o) {
if (this.area == o.area) return 0;
if (this.area > o.area) return 1;
if (this.area < o.area) return -1;
return 0;
}
}