org.jhotdraw.geom
Class Polygon2D
- java.lang.Object
-
- org.jhotdraw.geom.Polygon2D
-
- All Implemented Interfaces:
- java.awt.Shape, java.lang.Cloneable
- Direct Known Subclasses:
- Polygon2D.Double, Polygon2D.Float
public abstract class Polygon2D extends java.lang.Object implements java.awt.Shape, java.lang.CloneablePolygon2D.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classPolygon2D.DoubleTheDoubleclass defines a polygon with coordinates stored in double precision floating point.static classPolygon2D.FloatTheFloatclass defines a polygon with coordinates stored in float precision floating point.
-
Field Summary
Fields Modifier and Type Field and Description intnpointsThe total number of points.
-
Constructor Summary
Constructors Constructor and Description Polygon2D()Creates an empty polygon.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method and Description voidadd(java.awt.geom.Point2D p)abstract voidaddPoint(double x, double y)Appends the specified coordinates to thisPolygon.abstract booleancontains(double x, double y)abstract booleancontains(double x, double y, double w, double h)booleancontains(int x, int y)Determines whether the specified coordinates are inside thisPolygon.booleancontains(java.awt.Point p)Determines whether the specifiedPointis inside thisPolygon.booleancontains(java.awt.geom.Point2D p)booleancontains(java.awt.geom.Rectangle2D r)java.awt.RectanglegetBounds()Gets the bounding box of thisPolygon.abstract java.awt.geom.Rectangle2DgetBounds2D()abstract java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.AffineTransform at)Returns an iterator object that iterates along the boundary of thisPolygonand provides access to the geometry of the outline of thisPolygon.java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.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.abstract booleanintersects(double x, double y, double w, double h)booleanintersects(java.awt.geom.Rectangle2D r)abstract voidinvalidate()Invalidates or flushes any internally-cached data that depends on the vertex coordinates of thisPolygon.voidreset()Resets thisPolygonobject to an empty polygon.abstract voidtranslate(double deltaX, double deltaY)Translates the vertices of thePolygonbydeltaXalong the x axis and bydeltaYalong the y axis.
-
-
-
Field Detail
-
npoints
public int 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.
-
-
Method Detail
-
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:
Polygon.invalidate()
-
invalidate
public abstract 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:
Polygon.getBounds()
-
translate
public abstract void translate(double deltaX, double deltaY)Translates the vertices of thePolygonbydeltaXalong the x axis and bydeltaYalong the y axis.- Parameters:
deltaX- the amount to translate along the X axisdeltaY- the amount to translate along the Y axis
-
addPoint
public abstract 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:
Polygon.getBounds(),Polygon.contains(java.awt.Point)
-
add
public void add(java.awt.geom.Point2D p)
-
getBounds
public java.awt.Rectangle 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.- Specified by:
getBoundsin interfacejava.awt.Shape- Returns:
- a
Rectanglethat defines the bounds of thisPolygon.
-
contains
public boolean contains(java.awt.Point p)
Determines whether the specifiedPointis inside thisPolygon.- Parameters:
p- the specifiedPointto be tested- Returns:
trueif thePolygoncontains thePoint;falseotherwise.- See Also:
contains(double, double)
-
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(double, double)
-
getBounds2D
public abstract java.awt.geom.Rectangle2D getBounds2D()
- Specified by:
getBounds2Din interfacejava.awt.Shape
-
contains
public abstract boolean contains(double x, double y)- Specified by:
containsin interfacejava.awt.Shape
-
contains
public boolean contains(java.awt.geom.Point2D p)
- Specified by:
containsin interfacejava.awt.Shape
-
intersects
public abstract boolean intersects(double x, double y, double w, double h)- Specified by:
intersectsin interfacejava.awt.Shape
-
intersects
public boolean intersects(java.awt.geom.Rectangle2D r)
- Specified by:
intersectsin interfacejava.awt.Shape
-
contains
public abstract boolean contains(double x, double y, double w, double h)- Specified by:
containsin interfacejava.awt.Shape
-
contains
public boolean contains(java.awt.geom.Rectangle2D r)
- Specified by:
containsin interfacejava.awt.Shape
-
getPathIterator
public abstract java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at)
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.- Specified by:
getPathIteratorin interfacejava.awt.Shape- 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.
-
getPathIterator
public java.awt.geom.PathIterator getPathIterator(java.awt.geom.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. 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.- Specified by:
getPathIteratorin interfacejava.awt.Shape- 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.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG