@@ -73,6 +73,7 @@ public Rectangle(Rectangle rect) {
73
73
74
74
/**
75
75
* Calculates the common rectangle which includes all the input rectangles.
76
+ *
76
77
* @param rectangles list of input rectangles.
77
78
* @return common rectangle.
78
79
*/
@@ -98,6 +99,19 @@ public static Rectangle getCommonRectangle(Rectangle... rectangles) {
98
99
return new Rectangle (llx , lly , urx -llx , ury -lly );
99
100
}
100
101
102
+ /**
103
+ * Sets the rectangle by the coordinates, specifying its lower left and upper right points. May be used in chain.
104
+ * <br/>
105
+ * <br/>
106
+ * Note: this method will normalize coordinates, so the rectangle will have non negative width and height,
107
+ * and its x and y coordinates specified lower left point.
108
+ *
109
+ * @param llx the X coordinate of lower left point
110
+ * @param lly the Y coordinate of lower left point
111
+ * @param urx the X coordinate of upper right point
112
+ * @param ury the Y coordinate of upper right point
113
+ * @return this {@link Rectangle} instance.
114
+ */
101
115
public Rectangle setBbox (float llx , float lly , float urx , float ury ) {
102
116
// If llx is greater than urx, swap them (normalize)
103
117
if (llx > urx ) {
@@ -118,75 +132,139 @@ public Rectangle setBbox(float llx, float lly, float urx, float ury) {
118
132
return this ;
119
133
}
120
134
135
+ /**
136
+ * Gets the X coordinate of lower left point.
137
+ *
138
+ * @return the X coordinate of lower left point.
139
+ */
121
140
public float getX () {
122
141
return x ;
123
142
}
124
143
144
+ /**
145
+ * Sets the X coordinate of lower left point. May be used in chain.
146
+ *
147
+ * @param x the X coordinate of lower left point to be set.
148
+ * @return this {@link Rectangle} instance.
149
+ */
125
150
public Rectangle setX (float x ) {
126
151
this .x = x ;
127
152
return this ;
128
153
}
129
154
155
+ /**
156
+ * Gets the Y coordinate of lower left point.
157
+ *
158
+ * @return the Y coordinate of lower left point.
159
+ */
130
160
public float getY () {
131
161
return y ;
132
162
}
133
163
164
+ /**
165
+ * Sets the Y coordinate of lower left point. May be used in chain.
166
+ *
167
+ * @param y the Y coordinate of lower left point to be set.
168
+ * @return this {@link Rectangle} instance.
169
+ */
134
170
public Rectangle setY (float y ) {
135
171
this .y = y ;
136
172
return this ;
137
173
}
138
174
175
+ /**
176
+ * Gets the width of rectangle.
177
+ *
178
+ * @return the width of rectangle.
179
+ */
139
180
public float getWidth () {
140
181
return width ;
141
182
}
142
183
184
+ /**
185
+ * Sets the width of rectangle. May be used in chain.
186
+ *
187
+ * @param width the the width of rectangle to be set.
188
+ * @return this {@link Rectangle} instance.
189
+ */
143
190
public Rectangle setWidth (float width ) {
144
191
this .width = width ;
145
192
return this ;
146
193
}
147
194
195
+ /**
196
+ * Gets the height of rectangle.
197
+ *
198
+ * @return the height of rectangle.
199
+ */
148
200
public float getHeight () {
149
201
return height ;
150
202
}
151
203
204
+ /**
205
+ * Sets the height of rectangle. May be used in chain.
206
+ *
207
+ * @param height the the width of rectangle to be set.
208
+ * @return this {@link Rectangle} instance.
209
+ */
152
210
public Rectangle setHeight (float height ) {
153
211
this .height = height ;
154
212
return this ;
155
213
}
156
214
215
+ /**
216
+ * Increases the height of rectangle by the given value. May be used in chain.
217
+ *
218
+ * @param extra the value of the extra height to be added.
219
+ * @return this {@link Rectangle} instance.
220
+ */
157
221
public Rectangle increaseHeight (float extra ) {
158
222
this .height += extra ;
159
223
return this ;
160
224
}
161
225
226
+ /**
227
+ * Decreases the height of rectangle by the given value. May be used in chain.
228
+ *
229
+ * @param extra the value of the extra height to be subtracted.
230
+ * @return this {@link Rectangle} instance.
231
+ */
162
232
public Rectangle decreaseHeight (float extra ) {
163
233
this .height -= extra ;
164
234
return this ;
165
235
}
166
236
167
237
/**
168
- * Gets llx, the same: {@code getX()}.
238
+ * Gets the X coordinate of the left edge of the rectangle. Same as: {@code getX()}.
239
+ *
240
+ * @return the X coordinate of the left edge of the rectangle.
169
241
*/
170
242
public float getLeft () {
171
243
return x ;
172
244
}
173
245
174
246
/**
175
- * Gets urx, the same to {@code getX() + getWidth()}.
247
+ * Gets the X coordinate of the right edge of the rectangle. Same as: {@code getX() + getWidth()}.
248
+ *
249
+ * @return the X coordinate of the right edge of the rectangle.
176
250
*/
177
251
public float getRight () {
178
252
return x + width ;
179
253
}
180
254
181
255
/**
182
- * Gets ury, the same to {@code getY() + getHeight()}.
256
+ * Gets the Y coordinate of the upper edge of the rectangle. Same as: {@code getY() + getHeight()}.
257
+ *
258
+ * @return the Y coordinate of the upper edge of the rectangle.
183
259
*/
184
260
public float getTop () {
185
261
return y + height ;
186
262
}
187
263
188
264
/**
189
- * Gets lly, the same to {@code getY()}.
265
+ * Gets the Y coordinate of the lower edge of the rectangle. Same as: {@code getY()}.
266
+ *
267
+ * @return the Y coordinate of the lower edge of the rectangle.
190
268
*/
191
269
public float getBottom () {
192
270
return y ;
@@ -239,6 +317,11 @@ public String toString() {
239
317
getHeight ();
240
318
}
241
319
320
+ /**
321
+ * Gets the copy of this rectangle.
322
+ *
323
+ * @return the copied rectangle.
324
+ */
242
325
public Rectangle clone () {
243
326
return new Rectangle (x , y , width , height );
244
327
}
0 commit comments