JHotDraw 7.0.6

org.jhotdraw.geom
Class BezierPath

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<BezierPath.Node>
              extended by org.jhotdraw.geom.BezierPath
All Implemented Interfaces:
java.awt.Shape, java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<BezierPath.Node>, java.util.Collection<BezierPath.Node>, java.util.List<BezierPath.Node>, java.util.RandomAccess

public class BezierPath
extends java.util.ArrayList<BezierPath.Node>
implements java.awt.Shape

BezierPath allows the construction of paths consisting of straight lines, quadratic curves and cubic curves.

A BezierPath represents a geometric path constructed by vertices. Each Node has three control points: C0, C1, C2. A mask defines which control points are in use. The path passes through C0. C1 controls the curve going towards C0. C2 controls the curve going away from C0.

See Also:
Serialized Form

Nested Class Summary
static class BezierPath.Node
          Defines a vertex (node) of the bezier path.
 
Field Summary
static int C1_MASK
          Constant for control point C1.
static int C1C2_MASK
          Convenience constant for control point C1 and C2.
static int C2_MASK
          Constant for control point C2.
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
BezierPath()
          Creates a new instance.
 
Method Summary
 void add(int mask, java.awt.geom.Point2D.Double c0, java.awt.geom.Point2D.Double c1, java.awt.geom.Point2D.Double c2)
          Convenience method for adding a control point with three coordinates C0, C1 and C2 with a mask.
 void add(java.awt.geom.Point2D.Double c0)
          Convenience method for adding a control point with a single coordinate C0.
 void addPoint(double x, double y)
           
 java.awt.geom.Point2D.Double chop(java.awt.geom.Point2D.Double p)
          Returns a point on the edge of the bezier path which crosses the line from the center of the bezier path to the specified point.
 java.lang.Object clone()
          Creates a deep copy of the BezierPath.
 boolean contains(double x, double y)
           
 boolean contains(double x, double y, double w, double h)
           
 boolean contains(java.awt.geom.Point2D p)
           
 boolean contains(java.awt.geom.Rectangle2D r)
           
 void curveTo(double x1, double y1, double x2, double y2, double x3, double y3)
           
 int findSegment(java.awt.geom.Point2D.Double find, float tolerance)
          Gets the segment of the polyline that is hit by the given Point2D.Double.
 java.awt.geom.Point2D.Double get(int index, int coord)
          Convenience method for getting a single coordinate of a control point.
 java.awt.Rectangle getBounds()
           
 java.awt.geom.Rectangle2D getBounds2D()
           
 java.awt.geom.Rectangle2D.Double getBounds2DDouble()
           
 java.awt.geom.Point2D.Double getCenter()
          Returns the point at the center of the bezier path.
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at)
           
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at, double flatness)
           
 java.awt.geom.Point2D.Double getPointOnPath(double relative, double flatness)
          Returns a relative point on the path.
 int indexOfOutermostNode()
          Return the index of the control point that is furthest from the center
 boolean intersects(double x, double y, double w, double h)
           
 boolean intersects(java.awt.geom.Rectangle2D r)
           
 void invalidatePath()
          This must be called after the BezierPath has been changed.
 boolean isClosed()
           
 int joinSegments(java.awt.geom.Point2D.Double join, float tolerance)
          Joins two segments into one if the given Point2D.Double hits a node of the bezier path.
 void lineTo(double x1, double y1)
           
 void moveTo(double x1, double y1)
           
 boolean outlineContains(java.awt.geom.Point2D.Double p, double tolerance)
          Returns true, if the outline of this bezier path contains the specified point.
 void quadTo(double x1, double y1, double x2, double y2)
           
 void set(int index, int coord, java.awt.geom.Point2D.Double p)
          Convenience method for changing a single coordinate of a control point.
 void setClosed(boolean newValue)
           
 void setTo(BezierPath that)
           
 int splitSegment(java.awt.geom.Point2D.Double split, float tolerance)
          Splits the segment at the given Point2D.Double if a segment was hit.
 java.awt.geom.GeneralPath toGeneralPath()
          Converts the BezierPath into a GeneralPath.
 java.awt.geom.Point2D.Double[] toPolygonArray()
           
 void transform(java.awt.geom.AffineTransform tx)
          Transforms the BezierPath.
 void validatePath()
          Recomputes the BezierPath, if it is invalid.
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Field Detail

C1_MASK

public static final int C1_MASK
Constant for control point C1.

See Also:
Constant Field Values

C2_MASK

public static final int C2_MASK
Constant for control point C2.

See Also:
Constant Field Values

C1C2_MASK

public static final int C1C2_MASK
Convenience constant for control point C1 and C2.

See Also:
Constant Field Values
Constructor Detail

BezierPath

public BezierPath()
Creates a new instance.

Method Detail

add

public void add(java.awt.geom.Point2D.Double c0)
Convenience method for adding a control point with a single coordinate C0.


addPoint

public void addPoint(double x,
                     double y)

add

public void add(int mask,
                java.awt.geom.Point2D.Double c0,
                java.awt.geom.Point2D.Double c1,
                java.awt.geom.Point2D.Double c2)
Convenience method for adding a control point with three coordinates C0, C1 and C2 with a mask.


set

public void set(int index,
                int coord,
                java.awt.geom.Point2D.Double p)
Convenience method for changing a single coordinate of a control point.


get

public java.awt.geom.Point2D.Double get(int index,
                                        int coord)
Convenience method for getting a single coordinate of a control point.


invalidatePath

public void invalidatePath()
This must be called after the BezierPath has been changed.


validatePath

public void validatePath()
Recomputes the BezierPath, if it is invalid.


toGeneralPath

public java.awt.geom.GeneralPath toGeneralPath()
Converts the BezierPath into a GeneralPath.


contains

public boolean contains(java.awt.geom.Point2D p)
Specified by:
contains in interface java.awt.Shape

outlineContains

public boolean outlineContains(java.awt.geom.Point2D.Double p,
                               double tolerance)
Returns true, if the outline of this bezier path contains the specified point.

Parameters:
p - The point to be tested.
tolerance - The tolerance for the test.

intersects

public boolean intersects(java.awt.geom.Rectangle2D r)
Specified by:
intersects in interface java.awt.Shape

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at)
Specified by:
getPathIterator in interface java.awt.Shape

contains

public boolean contains(java.awt.geom.Rectangle2D r)
Specified by:
contains in interface java.awt.Shape

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at,
                                                  double flatness)
Specified by:
getPathIterator in interface java.awt.Shape

intersects

public boolean intersects(double x,
                          double y,
                          double w,
                          double h)
Specified by:
intersects in interface java.awt.Shape

getBounds2D

public java.awt.geom.Rectangle2D getBounds2D()
Specified by:
getBounds2D in interface java.awt.Shape

getBounds2DDouble

public java.awt.geom.Rectangle2D.Double getBounds2DDouble()

getBounds

public java.awt.Rectangle getBounds()
Specified by:
getBounds in interface java.awt.Shape

contains

public boolean contains(double x,
                        double y,
                        double w,
                        double h)
Specified by:
contains in interface java.awt.Shape

contains

public boolean contains(double x,
                        double y)
Specified by:
contains in interface java.awt.Shape

setClosed

public void setClosed(boolean newValue)

isClosed

public boolean isClosed()

clone

public java.lang.Object clone()
Creates a deep copy of the BezierPath.

Overrides:
clone in class java.util.ArrayList<BezierPath.Node>

transform

public void transform(java.awt.geom.AffineTransform tx)
Transforms the BezierPath.

Parameters:
tx - the transformation.

setTo

public void setTo(BezierPath that)

getCenter

public java.awt.geom.Point2D.Double getCenter()
Returns the point at the center of the bezier path.


chop

public java.awt.geom.Point2D.Double chop(java.awt.geom.Point2D.Double p)
Returns a point on the edge of the bezier path which crosses the line from the center of the bezier path to the specified point. If no edge crosses the line, the nearest C0 control point is returned.


indexOfOutermostNode

public int indexOfOutermostNode()
Return the index of the control point that is furthest from the center


getPointOnPath

public java.awt.geom.Point2D.Double getPointOnPath(double relative,
                                                   double flatness)
Returns a relative point on the path. Where 0 is the start point of the path and 1 is the end point of the path.

Parameters:
relative - a value between 0 and 1.

findSegment

public int findSegment(java.awt.geom.Point2D.Double find,
                       float tolerance)
Gets the segment of the polyline that is hit by the given Point2D.Double.

Returns:
the index of the segment or -1 if no segment was hit.

joinSegments

public int joinSegments(java.awt.geom.Point2D.Double join,
                        float tolerance)
Joins two segments into one if the given Point2D.Double hits a node of the bezier path.

Returns:
the index of the joined segment or -1 if no segment was joined.

splitSegment

public int splitSegment(java.awt.geom.Point2D.Double split,
                        float tolerance)
Splits the segment at the given Point2D.Double if a segment was hit.

Returns:
the index of the segment or -1 if no segment was hit.

moveTo

public void moveTo(double x1,
                   double y1)

lineTo

public void lineTo(double x1,
                   double y1)

quadTo

public void quadTo(double x1,
                   double y1,
                   double x2,
                   double y2)

curveTo

public void curveTo(double x1,
                    double y1,
                    double x2,
                    double y2,
                    double x3,
                    double y3)

toPolygonArray

public java.awt.geom.Point2D.Double[] toPolygonArray()

Copyright 1996-2006 © JHotDraw.org