-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathRect64.java
More file actions
116 lines (95 loc) · 2.34 KB
/
Rect64.java
File metadata and controls
116 lines (95 loc) · 2.34 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package clipper2.core;
public final class Rect64 {
public long left;
public long top;
public long right;
public long bottom;
private static final String InvalidRect = "Invalid Rect64 assignment";
public Rect64() {
}
public Rect64(long l, long t, long r, long b) {
if (r < l || b < t) {
throw new IllegalArgumentException(InvalidRect);
}
left = l;
top = t;
right = r;
bottom = b;
}
public Rect64(boolean isValid) {
if (isValid) {
left = 0;
top = 0;
right = 0;
bottom = 0;
} else {
left = Long.MAX_VALUE;
top = Long.MAX_VALUE;
right = Long.MIN_VALUE;
bottom = Long.MIN_VALUE;
}
}
public Rect64(Rect64 rec) {
left = rec.left;
top = rec.top;
right = rec.right;
bottom = rec.bottom;
}
public long getWidth() {
return right - left;
}
public void setWidth(long value) {
right = left + value;
}
public long getHeight() {
return bottom - top;
}
public void setHeight(long value) {
bottom = top + value;
}
public Path64 AsPath() {
Path64 result = new Path64(4);
result.add(new Point64(left, top));
result.add(new Point64(right, top));
result.add(new Point64(right, bottom));
result.add(new Point64(left, bottom));
return result;
}
public boolean IsEmpty() {
return bottom <= top || right <= left;
}
public boolean IsValid() {
return left < Long.MAX_VALUE;
}
public Point64 MidPoint() {
return new Point64((left + right) / 2, (top + bottom) / 2);
}
public boolean Contains(Point64 pt) {
return pt.x > left && pt.x < right && pt.y > top && pt.y < bottom;
}
public boolean Intersects(Rect64 rec) {
return (Math.max(left, rec.left) <= Math.min(right, rec.right)) && (Math.max(top, rec.top) <= Math.min(bottom, rec.bottom));
}
public boolean Contains(Rect64 rec) {
return rec.left >= left && rec.right <= right && rec.top >= top && rec.bottom <= bottom;
}
public static Rect64 opAdd(Rect64 lhs, Rect64 rhs) {
if (!lhs.IsValid()) {
return rhs.clone();
}
if (!rhs.IsValid()) {
return lhs.clone();
}
return new Rect64(Math.min(lhs.left, rhs.left), Math.min(lhs.top, rhs.top), Math.max(lhs.right, rhs.right),
Math.max(lhs.bottom, rhs.bottom));
}
@Override
public Rect64 clone() {
Rect64 varCopy = new Rect64();
varCopy.left = this.left;
varCopy.top = this.top;
varCopy.right = this.right;
varCopy.bottom = this.bottom;
return varCopy;
}
}