Package ro.sync.exml.view.graphics
Class Polygon
- java.lang.Object
-
- ro.sync.exml.view.graphics.BaseShape
-
- ro.sync.exml.view.graphics.Polygon
-
- All Implemented Interfaces:
Shape
,ro.sync.exml.view.graphics.ShapePointContributor
@API(type=EXTENDABLE, src=PRIVATE) public class Polygon extends BaseShape implements ro.sync.exml.view.graphics.ShapePointContributor
ThePolygon
class encapsulates a description of a closed, two-dimensional region within a coordinate space.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPoint(int x, int y)
Appends the specified coordinates to thisPolygon
.boolean
contains(int x, int y)
Check if this complicated shape contains the requested point.Rectangle
getBounds()
Shape
translate(int tx, int ty)
Translate the shape into another one.
-
-
-
Field Detail
-
npoints
public int npoints
The total number of points. The value ofnpoints
represents the number of valid points in thisPolygon
and might be less than the number of elements inxpoints
orypoints
. This value can be NULL.- See Also:
addPoint(int, int)
-
xpoints
public int[] xpoints
The array of x coordinates. The number of elements in this array might be more than the number of x coordinates in thisPolygon
. The extra elements allow new points to be added to thisPolygon
without re-creating this array. The value ofnpoints
is equal to the number of valid points in thisPolygon
.- See Also:
addPoint(int, int)
-
ypoints
public int[] ypoints
The array of y coordinates. The number of elements in this array might be more than the number of y coordinates in thisPolygon
. The extra elements allow new points to be added to thisPolygon
without re-creating this array. The value ofnpoints
is equal to the number of valid points in thisPolygon
.- See Also:
addPoint(int, int)
-
-
Constructor Detail
-
Polygon
public Polygon()
Creates an empty polygon.
-
Polygon
public Polygon(int[] xpoints, int[] ypoints, int npoints)
Constructs and initializes aPolygon
from the specified parameters.- Parameters:
xpoints
- an array of x coordinatesypoints
- an array of y coordinatesnpoints
- the total number of points in thePolygon
- Throws:
java.lang.NegativeArraySizeException
- if the value ofnpoints
is negative.java.lang.IndexOutOfBoundsException
- ifnpoints
is greater than the length ofxpoints
or the length ofypoints
.java.lang.NullPointerException
- ifxpoints
orypoints
isnull
.
-
-
Method Detail
-
addPoint
public void addPoint(int x, int y)
Appends the specified coordinates to thisPolygon
.If an operation that calculates the bounding box of this
Polygon
has already been performed, such asgetBounds
orcontains
, then this method updates the bounding box.- Specified by:
addPoint
in interfacero.sync.exml.view.graphics.ShapePointContributor
- Parameters:
x
- the specified x coordinatey
- the specified y coordinate- See Also:
Polygon.getBounds()
-
getBounds
public Rectangle getBounds()
- Specified by:
getBounds
in interfaceShape
- Returns:
- The bounds of this shape.
- See Also:
Shape.getBounds()
-
translate
public Shape translate(int tx, int ty)
Description copied from interface:Shape
Translate the shape into another one.- Specified by:
translate
in interfaceShape
- Parameters:
tx
- the distance by which coordinates are translated in the X axis directionty
- the distance by which coordinates are translated in the Y axis direction- Returns:
- The newly translated shape
- See Also:
Shape.translate(int, int)
-
-