Class FlatteningPathIterator3D

java.lang.Object
org.bzdev.geom.FlatteningPathIterator3D
All Implemented Interfaces:
PathIterator3D

public class FlatteningPathIterator3D extends Object implements PathIterator3D
Flattening path iterator class for three dimensions. This iterator adds segments to the segments returned by another path iterator by splitting quadratic and cubic Bézier-curve segments until the points along a segment deviate from a straight line by no more than the value provided by the flatness parameter. If the flatness parameter is 0.0, the split will continue until stopped by the recursion limit. In addition, a flatness parameter of 0.0 implies that all segments will be split including ones that are straight lines. For nonzero values of the flatness parameter, straight-line segments are not split unless there is a transform that is not known to be an affine transform.

The iterator has a recursion limit (the default value is 10) to prevent the number of segments from becoming excessively large. Incrementing the recursion limit by 1 can double the number of segments from that returned by the previous limit.

A transform can be provided in the constructors FlatteningPathIterator3D(PathIterator3D,Transform3D,double) and FlatteningPathIterator3D(PathIterator3D,Transform3D,double,int). The transform will be applied after the path is flattened, and will be applied only to the control points. Because of this, the path should be flattened sufficiently so that the transform can be approximated by an affine transform over the convex hull for the flattened path's control points. While the transform is applied after the path is flattened, the flatness test uses transformed values of the control points.

This class does not modify segment types, unlike FlatteningPathIterator which turns quadratic and cubic segments into straight lines. Not modifying segment types is useful when applying a transform that is not an affine transform.

  • Constructor Details

    • FlatteningPathIterator3D

      public FlatteningPathIterator3D(PathIterator3D src, double flatness) throws IllegalArgumentException
      Constructor. The default recursion limit is 10.
      Parameters:
      src - a path iterator to flatten
      flatness - the flatness constraint
      Throws:
      IllegalArgumentException
    • FlatteningPathIterator3D

      public FlatteningPathIterator3D(PathIterator3D src, Transform3D transform, double flatness) throws IllegalArgumentException
      Constructor given a transform. The transform is not constrained to be an affine transform. The default recursion limit is 10.
      Parameters:
      src - a path iterator to flatten
      transform - the transform to apply
      flatness - the flatness constraint
      Throws:
      IllegalArgumentException
    • FlatteningPathIterator3D

      public FlatteningPathIterator3D(PathIterator3D src, double flatness, int limit) throws IllegalArgumentException
      Constructor with a recursion limit. Both the flatness and the limit must be non-negative.
      Parameters:
      src - a path iterator to flatten
      flatness - the flatness constraint
      limit - the recursion limit
      Throws:
      IllegalArgumentException
    • FlatteningPathIterator3D

      public FlatteningPathIterator3D(PathIterator3D src, Transform3D transform, double flatness, int limit) throws IllegalArgumentException
      Constructor with a transform and a recursion limit. Both the flatness and the limit must be non-negative. The transform is not constrained to be an affine transform.
      Parameters:
      src - a path iterator to flatten
      transform - a transform to apply
      flatness - the flatness constraint
      limit - the recursion limit
      Throws:
      IllegalArgumentException
    • FlatteningPathIterator3D

      public FlatteningPathIterator3D(int type, double x0, double y0, double z0, double[] coords, double flatness, int limit)
      Constructor give a type and a double-precision coordinate array. Both the flatness and the limit must be non-negative. The transform is not constrained to be an affine transform. If the segment type is PathIterator3D.SEG_MOVETO, the arguments x0 and y0 are ignored.
      Parameters:
      type - the type of a segment (PathIterator3D.SEG_MOVETO, PathIterator3D.SEG_LINETO, PathIterator3D.SEG_QUADTO, PathIterator3D.SEG_CUBICTO)
      x0 - the starting X coordinate for the segment
      y0 - the starting Y coordinate for the segment,
      z0 - the starting Z coordinate for the segment,
      coords - the coordinates for the segment as returned by currentSegment(double[])
      flatness - the flatness constraint
      limit - the recursion limit
    • FlatteningPathIterator3D

      public FlatteningPathIterator3D(int type, float x0, float y0, float z0, float[] coords, double flatness, int limit)
      Constructor given a type and a single-precision coordinate array. Both the flatness and the limit must be non-negative. The transform is not constrained to be an affine transform.
      Parameters:
      type - the type of a segment (PathIterator3D.SEG_MOVETO, PathIterator3D.SEG_LINETO, PathIterator3D.SEG_QUADTO, PathIterator3D.SEG_CUBICTO)
      x0 - the starting X coordinate for the segment
      y0 - the starting Y coordinate for the segment,
      z0 - the starting Z coordinate for the segment,
      coords - the coordinates for the segment as returned by currentSegment(double[])
      flatness - the flatness constraint
      limit - the recursion limit
    • FlatteningPathIterator3D

      public FlatteningPathIterator3D(int type, double x0, double y0, double z0, double[] coords, Transform3D transform, double flatness, int limit)
      Constructor give a type, a double-precision coordinate array, and a transform. Both the flatness and the limit must be non-negative. The transform is not constrained to be an affine transform.
      Parameters:
      type - the type of a segment (PathIterator3D.SEG_MOVETO, PathIterator3D.SEG_LINETO, PathIterator3D.SEG_QUADTO, PathIterator3D.SEG_CUBICTO)
      x0 - the starting X coordinate for the segment
      y0 - the starting Y coordinate for the segment,
      z0 - the starting Z coordinate for the segment,
      coords - the coordinates for the segment as returned by currentSegment(double[])
      transform - a transform to apply
      flatness - the flatness constraint
      limit - the recursion limit
    • FlatteningPathIterator3D

      public FlatteningPathIterator3D(int type, float x0, float y0, float z0, float[] coords, Transform3D transform, double flatness, int limit)
      Constructor given a type, single-precision coordinate array and a transform. Both the flatness and the limit must be non-negative. The transform is not constrained to be an affine transform.
      Parameters:
      type - the type of a segment (PathIterator3D.SEG_MOVETO, PathIterator3D.SEG_LINETO, PathIterator3D.SEG_QUADTO, PathIterator3D.SEG_CUBICTO)
      x0 - the starting X coordinate for the segment
      y0 - the starting Y coordinate for the segment,
      z0 - the starting Z coordinate for the segment,
      coords - the coordinates for the segment as returned by currentSegment(double[])
      transform - a transform to apply
      flatness - the flatness constraint
      limit - the recursion limit
    • FlatteningPathIterator3D

      public FlatteningPathIterator3D(int type, double x0, double y0, double z0, double[] coords, AffineTransform3D transform, double flatness, int limit)
      Constructor give a type and double-precision coordinate array, with a transform that is an AffineTransform. Both the flatness and the limit must be non-negative. The transform is not constrained to be an affine transform.
      Parameters:
      type - the type of a segment (PathIterator3D.SEG_MOVETO, PathIterator3D.SEG_LINETO, PathIterator3D.SEG_QUADTO, PathIterator3D.SEG_CUBICTO)
      x0 - the starting X coordinate for the segment
      y0 - the starting Y coordinate for the segment,
      z0 - the starting Z coordinate for the segment,
      coords - the coordinates for the segment as returned by currentSegment(double[])
      transform - a transform to apply
      flatness - the flatness constraint
      limit - the recursion limit
    • FlatteningPathIterator3D

      public FlatteningPathIterator3D(int type, float x0, float y0, float z0, float[] coords, AffineTransform3D transform, double flatness, int limit)
      Constructor give a type and single-precision coordinate array, with a transform that is an AffineTransform3D. Both the flatness and the limit must be non-negative. The transform is not constrained to be an affine transform.
      Parameters:
      type - the type of a segment (PathIterator3D.SEG_MOVETO, PathIterator3D.SEG_LINETO, PathIterator3D.SEG_QUADTO, PathIterator3D.SEG_CUBICTO)
      x0 - the starting X coordinate for the segment
      y0 - the starting Y coordinate for the segment,
      z0 - the starting Z coordinate for the segment,
      coords - the coordinates for the segment as returned by currentSegment(double[])
      transform - a transform to apply
      flatness - the flatness constraint
      limit - the recursion limit
  • Method Details

    • getFlatness

      public double getFlatness()
      Get the flatness parameter.
      Returns:
      the flatness parameter
    • getRecursionLimit

      public int getRecursionLimit()
      Get the recursion limit.
      Returns:
      the recursion limit
    • currentSegment

      public int currentSegment(double[] coords)
      Description copied from interface: PathIterator3D
      Returns the coordinates and type of the current path segment in the iteration. The return value is the path-segment type: SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE. A double array of length 9 must be passed in and can be used to store the coordinates of the point(s). Each point is stored as a triplet of double x,y,z coordinates. SEG_MOVETO and SEG_LINETO types returns one point, SEG_QUADTO returns two points, SEG_CUBICTO returns 3 points and SEG_CLOSE does not return any points.
      Specified by:
      currentSegment in interface PathIterator3D
      Parameters:
      coords - - an array that holds the data returned from this method
      Returns:
      he path-segment type of the current path segment
    • currentSegment

      public int currentSegment(float[] coords)
      Description copied from interface: PathIterator3D
      Returns the coordinates and type of the current path segment in the iteration. The return value is the path-segment type: SEG_MOVETO, SEG_LINETO, SEG_QUADTO, SEG_CUBICTO, or SEG_CLOSE. A float array of length 9 must be passed in and can be used to store the coordinates of the point(s). Each point is stored as a triplet of float x,y,z coordinates. SEG_MOVETO and SEG_LINETO types returns one point, SEG_QUADTO returns two points, SEG_CUBICTO returns 3 points and SEG_CLOSE does not return any points.
      Specified by:
      currentSegment in interface PathIterator3D
      Parameters:
      coords - - an array that holds the data returned from this method
      Returns:
      the path-segment type of the current path segment.
    • isDone

      public boolean isDone()
      Description copied from interface: PathIterator3D
      Tests if the iteration is complete.
      Specified by:
      isDone in interface PathIterator3D
      Returns:
      true if all the segments have been read; false otherwise.
    • next

      public void next()
      Description copied from interface: PathIterator3D
      Moves the iterator to the next segment of the path forwards along the primary direction of traversal as long as there are more points in that direction.
      Specified by:
      next in interface PathIterator3D