public abstract class Shape extends Object
Modifier and Type | Field and Description |
---|---|
protected double |
height
The height of the bounding box.
|
protected Point2D |
position
The position of the center point of the bounding box.
|
protected double |
width
The width of the bounding box.
|
Modifier | Constructor and Description |
---|---|
protected |
Shape()
Constructs a shape having a bounding box of width
and height equal to zero, and center position (0, 0)
|
protected |
Shape(double w,
double h,
Point2D p)
Constructs a shape having a bounding box with width
w ,
height h , and center position p . |
Modifier and Type | Method and Description |
---|---|
double |
getArea()
Get the area of the shape.
|
double |
getHeight()
Get the height of the bounding box for the shape.
|
Point2D |
getPosition()
Get the position of the center of the bounding box for the shape.
|
double |
getWidth()
Get the width of the bounding box for the shape.
|
protected double width
protected double height
protected Point2D position
protected Shape()
protected Shape(double w, double h, Point2D p)
w
,
height h
, and center position p
.IllegalArgumentException
- if w < 0
IllegalArgumentException
- if h < 0
w
- the width of the shape's bounding boxh
- the height of the shape's bounding boxp
- the position of the center of the bounding boxpublic final Point2D getPosition()
public final double getWidth()
public final double getHeight()
public double getArea()
Shape
provides a default
implementation that returns the area of the shape's bounding
box. Subclasses should override this method to provide the
area of the actual shape.