Class SplinePath2D

All Implemented Interfaces:
Shape, Serializable, Cloneable
Direct Known Subclasses:
BasicSplinePath2D

public class SplinePath2D extends Path2D.Double
Path2D with smooth curves connecting sequences of points. This class extends Path2D.Double by using cubic Bézier splines to connect sequences of point. This can be done either by using a constructor (as a convenience) or by using the methods splineTo to add a smooth curve segment or addCycle to add smooth closed path. If splineTo is used, the starting point of the spline is the current point, which is initially set using the Path2D moveTo method. The smooth curves created are cubic Bézier curve segments arranged so that the first and second derivatives of their coordinates with respect to the curves' parameters match (one curve at u = 1 and the other at u = 0). This is equivalent to stating that for the composite curve, the second derivative exits at all points and is continuous.

For a call to splineTo, at the end points, the tangent to the curve points towards its neighbor. As a result, calling splineTo for points p1, p2, p3, p4, followed by a call to splineTo for points p5, p6, p7, p8 is not equivalent to calling splineTo once for points p1, p2, ..., p8: in the former case, the tangent lines can differ on both sides of point p4.

When addCycle is used, there is an implicit call to moveTo for the first point in the array and this point becomes the last point, but otherwise the end points are not treated specially. The usual winding rules apply in determining whether one is inside or outside a shape described by the path. Regardless of whether splineTo, addCycle, or constructor is used, the smoothed paths are simply sequences of calls to at most one initial moveTo method and some number of curveTo methods.

The algorithm is described in an article, "Smooth Bézier Spline Through Prescribed Points" Each segment is a Bézier curve given by

B(u) = (1-u)3P0 + 3(1-u)2uP1 + 3(1-u)u2P2 + t3P3.

For n-1 cubic splines with control points $P0,i P1,i, P1,2 and P3,i, with i in the interval [0, n-1], connecting the "knot" points K0 ... Kn, the P1 control points satisfy the equations

  • 2P1,0 + P1,1 = K0 + 2K1
  • P1,i-1 + 4P1,i + P1,i+1 = 4Ki + 2Ki+1 for i in [1, n-2]
  • 2P1,n-2 + 7P1,n-1 = 8Kn-1 + Kn.
The first and last of these equations make the second derivative of the curve vanish at the end points, whereas the rest make the second derivative at u=1 for a segment match the second derivative at u=0 for the next segment. Alternatively, the first and last equations can optionally be replaced by the equations
  • P1,0 = C1
  • P1,n-1 = 2C2 - Kn
respectively in order to explicitly set the first and/or last intermediate control points to values matching C1 and/or C2. When both C1 and C2 are provided, splines for each are computed and their control points are averaged using a weighted average based on the how close a knot is to each of the control points.

The initial and final control points for each segment are given by

  • P0,i = Ki
  • P3,i = Ki+1
with both defined for i in the interval [0, n-1], so that each segment starts and ends at a knot. The P2 control point is given by the equations
  • P2,i = 2Ki+1 - P1,i+1 for i in [0,n-2].
  • P2,n-1 = (Kn + P1,n-1)/2.
There is a typo in the article cited above giving the wrong value for the second control point P2,i for i in [0,n-2].

For a closed paths, a case not covered in the article cited above, the equation for P1 are given by

  • P1,n + 4P1,0 + P1,i+1 = 4Ki + 2Ki+1
  • P1,i-1 + 4P1,i + P1,i+1 = 4Ki + 2Ki+1 for i in [1, n-1]
  • P1,n-1 + 4P1,n + P1,0 = 4Kn + 2K0
The other control points for closed paths are given by
  • P0,i = Ki for i in [0,n]
  • P2,i = 2Ki+1 - P1,i+1 for i in [0, n-1]
  • P2,n = 2K0 - P1,0
  • P3,i = Ki+1 for i in [0, n-1].
  • P3,n = K0.
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.awt.geom.Path2D

    Path2D.Double, Path2D.Float
  • Field Summary

    Fields inherited from class java.awt.geom.Path2D

    WIND_EVEN_ODD, WIND_NON_ZERO
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new empty SplinePath2D object with a default winding rule of WIND_NON_ZERO.
    SplinePath2D(double[] x, double[] y, boolean closed)
    Constructs a new SplinePath2D object from arrays of x and y coordinates given a default winding rule of WIND_NON_ZERO.
    SplinePath2D(double[] x, double[] y, int n, boolean closed)
    Constructs a new SplinePath2D object from arrays containing at least n x and y coordinates given a default winding rule of WIND_NON_ZERO.
    SplinePath2D(int rule)
    Constructs a new empty SplinePath2D object with the specified winding rule to control operations that require the interior of the path to be defined.
    SplinePath2D(int rule, double[] x, double[] y, boolean closed)
    Constructs a new SplinePath2D object from arrays of x and y coordinates and specifying a winding rule.
    SplinePath2D(int rule, double[] x, double[] y, int n, boolean closed)
    Constructs a new SplinePath2D object from arrays containing at least n x and y coordinates and specifying a winding rule.
    SplinePath2D(int rule, int initialCapacity)
    Constructs a new empty SplinePath2D object with the specified winding rule and the specified initial capacity to store path segments.
    SplinePath2D(int rule, int initialCapacity, double[] x, double[] y, boolean closed)
    Constructs a new SplinePath2D object from arrays containing at least n x and y coordinates with the specified winding rule and initial capacity for storing segments.
    SplinePath2D(int rule, int initialCapacity, double[] x, double[] y, int n, boolean closed)
    Constructs a new SplinePath2D object from arrays containing at least n x and y coordinates with the specified winding rule and initial capacity for storing segments.
    SplinePath2D(int rule, int initialCapacity, Point2D[] pk, boolean closed)
    Constructs a new SplinePath2D object from an array of points, given a winding rule and initial capacity.
    SplinePath2D(int rule, int initialCapacity, Point2D[] pk, int n, boolean closed)
    Constructs a new SplinePath2D object from an array containing at least n points, given a winding rule and initial capacity.
    SplinePath2D(int rule, int initialCapacity, Point2D[] pk, int n, Point2D cpoint1, Point2D cpoint2)
    Constructs a new SplinePath2D object from an array containing at least n points, given a winding rule, initial capacity, and two control points.
    SplinePath2D(int rule, int initialCapacity, Point2D[] pk, Point2D cpoint1, Point2D cpoint2)
    Constructs a new SplinePath2D object from an array of points, given a winding rule, initial capacity, and two control points.
    SplinePath2D(int rule, int initialCapacity, CubicSpline xf, CubicSpline yf, boolean closed)
    Constructs a new SplinePath2D object given cubic splines specifying the x and y coordinates, a winding rule, and an initial capacity.
    SplinePath2D(int rule, int initialCapacity, RealValuedFunctOps xf, RealValuedFunctOps yf, double t1, double t2, int n, boolean closed)
    Constructs a new SplinePath2D object from functions giving x and y coordinates with the specified winding rule and initial capacity for storing segments.
    SplinePath2D(int rule, Point2D[] pk, boolean closed)
    Constructs a new SplinePath2D object from an array of points, given a winding rule.
    SplinePath2D(int rule, Point2D[] pk, int n, boolean closed)
    Constructs a new SplinePath2D object from an array containing at least n points, given a winding rule.
    SplinePath2D(int rule, Point2D[] pk, int offset, int n, boolean closed)
    Constructs a new SplinePath2D object from an array containing at least n points, given an offset into the array and given a winding rule.
    SplinePath2D(int rule, Point2D[] pk, int offset, int n, Point2D cpoint1, Point2D cpoint2)
    Constructs a new SplinePath2D object from an array containing at least n points, given an offset into the array and given a winding rule.
    SplinePath2D(int rule, Point2D[] pk, int n, Point2D cpoint1, Point2D cpoint2)
    Constructs a new SplinePath2D object from an array containing at least n points, given a winding rule and two control points.
    SplinePath2D(int rule, Point2D[] pk, Point2D cpoint1, Point2D cpoint2)
    Constructs a new SplinePath2D object from an array of points, given a winding rule and initial and final control points.
    SplinePath2D(int rule, CubicSpline xf, CubicSpline yf, boolean closed)
    Constructs a new SplinePath2D object given cubic splines specifying the x and y coordinates and a winding rule.
    SplinePath2D(int rule, RealValuedFunctOps xf, RealValuedFunctOps yf, double t1, double t2, int n, boolean closed)
    Constructs a new SplinePath2D object from arrays of x and y coordinates and specifying a winding rule.
    SplinePath2D(Point2D[] pk, boolean closed)
    Constructs a new SplinePath2D object from an array of points, given a default winding rule of WIND_NON_ZERO.
    SplinePath2D(Point2D[] pk, int n, boolean closed)
    Constructs a new SplinePath2D object from an array containing at least n points, given a default winding rule of WIND_NON_ZERO.
    SplinePath2D(Point2D[] pk, int offset, int n, boolean closed)
    Constructs a new SplinePath2D object from an array containing at least n points, starting at an offset and given a default winding rule of WIND_NON_ZERO.
    SplinePath2D(Point2D[] pk, int offset, int n, Point2D cpoint1, Point2D cpoint2)
    Constructs a new SplinePath2D object from an array containing at least n points, starting at an offset and given a default winding rule of WIND_NON_ZERO with two control points.
    SplinePath2D(Point2D[] pk, int n, Point2D cpoint1, Point2D cpoint2)
    Constructs a new SplinePath2D object from an array containing at least n points, given a default winding rule of WIND_NON_ZERO and two control points.
    SplinePath2D(Point2D[] pk, Point2D cpoint1, Point2D cpoint2)
    Constructs a new SplinePath2D object from an array of points, given a default winding rule of WIND_NON_ZERO and initial and final control points.
    Constructs a new SplinePath2D object from an arbitrary Shape object.
    Constructs a new SplinePath2D object from an arbitrary Shape object, transformed by an AffineTransform object.
    SplinePath2D(CubicSpline xf, CubicSpline yf, boolean closed)
    Constructs a new SplinePath2D object given cubic splines specifying the x and y coordinates and given a default winding rule of WIND_NON_ZERO.
    SplinePath2D(RealValuedFunctOps xf, RealValuedFunctOps yf, double t1, double t2, int n, boolean closed)
    Constructs a new SplinePath2D object given functions specifying the x and y coordinates and given a default winding rule of WIND_NON_ZERO.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addCycle(double[] x, double[] y)
    Add a sequence of segments that form a spline, specified as arrays of x and y coordinates, forming a closed path starting at index 0.
    void
    addCycle(double[] x, double[] y, int n)
    Add a sequence of segments that form a spline, specified as arrays of at least n x and y coordinates, forming a closed path starting at index 0.
    void
    addCycle(Point2D... points)
    Add a sequence of segments that form a spline, specified as Point2D arguments to the addCycle method, and forming a closed path starting at index 0.
    void
    addCycle(Point2D[] pk, int n)
    Add a sequence of segments that form a spline, specified as an array of at least n points, forming a closed path starting at index 0.
    void
    append(CubicSpline xf, CubicSpline yf, boolean connect)
    Append a spline to this path.
    void
    cycleTo(double[] x, double[] y)
    Add a sequence of segments that form a spline, specified as arrays of x and y coordinates, forming a smooth closed path.
    void
    cycleTo(double[] x, double[] y, int n)
    Add a sequence of segments that form a spline, specified as arrays of at least n x and y coordinates, forming a smooth closed path.
    void
    cycleTo(Point2D... points)
    Add a sequence of segments that form a spline, specified as Point2D arguments to the cycleTo method, and forming a smooth closed path.
    void
    cycleTo(Point2D[] pk, int n)
    Add a sequence of segments that form a spline, specified as an array of points, forming a smooth closed path.
    void
    cycleTo(RealValuedFunctOps xf, RealValuedFunctOps yf, double t1, double t2, int n)
    Add a sequence of segments that form a spline, specified as functions giving the x and y coordinates of points along the path and forming a smooth closed path.
    void
    splineTo(double[] x, double[] y)
    Add a sequence of segments that form a spline, specified as arrays of x and y coordinates.
    void
    splineTo(double[] x, double[] y, int n)
    Add a sequence of segments that form a spline, specified as arrays of at least n x and y coordinates.
    void
    splineTo(double[] x, double[] y, int n, Point2D cpoint1, Point2D cpoint2)
    Add a sequence of segments that form a spline, specified as arrays of at least n x and y coordinates, with initial and final control points.
    void
    splineTo(Point2D... points)
    Add a sequence of segments that form a spline, specified as arguments passed to the splineTo method.
    void
    splineTo(Point2D[] pk, int n)
    Add a sequence of segments that form a spline, specified as an array of points.
    void
    splineTo(Point2D[] pk, int offset, int n)
    Add a sequence of segments that form a spline, specified as an array of points with an offset.
    void
    splineTo(Point2D[] pk, int offset, int n, Point2D cpoint1, Point2D cpoint2)
    Add a sequence of segments that form a spline, specified as an array of points with an offset.
    void
    splineTo(Point2D[] pk, int n, Point2D cpoint1, Point2D cpoint2)
    Add a sequence of segments that form a spline, specified as an array of points, with initial and final control points.
    void
    splineTo(RealValuedFunctOps xf, RealValuedFunctOps yf, double t1, double t2, int n)
    Add a sequence of segments that form a spline, specified as functions giving the x and y coordinates.

    Methods inherited from class java.awt.geom.Path2D.Double

    append, clone, curveTo, getBounds2D, getPathIterator, lineTo, moveTo, quadTo, transform, trimToSize

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SplinePath2D

      public SplinePath2D()
      Constructs a new empty SplinePath2D object with a default winding rule of WIND_NON_ZERO.
    • SplinePath2D

      public SplinePath2D(int rule)
      Constructs a new empty SplinePath2D object with the specified winding rule to control operations that require the interior of the path to be defined.
      Parameters:
      rule - the winding rule (WIND_EVEN_ODD or WIND_NON_ZERO)
      See Also:
    • SplinePath2D

      public SplinePath2D(int rule, int initialCapacity)
      Constructs a new empty SplinePath2D object with the specified winding rule and the specified initial capacity to store path segments.
      Parameters:
      rule - the winding rule (WIND_EVEN_ODD or WIND_NON_ZERO)
      initialCapacity - an estimate for the number of path segments in the path
      See Also:
    • SplinePath2D

      public SplinePath2D(Shape s)
      Constructs a new SplinePath2D object from an arbitrary Shape object.
      Parameters:
      s - the specified Shape object
    • SplinePath2D

      public SplinePath2D(Shape s, AffineTransform at)
      Constructs a new SplinePath2D object from an arbitrary Shape object, transformed by an AffineTransform object.
      Parameters:
      s - the specified Shape object
      at - the specified AffineTransform object
    • SplinePath2D

      public SplinePath2D(Point2D[] pk, int n, boolean closed)
      Constructs a new SplinePath2D object from an array containing at least n points, given a default winding rule of WIND_NON_ZERO. The array specifies the "knots" of the spline - the points the spline is constrained to pass through.
      Parameters:
      pk - the array of points that make up the knots of a spline
      n - the number of points in the array to use, with valid indices in the range [0, n)
      closed - true if the spline forms a closed path; false otherwise
    • SplinePath2D

      public SplinePath2D(Point2D[] pk, int n, Point2D cpoint1, Point2D cpoint2)
      Constructs a new SplinePath2D object from an array containing at least n points, given a default winding rule of WIND_NON_ZERO and two control points. The array specifies the "knots" of the spline - the points the spline is constrained to pass through.
      Parameters:
      pk - the array of points that make up the knots of a spline
      n - the number of points in the array to use, with valid indices in the range [0, n)
      cpoint1 - the control point just after the start of the path
      cpoint2 - the control point just before the end of the path
    • SplinePath2D

      public SplinePath2D(Point2D[] pk, int offset, int n, boolean closed)
      Constructs a new SplinePath2D object from an array containing at least n points, starting at an offset and given a default winding rule of WIND_NON_ZERO. The array specifies the "knots" of the spline - the points the spline is constrained to pass through.
      Parameters:
      pk - the array of points that contain the knots of a spline
      offset - the offset into the array for the starting knot
      n - the number of points in the array to use, with valid indices in the range [offset, offset+n)
      closed - true if the spline forms a closed path; false otherwise
    • SplinePath2D

      public SplinePath2D(Point2D[] pk, int offset, int n, Point2D cpoint1, Point2D cpoint2)
      Constructs a new SplinePath2D object from an array containing at least n points, starting at an offset and given a default winding rule of WIND_NON_ZERO with two control points. The array specifies the "knots" of the spline - the points the spline is constrained to pass through.
      Parameters:
      pk - the array of points that contain the knots of a spline
      offset - the offset into the array for the starting knot
      n - the number of points in the array to use, with valid indices in the range [offset, offset+n)
      cpoint1 - the control point just after the start of the path
      cpoint2 - the control point just before the end of the path
    • SplinePath2D

      public SplinePath2D(Point2D[] pk, boolean closed)
      Constructs a new SplinePath2D object from an array of points, given a default winding rule of WIND_NON_ZERO. The array specifies the "knots" of the spline - the points the spline is constrained to pass through. When closed, the initial point should not be repeated by the final point.
      Parameters:
      pk - the array of points that make up the knots of a spline
      closed - true if the spline forms a closed path; false otherwise
    • SplinePath2D

      public SplinePath2D(Point2D[] pk, Point2D cpoint1, Point2D cpoint2)
      Constructs a new SplinePath2D object from an array of points, given a default winding rule of WIND_NON_ZERO and initial and final control points. The array specifies the "knots" of the spline - the points the spline is constrained to pass through. When closed, the initial point should not be repeated by the final point.
      Parameters:
      pk - the array of points that make up the knots of a spline
      cpoint1 - the control point just after the start of the path
      cpoint2 - the control point just before the end of the path
    • SplinePath2D

      public SplinePath2D(int rule, Point2D[] pk, int n, boolean closed)
      Constructs a new SplinePath2D object from an array containing at least n points, given a winding rule. The array specifies the "knots" of the spline - the points the spline is constrained to pass through. When closed, the initial point should not be repeated by the final point.
      Parameters:
      rule - the winding rule (WIND_EVEN_ODD or WIND_NON_ZERO)
      pk - the array of points that make up the knots of a spline
      n - the number of points in the array to use, with valid indices in the range [0, n)
      closed - true if the spline forms a closed path; false otherwise
      See Also:
    • SplinePath2D

      public SplinePath2D(int rule, Point2D[] pk, int n, Point2D cpoint1, Point2D cpoint2)
      Constructs a new SplinePath2D object from an array containing at least n points, given a winding rule and two control points. The array specifies the "knots" of the spline - the points the spline is constrained to pass through. When closed, the initial point should not be repeated by the final point.
      Parameters:
      rule - the winding rule (WIND_EVEN_ODD or WIND_NON_ZERO)
      pk - the array of points that make up the knots of a spline
      n - the number of points in the array to use, with valid indices in the range [0, n)
      cpoint1 - the control point just after the start of the path
      cpoint2 - the control point just before the end of the path
      See Also:
    • SplinePath2D

      public SplinePath2D(int rule, Point2D[] pk, int offset, int n, boolean closed)
      Constructs a new SplinePath2D object from an array containing at least n points, given an offset into the array and given a winding rule. The array specifies the "knots" of the spline - the points the spline is constrained to pass through. When closed, the initial point should not be repeated by the final point.
      Parameters:
      rule - the winding rule (WIND_EVEN_ODD or WIND_NON_ZERO)
      pk - the array of points that make up the knots of a spline
      offset - the staring index int the array for the spline's knots
      n - the number of points in the array to use, with valid indices in the range [offset, offset+n)
      closed - true if the spline forms a closed path; false otherwise
      See Also:
    • SplinePath2D

      public SplinePath2D(int rule, Point2D[] pk, int offset, int n, Point2D cpoint1, Point2D cpoint2)
      Constructs a new SplinePath2D object from an array containing at least n points, given an offset into the array and given a winding rule. The array specifies the "knots" of the spline - the points the spline is constrained to pass through. When closed, the initial point should not be repeated by the final point.
      Parameters:
      rule - the winding rule (WIND_EVEN_ODD or WIND_NON_ZERO)
      pk - the array of points that make up the knots of a spline
      offset - the staring index int the array for the spline's knots
      n - the number of points in the array to use, with valid indices in the range [offset, offset+n)
      cpoint1 - the control point just after the start of the path
      cpoint2 - the control point just before the end of the path
      See Also:
    • SplinePath2D

      public SplinePath2D(int rule, Point2D[] pk, boolean closed)
      Constructs a new SplinePath2D object from an array of points, given a winding rule. The array specifies the "knots" of the spline - the points the spline is constrained to pass through. When closed, the initial point should not be repeated by the final point.
      Parameters:
      rule - the winding rule (WIND_EVEN_ODD or WIND_NON_ZERO)
      pk - the array of points that make up the knots of a spline
      closed - true if the spline forms a closed path; false otherwise
      See Also:
    • SplinePath2D

      public SplinePath2D(int rule, Point2D[] pk, Point2D cpoint1, Point2D cpoint2)
      Constructs a new SplinePath2D object from an array of points, given a winding rule and initial and final control points. The array specifies the "knots" of the spline - the points the spline is constrained to pass through. When closed, the initial point should not be repeated by the final point.
      Parameters:
      rule - the winding rule (WIND_EVEN_ODD or WIND_NON_ZERO)
      pk - the array of points that make up the knots of a spline
      cpoint1 - the control point just after the start of the path
      cpoint2 - the control point just before the end of the path
      See Also:
    • SplinePath2D

      public SplinePath2D(int rule, int initialCapacity, Point2D[] pk, int n, boolean closed)
      Constructs a new SplinePath2D object from an array containing at least n points, given a winding rule and initial capacity. The array specifies the "knots" of the spline - the points the spline is constrained to pass through. When closed, the initial point should not be repeated by the final point.
      Parameters:
      rule - the winding rule (WIND_EVEN_ODD or WIND_NON_ZERO)
      initialCapacity - an estimate for the number of path segments in the path
      pk - the array of points that make up the knots of a spline
      n - the number of points in the array to use, with valid indices in the range [0, n)
      closed - true if the spline forms a closed path; false otherwise
      See Also:
    • SplinePath2D

      public SplinePath2D(int rule, int initialCapacity, Point2D[] pk, int n, Point2D cpoint1, Point2D cpoint2)
      Constructs a new SplinePath2D object from an array containing at least n points, given a winding rule, initial capacity, and two control points. The array specifies the "knots" of the spline - the points the spline is constrained to pass through. When closed, the initial point should not be repeated by the final point.
      Parameters:
      rule - the winding rule (WIND_EVEN_ODD or WIND_NON_ZERO)
      initialCapacity - an estimate for the number of path segments in the path
      pk - the array of points that make up the knots of a spline
      n - the number of points in the array to use, with valid indices in the range [0, n)
      cpoint1 - the control point just after the start of the path
      cpoint2 - the control point just before the end of the path
      See Also:
    • SplinePath2D

      public SplinePath2D(int rule, int initialCapacity, Point2D[] pk, boolean closed)
      Constructs a new SplinePath2D object from an array of points, given a winding rule and initial capacity. The array specifies the "knots" of the spline - the points the spline is constrained to pass through. When closed, the initial point should not be repeated by the final point.
      Parameters:
      rule - the winding rule (WIND_EVEN_ODD or WIND_NON_ZERO)
      initialCapacity - an estimate for the number of path segments in the path
      pk - the array of points that make up the knots of a spline
      closed - true if the spline forms a closed path; false otherwise
      See Also:
    • SplinePath2D

      public SplinePath2D(int rule, int initialCapacity, Point2D[] pk, Point2D cpoint1, Point2D cpoint2)
      Constructs a new SplinePath2D object from an array of points, given a winding rule, initial capacity, and two control points. The array specifies the "knots" of the spline - the points the spline is constrained to pass through. When closed, the initial point should not be repeated by the final point.
      Parameters:
      rule - the winding rule (WIND_EVEN_ODD or WIND_NON_ZERO)
      initialCapacity - an estimate for the number of path segments in the path
      pk - the array of points that make up the knots of a spline
      cpoint1 - the control point just after the start of the path
      cpoint2 - the control point just before the end of the path
      See Also:
    • SplinePath2D

      public SplinePath2D(double[] x, double[] y, int n, boolean closed)
      Constructs a new SplinePath2D object from arrays containing at least n x and y coordinates given a default winding rule of WIND_NON_ZERO. The array specifies the "knots" of the spline - the points the spline is constrained to pass through. When closed, the initial point should not be repeated by the final point.
      Parameters:
      x - the x coordinates to use, one for each knot
      y - the y coordinates to use, one for each knot
      n - the number of points in the array to use, with valid indices in the range [0, n)
      closed - true if the spline forms a closed path; false otherwise
    • SplinePath2D

      public SplinePath2D(CubicSpline xf, CubicSpline yf, boolean closed) throws IllegalArgumentException
      Constructs a new SplinePath2D object given cubic splines specifying the x and y coordinates and given a default winding rule of WIND_NON_ZERO. The spline must be created with the same number of "knots". The argument to each function will be rescaled so that it will be incremented by 1.0 when moving from one knot to the next. If closed is true and the initial knot is not at the same location as the final knot, a straight line segment will be used to close the path.

      This constructor is provided to support cases where the default algorithm for creating a spline is not appropriate: the class CubicSpline allows one to specify a number of types of splines, with most differing in how the ends are treated, but with one case (A Hermite spline) explicitly giving the derivative at each knot.

      Parameters:
      xf - the spline specifying the x coordinates to use
      yf - the spline specifying the y coordinates to use
      closed - true if the spline forms a closed path; false otherwise
      Throws:
      IllegalArgumentException - the splines xf and yf did not have the same number of knots
    • SplinePath2D

      public SplinePath2D(int rule, CubicSpline xf, CubicSpline yf, boolean closed) throws IllegalArgumentException
      Constructs a new SplinePath2D object given cubic splines specifying the x and y coordinates and a winding rule. The splines must be created with the same number of "knots". The argument to each spline will be rescaled so that it will be incremented by 1.0 when moving from one knot to the next. If closed is true and the initial knot is not at the same location as the final knot, a straight line segment will be used to close the path.

      This constructor is provided to support cases where the default algorithm for creating a spline is not appropriate: the class CubicSpline allows one to specify a number of types of splines, with most differing in how the ends are treated, but with one case (A Hermite spline) explicitly giving the derivative at each knot.

      Parameters:
      rule - the winding rule (WIND_EVEN_ODD or WIND_NON_ZERO)
      xf - the spline specifying the x coordinates to use
      yf - the spline specifying the y coordinates to use
      closed - true if the spline forms a closed path; false otherwise
      Throws:
      IllegalArgumentException - the splines xf and yf did not have the same number of knots
    • SplinePath2D

      public SplinePath2D(int rule, int initialCapacity, CubicSpline xf, CubicSpline yf, boolean closed) throws IllegalArgumentException
      Constructs a new SplinePath2D object given cubic splines specifying the x and y coordinates, a winding rule, and an initial capacity. The splines must be created with the same number of "knots". The argument to each spline will be rescaled so that it will be incremented by 1.0 when moving from one knot to the next. The path will be constructed using the control points associated with the cubic splines providing the x and y coordinates. If closed is true and the initial knot is not at the same location as the final knot, a straight line segment will be used to close the path.

      This constructor is provided to support cases where the default algorithm for creating a spline is not appropriate: the class CubicSpline allows one to specify a number of types of splines, with most differing in how the ends are treated, but with one case (A Hermite spline) explicitly giving the derivative at each knot.

      Parameters:
      rule - the winding rule (WIND_EVEN_ODD or WIND_NON_ZERO)
      initialCapacity - an estimate for the number of path segments in the path
      xf - the spline specifying the x coordinates to use
      yf - the spline specifying the y coordinates to use
      closed - true if the spline forms a closed path; false otherwise
      Throws:
      IllegalArgumentException - the splines xf and yf did not have the same number of knots
    • SplinePath2D

      public SplinePath2D(RealValuedFunctOps xf, RealValuedFunctOps yf, double t1, double t2, int n, boolean closed) throws IllegalArgumentException
      Constructs a new SplinePath2D object given functions specifying the x and y coordinates and given a default winding rule of WIND_NON_ZERO. When closed, the initial point should not be repeated by the final point.
      Parameters:
      xf - the function specifying the x coordinates to use
      yf - the function specifying the y coordinates to use
      t1 - an end point for the domain of the argument of xf and yf
      t2 - the other end point for the domain of the argument of xf and yf
      n - the number of segments between the points at which to evaluate the functions
      closed - true if the spline forms a closed path; false otherwise
      Throws:
      IllegalArgumentException - the arguments were illegal, typically because n was not positive or either t1 or t2 were not in the domain of xf or yf.
    • SplinePath2D

      public SplinePath2D(double[] x, double[] y, boolean closed)
      Constructs a new SplinePath2D object from arrays of x and y coordinates given a default winding rule of WIND_NON_ZERO. The array specifies the "knots" of the spline - the points the spline is constrained to pass through. When closed, the initial point should not be repeated by the final point.
      Parameters:
      x - the x coordinates to use, one for each knot
      y - the y coordinates to use, one for each knot
      closed - true if the spline forms a closed path; false otherwise
      Throws:
      IllegalArgumentException - the arguments were illegal, typically because the lengths of the arrays differ
    • SplinePath2D

      public SplinePath2D(int rule, double[] x, double[] y, int n, boolean closed)
      Constructs a new SplinePath2D object from arrays containing at least n x and y coordinates and specifying a winding rule. The array specifies the "knots" of the spline - the points the spline is constrained to pass through. When closed, the initial point should not be repeated by the final point.
      Parameters:
      rule - the winding rule (WIND_EVEN_ODD or WIND_NON_ZERO)
      x - the x coordinates to use, one for each knot
      y - the y coordinates to use, one for each knot
      n - the number of points in the array to use, with valid indices in the range [0, n)
      closed - true if the spline forms a closed path; false otherwise
      See Also:
    • SplinePath2D

      public SplinePath2D(int rule, double[] x, double[] y, boolean closed)
      Constructs a new SplinePath2D object from arrays of x and y coordinates and specifying a winding rule. The array specifies the "knots" of the spline - the points the spline is constrained to pass through. When closed, the initial point should not be repeated by the final point.
      Parameters:
      rule - the winding rule
      x - the x coordinates to use, one for each knot
      y - the y coordinates to use, one for each knot
      closed - true if the spline forms a closed path; false otherwise
      Throws:
      IllegalArgumentException - the arguments were illegal, typically because the lengths of the arrays differ
      See Also:
    • SplinePath2D

      public SplinePath2D(int rule, int initialCapacity, double[] x, double[] y, int n, boolean closed)
      Constructs a new SplinePath2D object from arrays containing at least n x and y coordinates with the specified winding rule and initial capacity for storing segments. The arrays specify the x and y coordinates of the "knots" of the spline - the points the spline is constrained to pass through. When closed, the initial point should not be repeated by the final point.
      Parameters:
      rule - the winding rule (WIND_EVEN_ODD or WIND_NON_ZERO)
      initialCapacity - an estimate for the number of path segments in the path
      x - the x coordinates to use, one for each knot
      y - the y coordinates to use, one for each knot
      n - the number of points in the array to use, with valid indices in the range [0, n)
      closed - true if the spline forms a closed path; false otherwise
      See Also:
    • SplinePath2D

      public SplinePath2D(int rule, RealValuedFunctOps xf, RealValuedFunctOps yf, double t1, double t2, int n, boolean closed) throws IllegalArgumentException
      Constructs a new SplinePath2D object from arrays of x and y coordinates and specifying a winding rule. The array specifies the "knots" of the spline - the points the spline is constrained to pass through. When closed, the initial point should not be repeated by the final point.
      Parameters:
      rule - the winding rule (WIND_EVEN_ODD or WIND_NON_ZERO)
      xf - the function specifying the x coordinates to use
      yf - the function specifying the y coordinates to use
      t1 - an end point for the domain of the argument of xf and yf
      t2 - the other end point for the domain of the argument of xf and yf
      n - the number of segments between the points at which to evaluate the functions
      closed - true if the spline forms a closed path; false otherwise
      Throws:
      IllegalArgumentException - the arguments were illegal, typically because n was not positive or either t1 or t2 were not in the domain of xf or yf.
      See Also:
    • SplinePath2D

      public SplinePath2D(int rule, int initialCapacity, RealValuedFunctOps xf, RealValuedFunctOps yf, double t1, double t2, int n, boolean closed) throws IllegalArgumentException
      Constructs a new SplinePath2D object from functions giving x and y coordinates with the specified winding rule and initial capacity for storing segments. When closed, the initial point should not be repeated by the final point.
      Parameters:
      rule - the winding rule (WIND_EVEN_ODD or WIND_NON_ZERO)
      initialCapacity - an estimate for the number of path segments in the path
      xf - the function specifying the x coordinates to use
      yf - the function specifying the y coordinates to use
      t1 - an end point for the domain of the argument of xf and yf
      t2 - the other end point for the domain of the argument of xf and yf
      n - the number of segments between the points at which to evaluate the functions
      closed - true if the spline forms a closed path; false otherwise
      Throws:
      IllegalArgumentException - the arguments were illegal, typically because n was not positive or either t1 or t2 were not in the domain of xf or yf.
      See Also:
    • SplinePath2D

      public SplinePath2D(int rule, int initialCapacity, double[] x, double[] y, boolean closed)
      Constructs a new SplinePath2D object from arrays containing at least n x and y coordinates with the specified winding rule and initial capacity for storing segments. The arrays specify the x and y coordinates of the "knots" of the spline - the points the spline is constrained to pass through. When closed, the initial point should not be repeated by the final point.
      Parameters:
      rule - the winding rule (WIND_EVEN_ODD or WIND_NON_ZERO)
      initialCapacity - an estimate for the number of path segments in the path
      x - the x coordinates to use, one for each knot
      y - the y coordinates to use, one for each knot
      closed - true if the spline forms a closed path; false otherwise
      Throws:
      IllegalArgumentException - the arguments were illegal, typically because the lengths of the arrays differ
      See Also:
  • Method Details

    • splineTo

      public void splineTo(Point2D[] pk, int n)
      Add a sequence of segments that form a spline, specified as an array of points. The array specifies the "knots" of the spline - the points the spline is constrained to pass through - and the spline will have matching first and second derivatives at intermediate points. At the end points, the direction of the tangent line points towards the adjacent knot. The initial point is the one previously added to the path via some other method (e.g., moveTo, lineTo, etc.).
      Parameters:
      pk - the array of points that make up the knots of a spline
      n - the number of points in the array to use, with valid indices in the range [0, n)
    • splineTo

      public void splineTo(Point2D[] pk, int n, Point2D cpoint1, Point2D cpoint2)
      Add a sequence of segments that form a spline, specified as an array of points, with initial and final control points. The array specifies the "knots" of the spline - the points the spline is constrained to pass through - and the spline will have matching first and second derivatives at intermediate points. At the end points, the direction of the tangent line points towards the adjacent knot. The initial point is the one previously added to the path via some other method (e.g., moveTo, lineTo, etc.).
      Parameters:
      pk - the array of points that make up the knots of a spline
      n - the number of points in the array to use, with valid indices in the range [0, n)
      cpoint1 - the control point just after the start of the spline
      cpoint2 - the control point just before the end of the spline
    • splineTo

      public void splineTo(Point2D[] pk, int offset, int n)
      Add a sequence of segments that form a spline, specified as an array of points with an offset. The array specifies the "knots" of the spline - the points the spline is constrained to pass through - and the spline will have matching first and second derivatives at intermediate points. At the end points, the direction of the tangent line points towards the adjacent knot. The initial point is the one previously added to the path via some other method (e.g., moveTo, lineTo, etc.).
      Parameters:
      pk - the array of points that make up the knots of a spline
      offset - the offset into the array for the starting point
      n - the number of points in the array to use, with valid indices in the range [0, n)
    • splineTo

      public void splineTo(Point2D[] pk, int offset, int n, Point2D cpoint1, Point2D cpoint2)
      Add a sequence of segments that form a spline, specified as an array of points with an offset. The array specifies the "knots" of the spline - the points the spline is constrained to pass through - and the spline will have matching first and second derivatives at intermediate points. At the end points, the direction of the tangent line points towards the adjacent knot. The initial point is the one previously added to the path via some other method (e.g., moveTo, lineTo, etc.).
      Parameters:
      pk - the array of points that make up the knots of a spline
      offset - the offset into the array for the starting point
      n - the number of points in the array to use, with valid indices in the range [0, n)
      cpoint1 - the control point just after the start of the spline
      cpoint2 - the control point just before the end of the spline
    • splineTo

      public void splineTo(Point2D... points)
      Add a sequence of segments that form a spline, specified as arguments passed to the splineTo method. The arguments specifies the "knots" of the spline - the points the spline is constrained to pass through - and the spline will have matching first and second derivatives at intermediate points. At the end points, the direction of the tangent line points towards the adjacent knot. The initial point is the one previously added to the path via some other method (e.g., moveTo, lineTo, etc.).
      Parameters:
      points - the array of points that make up the knots of a spline
    • splineTo

      public void splineTo(double[] x, double[] y, int n)
      Add a sequence of segments that form a spline, specified as arrays of at least n x and y coordinates. The arrays specify the "knots" of the spline - the points the spline is constrained to pass through - and the spline will have matching first and second derivatives at intermediate points. At the end points, the direction of the tangent line points towards the adjacent knot. The initial point is the one previously added to the path via some other method (e.g., moveTo, lineTo, etc.).
      Parameters:
      x - the x coordinates to use, one for each knot
      y - the y coordinates to use, one for each knot
      n - the number of points in the array to use, with valid indices in the range [0, n)
    • splineTo

      public void splineTo(double[] x, double[] y, int n, Point2D cpoint1, Point2D cpoint2)
      Add a sequence of segments that form a spline, specified as arrays of at least n x and y coordinates, with initial and final control points. The arrays specify the "knots" of the spline - the points the spline is constrained to pass through - and the spline will have matching first and second derivatives at intermediate points. At the end points, the direction of the tangent line points towards the adjacent knot. The initial point is the one previously added to the path via some other method (e.g., moveTo, lineTo, etc.).
      Parameters:
      x - the x coordinates to use, one for each knot
      y - the y coordinates to use, one for each knot
      n - the number of points in the array to use, with valid indices in the range [0, n)
      cpoint1 - the control point just after the start of the spline
      cpoint2 - the control point just before the end of the spline
    • splineTo

      public void splineTo(double[] x, double[] y)
      Add a sequence of segments that form a spline, specified as arrays of x and y coordinates. The arrays specify the "knots" of the spline - the points the spline is constrained to pass through - and the spline will have matching first and second derivatives at intermediate points. At the end points, the direction of the tangent line points towards the adjacent knot. The initial point is the one previously added to the path via some other method (e.g., moveTo, lineTo, etc.).
      Parameters:
      x - the x coordinates to use, one for each knot
      y - the y coordinates to use, one for each knot
      Throws:
      IllegalArgumentException - the arguments were illegal, typically because the lengths of the arrays differ
    • splineTo

      public void splineTo(RealValuedFunctOps xf, RealValuedFunctOps yf, double t1, double t2, int n) throws IllegalArgumentException
      Add a sequence of segments that form a spline, specified as functions giving the x and y coordinates. The "knots" of the spline - the points the spline is constrained to pass through - are at evenly spaced values of the argument passed to the functions, and the spline will have matching first and second derivatives at intermediate points. At the end points, the direction of the tangent line points towards the adjacent knot. The initial point is the one previously added to the path via some other method (e.g., moveTo, lineTo, etc.). The end points at t1 and t2 are included as knots.

      The number of segments is one less than the number of points so that n=2 implies that the function will be evaluated at t1, t2, and (t1 + t2)/2.

      Parameters:
      xf - the function giving the x coordinates for the path segment
      yf - the function giving the y coordinates for the path segment
      t1 - an end point for the domain of the argument of xf and yf
      t2 - the other end point for the domain of the argument of xf and yf
      n - the number of segments between the points at which to evaluate the functions
      Throws:
      IllegalArgumentException - the arguments were illegal, typically because n was not positive or either t1 or t2 were not in the domain of xf or yf.
    • append

      public void append(CubicSpline xf, CubicSpline yf, boolean connect) throws IllegalArgumentException
      Append a spline to this path. The spline is provided by a CubicSpline for the x coordinates and a CubicSpline for the y coordinates.
      Parameters:
      xf - the cubic spline providing the x coordinates
      yf - the cubic spline providing the y coordinates
      connect - true if the appended spline is to be connected to this path with a lineTo operation; false if a moveTo operation will be used instead
      Throws:
      IllegalArgumentException - the splines xf and yf did not have the same number of knots
    • cycleTo

      public void cycleTo(Point2D[] pk, int n)
      Add a sequence of segments that form a spline, specified as an array of points, forming a smooth closed path. The array specifies the "knots" of the spline - the points the spline is constrained to pass through - and the spline will have matching first and second derivatives at all points. The initial point is the one previously added to the path via some other method (e.g., moveTo, lineTo, etc.) and there is an implicit moveTo operation to this point. Element n-1 in the array pk should not repeat this initial point. The implicit moveTo may result in the path containing multiple moveTo segments back to back.
      Parameters:
      pk - the array of points that make up the knots of a spline
      n - the number of points in the array to use, with valid indices in the range [0, n)
    • cycleTo

      public void cycleTo(Point2D... points)
      Add a sequence of segments that form a spline, specified as Point2D arguments to the cycleTo method, and forming a smooth closed path. The points specify the "knots" of the spline - the points the spline is constrained to pass through - and the spline will have matching first and second derivatives at all points. The initial point is the one previously added to the path via some other method (e.g., moveTo, lineTo, etc.). The last argument should not repeat this initial point.
      Parameters:
      points - the points that make up the knots of a spline
    • cycleTo

      public void cycleTo(double[] x, double[] y, int n)
      Add a sequence of segments that form a spline, specified as arrays of at least n x and y coordinates, forming a smooth closed path. The array specifies the "knots" of the spline - the points the spline is constrained to pass through - and the spline will have matching first and second derivatives at all points. The initial point is the one previously added to the path via some other method (e.g., moveTo, lineTo, etc.) and there is an implicit moveTo operation to this point. The point specified by the array index n-1 should not repeat this initial point. The implicit moveTo may result in the path containing multiple moveTo segments back to back.
      Parameters:
      x - the x coordinates to use, one for each knot
      y - the y coordinates to use, one for each knot
      n - the number of points in the array to use, with valid indices in the range [0, n)
    • cycleTo

      public void cycleTo(double[] x, double[] y)
      Add a sequence of segments that form a spline, specified as arrays of x and y coordinates, forming a smooth closed path. The array specifies the "knots" of the spline - the points the spline is constrained to pass through - and the spline will have matching first and second derivatives at all points. The initial point is the one previously added to the path via some other method (e.g., moveTo, lineTo, etc.) and there is an implicit moveTo operation to this point. The point specified by the last elements in the x and y arrays should not repeat this initial point. The implicit moveTo may result in the path containing multiple moveTo segments back to back.
      Parameters:
      x - the x coordinates to use, one for each knot
      y - the y coordinates to use, one for each knot
      Throws:
      IllegalArgumentException - the arguments were illegal, typically because the lengths of the arrays differ
    • cycleTo

      public void cycleTo(RealValuedFunctOps xf, RealValuedFunctOps yf, double t1, double t2, int n) throws IllegalArgumentException
      Add a sequence of segments that form a spline, specified as functions giving the x and y coordinates of points along the path and forming a smooth closed path.

      The "knots" of the spline - the points the spline is constrained to pass through - are are at evenly spaced values of the argument passed to the functions, and the spline will have matching first and second derivatives at all points. The initial point is the one previously added to the path via some other method (e.g., moveTo, lineTo, etc.) and there is an implicit moveTo operation to this point. The end points at t1 and t2 are included as knots. The end point at t2 should not repeat the initial point. The implicit moveTo may result in the path containing multiple moveTo segments back to back.

      The number of segments is one less than the number of points so that n=2 implies that the function will be evaluated at t1, t2, and (t1 + t2)/2.

      Parameters:
      xf - the function giving the x coordinates for the path segment
      yf - the function giving the y coordinates for the path segment
      t1 - an end point for the domain of the argument of xf and yf
      t2 - the other end point for the domain of the argument of xf and yf
      n - the number of segments between points at which to evaluate the functions
      Throws:
      IllegalArgumentException - the arguments were illegal, typically because n was not positive or either t1 or t2 were not in the domain of xf or yf.
    • addCycle

      public void addCycle(Point2D[] pk, int n)
      Add a sequence of segments that form a spline, specified as an array of at least n points, forming a closed path starting at index 0. The array specifies the "knots" of the spline - the points the spline is constrained to pass through - and the spline will have matching first and second derivatives at all points. The initial point is pk[0] and there is an implicit moveTo operation for this point, which should not be repeated as the element at index n-1 of the array provided as this method's first argument.
      Parameters:
      pk - the array of points that make up the knots of a spline
      n - the number of points in the array to use, with valid indices in the range [0, n)
    • addCycle

      public void addCycle(Point2D... points)
      Add a sequence of segments that form a spline, specified as Point2D arguments to the addCycle method, and forming a closed path starting at index 0. The points specify the "knots" of the spline - the points the spline is constrained to pass through - and the spline will have matching first and second derivatives at all points. The initial point is the one specified by the first argument and there is an implicit moveTo operation for this point, which should not be repeated by the last argument.
      Parameters:
      points - the points that make up the knots of a spline
    • addCycle

      public void addCycle(double[] x, double[] y, int n)
      Add a sequence of segments that form a spline, specified as arrays of at least n x and y coordinates, forming a closed path starting at index 0. The array specifies the "knots" of the spline - the points the spline is constrained to pass through - and the spline will have matching first and second derivatives at all points. The initial point is (x[0], y[0]) and there is an implicit moveTo operation for this point, which should not be repeated by the point specified by the array arguments at index n-1.
      Parameters:
      x - the x coordinates to use, one for each knot
      y - the y coordinates to use, one for each knot
      n - the number of points in the array to use, with valid indices in the range [0, n)
    • addCycle

      public void addCycle(double[] x, double[] y)
      Add a sequence of segments that form a spline, specified as arrays of x and y coordinates, forming a closed path starting at index 0. The array specifies the "knots" of the spline - the points the spline is constrained to pass through - and the spline will have matching first and second derivatives at all points. The initial point is (x[0], y[0]) and there is an implicit moveTo operation for this point, which should not be repeated by the point specified by the last arguments of the x and y arrays.
      Parameters:
      x - the x coordinates to use, one for each knot
      y - the y coordinates to use, one for each knot
      Throws:
      IllegalArgumentException - the arguments were illegal, typically because the lengths of the arrays differ