Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2003, 2005 IBM Corporation and others. |
2 |
* Copyright (c) 2003, 2007 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 244-247
Link Here
|
244 |
height = (int)Math.floor(preciseHeight + preciseY + 0.000000001) - y; |
244 |
height = (int)Math.floor(preciseHeight + preciseY + 0.000000001) - y; |
245 |
} |
245 |
} |
246 |
|
246 |
|
|
|
247 |
/** |
248 |
* Updates this Rectangle's bounds to the minimum size which can hold both this |
249 |
* Rectangle and the coordinate (x,y). |
250 |
* |
251 |
* @return <code>this</code> for convenience |
252 |
* @param x1 X coordinate |
253 |
* @param y1 Y coordinate |
254 |
* @since 3.3 |
255 |
*/ |
256 |
public PrecisionRectangle union(double x1, double y1) { |
257 |
if (x1 < preciseX) { |
258 |
preciseWidth += (preciseX - x1); |
259 |
preciseX = x1; |
260 |
} else { |
261 |
double right = preciseX + preciseWidth; |
262 |
if (x1 >= right) { |
263 |
preciseWidth = x1 - preciseX; |
264 |
} |
265 |
} |
266 |
if (y1 < preciseY) { |
267 |
preciseHeight += (preciseY - y1); |
268 |
preciseY = y1; |
269 |
} else { |
270 |
double bottom = preciseY + preciseHeight; |
271 |
if (y1 >= bottom) { |
272 |
bottom = y1 + 1; |
273 |
preciseHeight = y1 - preciseY; |
274 |
} |
275 |
} |
276 |
updateInts(); |
277 |
return this; |
278 |
} |
279 |
|
280 |
/** |
281 |
* @see org.eclipse.draw2d.geometry.Rectangle#transpose() |
282 |
*/ |
283 |
public Rectangle transpose() { |
284 |
double temp = preciseX; |
285 |
preciseX = preciseY; |
286 |
preciseY = temp; |
287 |
temp = preciseWidth; |
288 |
preciseWidth = preciseHeight; |
289 |
preciseHeight = temp; |
290 |
super.transpose(); |
291 |
return this; |
292 |
} |
293 |
|
294 |
/** |
295 |
* @see org.eclipse.draw2d.geometry.Rectangle#setLocation(org.eclipse.draw2d.geometry.Point) |
296 |
*/ |
297 |
public Rectangle setLocation(Point loc) { |
298 |
if (loc instanceof PrecisionPoint) { |
299 |
PrecisionPoint preciseLoc = (PrecisionPoint) loc; |
300 |
this.preciseX = preciseLoc.preciseX; |
301 |
this.preciseY = preciseLoc.preciseY; |
302 |
updateInts(); |
303 |
return this; |
304 |
} else { |
305 |
return super.setLocation(loc); |
306 |
} |
307 |
} |
308 |
|
309 |
/** |
310 |
* Returns the precise geometric centre of the rectangle |
311 |
* |
312 |
* @return <code>PrecisionPoint</code> geometric center of the rectangle |
313 |
* @since 3.3 |
314 |
*/ |
315 |
public PrecisionPoint getPreciseCenter() { |
316 |
return new PrecisionPoint(preciseX + preciseWidth / 2.0, preciseY + preciseHeight / 2.0); |
317 |
} |
318 |
|
319 |
/** |
320 |
* Shrinks the sides of this Rectangle by the horizontal and vertical values |
321 |
* provided as input, and returns this Rectangle for convenience. The center of |
322 |
* this Rectangle is kept constant. |
323 |
* |
324 |
* @param h Horizontal reduction amount |
325 |
* @param v Vertical reduction amount |
326 |
* @return <code>this</code> for convenience |
327 |
* @since 3.3 |
328 |
*/ |
329 |
public Rectangle shrink(double h, double v) { |
330 |
preciseX += h; |
331 |
preciseWidth -= (h + h); |
332 |
preciseY += v; |
333 |
preciseHeight -= (v + v); |
334 |
updateInts(); |
335 |
return this; |
336 |
} |
337 |
|
338 |
/** |
339 |
* Expands the horizontal and vertical sides of this Rectangle with the values |
340 |
* provided as input, and returns this for convenience. The location of its |
341 |
* center is kept constant. |
342 |
* |
343 |
* @param h Horizontal increment |
344 |
* @param v Vertical increment |
345 |
* @return <code>this</code> for convenience |
346 |
* @since 3.3 |
347 |
*/ |
348 |
public Rectangle expand(double h, double v) { |
349 |
return shrink(-h, -v); |
350 |
} |
351 |
|
352 |
public Rectangle shrink(int h, int v) { |
353 |
return shrink((double)h, (double)v); |
354 |
} |
355 |
|
356 |
/** |
357 |
* Determines whether an (x,y) coordinates is contained within the rectangle |
358 |
* |
359 |
* @param x x coordinate |
360 |
* @param y y coordinate |
361 |
* @return <code>true</code> if coordinate (x,y) is contained within the rectangle |
362 |
* @since 3.3 |
363 |
*/ |
364 |
public boolean contains(double x, double y) { |
365 |
return preciseX <= x && x <= preciseX + preciseWidth |
366 |
&& preciseY <= y && y <= preciseY + preciseHeight; |
367 |
} |
368 |
|
369 |
/** |
370 |
* @see org.eclipse.draw2d.geometry.Rectangle#contains(org.eclipse.draw2d.geometry.Point) |
371 |
*/ |
372 |
public boolean contains(Point p) { |
373 |
if (p instanceof PrecisionPoint) { |
374 |
PrecisionPoint pt = (PrecisionPoint)p; |
375 |
return contains(pt.preciseX, pt.preciseY); |
376 |
} |
377 |
return super.contains(p); |
378 |
} |
379 |
|
247 |
} |
380 |
} |