public class Polygon extends Object
Constructor and Description |
---|
Polygon()
Initializes this polygon to be empty, that is, it contains
no points at all.
|
Polygon(String line)
Initializes this polygon to consist of the line segments defined
by the points specified by the given string.
|
Modifier and Type | Method and Description |
---|---|
void |
addPoint(int x,
int y)
Appends the point with the given x- and y-coordinate to this polygon.
|
boolean |
contains(int x,
int y)
Tests if the point with the given x- and y-coordinate is
contained in this polygon.
|
boolean |
intersects(int x,
int y,
int width,
int height)
Tests if the given rectangle is contained in this polygon.
|
void |
translate(int deltaX,
int deltaY)
Translates the points of the polygon by the given deltaX along
the x-axis and by the given deltaY along the y-axis.
|
public Polygon()
public Polygon(String line)
0 0 2 2 4 0
line
- string describing the points that define this polygon.public void addPoint(int x, int y)
x
- the x-coordinate of the point to be added.y
- the y-coordinate of the point to be added.public boolean contains(int x, int y)
x
- the x-coordinate of the point to be tested.y
- the y-coordinate of the point to be tested.public boolean intersects(int x, int y, int width, int height)
x
- the x-coordinate of the upper-left corner of the rectangle.y
- the y-coordinate of the upper-left corner of the rectangle.width
- the width of the rectangle.height
- the height of the rectangle.public void translate(int deltaX, int deltaY)
deltaX
- the amount to translate along the x-axisdeltaY
- the amount to translate along the y-axis