This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


java.awt.geom
class Path2D

java.lang.Object extended by java.awt.geom.Path2D
All Implemented Interfaces:
Shape, Cloneable
Direct Known Subclasses:
Path2D.Double, Path2D.Float

public abstract class Path2D
extends Object
implements Shape, Cloneable

The {@code Path2D} class provides a simple, yet flexible shape which represents an arbitrary geometric path. It can fully represent any path which can be iterated by the {@link PathIterator} interface including all of its segment types and winding rules and it implements all of the basic hit testing methods of the {@link Shape} interface.

Use {@link Path2D.Float} when dealing with data that can be represented and used with floating point precision. Use {@link Path2D.Double} for data that requires the accuracy or range of double precision.

{@code Path2D} provides exactly those facilities required for basic construction and management of a geometric path and implementation of the above interfaces with little added interpretation. If it is useful to manipulate the interiors of closed geometric shapes beyond simple hit testing then the {@link Area} class provides additional capabilities specifically targeted at closed figures. While both classes nominally implement the {@code Shape} interface, they differ in purpose and together they provide two useful views of a geometric shape where {@code Path2D} deals primarily with a trajectory formed by path segments and {@code Area} deals more with interpretation and manipulation of enclosed regions of 2D geometric space.

The {@link PathIterator} interface has more detailed descriptions of the types of segments that make up a path and the winding rules that control how to determine which regions are inside or outside the path.


Nested Class Summary
static class

           The class defines a geometric path with coordinates stored in double precision floating point.
static class

           The class defines a geometric path with coordinates stored in single precision floating point.
 
Field Summary
static int WIND_EVEN_ODD
          An even-odd winding rule for determining the interior of a path.
static int WIND_NON_ZERO
          A non-zero winding rule for determining the interior of a path.
 
Method Summary
abstract void
append(PathIterator pi, boolean connect)

          Appends the geometry of the specified java.awt.geom.PathIterator object to the path, possibly connecting the new geometry to the existing path segments with a line segment.
 void
append(Shape s, boolean connect)

          Appends the geometry of the specified object to the path, possibly connecting the new geometry to the existing path segments with a line segment.
abstract Object

          Creates a new object of the same class as this object.
 void

          Closes the current subpath by drawing a straight line back to the coordinates of the last .
 boolean
contains(double x, double y)

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

          
static boolean
contains(PathIterator pi, double x, double y)

          Tests if the specified coordinates are inside the closed boundary of the specified java.awt.geom.PathIterator.
static boolean
contains(PathIterator pi, double x, double y, double w, double h)

          Tests if the specified rectangular area is entirely inside the closed boundary of the specified java.awt.geom.PathIterator.
static boolean

          Tests if the specified java.awt.geom.Point2D is inside the closed boundary of the specified java.awt.geom.PathIterator.
static boolean

          Tests if the specified java.awt.geom.Rectangle2D is entirely inside the closed boundary of the specified java.awt.geom.PathIterator.
 boolean

          
 boolean

          
 Shape

          Returns a new representing a transformed version of this .
abstract void
curveTo(double x1, double y1, double x2, double y2, double x3, double y3)

          Adds a curved segment, defined by three new points, to the path by drawing a Bézier curve that intersects both the current coordinates and the specified coordinates , using the specified points and as Bézier control points.
 Rectangle

          
 Point2D

          Returns the coordinates most recently added to the end of the path as a java.awt.geom.Point2D object.
 PathIterator
getPathIterator(AffineTransform at, double flatness)

          
 int

          Returns the fill style winding rule.
 boolean
intersects(double x, double y, double w, double h)

          
static boolean
intersects(PathIterator pi, double x, double y, double w, double h)

          Tests if the interior of the specified java.awt.geom.PathIterator intersects the interior of a specified set of rectangular coordinates.
static boolean

          Tests if the interior of the specified java.awt.geom.PathIterator intersects the interior of a specified java.awt.geom.Rectangle2D.
 boolean

          
abstract void
lineTo(double x, double y)

          Adds a point to the path by drawing a straight line from the current coordinates to the new specified coordinates specified in double precision.
abstract void
moveTo(double x, double y)

          Adds a point to the path by moving to the specified coordinates specified in double precision.
abstract void
quadTo(double x1, double y1, double x2, double y2)

          Adds a curved segment, defined by two new points, to the path by drawing a Quadratic curve that intersects both the current coordinates and the specified coordinates , using the specified point as a quadratic parametric control point.
 void

          Resets the path to empty.
 void
setWindingRule(int rule)

          Sets the winding rule for this path to the specified value.
abstract void

          Transforms the geometry of this path using the specified java.awt.geom.AffineTransform.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WIND_EVEN_ODD

public static final int WIND_EVEN_ODD
An even-odd winding rule for determining the interior of a path.

WIND_NON_ZERO

public static final int WIND_NON_ZERO
A non-zero winding rule for determining the interior of a path.
Method Detail

append

public abstract void append(PathIterator pi,
                            boolean connect)
Appends the geometry of the specified {@link PathIterator} object to the path, possibly connecting the new geometry to the existing path segments with a line segment. If the {@code connect} parameter is {@code true} and the path is not empty then any initial {@code moveTo} in the geometry of the appended {@code Shape} is turned into a {@code lineTo} segment. If the destination coordinates of such a connecting {@code lineTo} segment match the ending coordinates of a currently open subpath then the segment is omitted as superfluous. The winding rule of the specified {@code Shape} is ignored and the appended geometry is governed by the winding rule specified for this path.

Parameters:
pi - the {@code PathIterator} whose geometry is appended to this path
connect - a boolean to control whether or not to turn an initial {@code moveTo} segment into a {@code lineTo} segment to connect the new geometry to the existing path

append

public final void append(Shape s,
                         boolean connect)
Appends the geometry of the specified {@code Shape} object to the path, possibly connecting the new geometry to the existing path segments with a line segment. If the {@code connect} parameter is {@code true} and the path is not empty then any initial {@code moveTo} in the geometry of the appended {@code Shape} is turned into a {@code lineTo} segment. If the destination coordinates of such a connecting {@code lineTo} segment match the ending coordinates of a currently open subpath then the segment is omitted as superfluous. The winding rule of the specified {@code Shape} is ignored and the appended geometry is governed by the winding rule specified for this path.

Parameters:
s - the {@code Shape} whose geometry is appended to this path
connect - a boolean to control whether or not to turn an initial {@code moveTo} segment into a {@code lineTo} segment to connect the new geometry to the existing path

clone

public abstract Object clone()
Creates a new object of the same class as this object.

Overrides:
clone in class Object
Returns:
a clone of this instance.

closePath

public final synchronized void closePath()
Closes the current subpath by drawing a straight line back to the coordinates of the last {@code moveTo}. If the path is already closed then this method has no effect.


contains

public final boolean contains(double x,
                              double y)
{@inheritDoc}

Parameters:
x
y

contains

public final boolean contains(double x,
                              double y,
                              double w,
                              double h)
{@inheritDoc}

This method object may conservatively return false in cases where the specified rectangular area intersects a segment of the path, but that segment does not represent a boundary between the interior and exterior of the path. Such segments could lie entirely within the interior of the path if they are part of a path with a {@link #WIND_NON_ZERO} winding rule or if the segments are retraced in the reverse direction such that the two sets of segments cancel each other out without any exterior area falling between them. To determine whether segments represent true boundaries of the interior of the path would require extensive calculations involving all of the segments of the path and the winding rule and are thus beyond the scope of this implementation.

Parameters:
x
y
w
h

contains

public static boolean contains(PathIterator pi,
                               double x,
                               double y)
Tests if the specified coordinates are inside the closed boundary of the specified {@link PathIterator}.

This method provides a basic facility for implementors of the {@link Shape} interface to implement support for the {@link Shape#contains(double, double)} method.

Parameters:
pi - the specified {@code PathIterator}
x - the specified X coordinate
y - the specified Y coordinate
Returns:
{@code true} if the specified coordinates are inside the specified {@code PathIterator}; {@code false} otherwise

contains

public static boolean contains(PathIterator pi,
                               double x,
                               double y,
                               double w,
                               double h)
Tests if the specified rectangular area is entirely inside the closed boundary of the specified {@link PathIterator}.

This method provides a basic facility for implementors of the {@link Shape} interface to implement support for the {@link Shape#contains(double, double, double, double)} method.

This method object may conservatively return false in cases where the specified rectangular area intersects a segment of the path, but that segment does not represent a boundary between the interior and exterior of the path. Such segments could lie entirely within the interior of the path if they are part of a path with a {@link #WIND_NON_ZERO} winding rule or if the segments are retraced in the reverse direction such that the two sets of segments cancel each other out without any exterior area falling between them. To determine whether segments represent true boundaries of the interior of the path would require extensive calculations involving all of the segments of the path and the winding rule and are thus beyond the scope of this implementation.

Parameters:
pi - the specified {@code PathIterator}
x - the specified X coordinate
y - the specified Y coordinate
w - the width of the specified rectangular area
h - the height of the specified rectangular area
Returns:
{@code true} if the specified {@code PathIterator} contains the specified rectangluar area; {@code false} otherwise.

contains

public static boolean contains(PathIterator pi,
                               Point2D p)
Tests if the specified {@link Point2D} is inside the closed boundary of the specified {@link PathIterator}.

This method provides a basic facility for implementors of the {@link Shape} interface to implement support for the {@link Shape#contains(Point2D)} method.

Parameters:
pi - the specified {@code PathIterator}
p - the specified {@code Point2D}
Returns:
{@code true} if the specified coordinates are inside the specified {@code PathIterator}; {@code false} otherwise

contains

public static boolean contains(PathIterator pi,
                               Rectangle2D r)
Tests if the specified {@link Rectangle2D} is entirely inside the closed boundary of the specified {@link PathIterator}.

This method provides a basic facility for implementors of the {@link Shape} interface to implement support for the {@link Shape#contains(Rectangle2D)} method.

This method object may conservatively return false in cases where the specified rectangular area intersects a segment of the path, but that segment does not represent a boundary between the interior and exterior of the path. Such segments could lie entirely within the interior of the path if they are part of a path with a {@link #WIND_NON_ZERO} winding rule or if the segments are retraced in the reverse direction such that the two sets of segments cancel each other out without any exterior area falling between them. To determine whether segments represent true boundaries of the interior of the path would require extensive calculations involving all of the segments of the path and the winding rule and are thus beyond the scope of this implementation.

Parameters:
pi - the specified {@code PathIterator}
r - a specified {@code Rectangle2D}
Returns:
{@code true} if the specified {@code PathIterator} contains the specified {@code Rectangle2D}; {@code false} otherwise.

contains

public final boolean contains(Point2D p)
{@inheritDoc}

Parameters:
p

contains

public final boolean contains(Rectangle2D r)
{@inheritDoc}

This method object may conservatively return false in cases where the specified rectangular area intersects a segment of the path, but that segment does not represent a boundary between the interior and exterior of the path. Such segments could lie entirely within the interior of the path if they are part of a path with a {@link #WIND_NON_ZERO} winding rule or if the segments are retraced in the reverse direction such that the two sets of segments cancel each other out without any exterior area falling between them. To determine whether segments represent true boundaries of the interior of the path would require extensive calculations involving all of the segments of the path and the winding rule and are thus beyond the scope of this implementation.

Parameters:
r

createTransformedShape

public final synchronized Shape createTransformedShape(AffineTransform at)
Returns a new {@code Shape} representing a transformed version of this {@code Path2D}. Note that the exact type and coordinate precision of the return value is not specified for this method. The method will return a Shape that contains no less precision for the transformed geometry than this {@code Path2D} currently maintains, but it may contain no more precision either. If the tradeoff of precision vs. storage size in the result is important then the convenience constructors in the {@link Path2D.Float#Path2D.Float(Shape, AffineTransform) Path2D.Float} and {@link Path2D.Double#Path2D.Double(Shape, AffineTransform) Path2D.Double} subclasses should be used to make the choice explicit.

Parameters:
at - the {@code AffineTransform} used to transform a new {@code Shape}.
Returns:
a new {@code Shape}, transformed with the specified {@code AffineTransform}.

curveTo

public abstract void curveTo(double x1,
                             double y1,
                             double x2,
                             double y2,
                             double x3,
                             double y3)
Adds a curved segment, defined by three new points, to the path by drawing a Bézier curve that intersects both the current coordinates and the specified coordinates {@code (x3,y3)}, using the specified points {@code (x1,y1)} and {@code (x2,y2)} as Bézier control points. All coordinates are specified in double precision.

Parameters:
x1 - the X coordinate of the first Bézier control point
y1 - the Y coordinate of the first Bézier control point
x2 - the X coordinate of the second Bézier control point
y2 - the Y coordinate of the second Bézier control point
x3 - the X coordinate of the final end point
y3 - the Y coordinate of the final end point

getBounds

public final Rectangle getBounds()
{@inheritDoc}


getCurrentPoint

public final synchronized Point2D getCurrentPoint()
Returns the coordinates most recently added to the end of the path as a {@link Point2D} object.

Returns:
a {@code Point2D} object containing the ending coordinates of the path or {@code null} if there are no points in the path.

getPathIterator

public PathIterator getPathIterator(AffineTransform at,
                                    double flatness)
{@inheritDoc}

The iterator for this class is not multi-threaded safe, which means that this {@code Path2D} class does not guarantee that modifications to the geometry of this {@code Path2D} object do not affect any iterations of that geometry that are already in process.

Parameters:
at
flatness

getWindingRule

public final synchronized int getWindingRule()
Returns the fill style winding rule.

Returns:
an integer representing the current winding rule.

intersects

public final boolean intersects(double x,
                                double y,
                                double w,
                                double h)
{@inheritDoc}

This method object may conservatively return true in cases where the specified rectangular area intersects a segment of the path, but that segment does not represent a boundary between the interior and exterior of the path. Such a case may occur if some set of segments of the path are retraced in the reverse direction such that the two sets of segments cancel each other out without any interior area between them. To determine whether segments represent true boundaries of the interior of the path would require extensive calculations involving all of the segments of the path and the winding rule and are thus beyond the scope of this implementation.

Parameters:
x
y
w
h

intersects

public static boolean intersects(PathIterator pi,
                                 double x,
                                 double y,
                                 double w,
                                 double h)
Tests if the interior of the specified {@link PathIterator} intersects the interior of a specified set of rectangular coordinates.

This method provides a basic facility for implementors of the {@link Shape} interface to implement support for the {@link Shape#intersects(double, double, double, double)} method.

This method object may conservatively return true in cases where the specified rectangular area intersects a segment of the path, but that segment does not represent a boundary between the interior and exterior of the path. Such a case may occur if some set of segments of the path are retraced in the reverse direction such that the two sets of segments cancel each other out without any interior area between them. To determine whether segments represent true boundaries of the interior of the path would require extensive calculations involving all of the segments of the path and the winding rule and are thus beyond the scope of this implementation.

Parameters:
pi - the specified {@code PathIterator}
x - the specified X coordinate
y - the specified Y coordinate
w - the width of the specified rectangular coordinates
h - the height of the specified rectangular coordinates
Returns:
{@code true} if the specified {@code PathIterator} and the interior of the specified set of rectangular coordinates intersect each other; {@code false} otherwise.

intersects

public static boolean intersects(PathIterator pi,
                                 Rectangle2D r)
Tests if the interior of the specified {@link PathIterator} intersects the interior of a specified {@link Rectangle2D}.

This method provides a basic facility for implementors of the {@link Shape} interface to implement support for the {@link Shape#intersects(Rectangle2D)} method.

This method object may conservatively return true in cases where the specified rectangular area intersects a segment of the path, but that segment does not represent a boundary between the interior and exterior of the path. Such a case may occur if some set of segments of the path are retraced in the reverse direction such that the two sets of segments cancel each other out without any interior area between them. To determine whether segments represent true boundaries of the interior of the path would require extensive calculations involving all of the segments of the path and the winding rule and are thus beyond the scope of this implementation.

Parameters:
pi - the specified {@code PathIterator}
r - the specified {@code Rectangle2D}
Returns:
{@code true} if the specified {@code PathIterator} and the interior of the specified {@code Rectangle2D} intersect each other; {@code false} otherwise.

intersects

public final boolean intersects(Rectangle2D r)
{@inheritDoc}

This method object may conservatively return true in cases where the specified rectangular area intersects a segment of the path, but that segment does not represent a boundary between the interior and exterior of the path. Such a case may occur if some set of segments of the path are retraced in the reverse direction such that the two sets of segments cancel each other out without any interior area between them. To determine whether segments represent true boundaries of the interior of the path would require extensive calculations involving all of the segments of the path and the winding rule and are thus beyond the scope of this implementation.

Parameters:
r

lineTo

public abstract void lineTo(double x,
                            double y)
Adds a point to the path by drawing a straight line from the current coordinates to the new specified coordinates specified in double precision.

Parameters:
x - the specified X coordinate
y - the specified Y coordinate

moveTo

public abstract void moveTo(double x,
                            double y)
Adds a point to the path by moving to the specified coordinates specified in double precision.

Parameters:
x - the specified X coordinate
y - the specified Y coordinate

quadTo

public abstract void quadTo(double x1,
                            double y1,
                            double x2,
                            double y2)
Adds a curved segment, defined by two new points, to the path by drawing a Quadratic curve that intersects both the current coordinates and the specified coordinates {@code (x2,y2)}, using the specified point {@code (x1,y1)} as a quadratic parametric control point. All coordinates are specified in double precision.

Parameters:
x1 - the X coordinate of the quadratic control point
y1 - the Y coordinate of the quadratic control point
x2 - the X coordinate of the final end point
y2 - the Y coordinate of the final end point

reset

public final synchronized void reset()
Resets the path to empty. The append position is set back to the beginning of the path and all coordinates and point types are forgotten.


setWindingRule

public final void setWindingRule(int rule)
Sets the winding rule for this path to the specified value.

Parameters:
rule - an integer representing the specified winding rule

transform

public abstract void transform(AffineTransform at)
Transforms the geometry of this path using the specified {@link AffineTransform}. The geometry is transformed in place, which permanently changes the boundary defined by this object.

Parameters:
at - the {@code AffineTransform} used to transform the area


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.