Class PathSplitter

java.lang.Object
org.bzdev.geom.PathSplitter

public class PathSplitter extends Object
Utility class with static methods for splitting paths into subpaths.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static Point2D
    split(double[] first, double[] second, double t, int degree, double x, double y, double[] coords)
    Split a Bézier curve of degree n at a point t∈[0,1].
    static void
    split(int type, double startX, double startY, double[] coords, int offset, double[] scoords, int soffset, double u)
    Split a path segment with 2 dimensions into two parts.
    static void
    split(int type, double startX, double startY, double startZ, double[] coords, int offset, double[] scoords, int soffset, double u)
    Split a path segment with 3 dimensions into two parts.
    static Path2D[]
    split(Path2D path)
    Split a path (2 dimensions).
    static Path2D[]
    Split a path (2 dimensions) with an affine transformation.
    static Path3D[]
    split(Path3D path)
    Split a path (3 dimensions).
    static Path3D[]
    Split a path (3 dimensions) with an affine transformation.
    static Path2D
    subpath(Path2D path, double u1, double u2)
    Get a subpath of a path with 2 dimensions.
    static Path2D
    subpath(Path2D path, int start, double u1, int end, double u2)
    Get a subpath of a path with 2 dimensions, specifying path parameters by a segment index and a path parameter specific to that index.
    static Path3D
    subpath(Path3D path, double u1, double u2)
    Get a subpath of a path with three dimensions.
    static Path3D
    subpath(Path3D path, int start, double u1, int end, double u2)
    Get a subpath of a path with three dimensions, specifying path parameters by a segment index and a path parameter specific to that index.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • split

      public static Path2D[] split(Path2D path)
      Split a path (2 dimensions). The paths end in two ways. If a path-segment's type is PathIterator.SEG_CLOSE, a new path starts, optionally with segment whose type is PathIterator.SEG_MOVETO. If a PathIterator.SEG_MOVETO segment is not preceded by a PathIterator.SEG_CLOSE segment, the PathIterator.SEG_MOVETO segment becomes the first segment in the next path.
      Parameters:
      path - the path to split
      Returns:
      an array of subpaths
    • split

      public static Path2D[] split(Path2D path, AffineTransform at)
      Split a path (2 dimensions) with an affine transformation. The paths end in two ways. If a path-segment's type is PathIterator.SEG_CLOSE, a new path starts, optionally with segment whose type is PathIterator.SEG_MOVETO. If a PathIterator.SEG_MOVETO segment is not preceded by a PathIterator.SEG_CLOSE segment, the PathIterator.SEG_MOVETO segment becomes the first segment in the next path.
      Parameters:
      path - the path to split
      at - the affine transformation to apply to the path's components; null if there is none
      Returns:
      an array of subpaths
    • split

      public static Path3D[] split(Path3D path)
      Split a path (3 dimensions). The paths end in two ways. If a path-segment's type is PathIterator3D.SEG_CLOSE, a new path starts, optionally with segment whose type is PathIterator3D.SEG_MOVETO. If a PathIterator3D.SEG_MOVETO segment is not preceded by a PathIterator3D.SEG_CLOSE segment, the PathIterator3D.SEG_MOVETO segment becomes the first segment in the next path.
      Parameters:
      path - the path to split
      Returns:
      an array of subpaths
    • split

      public static Path3D[] split(Path3D path, AffineTransform3D at)
      Split a path (3 dimensions) with an affine transformation. The paths end in two ways. If a path-segment's type is PathIterator3D.SEG_CLOSE, a new path starts, optionally with segment whose type is PathIterator3D.SEG_MOVETO. If a PathIterator3D.SEG_MOVETO segment is not preceded by a PathIterator3D.SEG_CLOSE segment, the PathIterator3D.SEG_MOVETO segment becomes the first segment in the next path.
      Parameters:
      path - the path to split
      at - the affine transformation to apply to the path's components; null if there is none
      Returns:
      an array of subpaths
    • split

      public static void split(int type, double startX, double startY, double[] coords, int offset, double[] scoords, int soffset, double u)
      Split a path segment with 2 dimensions into two parts. The path parameter u is the fractional distance at which the split occurs, measured from the start of the line segment to its end. The parameter u must be in the range [0,1]. The X, and Y coordinates of each control point are adjacent in the coords array in that order. the 0th control point's coordinates are (startX,startY). The coords array provides the other control points with the first followed by the second. This is the same order used by PathIterator.currentSegment(double[]).

      The scoords argument contains control points from the split curves, denoted as the first curve and second curve. The scoords argument contains the first control point of the first curve, followed by its second and control point if present. This last control point is also the 0th control point of the second curve. The remainder of the scoords array contains the first control point of the second curve followed by the second and control points, if present, of the second curve. For eac control point, the array contains that control point's X coordinate, followed by its Y coordinate. The 0th control point for the original curve is the 0th control point for the first curve and is not copied into the scoords array.

      The minimum length for the coords array is 6 and the minimum length for the scoords array is 12.

      Parameters:
      type - the segment type (PathIterator.SEG_LINETO, PathIterator.SEG_QUADTO, or PathIterator.SEG_CUBICTO)
      startX - the starting X coordinate
      startY - the starting Y coordinate
      coords - an array containing the remaining control points
      offset - the offset for the 1st control point
      scoords - an array containing the control points for a pair of Bézier curves.
      soffset - the offset for the 0th control point of the first cubic B&ecute;zier curve of the pair of curves created
      u - the path parameter at which a curve is to be split
      Throws:
      IllegalArgumentException - a parameter was out of range
    • split

      public static void split(int type, double startX, double startY, double startZ, double[] coords, int offset, double[] scoords, int soffset, double u)
      Split a path segment with 3 dimensions into two parts. The path parameter u is the fractional distance at which the split occurs, measured from the startof the line segment to its end. The parameter u must be in the range [0,1]. The X, Y, and Z coordinates of each control point are adjacent in the coords array in that order. the 0th control point's coordinates are (startX,startY,startZ). The coords array provides the other control points with the first followed by the second. This is the same order used by PathIterator3D.currentSegment(double[]).

      The scoords argument contains control points from the split curves, denoted as the first curve and second curve. The scoords argument contains the first control point of the first curve, followed by its second and third control points if present. The last of these control points is also the 0th control point of the second curve. The remainder of the scoords array contains the first control point of the second curve followed by the second and thir control point of the second curve if present. For each control point, the array contains that control point's X coordinate, followed by its Y coordinate, and finally its Z coordinate. The* 0th control point for the original curve is the 0th control point for the first curve and is not copied into the scoords array.

      The minimum length for the coords array is 9 and the minimum length for the scoords array is 18.

      Parameters:
      type - the segment type (PathIterator3D.SEG_LINETO, PathIterator3D.SEG_QUADTO, or PathIterator3D.SEG_CUBICTO)
      startX - the starting X coordinate
      startY - the starting Y coordinate
      startZ - the starting Z coordinate
      coords - an array containing the remaining control points
      offset - the offset for the 1st control point
      scoords - an array containing the control points for a pair of Bézier curves.
      soffset - the offset for the 0th control point of the first cubic B&ecute;zier curve of the pair of curves created
      u - the path parameter at which a curve is to be split
    • split

      public static Point2D split(double[] first, double[] second, double t, int degree, double x, double y, double[] coords)
      Split a Bézier curve of degree n at a point t∈[0,1]. After the split, the first curve's initial point will be (x, y) and its remaining control points will be in the array first. The second curve's initial point will be returned and its remaining control points will be in the array second. For all the arrays, the initial point of the curve is excluded and the array contains the remaining control points in order, with X values immediately followed by the corresponding Y values, the same convention used by the PathIterator interface.

      See A Primer on Bézier Curves for a description of how to use de Casteljau's algorithm for splitting a Bézier curve.

      Parameters:
      first - the control point array for the first curve; null if these control points should not be computed
      second - the control point array for the second curve; null if these control points should not be computed
      t - the point at which the curve is split
      degree - the degree of the initial Bézier curve
      x - the starting X coordinate for the initial Bézier curve
      y - the starting Y coordinate for the initial Bézier curve
      coords - the coordinates for the remaining control points for the initial Bézier curve, where the control points appear in order as pairs of X followed by Y coordinates
      Returns:
      the initial point of the second curve; null if the argument second is null
    • subpath

      public static Path2D subpath(Path2D path, double u1, double u2) throws IllegalArgumentException
      Get a subpath of a path with 2 dimensions. The path returned will be the same as a portion of the path provided in the first argument. The path parameters are those for the path provided by this method's first argument. For the ith segment in a path, The value of a path parameter is (i + u) where u ∈ [0,1].
      Parameters:
      path - the path whose subpath will be computed
      u1 - the path parameter determining the start of the new path
      u2 - the path parameter determining the end of the new path.
      Returns:
      the subpath
      Throws:
      IllegalArgumentException
    • subpath

      public static Path2D subpath(Path2D path, int start, double u1, int end, double u2)
      Get a subpath of a path with 2 dimensions, specifying path parameters by a segment index and a path parameter specific to that index.
      Parameters:
      path - the path whose subpath will be computed
      start - the index for the path segment determining the start of the new path
      u1 - the path parameter for segment start determining the start of the new path, with a range of [0,1]
      end - the index for the path segment determining the end of the new path
      u2 - the path parameter for segment end determining the end of the new path, with a range of [0,1]
      Returns:
      the subpath
    • subpath

      public static Path3D subpath(Path3D path, double u1, double u2) throws IllegalArgumentException
      Get a subpath of a path with three dimensions. The path parameters are those for the path provided by this method's first argument. For the ith segment in a path, The value of a path parameter is (i + u) where u ∈ [0,1].
      Parameters:
      path - the path whose subpath will be computed
      u1 - the path parameter determining the start of the new path
      u2 - the path parameter determining the end of the new path.
      Returns:
      the subpath
      Throws:
      IllegalArgumentException
    • subpath

      public static Path3D subpath(Path3D path, int start, double u1, int end, double u2)
      Get a subpath of a path with three dimensions, specifying path parameters by a segment index and a path parameter specific to that index.
      Parameters:
      path - the path whose subpath will be computed
      start - the index for the path segment determining the start of the new path
      u1 - the path parameter for segment start determining the start of the new path, with a range of [0,1]
      end - the index for the path segment determining the end of the new path
      u2 - the path parameter for segment end determining the end of the new path, with a range of [0,1]
      Returns:
      the subpath