java.lang.Object
org.bzdev.geom.ConditionalPathIterator2D
- All Implemented Interfaces:
PathIterator
Conditional path iterator class for two dimensions.
This iterator adds segments to the segments returned by
another path iterator by splitting quadratic and cubic Bézier-curve
segments unless the points along a segment fails to satisfy a condition
that indicates that splitting should continue. If that condition is not
satisfied, splitting may continue in some circumstances: the
second control point, for example, should not be closer to the initial
control point than the first control point. The condition is a predicate
whose argument is a control point array including the end points of a
segment. It will have a length of 6 for qudratic segments and a length of
8 for cubic segments.
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.
The path may be partially flattened.
This class does not modify segment types, unlike
FlatteningPathIterator
which turns quadratic
and cubic segments into straight lines.
-
Field Summary
Fields inherited from interface java.awt.geom.PathIterator
SEG_CLOSE, SEG_CUBICTO, SEG_LINETO, SEG_MOVETO, SEG_QUADTO, WIND_EVEN_ODD, WIND_NON_ZERO
-
Constructor Summary
ConstructorsConstructorDescriptionConditionalPathIterator2D
(int type, double x0, double y0, double[] coords, AffineTransform transform, Predicate<double[]> condition, int limit) Constructor give a type and double-precision coordinate array, with an AffineTransform.ConditionalPathIterator2D
(int type, double x0, double y0, double[] coords, Predicate<double[]> condition, int limit) Constructor give a type and a double-precision coordinate array.ConditionalPathIterator2D
(int type, float x0, float y0, float[] coords, AffineTransform transform, Predicate<double[]> condition, int limit) Constructor give a type and single-precision coordinate array, with an AffineTransform.ConditionalPathIterator2D
(int type, float x0, float y0, float[] coords, Predicate<double[]> condition, int limit) Constructor given a type and a single-precision coordinate array.ConditionalPathIterator2D
(PathIterator src, AffineTransform transform, Predicate<double[]> condition) Constructor given an affine transform.ConditionalPathIterator2D
(PathIterator src, AffineTransform transform, Predicate<double[]> condition, int limit) Constructor given an affine transform and a recursion limit.ConditionalPathIterator2D
(PathIterator src, Predicate<double[]> condition) Constructor.ConditionalPathIterator2D
(PathIterator src, Predicate<double[]> condition, int limit) Constructor with a recursion limit. -
Method Summary
Modifier and TypeMethodDescriptionint
currentSegment
(double[] coords) int
currentSegment
(float[] coords) Predicate<double[]>
Get the condition.int
Get the recursion limit.int
boolean
isDone()
void
next()
-
Constructor Details
-
ConditionalPathIterator2D
public ConditionalPathIterator2D(PathIterator src, Predicate<double[]> condition) throws IllegalArgumentException Constructor. The default recursion limit is 10. The condition's test method must return true if the the path is to be flattened further and false otherwise. The test method's argument is an array containing the control points, including the starting point for a segment. The length of the array is 6 when a segment's type isPathIterator.SEG_QUADTO
and is 8 when a segment's type isPathIterator.SEG_CUBICTO
. Segments whose type isPathIterator.SEG_MOVETO
,PathIterator.SEG_LINETO
, orPathIterator.SEG_CLOSE
are not flattened.- Parameters:
src
- a path iterator to flattencondition
- the condition- Throws:
IllegalArgumentException
-
ConditionalPathIterator2D
public ConditionalPathIterator2D(PathIterator src, AffineTransform transform, Predicate<double[]> condition) throws IllegalArgumentException Constructor given an affine transform. The transform is not constrained to be an affine transform. The default recursion limit is 10. The condition's test method must return true if the the path is to be flattened further and false otherwise. The test method's argument is an array containing the control points, including the starting point for a segment. The length of the array is 6 when a segment's type isPathIterator.SEG_QUADTO
and is 8 when a segment's type isPathIterator.SEG_CUBICTO
. Segments whose type isPathIterator.SEG_MOVETO
,PathIterator.SEG_LINETO
, orPathIterator.SEG_CLOSE
are not flattened.- Parameters:
src
- a path iterator to flattentransform
- the transform to applycondition
- the condition- Throws:
IllegalArgumentException
-
ConditionalPathIterator2D
public ConditionalPathIterator2D(PathIterator src, Predicate<double[]> condition, int limit) throws IllegalArgumentException Constructor with a recursion limit. The limit must be non-negative. The condition's test method must return true if the the path is to be flattened further and false otherwise. The test method's argument is an array containing the control points, including the starting point for a segment. The length of the array is 6 when a segment's type isPathIterator.SEG_QUADTO
and is 8 when a segment's type isPathIterator.SEG_CUBICTO
. Segments whose type isPathIterator.SEG_MOVETO
,PathIterator.SEG_LINETO
, orPathIterator.SEG_CLOSE
are not flattened.- Parameters:
src
- a path iterator to flattencondition
- the conditionlimit
- the recursion limit- Throws:
IllegalArgumentException
-
ConditionalPathIterator2D
public ConditionalPathIterator2D(int type, double x0, double y0, double[] coords, Predicate<double[]> condition, int limit) Constructor give a type and a double-precision coordinate array. The the limit must be non-negative. The condition's test method must return true if the the path is to be flattened further and false otherwise. The test method's argument is an array containing the control points, including the starting point for a segment. The length of the array is 6 when a segment's type isPathIterator.SEG_QUADTO
and is 8 when a segment's type isPathIterator.SEG_CUBICTO
. Segments whose type isPathIterator.SEG_MOVETO
,PathIterator.SEG_LINETO
, orPathIterator.SEG_CLOSE
are not flattened. If the segment type is PathIterator.SEG_MOVETO, the arguments x0 and y0 are ignored.- Parameters:
type
- the type of a segment (PathIterator.SEG_MOVETO
,PathIterator.SEG_LINETO
,PathIterator.SEG_QUADTO
,PathIterator.SEG_CUBICTO
)x0
- the starting X coordinate for the segmenty0
- the starting Y coordinate for the segment,coords
- the coordinates for the segment as returned bycurrentSegment(double[])
condition
- the conditionlimit
- the recursion limit
-
ConditionalPathIterator2D
public ConditionalPathIterator2D(int type, float x0, float y0, float[] coords, Predicate<double[]> condition, int limit) Constructor given a type and a single-precision coordinate array. The limit must be non-negative. The condition's test method must return true if the the path is to be flattened further and false otherwise. The test method's argument is an array containing the control points, including the starting point for a segment. The length of the array is 6 when a segment's type isPathIterator.SEG_QUADTO
and is 8 when a segment's type isPathIterator.SEG_CUBICTO
. Segments whose type isPathIterator.SEG_MOVETO
,PathIterator.SEG_LINETO
, orPathIterator.SEG_CLOSE
are not flattened.- Parameters:
type
- the type of a segment (PathIterator.SEG_MOVETO
,PathIterator.SEG_LINETO
,PathIterator.SEG_QUADTO
,PathIterator.SEG_CUBICTO
)x0
- the starting X coordinate for the segmenty0
- the starting Y coordinate for the segment,coords
- the coordinates for the segment as returned bycurrentSegment(double[])
condition
- the conditionlimit
- the recursion limit
-
ConditionalPathIterator2D
public ConditionalPathIterator2D(PathIterator src, AffineTransform transform, Predicate<double[]> condition, int limit) throws IllegalArgumentException Constructor given an affine transform and a recursion limit. The limit must be non-negative. The condition's test method must return true if the the path is to be flattened further and false otherwise. The test method's argument is an array containing the control points, including the starting point for a segment. The length of the array is 6 when a segment's type isPathIterator.SEG_QUADTO
and is 8 when a segment's type isPathIterator.SEG_CUBICTO
. Segments whose type isPathIterator.SEG_MOVETO
,PathIterator.SEG_LINETO
, orPathIterator.SEG_CLOSE
are not flattened.- Parameters:
src
- a path iterator to flattentransform
- a transform to applycondition
- the conditionlimit
- the recursion limit- Throws:
IllegalArgumentException
-
ConditionalPathIterator2D
public ConditionalPathIterator2D(int type, double x0, double y0, double[] coords, AffineTransform transform, Predicate<double[]> condition, int limit) Constructor give a type and double-precision coordinate array, with an AffineTransform. The limit must be non-negative. The condition's test method must return true if the the path is to be flattened further and false otherwise. The test method's argument is an array containing the control points, including the starting point for a segment. The length of the array is 6 when a segment's type isPathIterator.SEG_QUADTO
and is 8 when a segment's type isPathIterator.SEG_CUBICTO
. Segments whose type isPathIterator.SEG_MOVETO
,PathIterator.SEG_LINETO
, orPathIterator.SEG_CLOSE
are not flattened.- Parameters:
type
- the type of a segment (PathIterator.SEG_MOVETO
,PathIterator.SEG_LINETO
,PathIterator.SEG_QUADTO
,PathIterator.SEG_CUBICTO
)x0
- the starting X coordinate for the segmenty0
- the starting Y coordinate for the segment,coords
- the coordinates for the segment as returned bycurrentSegment(double[])
transform
- a transform to applycondition
- the conditionlimit
- the recursion limit
-
ConditionalPathIterator2D
public ConditionalPathIterator2D(int type, float x0, float y0, float[] coords, AffineTransform transform, Predicate<double[]> condition, int limit) Constructor give a type and single-precision coordinate array, with an AffineTransform. The limit must be non-negative. The condition's test method must return true if the the path is to be flattened further and false otherwise. The test method's argument is an array containing the control points, including the starting point for a segment. The length of the array is 6 when a segment's type isPathIterator.SEG_QUADTO
and is 8 when a segment's type isPathIterator.SEG_CUBICTO
. Segments whose type isPathIterator.SEG_MOVETO
,PathIterator.SEG_LINETO
, orPathIterator.SEG_CLOSE
are not flattened.- Parameters:
type
- the type of a segment (PathIterator.SEG_MOVETO
,PathIterator.SEG_LINETO
,PathIterator.SEG_QUADTO
,PathIterator.SEG_CUBICTO
)x0
- the starting X coordinate for the segmenty0
- the starting Y coordinate for the segment,coords
- the coordinates for the segment as returned bycurrentSegment(double[])
transform
- a transform to applycondition
- the conditionlimit
- the recursion limit
-
-
Method Details
-
getCondition
Get the condition.- Returns:
- the condition
-
getRecursionLimit
public int getRecursionLimit()Get the recursion limit.- Returns:
- the recursion limit
-
currentSegment
public int currentSegment(double[] coords) - Specified by:
currentSegment
in interfacePathIterator
-
currentSegment
public int currentSegment(float[] coords) - Specified by:
currentSegment
in interfacePathIterator
-
isDone
public boolean isDone()- Specified by:
isDone
in interfacePathIterator
-
next
public void next()- Specified by:
next
in interfacePathIterator
-
getWindingRule
public int getWindingRule()- Specified by:
getWindingRule
in interfacePathIterator
-