Class Path2D

Object
Path2D

public class Path2D extends Object
Adapted from java.awt.geom.Path2D, merged with PathIterator and stripped to the bare bones. In particular, all the Shape stuff and AffineTransform removed. Generally made more GWT friendly.
Author:
Christoph Hauert
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Adapted from java.awt.geom.PathIterator, merged with Path2D Iterator and CopyIterator.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) double[]
     
    (package private) static final int
     
    (package private) static final int
     
    (package private) static final int
     
    (package private) static final int
     
    (package private) int
     
    (package private) int
     
    (package private) byte[]
     
    private static final byte
     
    private static final byte
     
    private static final byte
     
    private static final byte
     
    private static final byte
     
    static final int
    An even-odd winding rule for determining the interior of a path.
    static final int
    A non-zero winding rule for determining the interior of a path.
    (package private) int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new empty double precision Path2D object with a default winding rule of WIND_NON_ZERO.
    Path2D(int rule)
    Constructs a new empty double precision Path2D object with the specified winding rule to control operations that require the interior of the path to be defined.
    Path2D(int rule, int initialCapacity)
    Constructs a new empty double precision Path2D object with the specified winding rule and the specified initial capacity to store path segments.
    Constructs a new double precision Path2D object from an arbitrary Path2D object, transformed by an AffineTransform object.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) void
    append(double x, double y)
    Append the point with coordinates (x,y) to this path.
    final void
    append(Path2D.Iterator pi, boolean connect)
    Appends the geometry of the specified Path2D.Iterator object to the path, possibly connecting the new geometry to the existing path segments with a line segment.
    (package private) double[]
     
    final void
    Closes the current subpath by drawing a straight line back to the coordinates of the last moveTo.
    static Path2D
    createPolygon2D(double[] x, double[] y)
    Construct a polygon from array of x- and y coordinates.
    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.
    (package private) static double[]
    expandCoords(double[] oldCoords, int needed)
     
    (package private) static byte[]
    expandPointTypes(byte[] oldPointTypes, int needed)
     
    Returns a high precision and more accurate bounding box of the Path2D than the getBounds method.
    final Point2D
    Returns the coordinates most recently added to the end of the path as a Point2D object.
    Returns an iterator object that iterates along this path.
    (package private) Point2D
    getPoint(int coordindex)
    Return the point in the Path2D with the specified index.
    final int
    Returns the fill style winding rule.
    boolean
    Check if the path is empty.
    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
    moveTo(double x, double y)
    Adds a point to the path by moving to the specified coordinates specified in double precision.
    (package private) void
    needRoom(boolean needMove, int newCoords)
     
    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
    Resets the path to empty.
    final void
    setWindingRule(int rule)
    Sets the winding rule for this path to the specified value.
     
    final void
    Transforms the geometry of this path using the specified AffineTransform.
    void
    translate(double dx, double dy)
    Translate path.
    final void
    Trim excessive storage of Path2D.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • Path2D

      public Path2D()
      Constructs a new empty double precision Path2D object with a default winding rule of WIND_NON_ZERO.
      Since:
      1.6
    • Path2D

      public Path2D(int rule)
      Constructs a new empty double precision Path2D object with the specified winding rule to control operations that require the interior of the path to be defined.
      Parameters:
      rule - the winding rule
      Since:
      1.6
      See Also:
    • Path2D

      public Path2D(int rule, int initialCapacity)
      Constructs a new empty double precision Path2D object with the specified winding rule and the specified initial capacity to store path segments. This number is an initial guess as to how many path segments are in the path, but the storage is expanded as needed to store whatever path segments are added to this path.
      Parameters:
      rule - the winding rule
      initialCapacity - the estimate for the number of path segments in the path
      Since:
      1.6
      See Also:
    • Path2D

      public Path2D(Path2D p2d, AffineTransform at)
      Constructs a new double precision Path2D object from an arbitrary Path2D object, transformed by an AffineTransform object. All of the initial geometry and the winding rule for this path are taken from the specified Path2D object and transformed by the specified AffineTransform object.
      Parameters:
      p2d - the specified Path2D object
      at - the specified AffineTransform object
      Since:
      1.6
  • Method Details

    • expandPointTypes

      static byte[] expandPointTypes(byte[] oldPointTypes, int needed)
    • trimToSize

      public final void trimToSize()
      Trim excessive storage of Path2D. No data is lost.
    • cloneCoordsDouble

      double[] cloneCoordsDouble(AffineTransform at)
    • append

      void append(double x, double y)
      Append the point with coordinates (x,y) to this path.
      Parameters:
      x - the x coordinate of the point
      y - the y coordinate of the point
    • getPoint

      Point2D getPoint(int coordindex)
      Return the point in the Path2D with the specified index.
      Parameters:
      coordindex - the index of the point
      Returns:
      the point in the path
    • needRoom

      void needRoom(boolean needMove, int newCoords)
    • expandCoords

      static double[] expandCoords(double[] oldCoords, int needed)
    • moveTo

      public final 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
      Since:
      1.6
    • lineTo

      public 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.
      Parameters:
      x - the specified X coordinate
      y - the specified Y coordinate
      Since:
      1.6
    • quadTo

      public 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. 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
      Since:
      1.6
    • curveTo

      public 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. 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
      Since:
      1.6
    • append

      public final void append(Path2D.Iterator pi, boolean connect)
      Appends the geometry of the specified Path2D.Iterator object to the path, possibly connecting the new geometry to the existing path segments with a line segment. If the connect parameter is true and the path is not empty then any initial moveTo in the geometry of the appended Iterator is turned into a lineTo segment. If the destination coordinates of such a connecting lineTo segment match the ending coordinates of a currently open subpath then the segment is omitted as superfluous. The winding rule of the specified Iterator is ignored and the appended geometry is governed by the winding rule specified for this path.
      Parameters:
      pi - the Iterator whose geometry is appended to this path
      connect - 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
      Since:
      1.6
    • transform

      public final void transform(AffineTransform at)
      Transforms the geometry of this path using the specified AffineTransform. The geometry is transformed in place, which permanently changes the boundary defined by this object.
      Parameters:
      at - the AffineTransform used to transform the area
      Since:
      1.6
    • translate

      public void translate(double dx, double dy)
      Translate path.
      Parameters:
      dx - shift path horizontally by dx
      dy - shift path vertically by dy
    • getBounds2D

      public final Rectangle2D getBounds2D()
      Returns a high precision and more accurate bounding box of the Path2D than the getBounds method. Note that there is no guarantee that the returned Rectangle2D is the smallest bounding box that encloses the Path2D, only that the Path2D lies entirely within the indicated Rectangle2D. The bounding box returned by this method is usually tighter than that returned by the getBounds method and never fails due to overflow problems since the return value can be an instance of the Rectangle2D that uses double precision values to store the dimensions.
      Returns:
      an instance of Rectangle2D that is a high-precision bounding box of the Path2D.
      Since:
      1.6
      Implementation Notes:
      getBounds() is not implemented
    • getPathIterator

      public final Path2D.Iterator getPathIterator()
      Returns an iterator object that iterates along this path. boundary and provides access to a flattened view of the Path2D outline geometry.

      Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE point types are returned by the iterator.

      Each call to this method returns a fresh PathIterator object that traverses the path independently from any other PathIterator objects in use at the same time.

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

      Returns:
      a new PathIterator that iterates along the path
      Since:
      1.6
    • createPolygon2D

      public static Path2D createPolygon2D(double[] x, double[] y)
      Construct a polygon from array of x- and y coordinates. Essentially replaces java.awt.Polygon.
      Parameters:
      x - array of x-coordinates
      y - array of y-coordinates
      Returns:
      path of polygon
    • closePath

      public final void closePath()
      Closes the current subpath by drawing a straight line back to the coordinates of the last moveTo. If the path is already closed then this method has no effect.
      Since:
      1.6
    • getWindingRule

      public final int getWindingRule()
      Returns the fill style winding rule.
      Returns:
      an integer representing the current winding rule.
      Since:
      1.6
      See Also:
    • 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
      Throws:
      IllegalArgumentException - if rule is not either WIND_EVEN_ODD or WIND_NON_ZERO
      Since:
      1.6
      See Also:
    • getCurrentPoint

      public final Point2D getCurrentPoint()
      Returns the coordinates most recently added to the end of the path as a Point2D object.
      Returns:
      a Point2D object containing the ending coordinates of the path or null if there are no points in the path.
      Since:
      1.6
    • reset

      public final 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.
      Since:
      1.6
    • isEmpty

      public boolean isEmpty()
      Check if the path is empty.
      Returns:
      true if the path is empty
    • toString

      public String toString()
      Overrides:
      toString in class Object