Class Rectangle
 java.lang.Object

 org.eclipse.swt.graphics.Rectangle

public final class Rectangle extends java.lang.Object
Instances of this class represent rectangular areas in an (x, y) coordinate system. The top left corner of the rectangle is specified by its x and y values, and the extent of the rectangle is specified by its width and height.The coordinate space for rectangles and points is considered to have increasing values downward and to the right from its origin making this the normal, computer graphics oriented notion of (x, y) coordinates rather than the strict mathematical one.
The hashCode() method in this class uses the values of the public fields to compute the hash value. When storing instances of the class in hashed collections, do not modify these fields after the object has been inserted.
Application code does not need to explicitly release the resources managed by each instance when those instances are no longer required, and thus no
dispose()
method is provided. Since:
 1.0
 See Also:
Point


Constructor Summary
Constructors Constructor Description Rectangle(int x, int y, int width, int height)
Construct a new instance of this class given the x, y, width and height values.

Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(Rectangle rect)
Destructively replaces the x, y, width and height values in the receiver with ones which represent the union of the rectangles specified by the receiver and the given rectangle.boolean
contains(int x, int y)
Returnstrue
if the point specified by the arguments is inside the area specified by the receiver, andfalse
otherwise.boolean
contains(Point pt)
Returnstrue
if the given point is inside the area specified by the receiver, andfalse
otherwise.boolean
equals(java.lang.Object object)
Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison.int
hashCode()
Returns an integer hash code for the receiver.void
intersect(Rectangle rect)
Destructively replaces the x, y, width and height values in the receiver with ones which represent the intersection of the rectangles specified by the receiver and the given rectangle.Rectangle
intersection(Rectangle rect)
Returns a new rectangle which represents the intersection of the receiver and the given rectangle.boolean
intersects(int x, int y, int width, int height)
Returnstrue
if the rectangle described by the arguments intersects with the receiver andfalse
otherwise.boolean
intersects(Rectangle rect)
Returnstrue
if the given rectangle intersects with the receiver andfalse
otherwise.boolean
isEmpty()
Returnstrue
if the receiver does not cover any area in the (x, y) coordinate plane, andfalse
if the receiver does cover some area in the plane.java.lang.String
toString()
Returns a string containing a concise, humanreadable description of the receiver.Rectangle
union(Rectangle rect)
Returns a new rectangle which represents the union of the receiver and the given rectangle.



Constructor Detail

Rectangle
public Rectangle(int x, int y, int width, int height)
Construct a new instance of this class given the x, y, width and height values. Parameters:
x
 the x coordinate of the origin of the rectangley
 the y coordinate of the origin of the rectanglewidth
 the width of the rectangleheight
 the height of the rectangle


Method Detail

add
public void add(Rectangle rect)
Destructively replaces the x, y, width and height values in the receiver with ones which represent the union of the rectangles specified by the receiver and the given rectangle.The union of two rectangles is the smallest single rectangle that completely covers both of the areas covered by the two given rectangles.
 Parameters:
rect
 the rectangle to merge with the receiver Throws:
java.lang.IllegalArgumentException
 ERROR_NULL_ARGUMENT  if the argument is null

contains
public boolean contains(int x, int y)
Returnstrue
if the point specified by the arguments is inside the area specified by the receiver, andfalse
otherwise. Parameters:
x
 the x coordinate of the point to test for containmenty
 the y coordinate of the point to test for containment Returns:
true
if the rectangle contains the point andfalse
otherwise

contains
public boolean contains(Point pt)
Returnstrue
if the given point is inside the area specified by the receiver, andfalse
otherwise. Parameters:
pt
 the point to test for containment Returns:
true
if the rectangle contains the point andfalse
otherwise Throws:
java.lang.IllegalArgumentException
 ERROR_NULL_ARGUMENT  if the argument is null

equals
public boolean equals(java.lang.Object object)
Compares the argument to the receiver, and returns true if they represent the same object using a class specific comparison. Overrides:
equals
in classjava.lang.Object
 Parameters:
object
 the object to compare with this object Returns:
true
if the object is the same as this object andfalse
otherwise See Also:
hashCode()

hashCode
public int hashCode()
Returns an integer hash code for the receiver. Any two objects that returntrue
when passed toequals
must return the same value for this method. Overrides:
hashCode
in classjava.lang.Object
 Returns:
 the receiver's hash
 See Also:
equals(Object)

intersect
public void intersect(Rectangle rect)
Destructively replaces the x, y, width and height values in the receiver with ones which represent the intersection of the rectangles specified by the receiver and the given rectangle. Parameters:
rect
 the rectangle to intersect with the receiver Throws:
java.lang.IllegalArgumentException
 ERROR_NULL_ARGUMENT  if the argument is null

intersection
public Rectangle intersection(Rectangle rect)
Returns a new rectangle which represents the intersection of the receiver and the given rectangle.The intersection of two rectangles is the rectangle that covers the area which is contained within both rectangles.
 Parameters:
rect
 the rectangle to intersect with the receiver Returns:
 the intersection of the receiver and the argument
 Throws:
java.lang.IllegalArgumentException
 ERROR_NULL_ARGUMENT  if the argument is null

intersects
public boolean intersects(int x, int y, int width, int height)
Returnstrue
if the rectangle described by the arguments intersects with the receiver andfalse
otherwise.Two rectangles intersect if the area of the rectangle representing their intersection is not empty.
 Parameters:
x
 the x coordinate of the origin of the rectangley
 the y coordinate of the origin of the rectanglewidth
 the width of the rectangleheight
 the height of the rectangle Returns:
true
if the rectangle intersects with the receiver, andfalse
otherwise Throws:
java.lang.IllegalArgumentException
 ERROR_NULL_ARGUMENT  if the argument is null
 Since:
 1.0
 See Also:
intersection(Rectangle)
,isEmpty()

intersects
public boolean intersects(Rectangle rect)
Returnstrue
if the given rectangle intersects with the receiver andfalse
otherwise.Two rectangles intersect if the area of the rectangle representing their intersection is not empty.
 Parameters:
rect
 the rectangle to test for intersection Returns:
true
if the rectangle intersects with the receiver, andfalse
otherwise Throws:
java.lang.IllegalArgumentException
 ERROR_NULL_ARGUMENT  if the argument is null
 See Also:
intersection(Rectangle)
,isEmpty()

isEmpty
public boolean isEmpty()
Returnstrue
if the receiver does not cover any area in the (x, y) coordinate plane, andfalse
if the receiver does cover some area in the plane.A rectangle is considered to cover area in the (x, y) coordinate plane if both its width and height are nonzero.
 Returns:
true
if the receiver is empty, andfalse
otherwise

toString
public java.lang.String toString()
Returns a string containing a concise, humanreadable description of the receiver. Overrides:
toString
in classjava.lang.Object
 Returns:
 a string representation of the rectangle

union
public Rectangle union(Rectangle rect)
Returns a new rectangle which represents the union of the receiver and the given rectangle.The union of two rectangles is the smallest single rectangle that completely covers both of the areas covered by the two given rectangles.
 Parameters:
rect
 the rectangle to perform union with Returns:
 the union of the receiver and the argument
 Throws:
java.lang.IllegalArgumentException
 ERROR_NULL_ARGUMENT  if the argument is null
 See Also:
add(Rectangle)

