edu.neu.ccs.gui
Class Rect

java.lang.Object
  |
  +--java.awt.geom.RectangularShape
        |
        +--java.awt.geom.Rectangle2D
              |
              +--java.awt.geom.Rectangle2D.Double
                    |
                    +--edu.neu.ccs.gui.Rect
All Implemented Interfaces:
Cloneable, Shape
Direct Known Subclasses:
Square

public class Rect
extends Rectangle2D.Double

Class Rect extends Rectangle2D.Double in order to provide a much shorter name that does not explicitly refer to an inner class and to add error checking that prevents the width and height from being set to negative values.

Since:
2.4.0

Field Summary
 
Fields inherited from class java.awt.geom.Rectangle2D.Double
height, width, x, y
 
Fields inherited from class java.awt.geom.Rectangle2D
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
 
Constructor Summary
Rect()
          Constructs a new Rect initialized to location (0, 0) and size (0, 0).
Rect(double r, double s)
          Constructs a new Rect initialized to center (0, 0) and with the given radii: r = half-width and s = half-height.
Rect(double x, double y, double w, double h)
          Constructs and initializes a Rect from the specified double coordinates.
Rect(Rectangle2D rect)
          Constructs and initializes a Rect from the specified Rectangle2D object.
 
Method Summary
 Rect createIntersectionRect(Rectangle2D rect)
          Mimics the inherited method createIntersection but makes the return type Rect.
 Rect createUnionRect(Rectangle2D rect)
          Mimics the inherited method createUnion but makes the return type Rect.
 void setFrame(double x, double y, double w, double h)
          Overrides the corresponding inherited method to use the method setXYWH.
 void setFrame(Point2D point, Dimension2D dimension)
          Overrides the corresponding inherited method to use the method setXYWH.
 void setFrame(Rectangle2D rect)
          Overrides the corresponding inherited method to use the method setXYWH.
 void setRect(double x, double y, double w, double h)
          Overrides the corresponding inherited method to use the method setXYWH.
 void setRect(Rectangle2D rect)
          Overrides the corresponding inherited method to use the method setXYWH.
 void setX1Y1X2Y2(double x1, double y1, double x2, double y2)
          Sets the parameters of the Rect with error checking using the coordinates of any pair of opposite corners.
 void setXYRS(double x, double y, double r, double s)
          Sets the parameters of the Rect with error checking using the center (x,y) and the inner radii: r = half-width and s = half-height.
 void setXYWH(double x, double y, double w, double h)
          Sets the parameters of the Rect with error checking.
 String toString()
          Returns a String representation of the data in this Rect.
 
Methods inherited from class java.awt.geom.Rectangle2D.Double
createIntersection, createUnion, getBounds2D, getHeight, getWidth, getX, getY, isEmpty, outcode
 
Methods inherited from class java.awt.geom.Rectangle2D
add, add, add, contains, contains, equals, getPathIterator, getPathIterator, hashCode, intersect, intersects, intersectsLine, intersectsLine, outcode, union
 
Methods inherited from class java.awt.geom.RectangularShape
clone, contains, contains, getBounds, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Rect

public Rect()
Constructs a new Rect initialized to location (0, 0) and size (0, 0).


Rect

public Rect(double x,
            double y,
            double w,
            double h)
Constructs and initializes a Rect from the specified double coordinates. Calls setXYWH.

Parameters:
x - the proposed top-left x-coordinate
y - the proposed top-left y-coordinate
w - the proposed width
h - the proposed height

Rect

public Rect(Rectangle2D rect)

Constructs and initializes a Rect from the specified Rectangle2D object. Calls setXYWH.

Initializes to location (0, 0) and size (0, 0) if the given rect is null.

Parameters:
rect - the Rectangle2D object to copy

Rect

public Rect(double r,
            double s)

Constructs a new Rect initialized to center (0, 0) and with the given radii: r = half-width and s = half-height. Calls setXYRS

Parameters:
r - the proposed x-radius or half-width
s - the proposed y-radius or half-height
Method Detail

setXYWH

public void setXYWH(double x,
                    double y,
                    double w,
                    double h)

Sets the parameters of the Rect with error checking.

If the width w is negative, then w is replaced by its absolute value and then x is replaced by (x - w).

If the height h is negative, then h is replaced by its absolute value and then y is replaced by (y - h).

This method guarantees that the internal width and height are always greater than or equal to zero.

Parameters:
x - the proposed top-left x-coordinate
y - the proposed top-left y-coordinate
w - the proposed width
h - the proposed height

setXYRS

public void setXYRS(double x,
                    double y,
                    double r,
                    double s)

Sets the parameters of the Rect with error checking using the center (x,y) and the inner radii: r = half-width and s = half-height.

If the radius r is negative, then r is replaced by its absolute value.

If the radius s is negative, then s is replaced by its absolute value.

This method guarantees that the internal width and height are always greater than or equal to zero.

Parameters:
x - the proposed center x-coordinate
y - the proposed center y-coordinate
r - the proposed x-radius or half-width
s - the proposed y-radius or half-height

setX1Y1X2Y2

public void setX1Y1X2Y2(double x1,
                        double y1,
                        double x2,
                        double y2)

Sets the parameters of the Rect with error checking using the coordinates of any pair of opposite corners.

Parameters:
x1 - the x-coordinate of one corner
y1 - the y-coordinate of one corner
x2 - the x-coordinate of the opposite corner
y2 - the y-coordinate of the opposite corner

setFrame

public void setFrame(double x,
                     double y,
                     double w,
                     double h)

Overrides the corresponding inherited method to use the method setXYWH.

Overrides:
setFrame in class Rectangle2D
Parameters:
x - the proposed top-left x-coordinate
y - the proposed top-left y-coordinate
w - the proposed width
h - the proposed height

setFrame

public void setFrame(Rectangle2D rect)

Overrides the corresponding inherited method to use the method setXYWH.

Does nothing if the given rect is null.

Overrides:
setFrame in class RectangularShape
Parameters:
rect - the Rectangle2D object to copy

setFrame

public void setFrame(Point2D point,
                     Dimension2D dimension)

Overrides the corresponding inherited method to use the method setXYWH.

Does nothing if the given point or dimension is null.

Overrides:
setFrame in class RectangularShape
Parameters:
point - the top-left corner
dimension - the dimension with the width and height

setRect

public void setRect(double x,
                    double y,
                    double w,
                    double h)

Overrides the corresponding inherited method to use the method setXYWH.

Overrides:
setRect in class Rectangle2D.Double
Parameters:
x - the proposed top-left x-coordinate
y - the proposed top-left y-coordinate
w - the proposed width
h - the proposed height

setRect

public void setRect(Rectangle2D rect)

Overrides the corresponding inherited method to use the method setXYWH.

Does nothing if the given rect is null.

Overrides:
setRect in class Rectangle2D.Double
Parameters:
rect - the Rectangle2D object to copy

createIntersectionRect

public Rect createIntersectionRect(Rectangle2D rect)

Mimics the inherited method createIntersection but makes the return type Rect.

Parameters:
rect - the rectangle to intersect with this rectangle
Returns:
returns the largest rectangle contained within r and this rectangle

createUnionRect

public Rect createUnionRect(Rectangle2D rect)

Mimics the inherited method createUnion but makes the return type Rect.

Parameters:
rect - the rectangle to union with this rectangle
Returns:
returns the smallest rectangle that contains r and this rectangle

toString

public String toString()

Returns a String representation of the data in this Rect.

The format is similar to that used by Java but simpler:

Rect[x=...,y=...,w=...,h=...]

where (x,y) is the top-left corner and (w,h) are the dimensions.

Overrides:
toString in class Rectangle2D.Double