forked from phu004/JavaRTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRect.java
More file actions
58 lines (46 loc) · 1.01 KB
/
Copy pathRect.java
File metadata and controls
58 lines (46 loc) · 1.01 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
package core;
import entity.solidObject;
//this clase define a rectangle in Cartesian coordinate
public class Rect {
public int x1,x2,y1,y2,width,height;
public solidObject owner;
public Rect(int x1, int y1, int width, int height){
this.x1 = x1;
this.y1 = y1;
this.width = width;
this.height = height;
x2 = x1 + width - 1;
y2 = y1 - height + 1;
}
public void setOrigin(int x1, int y1){
this.x1 = x1;
this.y1 = y1;
x2 = x1 + width - 1;
y2 = y1 - height + 1;
}
public boolean intersect(Rect r){
return !(x1 > r.x2 || r.x1 > x2 || y2 > r.y1 || r.y2 > y1);
}
public boolean contains(int x, int y){
return x >= x1 && x <=x2 && y <= y1 && y >= y2;
}
public void expand(int r){
x1-=r;
x2+=r;
y1+=r;
y2-=r;
width+=2*r;
height+=2*r;
}
public void shrink(int r){
x1+=r;
x2-=r;
y1-=r;
y2+=r;
width-=2*r;
height-=2*r;
}
public String toString(){
return x1 + " " + y1 + " " + width + " " + height;
}
}