JHotDraw 7.5.1

org.jhotdraw.geom
Class Polygon2D

java.lang.Object
  extended by 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.Cloneable

Polygon2D.

Version:
$Id: Polygon2D.java 666 2010-07-28 19:11:46Z rawcoder $
Author:
Werner Randelshofer

Nested Class Summary
static class Polygon2D.Double
          The Double class defines a polygon with coordinates stored in double precision floating point.
static class Polygon2D.Float
          The Float class defines a polygon with coordinates stored in float precision floating point.
 
Field Summary
 int npoints
          The total number of points.
 
Constructor Summary
Polygon2D()
          Creates an empty polygon.
 
Method Summary
 void add(java.awt.geom.Point2D p)
           
abstract  void addPoint(double x, double y)
          Appends the specified coordinates to this Polygon.
abstract  boolean contains(double x, double y)
          
abstract  boolean contains(double x, double y, double w, double h)
          
 boolean contains(int x, int y)
          Determines whether the specified coordinates are inside this Polygon.
 boolean contains(java.awt.Point p)
          Determines whether the specified Point is inside this Polygon.
 boolean contains(java.awt.geom.Point2D p)
          
 boolean contains(java.awt.geom.Rectangle2D r)
          
 java.awt.Rectangle getBounds()
          Gets the bounding box of this Polygon.
abstract  java.awt.geom.Rectangle2D getBounds2D()
          
abstract  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.
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at, double flatness)
          Returns an iterator object that iterates along the boundary of the Shape and provides access to the geometry of the outline of the Shape.
abstract  boolean intersects(double x, double y, double w, double h)
          
 boolean intersects(java.awt.geom.Rectangle2D r)
          
abstract  void invalidate()
          Invalidates or flushes any internally-cached data that depends on the vertex coordinates of this Polygon.
 void reset()
          Resets this Polygon object to an empty polygon.
abstract  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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

npoints

public int npoints
The total number of points. The value of npoints represents the number of valid points in this Polygon and might be less than the number of elements in xpoints or ypoints. This value can be NULL.

Constructor Detail

Polygon2D

public Polygon2D()
Creates an empty polygon.

Method Detail

reset

public void reset()
Resets this Polygon object 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 empty Polygon might 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 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.

See Also:
Polygon.getBounds()

translate

public abstract 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.

Parameters:
deltaX - the amount to translate along the X axis
deltaY - the amount to translate along the Y axis

addPoint

public abstract void addPoint(double x,
                              double y)
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.

Parameters:
x - the specified X coordinate
y - 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 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
Returns:
a Rectangle that defines the bounds of this Polygon.

contains

public boolean contains(java.awt.Point p)
Determines whether the specified Point is inside this Polygon.

Parameters:
p - the specified Point to be tested
Returns:
true if the Polygon contains the Point; false otherwise.
See Also:
contains(double, double)

contains

public boolean contains(int x,
                        int y)
Determines whether the specified coordinates are inside this Polygon.

Parameters:
x - the specified X coordinate to be tested
y - the specified Y coordinate to be tested
Returns:
true if this Polygon contains the specified coordinates (x,y); false otherwise.
See Also:
contains(double, double)

getBounds2D

public abstract java.awt.geom.Rectangle2D getBounds2D()

Specified by:
getBounds2D in interface java.awt.Shape

contains

public abstract boolean contains(double x,
                                 double y)

Specified by:
contains in interface java.awt.Shape

contains

public boolean contains(java.awt.geom.Point2D p)

Specified by:
contains in interface java.awt.Shape

intersects

public abstract boolean intersects(double x,
                                   double y,
                                   double w,
                                   double h)

Specified by:
intersects in interface java.awt.Shape

intersects

public boolean intersects(java.awt.geom.Rectangle2D r)

Specified by:
intersects in interface java.awt.Shape

contains

public abstract boolean contains(double x,
                                 double y,
                                 double w,
                                 double h)

Specified by:
contains in interface java.awt.Shape

contains

public boolean contains(java.awt.geom.Rectangle2D r)

Specified by:
contains in interface java.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 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
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.

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at,
                                                  double flatness)
Returns an iterator object that iterates along the boundary of the Shape and provides access to the geometry of the outline of the Shape. Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE point types are returned by the iterator. Since polygons are already flat, the flatness parameter is ignored. An optional AffineTransform can be specified in which case the coordinates returned in the iteration are transformed accordingly.

Specified by:
getPathIterator in interface java.awt.Shape
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
flatness - 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 the flatness parameter is ignored.
Returns:
a PathIterator object that provides access to the Shape object's geometry.

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