-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathRectD.java
More file actions
124 lines (98 loc) · 2.32 KB
/
RectD.java
File metadata and controls
124 lines (98 loc) · 2.32 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
117
118
119
120
121
122
123
124
package clipper2.core;
import java.util.Arrays;
public final class RectD {
public double left;
public double top;
public double right;
public double bottom;
private static final String InvalidRect = "Invalid RectD assignment";
public RectD() {
}
public RectD(double l, double t, double r, double b) {
if (r < l || b < t) {
throw new IllegalArgumentException(InvalidRect);
}
left = l;
top = t;
right = r;
bottom = b;
}
public RectD(RectD rec) {
left = rec.left;
top = rec.top;
right = rec.right;
bottom = rec.bottom;
}
public RectD(boolean isValid) {
if (isValid) {
left = 0;
top = 0;
right = 0;
bottom = 0;
} else {
left = Double.MAX_VALUE;
top = Double.MAX_VALUE;
right = -Double.MAX_VALUE;
bottom = -Double.MAX_VALUE;
}
}
public double getWidth() {
return right - left;
}
public void setWidth(double value) {
right = left + value;
}
public double getHeight() {
return bottom - top;
}
public void setHeight(double value) {
bottom = top + value;
}
public boolean IsEmpty() {
return bottom <= top || right <= left;
}
public boolean isEmpty() {
return IsEmpty();
}
public PointD MidPoint() {
return new PointD((left + right) / 2, (top + bottom) / 2);
}
public PointD midPoint() {
return MidPoint();
}
public boolean Contains(PointD pt) {
return pt.x > left && pt.x < right && pt.y > top && pt.y < bottom;
}
public boolean contains(PointD pt) {
return Contains(pt);
}
public boolean Contains(RectD rec) {
return rec.left >= left && rec.right <= right && rec.top >= top && rec.bottom <= bottom;
}
public boolean contains(RectD rec) {
return Contains(rec);
}
public boolean Intersects(RectD rec) {
return (Math.max(left, rec.left) < Math.min(right, rec.right)) && (Math.max(top, rec.top) < Math.min(bottom, rec.bottom));
}
public boolean intersects(RectD rec) {
return Intersects(rec);
}
public PathD AsPath() {
PathD result = new PathD(
Arrays.asList(new PointD(left, top), new PointD(right, top), new PointD(right, bottom), new PointD(left, bottom)));
return result;
}
public PathD asPath() {
return AsPath();
}
@Override
public RectD clone() {
RectD varCopy = new RectD();
varCopy.left = this.left;
varCopy.top = this.top;
varCopy.right = this.right;
varCopy.bottom = this.bottom;
return varCopy;
}
}