public interface GeometricalForm extends java.lang.Comparable<GeometricalForm>
Furthermore the forms may be compared. First the areas of the forms are compared and if the areas are equal then the the perimeters are compared. The area and the perimeter of a Point are 0. The area of a Line is 0 and its perimeter is the length of the line.
The forms may be moved, but may not be modyfied in any other way. Only positive x och y coordinates are allowed for the position. Negative values for the coordinates gives an IllegalPositionException, which is declared in this package.
Finally, the forms may be compared for equality, where all components except the positions of the forms are compared.
Modifier and Type | Method and Description |
---|---|
int |
compareTo(GeometricalForm f)
The method compareTo compares the area and perimeter of the forms
to decide if the given geometrical form is less or greater
than this object.
|
void |
fill(java.awt.Graphics g)
Fill the area of the form at the position of the form
with the color of the form.
|
int |
getArea()
Get the area of this form rounded
to closest integer.
|
java.awt.Color |
getColor()
Get the colour of this form.
|
int |
getHeight()
Get the height of the surrounding rectangle of this form.
|
int |
getPerimeter()
Get the perimeter of this form rounded
to closest integer.
|
int |
getWidth()
Get the width of the surrounding rectangle of this form.
|
int |
getX()
Get the x coordinate of the position of this form.
|
int |
getY()
Get the y coordinate of the position of this form.
|
void |
move(int dx,
int dy)
Move the form the given distances.
|
void |
place(int x,
int y)
Place the form on given coordinates.
|
int getArea()
int compareTo(GeometricalForm f)
compareTo
in interface java.lang.Comparable<GeometricalForm>
f
- The geometrical form to compare with.void fill(java.awt.Graphics g)
g
- A graphic pen to draw with.java.awt.Color getColor()
int getWidth()
int getHeight()
int getX()
int getY()
void move(int dx, int dy) throws IllegalPositionException
dx
- move the form dx points to the right.dy
- move the form dy points down.IllegalPositionException
- if any coordinate becomes negative.int getPerimeter()
void place(int x, int y) throws IllegalPositionException
x
- Distance right from origo.y
- Distance down from origo.IllegalPositionException
- if any coordinate is negative.IllegalPositionException