-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRect.java
More file actions
49 lines (42 loc) · 1.45 KB
/
Copy pathRect.java
File metadata and controls
49 lines (42 loc) · 1.45 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
public class Rect {
public final int x1;
public final int y1;
public final int x2;
public final int y2;
public final int height;
public final int width;
public int id; // assignable with no consequence?
public boolean[] pointerTrail; // not actually a trail
public Rect(int x1, int y1, int x2, int y2) {
if (x2<x1 || y2<y1) throw new UnsupportedOperationException("INVALID RECTANGLE");
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.height = y2 - y1;
this.width = x2 - x1;
}
public Rect(int x1, int y1, int x2, int y2, int id) {
this(x1,y1,x2,y2);
this.id = id;
}
public static Rect place(int x, int y, int width, int height) {
return new Rect(x,y,x+width,y+height);
}
// true if other is on the left
public boolean touchLeft(Rect other) {
return this.x1 == other.x2 && this.y1 < other.y2 && this.y2 > other.y1;
}
// true if other is below
public boolean touchBottom(Rect other) {
return this.y1 == other.y2 && this.x1 < other.x2 && this.x2 > other.x1;
}
public boolean overlaps(Rect other) {
return this.x2 > other.x1 && this.x1 < other.x2 &&
this.y2 > other.y1 && this.y1 < other.y2;
//if (r) System.out.println(this + " | " + other);
}
public String toString() {
return "("+x1+","+y1+","+x2+","+y2+")";
}
}