public final class Rectangle extends Object implements org.eclipse.swt.internal.SerializableCompatibility
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.
Modifier and Type  Field and Description 

int 
height
the height of the rectangle

int 
width
the width of the rectangle

int 
x
the x coordinate of the rectangle

int 
y
the y coordinate of the rectangle

Constructor and 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.

Modifier and Type  Method and 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)
Returns
true if the point specified by the
arguments is inside the area specified by the receiver,
and false otherwise. 
boolean 
contains(Point pt)
Returns
true if the given point is inside the
area specified by the receiver, and false
otherwise. 
boolean 
equals(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)
Returns
true if the rectangle described by the
arguments intersects with the receiver and false
otherwise. 
boolean 
intersects(Rectangle rect)
Returns
true if the given rectangle intersects
with the receiver and false otherwise. 
boolean 
isEmpty()
Returns
true if the receiver does not cover any
area in the (x, y) coordinate plane, and false if
the receiver does cover some area in the plane. 
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.

public int x
public int y
public int width
public int height
public Rectangle(int x, int y, int width, int height)
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 rectanglepublic void add(Rectangle rect)
The union of two rectangles is the smallest single rectangle that completely covers both of the areas covered by the two given rectangles.
rect
 the rectangle to merge with the receiverIllegalArgumentException
 public boolean contains(int x, int y)
true
if the point specified by the
arguments is inside the area specified by the receiver,
and false
otherwise.x
 the x coordinate of the point to test for containmenty
 the y coordinate of the point to test for containmenttrue
if the rectangle contains the point and false
otherwisepublic boolean contains(Point pt)
true
if the given point is inside the
area specified by the receiver, and false
otherwise.pt
 the point to test for containmenttrue
if the rectangle contains the point and false
otherwiseIllegalArgumentException
 public boolean equals(Object object)
equals
in class Object
object
 the object to compare with this objecttrue
if the object is the same as this object and false
otherwisehashCode()
public int hashCode()
true
when passed to
equals
must return the same value for this
method.hashCode
in class Object
equals(Object)
public void intersect(Rectangle rect)
rect
 the rectangle to intersect with the receiverIllegalArgumentException
 public Rectangle intersection(Rectangle rect)
The intersection of two rectangles is the rectangle that covers the area which is contained within both rectangles.
rect
 the rectangle to intersect with the receiverIllegalArgumentException
 public boolean intersects(int x, int y, int width, int height)
true
if the rectangle described by the
arguments intersects with the receiver and false
otherwise.
Two rectangles intersect if the area of the rectangle representing their intersection is not empty.
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 rectangletrue
if the rectangle intersects with the receiver, and false
otherwiseIllegalArgumentException
 intersection(Rectangle)
,
isEmpty()
public boolean intersects(Rectangle rect)
true
if the given rectangle intersects
with the receiver and false
otherwise.
Two rectangles intersect if the area of the rectangle representing their intersection is not empty.
rect
 the rectangle to test for intersectiontrue
if the rectangle intersects with the receiver, and false
otherwiseIllegalArgumentException
 intersection(Rectangle)
,
isEmpty()
public boolean isEmpty()
true
if the receiver does not cover any
area in the (x, y) coordinate plane, and false
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.
true
if the receiver is empty, and false
otherwisepublic String toString()
public Rectangle union(Rectangle rect)
The union of two rectangles is the smallest single rectangle that completely covers both of the areas covered by the two given rectangles.
rect
 the rectangle to perform union withIllegalArgumentException
 add(Rectangle)
Copyright (c) 2000, 2013 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.