GeneralPath (Java SE 26 & JDK 26)
Description: declaration: module: java.desktop, package: java.awt.geom, class: GeneralPath
Keywords: java.awt.geom.GeneralPath class

# Class GeneralPath

java.lang.Object
java.awt.geom.Path2D
java.awt.geom.Path2D.Float
java.awt.geom.GeneralPath

All Implemented Interfaces:
  `Shape, Serializable, Cloneable`

public final class GeneralPath extends Path2D.Float
The `GeneralPath` class represents a geometric path constructed from straight lines, and quadratic and cubic (Bézier) curves. It can contain multiple subpaths.

`GeneralPath` is a legacy final class which exactly implements the behavior of its superclass `Path2D.Float`. Together with `Path2D.Double`, the `Path2D` classes provide full implementations of a general geometric path that support all of the functionality of the `Shape` and `PathIterator` interfaces with the ability to explicitly select different levels of internal coordinate precision.

Use `Path2D.Float` (or this legacy `GeneralPath` subclass) 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.

Since:
  1.2
See Also:
  - Serialized Form

- ## Nested Class Summary

  ### Nested classes/interfaces declared in class Path2D

  `Path2D.Double, Path2D.Float`
  Modifier and Type
  Class
  Description
  `static class`
  `Path2D.Double`
  The `Double` class defines a geometric path with coordinates stored in double precision floating point.
  `static class`
  `Path2D.Float`
  The `Float` class defines a geometric path with coordinates stored in single precision floating point.

- ## Field Summary

  ### Fields declared in class Path2D

  `WIND_EVEN_ODD, WIND_NON_ZERO`
  Modifier and Type
  Field
  Description
  `static final int`
  `WIND_EVEN_ODD`
  An even-odd winding rule for determining the interior of a path.
  `static final int`
  `WIND_NON_ZERO`
  A non-zero winding rule for determining the interior of a path.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `GeneralPath()`
  Constructs a new empty single precision `GeneralPath` object with a default winding rule of `Path2D.WIND_NON_ZERO`.
  `GeneralPath(int rule)`
  Constructs a new `GeneralPath` object with the specified winding rule to control operations that require the interior of the path to be defined.
  `GeneralPath(int rule, int initialCapacity)`
  Constructs a new `GeneralPath` object with the specified winding rule and the specified initial capacity to store path coordinates.
  `GeneralPath(Shape s)`
  Constructs a new `GeneralPath` object from an arbitrary `Shape` object.

- ## Method Summary

  ### Methods declared in class Path2D.Float

  `append, clone, curveTo, curveTo, getBounds2D, getPathIterator, lineTo, lineTo, moveTo, moveTo, quadTo, quadTo, transform, trimToSize`
  Modifier and Type
  Method
  Description
  `final void`
  `append(PathIterator pi, boolean 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.
  `final Object`
  `clone()`
  Creates a new object of the same class as this object.
  `final 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 `(x3,y3)`, using the specified points `(x1,y1)` and `(x2,y2)` as Bézier control points.
  `final void`
  `curveTo(float x1, float y1, float x2, float y2, float x3, float 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.
  `final Rectangle2D`
  `getBounds2D()`
  Returns a high precision and more accurate bounding box of the `Shape` than the `getBounds` method.
  `final PathIterator`
  `getPathIterator(AffineTransform at)`
  Returns an iterator object that iterates along the `Shape` boundary and provides access to the geometry of the `Shape` outline.
  `final 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.
  `final void`
  `lineTo(float x, float y)`
  Adds a point to the path by drawing a straight line from the current coordinates to the new specified coordinates specified in float precision.
  `final void`
  `moveTo(double x, double y)`
  Adds a point to the path by moving to the specified coordinates specified in double precision.
  `final void`
  `moveTo(float x, float y)`
  Adds a point to the path by moving to the specified coordinates specified in float precision.
  `final 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 `(x2,y2)`, using the specified point `(x1,y1)` as a quadratic parametric control point.
  `final void`
  `quadTo(float x1, float y1, float x2, float 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.
  `final void`
  `transform(AffineTransform at)`
  Transforms the geometry of this path using the specified `AffineTransform`.
  `final void`
  `trimToSize()`
  Trims the capacity of this Path2D instance to its current size.

  ### Methods declared in class Path2D

  `append, closePath, contains, contains, contains, contains, contains, contains, contains, contains, createTransformedShape, getBounds, getCurrentPoint, getPathIterator, getWindingRule, intersects, intersects, intersects, intersects, reset, setWindingRule`
  Modifier and Type
  Method
  Description
  `final void`
  `append(Shape s, boolean 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.
  `final void`
  `closePath()`
  Closes the current subpath by drawing a straight line back to the coordinates of the last `moveTo`.
  `final boolean`
  `contains(double x, double y)`
  Tests if the specified coordinates are inside the boundary of the `Shape`, as described by the definition of insideness.
  `final boolean`
  `contains(double x, double y, double w, double h)`
  Tests if the interior of the `Shape` entirely contains the specified rectangular area.
  `static boolean`
  `contains(PathIterator pi, double x, double y)`
  Tests if the specified coordinates are inside the closed boundary of the specified `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 `PathIterator`.
  `static boolean`
  `contains(PathIterator pi, Point2D p)`
  Tests if the specified `Point2D` is inside the closed boundary of the specified `PathIterator`.
  `static boolean`
  `contains(PathIterator pi, Rectangle2D r)`
  Tests if the specified `Rectangle2D` is entirely inside the closed boundary of the specified `PathIterator`.
  `final boolean`
  `contains(Point2D p)`
  Tests if a specified `Point2D` is inside the boundary of the `Shape`, as described by the definition of insideness.
  `final boolean`
  `contains(Rectangle2D r)`
  Tests if the interior of the `Shape` entirely contains the specified `Rectangle2D`.
  `final Shape`
  `createTransformedShape(AffineTransform at)`
  Returns a new `Shape` representing a transformed version of this `Path2D`.
  `final Rectangle`
  `getBounds()`
  Returns an integer `Rectangle` that completely encloses the `Shape`.
  `final Point2D`
  `getCurrentPoint()`
  Returns the coordinates most recently added to the end of the path as a `Point2D` object.
  `final PathIterator`
  `getPathIterator(AffineTransform at, double flatness)`
  Returns an iterator object that iterates along the `Shape` boundary and provides access to a flattened view of the `Shape` outline geometry.
  `final int`
  `getWindingRule()`
  Returns the fill style winding rule.
  `final boolean`
  `intersects(double x, double y, double w, double h)`
  Tests if the interior of the `Shape` intersects the interior of a specified rectangular area.
  `static boolean`
  `intersects(PathIterator pi, double x, double y, double w, double h)`
  Tests if the interior of the specified `PathIterator` intersects the interior of a specified set of rectangular coordinates.
  `static boolean`
  `intersects(PathIterator pi, Rectangle2D r)`
  Tests if the interior of the specified `PathIterator` intersects the interior of a specified `Rectangle2D`.
  `final boolean`
  `intersects(Rectangle2D r)`
  Tests if the interior of the `Shape` intersects the interior of a specified `Rectangle2D`.
  `final void`
  `reset()`
  Resets the path to empty.
  `final void`
  `setWindingRule(int rule)`
  Sets the winding rule for this path to the specified value.

  ### Methods declared in class Object

  `equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
  Modifier and Type
  Method
  Description
  `boolean`
  `equals(Object obj)`
  Indicates whether some other object is "equal to" this one.
  `protected void`
  `finalize()`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Finalization is deprecated and subject to removal in a future release.
  `final Class<?>`
  `getClass()`
  Returns the runtime class of this `Object`.
  `int`
  `hashCode()`
  Returns a hash code value for this object.
  `final void`
  `notify()`
  Wakes up a single thread that is waiting on this object's monitor.
  `final void`
  `notifyAll()`
  Wakes up all threads that are waiting on this object's monitor.
  `String`
  `toString()`
  Returns a string representation of the object.
  `final void`
  `wait()`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted.
  `final void`
  `wait(long timeoutMillis)`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
  `final void`
  `wait(long timeoutMillis, int nanos)`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

- ## Constructor Details

  - ### GeneralPath

    public GeneralPath()
    Constructs a new empty single precision `GeneralPath` object with a default winding rule of `Path2D.WIND_NON_ZERO`.
    Since:
      1.2

  - ### GeneralPath

    public GeneralPath(int rule)
    Constructs a new `GeneralPath` object with the specified winding rule to control operations that require the interior of the path to be defined.
    Parameters:
      `rule` - the winding rule
    Throws:
      `IllegalArgumentException` - if `rule` is not either `Path2D.WIND_EVEN_ODD` or `Path2D.WIND_NON_ZERO`
    Since:
      1.2
    See Also:
      - `Path2D.WIND_EVEN_ODD`
      - `Path2D.WIND_NON_ZERO`

  - ### GeneralPath

    public GeneralPath(int rule, int initialCapacity)
    Constructs a new `GeneralPath` object with the specified winding rule and the specified initial capacity to store path coordinates. This number is an initial guess as to how many path segments will be added to the path, but the storage is expanded as needed to store whatever path segments are added.
    Parameters:
      `rule` - the winding rule
      `initialCapacity` - the estimate for the number of path segments in the path
    Throws:
      `IllegalArgumentException` - if `rule` is not either `Path2D.WIND_EVEN_ODD` or `Path2D.WIND_NON_ZERO`
      `NegativeArraySizeException` - if `initialCapacity` is negative
    Since:
      1.2
    See Also:
      - `Path2D.WIND_EVEN_ODD`
      - `Path2D.WIND_NON_ZERO`

  - ### GeneralPath

    public GeneralPath(Shape s)
    Constructs a new `GeneralPath` object from an arbitrary `Shape` object. All of the initial geometry and the winding rule for this path are taken from the specified `Shape` object.
    Parameters:
      `s` - the specified `Shape` object
    Throws:
      `NullPointerException` - if `s` is `null`
    Since:
      1.2