Package edu.cnu.mdi.graphics.world
Class WorldPolygon
java.lang.Object
edu.cnu.mdi.graphics.world.WorldPolygon
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Rectangle2D.DoubleThe bounds of thisPolygon.intThe total number of points.double[]The array of X coordinates.double[]The array of Y coordinates. -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty polygon.WorldPolygon(double[] xpoints, double[] ypoints, int npoints) Constructs and initializes aPolygonfrom the specified parameters.WorldPolygon(Point2D.Double w1, Point2D.Double w2, Point2D.Double w3, Point2D.Double w4) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPoint(double x, double y) Appends the specified coordinates to thisPolygon.booleancontains(double x, double y) Determines whether the specified coordinates are inside thisPolygon.booleancontains(int x, int y) Determines whether the specified coordinates are inside thisPolygon.booleanDetermines whether the specifiedPoint2Dis inside thisPolygon.Returns the bounds of thisPolygon.Gets the bounding box of thisPolygon.voidInvalidates or flushes any internally-cached data that depends on the vertex coordinates of thisPolygon.voidreset()Resets thisPolygonobject to an empty polygon.
-
Field Details
-
npoints
public int npoints -
xpoints
public double[] xpointsThe 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. -
ypoints
public double[] ypointsThe 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. -
bounds
The bounds of thisPolygon. This value can be null.
-
-
Constructor Details
-
WorldPolygon
public WorldPolygon()Creates an empty polygon. -
WorldPolygon
public WorldPolygon(double[] xpoints, double[] ypoints, int npoints) 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.
-
WorldPolygon
-
-
Method Details
-
reset
public void 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.- See Also:
-
invalidate
public void 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.- See Also:
-
addPoint
public void addPoint(double x, double y) 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- See Also:
-
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.
-
contains
public boolean contains(int x, int y) 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.- See Also:
-
contains
public boolean contains(double x, double y) 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.
-
getBoundingBox
Returns the bounds of thisPolygon.- Returns:
- the bounds of this
Polygon.
-
contains
Determines whether the specifiedPoint2Dis inside thisPolygon.- Parameters:
p- the specifiedPoint2Dto be tested- Returns:
trueif thisPolygoncontains the specifiedPoint2D;falseotherwise.- See Also:
-