498 |
} |
} |
499 |
|
|
500 |
/** |
/** |
501 |
|
* Return the hashcode for this rectangle. The formula is not documented, but |
502 |
|
* appears to be the same as: |
503 |
|
* <pre> |
504 |
|
* long l = Double.doubleToLongBits(getX()) |
505 |
|
* + 37 * Double.doubleToLongBits(getY()) |
506 |
|
* + 43 * Double.doubleToLongBits(getWidth()) |
507 |
|
* + 47 * Double.doubleToLongBits(getHeight()); |
508 |
|
* return (int) ((l >> 32) ^ l); |
509 |
|
* </pre> |
510 |
|
* |
511 |
|
* @return the hashcode |
512 |
|
*/ |
513 |
|
public int hashCode() |
514 |
|
{ |
515 |
|
// Talk about a fun time reverse engineering this one! |
516 |
|
long l = Double.doubleToLongBits(getX()) |
517 |
|
+ 37 * Double.doubleToLongBits(getY()) |
518 |
|
+ 43 * Double.doubleToLongBits(getWidth()) |
519 |
|
+ 47 * Double.doubleToLongBits(getHeight()); |
520 |
|
return (int) ((l >> 32) ^ l); |
521 |
|
} |
522 |
|
|
523 |
|
/** |
524 |
|
* Tests this rectangle for equality against the specified object. This |
525 |
|
* will be true if an only if the specified object is an instance of |
526 |
|
* Rectangle2D with the same coordinates and dimensions. |
527 |
|
* |
528 |
|
* @param obj the object to test against for equality |
529 |
|
* @return true if the specified object is equal to this one |
530 |
|
*/ |
531 |
|
public boolean equals(Object obj) |
532 |
|
{ |
533 |
|
if (! (obj instanceof Rectangle2D)) |
534 |
|
return false; |
535 |
|
Rectangle2D r = (Rectangle2D) obj; |
536 |
|
return r.getX() == getX() && r.getY() == getY() |
537 |
|
&& r.getWidth() == getWidth() && r.getHeight() == getHeight(); |
538 |
|
} |
539 |
|
|
540 |
|
/** |
541 |
* This class defines a rectangle in <code>double</code> precision. |
* This class defines a rectangle in <code>double</code> precision. |
542 |
* |
* |
543 |
* @author Eric Blake <ebb9@email.byu.edu> |
* @author Eric Blake <ebb9@email.byu.edu> |