acm.graphics
Class GRectangle

java.lang.Object
  extended by acm.graphics.GRectangle

public class GRectangle
extends Object
implements Serializable

This class is a double-precision version of the Rectangle class in java.awt.


Constructor Summary
GRectangle()
Constructs a new empty GRectangle.
GRectangle(double width, double height)
Constructs a GRectangle at the origin with the specified width and height.
GRectangle(double x, double y, double width, double height)
Constructs a new GRectangle with the specified coordinates and size.
GRectangle(GDimension size)
Constructs a new GRectangle at the origin with the specified size.
GRectangle(GPoint pt)
Constructs a new empty GRectangle at the specified location.
GRectangle(GPoint pt, GDimension size)
Constructs a new GRectangle with the specified location and size.
GRectangle(GRectangle r)
Constructs a new GRectangle from an existing one.
 
Method Summary
 void add(double x, double y)
Adds the specified point to the rectangle.
 void add(GRectangle r)
Adjusts the bounds of the current GRectangle so that it contains the rectangle represented by the argument.
 boolean contains(double x, double y)
Returns true if the GRectangle contains the specified point.
 boolean contains(GPoint pt)
Returns true if the GRectangle contains the specified point.
 GRectangle getBounds()
Returns a new GRectangle whose bounds are the same as this one.
 double getHeight()
Returns the height of this GDimension.
 GPoint getLocation()
Returns a new GPoint with the location of the rectangle.
 GDimension getSize()
Returns a new GDimension object with the size of the GRectangle.
 double getWidth()
Returns the width of this GDimension.
 double getX()
Returns the x coordinate of this GRectangle.
 double getY()
Returns the y coordinate of this GRectangle.
 void grow(double dx, double dy)
Adjusts the edges of a rectangle by the specified dx and dy offsets along each of its borders.
 GRectangle intersection(GRectangle r2)
Returns the largest rectangle that is contained in both r1 and r2.
 boolean intersects(GRectangle r2)
Returns true if r1 and r2 have a nonempty intersection.
 boolean isEmpty()
Returns true if the rectangle is empty.
 void setBounds(double x, double y, double width, double height)
Sets the components of a GRectangle from the specified values.
 void setBounds(GPoint pt, GDimension size)
Sets the components of a GRectangle from the specified location and size.
 void setBounds(GRectangle bounds)
Sets the bounds of one GRectangle equal to that of another.
 void setLocation(double x, double y)
Sets the location of the GRectangle to the specified x and y values.
 void setLocation(GPoint pt)
Sets the location of the GRectangle to the specified point.
 void setSize(double width, double height)
Sets the size of the GRectangle to the specified values.
 void setSize(GDimension size)
Sets the size of the GRectangle to the specified dimension.
 Rectangle toRectangle()
Converts this GRectangle to the nearest integer-based Rectangle.
 void translate(double dx, double dy)
Adjusts the coordinates of a rectangle by the specified dx and dy offsets.
 GRectangle union(GRectangle r2)
Returns the smallest rectangle that contains both r1 and r2.
 

Constructor Detail

public GRectangle()

Constructs a new empty GRectangle.

 
Usage: rect = new GRectangle(); 
 


public GRectangle(double width, double height)

Constructs a GRectangle at the origin with the specified width and height.

 
Usage: rect = new GRectangle(width, height); 
Parameters: 
width  The width of the rectangle
height  The height of the rectangle
 


public GRectangle(double x, double y, double width, double height)

Constructs a new GRectangle with the specified coordinates and size.

 
Usage: rect = new GRectangle(x, y, width, height); 
Parameters: 
 The x-coordinate of the rectangle
 The y-coordinate of the rectangle
width  The width of the rectangle
height  The height of the rectangle
 


public GRectangle(GDimension size)

Constructs a new GRectangle at the origin with the specified size.

 
Usage: rect = new GRectangle(size); 
Parameter: 
size  The dimensions of the rectangle
 


public GRectangle(GPoint pt)

Constructs a new empty GRectangle at the specified location.

 
Usage: rect = new GRectangle(pt); 
Parameter: 
pt  The location of the upper left corner of the rectangle
 


public GRectangle(GPoint pt, GDimension size)

Constructs a new GRectangle with the specified location and size.

 
Usage: rect = new GRectangle(pt, size); 
Parameters: 
pt  The location of the upper left corner of the rectangle
size  The dimensions of the rectangle
 


public GRectangle(GRectangle r)

Constructs a new GRectangle from an existing one.

 
Usage: rect = new GRectangle(r); 
Parameter: 
 The original rectangle
 

Method Detail

public void add(double x, double y)

Adds the specified point to the rectangle.

 
Usage: rect.add(x, y); 
Parameters: 
 The x coordinate of the new point
 The y coordinate of the new point
 


public void add(GRectangle r)

Adjusts the bounds of the current GRectangle so that it contains the rectangle represented by the argument.

 
Usage: rect.add(r); 
Parameter: 
 A new rectangle to include in this one
 


public boolean contains(double x, double y)

Returns true if the GRectangle contains the specified point.

 
Usage: if (rect.contains(x, y)) . . . 
Parameters: 
 The x-coordinate of the point being tested
 The y-coordinate of the point being tested
Returns: true if the rectangle contains (xy), and false otherwise
 


public boolean contains(GPoint pt)

Returns true if the GRectangle contains the specified point.

 
Usage: if (rect.contains(pt)) . . . 
Parameter: 
pt  The point being tested
Returns: true if the rectangle contains pt, and false otherwise
 


public GRectangle getBounds()

Returns a new GRectangle whose bounds are the same as this one.

 
Usage: r = rect.getBounds(); 
Returns: A new rectangle with the same bounds
 


public double getHeight()

Returns the height of this GDimension.

 
Usage: height = rect.getHeight(); 
Returns: The height of this GDimension
 


public GPoint getLocation()

Returns a new GPoint with the location of the rectangle.

 
Usage: pt = rect.getLocation(); 
Returns: The location of the rectangle as a GPoint
 


public GDimension getSize()

Returns a new GDimension object with the size of the GRectangle.

 
Usage: size = rect.getSize(); 
Returns: The size of the rectangle as a GDimension
 


public double getWidth()

Returns the width of this GDimension.

 
Usage: width = rect.getWidth(); 
Returns: The width of this GDimension
 


public double getX()

Returns the x coordinate of this GRectangle.

 
Usage: x = rect.getX(); 
Returns: The x coordinate of this GRectangle
 


public double getY()

Returns the y coordinate of this GRectangle.

 
Usage: y = rect.getY(); 
Returns: The y coordinate of this GRectangle
 


public void grow(double dx, double dy)

Adjusts the edges of a rectangle by the specified dx and dy offsets along each of its borders.

 
Usage: rect.grow(dx, dy); 
Parameters: 
dx  The offset to extend each of the left and right borders
dy  The offset to extend each of the top and bottom borders
 


public GRectangle intersection(GRectangle r2)

Returns the largest rectangle that is contained in both r1 and r2.

 
Usage: r3 = r1.intersection(r2); 
Parameter: 
r2  A second rectangle
Returns: The intersection of this rectangle and r2
 


public boolean intersects(GRectangle r2)

Returns true if r1 and r2 have a nonempty intersection.

 
Usage: if (r1.intersects(r2)) . . . 
Parameter: 
r2  A second rectangle
Returns: true if the two rectangles intersect, and false otherwise
 


public boolean isEmpty()

Returns true if the rectangle is empty.

 
Usage: if (rect.isEmpty()) . . . 
Returns: true if the rectangle is empty, and false otherwise
 


public void setBounds(double x, double y, double width, double height)

Sets the components of a GRectangle from the specified values.

 
Usage: rect.setBounds(x, y, width, height); 
Parameters: 
 The x-coordinate of the rectangle
 The y-coordinate of the rectangle
width  The width of the rectangle
height  The height of the rectangle
 


public void setBounds(GPoint pt, GDimension size)

Sets the components of a GRectangle from the specified location and size.

 
Usage: rect.setBounds(pt, size); 
Parameters: 
pt  The location of the upper left corner of the rectangle
size  The dimensions of the rectangle
 


public void setBounds(GRectangle bounds)

Sets the bounds of one GRectangle equal to that of another.

 
Usage: rect.setBounds(bounds); 
Parameter: 
bounds  A GRectangle specifying the new bounds
 


public void setLocation(double x, double y)

Sets the location of the GRectangle to the specified x and y values.

 
Usage: rect.setLocation(x, y); 
Parameters: 
 The new x-coordinate for the rectangle
 The new y-coordinate for the rectangle
 


public void setLocation(GPoint pt)

Sets the location of the GRectangle to the specified point.

 
Usage: rect.setLocation(pt); 
Parameter: 
pt  The new location for the rectangle
 


public void setSize(double width, double height)

Sets the size of the GRectangle to the specified values.

 
Usage: rect.setSize(width, height); 
Parameters: 
width  The new width of the rectangle
height  The new height of the rectangle
 


public void setSize(GDimension size)

Sets the size of the GRectangle to the specified dimension.

 
Usage: rect.setSize(size); 
Parameter: 
size  The new dimensions of the rectangle
 


public Rectangle toRectangle()

Converts this GRectangle to the nearest integer-based Rectangle.

 
Usage: size = dim.toRectangle(); 
Returns: The closest integer-based Rectangle
 


public void translate(double dx, double dy)

Adjusts the coordinates of a rectangle by the specified dx and dy offsets.

 
Usage: rect.translate(dx, dy); 
Parameters: 
dx  The change in the x direction (positive is rightward)
dy  The change in the y direction (positive is downward)
 


public GRectangle union(GRectangle r2)

Returns the smallest rectangle that contains both r1 and r2.

 
Usage: r3 = r1.union(r2); 
Parameter: 
r2  A second rectangle
Returns: The union of this rectangle and r2