Package armyc2.c2sd.graphics2d
Class Polygon
java.lang.Object
armyc2.c2sd.graphics2d.Polygon
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPoint(int x, int y) Appends the specified coordinates to thisPolygon.booleancontains(double x, double y) booleancontains(double x, double y, double w, double h) booleancontains(int x, int y) Determines whether the specified coordinates are inside thisPolygon.booleanDetermines whether the specifiedPointis inside thisPolygon.booleanbooleanDeprecated.Gets the bounding box of thisPolygon.Returns an iterator object that iterates along the boundary of thisPolygonand provides access to the geometry of the outline of thisPolygon.getPathIterator(AffineTransform at, double flatness) Returns an iterator object that iterates along the boundary of theShapeand provides access to the geometry of the outline of theShape.booleaninside(int x, int y) Deprecated.As of JDK version 1.1, replaced bycontains(int, int).booleanintersects(double x, double y, double w, double h) booleanvoidInvalidates or flushes any internally-cached data that depends on the vertex coordinates of thisPolygon.voidreset()Resets thisPolygonobject to an empty polygon.
-
Field Details
-
npoints
The total number of points. The value ofnpointsrepresents the number of valid points in thisPolygonand might be less than the number of elements inxpointsorypoints. This value can be NULL.- Since:
- 1.0
- See Also:
-
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 thisPolygonwithout re-creating this array. The value ofnpointsis equal to the number of valid points in thisPolygon.- Since:
- 1.0
- See Also:
-
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 thisPolygonwithout re-creating this array. The value ofnpointsis equal to the number of valid points in thisPolygon.- Since:
- 1.0
- See Also:
-
bounds
The bounds of thisPolygon. This value can be null.- Since:
- 1.0
- See Also:
-
-
Constructor Details
-
Polygon
public Polygon()Creates an empty polygon.- Since:
- 1.0
-
Polygon
Constructs and initializes aPolygonfrom the specified parameters.- Parameters:
xpoints- an array of X coordinatesypoints- an array of Y coordinatesnpoints- the total number of points in thePolygon- Throws:
NegativeArraySizeException- if the value ofnpointsis negative.IndexOutOfBoundsException- ifnpointsis greater than the length ofxpointsor the length ofypoints.NullPointerException- ifxpointsorypointsisnull.- Since:
- 1.0
-
-
Method Details
-
reset
Resets thisPolygonobject to an empty polygon. The coordinate arrays and the data in them are left untouched but the number of points is reset to zero to mark the old vertex data as invalid and to start accumulating new vertex data at the beginning. All internally-cached data relating to the old vertices are discarded. Note that since the coordinate arrays from before the reset are reused, creating a new emptyPolygonmight be more memory efficient than resetting the current one if the number of vertices in the new polygon data is significantly smaller than the number of vertices in the data from before the reset.- Since:
- 1.4
-
invalidate
Invalidates or flushes any internally-cached data that depends on the vertex coordinates of thisPolygon. This method should be called after any direct manipulation of the coordinates in thexpointsorypointsarrays to avoid inconsistent results from methods such asgetBoundsorcontainsthat might cache data from earlier computations relating to the vertex coordinates.- Since:
- 1.4
-
addPoint
Appends the specified coordinates to thisPolygon.If an operation that calculates the bounding box of this
Polygonhas already been performed, such asgetBoundsorcontains, then this method updates the bounding box.- Parameters:
x- the specified X coordinatey- the specified Y coordinate- Since:
- 1.0
-
getBounds
Gets the bounding box of thisPolygon. The bounding box is the smallestRectanglewhose sides are parallel to the x and y axes of the coordinate space, and can completely contain thePolygon.- Returns:
- a
Rectanglethat defines the bounds of thisPolygon. - Since:
- 1.1
-
getBoundingBox
Deprecated.As of JDK version 1.1, replaced bygetBounds().Returns the bounds of thisPolygon.- Returns:
- the bounds of this
Polygon. - Since:
- 1.0
-
contains
Determines whether the specifiedPointis inside thisPolygon.- Parameters:
p- the specifiedPointto be tested- Returns:
trueif thePolygoncontains thePoint;falseotherwise.- Since:
- 1.0
- See Also:
-
contains
Determines whether the specified coordinates are inside thisPolygon.- Parameters:
x- the specified X coordinate to be testedy- the specified Y coordinate to be tested- Returns:
trueif thisPolygoncontains the specified coordinates(x,y);falseotherwise.- Since:
- 1.1
- See Also:
-
inside
Deprecated.As of JDK version 1.1, replaced bycontains(int, int).Determines whether the specified coordinates are contained in thisPolygon.- Parameters:
x- the specified X coordinate to be testedy- the specified Y coordinate to be tested- Returns:
trueif thisPolygoncontains the specified coordinates(x,y);falseotherwise.- Since:
- 1.0
- See Also:
-
getBounds2D
- Since:
- 1.2
-
contains
- Since:
- 1.2
-
contains
- Since:
- 1.2
-
intersects
- Since:
- 1.2
-
intersects
- Since:
- 1.2
-
contains
- Since:
- 1.2
-
contains
- Since:
- 1.2
-
getPathIterator
Returns an iterator object that iterates along the boundary of thisPolygonand provides access to the geometry of the outline of thisPolygon. An optionalAffineTransformcan be specified so that the coordinates returned in the iteration are transformed accordingly.- Parameters:
at- an optionalAffineTransformto be applied to the coordinates as they are returned in the iteration, ornullif untransformed coordinates are desired- Returns:
- a
PathIteratorobject that provides access to the geometry of thisPolygon. - Since:
- 1.2
-
getPathIterator
Returns an iterator object that iterates along the boundary of theShapeand provides access to the geometry of the outline of theShape. Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE point types are returned by the iterator. Since polygons are already flat, theflatnessparameter is ignored. An optionalAffineTransformcan be specified in which case the coordinates returned in the iteration are transformed accordingly.- Parameters:
at- an optionalAffineTransformto be applied to the coordinates as they are returned in the iteration, ornullif untransformed coordinates are desiredflatness- the maximum amount that the control points for a given curve can vary from colinear before a subdivided curve is replaced by a straight line connecting the endpoints. Since polygons are already flat theflatnessparameter is ignored.- Returns:
- a
PathIteratorobject that provides access to theShapeobject's geometry. - Since:
- 1.2
-
getBounds().