Rect.java
8.17 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa.ut;
import com.adobe.xfa.ut.Angle;
import com.adobe.xfa.ut.CoordPair;
import com.adobe.xfa.ut.UnitSpan;
public final class Rect {
public static final Rect ZERO = new Rect();
private final UnitSpan mLeft;
private final UnitSpan mTop;
private final UnitSpan mRight;
private final UnitSpan mBottom;
public Rect() {
this.mLeft = UnitSpan.ZERO;
this.mTop = UnitSpan.ZERO;
this.mRight = UnitSpan.ZERO;
this.mBottom = UnitSpan.ZERO;
}
public Rect(Rect source) {
this(source.mLeft, source.mTop, source.mRight, source.mBottom);
}
public Rect(CoordPair topLeft, CoordPair bottomRight) {
this(topLeft.x(), topLeft.y(), bottomRight.x(), bottomRight.y());
}
public Rect(UnitSpan left, UnitSpan top, UnitSpan right, UnitSpan bottom) {
if (left.lte(right)) {
this.mLeft = left;
this.mRight = right;
} else {
this.mLeft = right;
this.mRight = left;
}
if (top.lte(bottom)) {
this.mTop = top;
this.mBottom = bottom;
} else {
this.mTop = bottom;
this.mBottom = top;
}
}
public UnitSpan left() {
return this.mLeft;
}
public UnitSpan top() {
return this.mTop;
}
public UnitSpan right() {
return this.mRight;
}
public UnitSpan bottom() {
return this.mBottom;
}
public Rect leftRight(UnitSpan newLeft, UnitSpan newRight) {
return new Rect(newLeft, this.mTop, newRight, this.mBottom);
}
public Rect topBottom(UnitSpan newTop, UnitSpan newBottom) {
return new Rect(this.mLeft, newTop, this.mRight, newBottom);
}
public Rect leftWidth(UnitSpan newLeft, UnitSpan newWidth) {
return this.leftRight(newLeft, newLeft.add(newWidth));
}
public Rect rightWidth(UnitSpan newRight, UnitSpan newWidth) {
return this.leftRight(newRight.subtract(newWidth), newRight);
}
public Rect topHeight(UnitSpan newTop, UnitSpan newHeight) {
return this.topBottom(newTop, newTop.add(newHeight));
}
public Rect bottomHeight(UnitSpan newBottom, UnitSpan newHeight) {
return this.topBottom(newBottom.subtract(newHeight), newBottom);
}
public CoordPair topLeft() {
return new CoordPair(this.mLeft, this.mTop);
}
public CoordPair topRight() {
return new CoordPair(this.mRight, this.mTop);
}
public CoordPair bottomLeft() {
return new CoordPair(this.mLeft, this.mBottom);
}
public CoordPair bottomRight() {
return new CoordPair(this.mRight, this.mBottom);
}
public Rect changeUnits(int eNewUnits) {
return new Rect(this.mLeft.changeUnits(eNewUnits), this.mTop.changeUnits(eNewUnits), this.mRight.changeUnits(eNewUnits), this.mBottom.changeUnits(eNewUnits));
}
public Rect topLeft(CoordPair newTopLeft) {
return new Rect(newTopLeft.x(), newTopLeft.y(), this.mRight, this.mBottom);
}
public Rect topRight(CoordPair newTopRight) {
return new Rect(this.mLeft, newTopRight.y(), newTopRight.x(), this.mBottom);
}
public Rect bottomLeft(CoordPair newBottomLeft) {
return new Rect(newBottomLeft.x(), this.mTop, this.mRight, newBottomLeft.y());
}
public Rect bottomRight(CoordPair newBottomRight) {
return new Rect(this.mLeft, this.mTop, newBottomRight.x(), newBottomRight.y());
}
public UnitSpan height() {
return this.mBottom.subtract(this.mTop);
}
public UnitSpan width() {
return this.mRight.subtract(this.mLeft);
}
public Rect height(UnitSpan newHeight, boolean bStretchTop) {
return bStretchTop ? this.bottomHeight(this.mBottom, newHeight) : this.topHeight(this.mTop, newHeight);
}
public Rect width(UnitSpan newWidth, boolean bStretchLeft) {
return bStretchLeft ? this.rightWidth(this.mRight, newWidth) : this.leftWidth(this.mLeft, newWidth);
}
public CoordPair centre() {
return new CoordPair(this.mLeft.add(this.mRight).divide(2), this.mTop.add(this.mBottom).divide(2));
}
public boolean contains(CoordPair point) {
return point.x().gte(this.mLeft) && point.x().lte(this.mRight) && point.y().gte(this.mTop) && point.y().lte(this.mBottom);
}
public boolean contains(Rect rect) {
return this.contains(rect.topLeft()) && this.contains(rect.bottomRight());
}
public boolean overlaps(Rect rect) {
return rect.mRight.gte(this.mLeft) && rect.mLeft.lte(this.mRight) && rect.mBottom.gte(this.mTop) && rect.mTop.lte(this.mBottom);
}
public boolean disjoint(Rect rect) {
return rect.mRight.lte(this.mLeft) || rect.mLeft.gte(this.mRight) || rect.mBottom.lte(this.mTop) || rect.mTop.gte(this.mBottom);
}
public boolean isDegenerate() {
return this.mRight.lte(this.mLeft) || this.mBottom.lte(this.mTop);
}
public Rect rotate(CoordPair point, Angle angle) {
if (angle.degrees() == 0) {
return this;
}
CoordPair rTopLeft = this.topLeft().rotatePoint(point, angle);
CoordPair rTopRight = this.topRight().rotatePoint(point, angle);
CoordPair rBottomLeft = this.bottomLeft().rotatePoint(point, angle);
CoordPair rBottomRight = this.bottomRight().rotatePoint(point, angle);
return new Rect(this.minUnit(rTopLeft.x(), rTopRight.x(), rBottomLeft.x(), rBottomRight.x()), this.minUnit(rTopLeft.y(), rTopRight.y(), rBottomLeft.y(), rBottomRight.y()), this.maxUnit(rTopLeft.x(), rTopRight.x(), rBottomLeft.x(), rBottomRight.x()), this.maxUnit(rTopLeft.y(), rTopRight.y(), rBottomLeft.y(), rBottomRight.y()));
}
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object == null) {
return false;
}
if (object.getClass() != this.getClass()) {
return false;
}
Rect cmp = (Rect)object;
return this.mLeft.equals(cmp.mLeft) && this.mTop.equals(cmp.mTop) && this.mRight.equals(cmp.mRight) && this.mBottom.equals(cmp.mBottom);
}
public int hashCode() {
int hash = 13;
hash = hash * 31 ^ this.mLeft.hashCode();
hash = hash * 31 ^ this.mTop.hashCode();
hash = hash * 31 ^ this.mRight.hashCode();
hash = hash * 31 ^ this.mBottom.hashCode();
return hash;
}
public boolean notEquals(Object compare) {
return !this.equals(compare);
}
public Rect add(CoordPair add) {
return new Rect(this.mLeft.add(add.x()), this.mTop.add(add.y()), this.mRight.add(add.x()), this.mBottom.add(add.y()));
}
public Rect subtract(CoordPair subtract) {
return new Rect(this.mLeft.subtract(subtract.x()), this.mTop.subtract(subtract.y()), this.mRight.subtract(subtract.x()), this.mBottom.subtract(subtract.y()));
}
public Rect union(Rect union) {
return new Rect(this.minUnit(this.mLeft, union.mLeft), this.minUnit(this.mTop, union.mTop), this.maxUnit(this.mRight, union.mRight), this.maxUnit(this.mBottom, union.mBottom));
}
public Rect intersection(Rect intersect) {
UnitSpan left = this.maxUnit(this.mLeft, intersect.mLeft);
UnitSpan top = this.maxUnit(this.mTop, intersect.mTop);
UnitSpan right = this.minUnit(this.mRight, intersect.mRight);
UnitSpan bottom = this.minUnit(this.mBottom, intersect.mBottom);
return left.gt(right) || top.gt(bottom) ? ZERO : new Rect(left, top, right, bottom);
}
public static Rect zero() {
return ZERO;
}
private UnitSpan minUnit(UnitSpan point1, UnitSpan point2) {
return point1.lt(point2) ? point1 : point2;
}
private UnitSpan maxUnit(UnitSpan point1, UnitSpan point2) {
return point1.gt(point2) ? point1 : point2;
}
private UnitSpan minUnit(UnitSpan point1, UnitSpan point2, UnitSpan point3, UnitSpan point4) {
return this.minUnit(this.minUnit(point1, point2), this.minUnit(point3, point4));
}
private UnitSpan maxUnit(UnitSpan point1, UnitSpan point2, UnitSpan point3, UnitSpan point4) {
return this.maxUnit(this.maxUnit(point1, point2), this.maxUnit(point3, point4));
}
}