JHotDraw 7.5.1

org.jhotdraw.geom
Class Polygon2D.Double

java.lang.Object
  extended by org.jhotdraw.geom.Polygon2D
      extended by org.jhotdraw.geom.Polygon2D.Double
All Implemented Interfaces:
java.awt.Shape, java.io.Serializable, java.lang.Cloneable
Enclosing class:
Polygon2D

public static class Polygon2D.Double
extends Polygon2D
implements java.io.Serializable

The Double class defines a polygon with coordinates stored in double precision floating point.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jhotdraw.geom.Polygon2D
Polygon2D.Double, Polygon2D.Float
 
Field Summary
protected  java.awt.geom.Rectangle2D.Double bounds
          The bounds of this Polygon.
 double[] xpoints
          The array of X coordinates.
 double[] ypoints
          The array of Y coordinates.
 
Fields inherited from class org.jhotdraw.geom.Polygon2D
npoints
 
Constructor Summary
Polygon2D.Double()
           
Polygon2D.Double(double[] xpoints, double[] ypoints, int npoints)
          Constructs and initializes a Polygon from the specified parameters.
 
Method Summary
 void addPoint(double x, double y)
          Appends the specified coordinates to this Polygon.
 boolean contains(double x, double y)
          
 boolean contains(double x, double y, double w, double h)
          
 java.awt.Rectangle getBounds()
          Gets the bounding box of this Polygon.
 java.awt.geom.Rectangle2D getBounds2D()
          
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at)
          Returns an iterator object that iterates along the boundary of this Polygon and provides access to the geometry of the outline of this Polygon.
 boolean intersects(double x, double y, double w, double h)
          
 void invalidate()
          Invalidates or flushes any internally-cached data that depends on the vertex coordinates of this Polygon.
 void translate(double deltaX, double deltaY)
          Translates the vertices of the Polygon by deltaX along the x axis and by deltaY along the y axis.
 
Methods inherited from class org.jhotdraw.geom.Polygon2D
add, contains, contains, contains, contains, getPathIterator, intersects, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xpoints

public double[] xpoints
The array of X coordinates. The number of elements in this array might be more than the number of X coordinates in this Polygon. The extra elements allow new points to be added to this Polygon without re-creating this array. The value of npoints is equal to the number of valid points in this Polygon.


ypoints

public double[] ypoints
The array of Y coordinates. The number of elements in this array might be more than the number of Y coordinates in this Polygon. The extra elements allow new points to be added to this Polygon without re-creating this array. The value of npoints is equal to the number of valid points in this Polygon.


bounds

protected java.awt.geom.Rectangle2D.Double bounds
The bounds of this Polygon. This value can be null.

Constructor Detail

Polygon2D.Double

public Polygon2D.Double()

Polygon2D.Double

public Polygon2D.Double(double[] xpoints,
                        double[] ypoints,
                        int npoints)
Constructs and initializes a Polygon from the specified parameters.

Parameters:
xpoints - an array of X coordinates
ypoints - an array of Y coordinates
npoints - the total number of points in the Polygon
Throws:
java.lang.NegativeArraySizeException - if the value of npoints is negative.
java.lang.IndexOutOfBoundsException - if npoints is greater than the length of xpoints or the length of ypoints.
java.lang.NullPointerException - if xpoints or ypoints is null.
Method Detail

translate

public void translate(double deltaX,
                      double deltaY)
Translates the vertices of the Polygon by deltaX along the x axis and by deltaY along the y axis.

Specified by:
translate in class Polygon2D
Parameters:
deltaX - the amount to translate along the X axis
deltaY - the amount to translate along the Y axis

invalidate

public void invalidate()
Description copied from class: Polygon2D
Invalidates or flushes any internally-cached data that depends on the vertex coordinates of this Polygon. This method should be called after any direct manipulation of the coordinates in the xpoints or ypoints arrays to avoid inconsistent results from methods such as getBounds or contains that might cache data from earlier computations relating to the vertex coordinates.

Specified by:
invalidate in class Polygon2D
See Also:
Polygon.getBounds()

contains

public boolean contains(double x,
                        double y)
Description copied from class: Polygon2D

Specified by:
contains in interface java.awt.Shape
Specified by:
contains in class Polygon2D

intersects

public boolean intersects(double x,
                          double y,
                          double w,
                          double h)
Description copied from class: Polygon2D

Specified by:
intersects in interface java.awt.Shape
Specified by:
intersects in class Polygon2D

addPoint

public void addPoint(double x,
                     double y)
Description copied from class: Polygon2D
Appends the specified coordinates to this Polygon.

If an operation that calculates the bounding box of this Polygon has already been performed, such as getBounds or contains, then this method updates the bounding box.

Specified by:
addPoint in class Polygon2D
Parameters:
x - the specified X coordinate
y - the specified Y coordinate
See Also:
Polygon.getBounds(), Polygon.contains(java.awt.Point)

getBounds

public java.awt.Rectangle getBounds()
Description copied from class: Polygon2D
Gets the bounding box of this Polygon. The bounding box is the smallest Rectangle whose sides are parallel to the x and y axes of the coordinate space, and can completely contain the Polygon.

Specified by:
getBounds in interface java.awt.Shape
Overrides:
getBounds in class Polygon2D
Returns:
a Rectangle that defines the bounds of this Polygon.

getBounds2D

public java.awt.geom.Rectangle2D getBounds2D()
Description copied from class: Polygon2D

Specified by:
getBounds2D in interface java.awt.Shape
Specified by:
getBounds2D in class Polygon2D

contains

public boolean contains(double x,
                        double y,
                        double w,
                        double h)
Description copied from class: Polygon2D

Specified by:
contains in interface java.awt.Shape
Specified by:
contains in class Polygon2D

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at)
Description copied from class: Polygon2D
Returns an iterator object that iterates along the boundary of this Polygon and provides access to the geometry of the outline of this Polygon. An optional AffineTransform can be specified so that the coordinates returned in the iteration are transformed accordingly.

Specified by:
getPathIterator in interface java.awt.Shape
Specified by:
getPathIterator in class Polygon2D
Parameters:
at - an optional AffineTransform to be applied to the coordinates as they are returned in the iteration, or null if untransformed coordinates are desired
Returns:
a PathIterator object that provides access to the geometry of this Polygon.

Copyright 1996-2010 (c) by the authors and contributors of the JHotDraw project.
Some rights reserved.