APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.awt.geom

public abstract sealed Class Path2D

extends Object
implements Shape, Cloneable
permits Double, Float
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, java.awt.Shape
Known Direct Subclasses
java.awt.geom.Path2D.Float, java.awt.geom.Path2D.Double
Imports
java.awt.Rectangle, .Shape, java.io.IOException, .Serial, .Serializable, .StreamCorruptedException, java.util.Arrays, sun.awt.geom.Curve

The 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 PathIterator interface including all of its segment types and winding rules and it implements all of the basic hit testing methods of the Shape interface.

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

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 Area class provides additional capabilities specifically targeted at closed figures. While both classes nominally implement the Shape interface, they differ in purpose and together they provide two useful views of a geometric shape where Path2D deals primarily with a trajectory formed by path segments and Area deals more with interpretation and manipulation of enclosed regions of 2D geometric space.

The 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.

Author
Jim Graham
Since
1.6

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Path2D.Double

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

public static class
Path2D.Float

The Float class defines a geometric path with coordinates stored in single precision floating point.

pack-priv abstract static class

Field Summary

Modifier and TypeField and Description
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv transient int
pack-priv transient int
pack-priv transient byte[]
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
private static final byte
public static final int
WIND_EVEN_ODD

An even-odd winding rule for determining the interior of a path.

public static final int
WIND_NON_ZERO

A non-zero winding rule for determining the interior of a path.

pack-priv transient int

Constructor Summary

AccessConstructor and Description
pack-priv
Path2D()

Constructs a new empty Path2D object.

pack-priv
Path2D(int
the winding rule
rule
,
int
the size to make the initial array to store the path segment types
initialTypes
)

Constructs a new Path2D object from the given specified initial values.

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract void
append(float x, float y)

pack-priv abstract void
append(double x, double y)

public final void
append(Shape
the Shape whose geometry is appended to this path
s
,
boolean
a boolean to control whether or not to turn an initial moveTo segment into a lineTo segment to connect the new geometry to the existing path
connect
)

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

public abstract void
append(PathIterator
the PathIterator whose geometry is appended to this path
pi
,
boolean
a boolean to control whether or not to turn an initial moveTo segment into a lineTo segment to connect the new geometry to the existing path
connect
)

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

public abstract Object

Returns:

a clone of this instance.
clone
()

Overrides java.lang.Object.clone.

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

pack-priv abstract double[]
pack-priv abstract float[]
public final synchronized void
closePath()

Closes the current subpath by drawing a straight line back to the coordinates of the last moveTo.

public static boolean

Returns:

true if the specified coordinates are inside the specified PathIterator; false otherwise
contains
(PathIterator
the specified PathIterator
pi
,
double
the specified X coordinate
x
,
double
the specified Y coordinate
y
)

Tests if the specified coordinates are inside the closed boundary of the specified PathIterator.

public static boolean

Returns:

true if the specified coordinates are inside the specified PathIterator; false otherwise
contains
(PathIterator
the specified PathIterator
pi
,
Point2D
the specified Point2D
p
)

Tests if the specified Point2D is inside the closed boundary of the specified PathIterator.

public final boolean
contains(double x, double y)

Implements java.awt.Shape.contains.

Tests if the specified coordinates are inside the boundary of the Shape, as described by the definition of insideness.

public final boolean
contains(Point2D p)

Implements java.awt.Shape.contains.

Tests if a specified Point2D is inside the boundary of the Shape, as described by the definition of insideness.

public static boolean

Returns:

true if the specified PathIterator contains the specified rectangular area; false otherwise.
contains
(PathIterator
the specified PathIterator
pi
,
double
the specified X coordinate
x
,
double
the specified Y coordinate
y
,
double
the width of the specified rectangular area
w
,
double
the height of the specified rectangular area
h
)

Tests if the specified rectangular area is entirely inside the closed boundary of the specified PathIterator.

public static boolean

Returns:

true if the specified PathIterator contains the specified Rectangle2D; false otherwise.
contains
(PathIterator
the specified PathIterator
pi
,
Rectangle2D
a specified Rectangle2D
r
)

Tests if the specified Rectangle2D is entirely inside the closed boundary of the specified PathIterator.

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

Implements java.awt.Shape.contains.

Tests if the interior of the Shape entirely contains the specified rectangular area.

public final boolean
contains(Rectangle2D r)

Implements java.awt.Shape.contains.

Tests if the interior of the Shape entirely contains the specified Rectangle2D.

public final synchronized Shape

Returns:

a new Shape, transformed with the specified AffineTransform.
createTransformedShape
(AffineTransform
the AffineTransform used to transform a new Shape.
at
)

Returns a new Shape representing a transformed version of this Path2D.

public abstract void
curveTo(double
the X coordinate of the first Bézier control point
x1
,
double
the Y coordinate of the first Bézier control point
y1
,
double
the X coordinate of the second Bézier control point
x2
,
double
the Y coordinate of the second Bézier control point
y2
,
double
the X coordinate of the final end point
x3
,
double
the Y coordinate of the final end point
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 (x3,y3), using the specified points (x1,y1) and (x2,y2) as Bézier control points.

pack-priv static byte[]
expandPointTypes(byte[] oldPointTypes, int needed)

public final Rectangle
getBounds()

Implements java.awt.Shape.getBounds.

Returns an integer Rectangle that completely encloses the Shape.

pack-priv static Rectangle2D

Returns:

an instance of Rectangle2D that is a high-precision bounding box of the PathIterator.
getBounds2D
(final PathIterator
the specified PathIterator
pi
)

Returns a high precision bounding box of the specified PathIterator.

public final synchronized Point2D

Returns:

a Point2D object containing the ending coordinates of the path or null if there are no points in the path.
getCurrentPoint
()

Returns the coordinates most recently added to the end of the path as a Point2D object.

public final PathIterator
getPathIterator(AffineTransform at, double flatness)

Implements java.awt.Shape.getPathIterator.

Returns an iterator object that iterates along the Shape boundary and provides access to a flattened view of the Shape outline geometry.

pack-priv abstract Point2D
getPoint(int coordindex)

public final synchronized int

Returns:

an integer representing the current winding rule.
getWindingRule
()

Returns the fill style winding rule.

public static boolean

Returns:

true if the specified PathIterator and the interior of the specified set of rectangular coordinates intersect each other; false otherwise.
intersects
(PathIterator
the specified PathIterator
pi
,
double
the specified X coordinate
x
,
double
the specified Y coordinate
y
,
double
the width of the specified rectangular coordinates
w
,
double
the height of the specified rectangular coordinates
h
)

Tests if the interior of the specified PathIterator intersects the interior of a specified set of rectangular coordinates.

public static boolean

Returns:

true if the specified PathIterator and the interior of the specified Rectangle2D intersect each other; false otherwise.
intersects
(PathIterator
the specified PathIterator
pi
,
Rectangle2D
the specified Rectangle2D
r
)

Tests if the interior of the specified PathIterator intersects the interior of a specified Rectangle2D.

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

Implements java.awt.Shape.intersects.

Tests if the interior of the Shape intersects the interior of a specified rectangular area.

public final boolean
intersects(Rectangle2D r)

Implements java.awt.Shape.intersects.

Tests if the interior of the Shape intersects the interior of a specified Rectangle2D.

public abstract void
lineTo(double
the specified X coordinate
x
,
double
the specified Y coordinate
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.

public abstract void
moveTo(double
the specified X coordinate
x
,
double
the specified Y coordinate
y
)

Adds a point to the path by moving to the specified coordinates specified in double precision.

pack-priv abstract void
needRoom(boolean needMove, int newCoords)

pack-priv abstract int
pointCrossings(double px, double py)

public abstract void
quadTo(double
the X coordinate of the quadratic control point
x1
,
double
the Y coordinate of the quadratic control point
y1
,
double
the X coordinate of the final end point
x2
,
double
the Y coordinate of the final end point
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 (x2,y2), using the specified point (x1,y1) as a quadratic parametric control point.

pack-priv final void
readObject(ObjectInputStream s, boolean storedbl)

pack-priv abstract int
rectCrossings(double rxmin, double rymin, double rxmax, double rymax)

public final synchronized void
reset()

Resets the path to empty.

public final void
setWindingRule(int
an integer representing the specified winding rule
rule
)

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

public abstract void
transform(AffineTransform
the AffineTransform used to transform the area
at
)

Transforms the geometry of this path using the specified AffineTransform.

public abstract void
trimToSize()

Trims the capacity of this Path2D instance to its current size.

pack-priv final void
writeObject(ObjectOutputStream s, boolean isdbl)

Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait