edu.neu.ccs.gui
Class Square

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

public class Square
extends Rect

Class Square extends Rect but requires that its location be specifed by its center and its size be specified by the radius of the inscribed circle. The side of the square is twice this radius and is the value returned by either getWidth or getHeight.

The design of this class makes it similar to the class Circle.

Inherited methods that would permit the caller to make the width and height have different values are overridden to do nothing.

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
Square()
          Constructs a new Square initialized to center (0, 0) and radius 0.
Square(double r)
          Constructs a new Square initialized to center (0, 0) and with the given inner radius: r = half-width.
Square(double x, double y, double r)
          Constructs and initializes a Square from the specified double coordinates.
Square(Square square)
          Constructs and initializes a Square from the specified Square object.
 
Method Summary
 double getRadius()
          Returns the radius.
 void setSquare(Square square)
          Uses the data from the given square to set the parameters of this square.
 void setXYR(double x, double y, double r)
          Sets the parameters of the Square with error checking.
 void setXYWH(double x, double y, double w, double h)
          Overrides the inherited method to do nothing since a square cannot have a distinct width and height.
 String toString()
          Returns a String representation of the data in this Square.
 
Methods inherited from class edu.neu.ccs.gui.Rect
createIntersectionRect, createUnionRect, setFrame, setFrame, setFrame, setRect, setRect, setX1Y1X2Y2, setXYRS
 
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

Square

public Square()
Constructs a new Square initialized to center (0, 0) and radius 0.


Square

public Square(double x,
              double y,
              double r)
Constructs and initializes a Square from the specified double coordinates. Calls setXYR.

Parameters:
x - the proposed center x-coordinate
y - the proposed center y-coordinate
r - the proposed inner radius

Square

public Square(double r)

Constructs a new Square initialized to center (0, 0) and with the given inner radius: r = half-width. Calls setXYR

Parameters:
r - the proposed inner radius or half-width

Square

public Square(Square square)

Constructs and initializes a Square from the specified Square object. Calls setXYR indirectly.

Initializes to center (0, 0) and inner radius 0 if the given square is null.

Parameters:
square - the Square object to copy
Method Detail

setXYR

public void setXYR(double x,
                   double y,
                   double r)

Sets the parameters of the Square with error checking.

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

The square is then set up as a rectangle with corner location (x-r, y-r) and common width and height equal to 2*r.

Parameters:
x - the proposed center x-coordinate
y - the proposed center y-coordinate
r - the proposed inner radius

setSquare

public void setSquare(Square square)

Uses the data from the given square to set the parameters of this square.

Does nothing if the given square is null.

Parameters:
square - the Square object to copy

getRadius

public double getRadius()
Returns the radius.


setXYWH

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

Overrides the inherited method to do nothing since a square cannot have a distinct width and height.

The fact that this method does nothing implies that the following methods inherited from Rect and other base classes also do nothing:

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

toString

public String toString()

Returns a String representation of the data in this Square.

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

Square[x=...,y=...,r=...]

where (x,y) is the center and r is the radius.

Overrides:
toString in class Rect