public interface PathIterator

This interface provides a directed path over the boundary of a shape. The path can contain 1st through 3rd order Bezier curves (lines, and quadratic and cubic splines). A shape can have multiple disjoint paths via the #SEG_MOVETO directive, and can close a circular path back to the previous #SEG_MOVETO via the #SEG_CLOSE directive.

Fields

public static final int WIND_EVEN_ODD = 0The even-odd winding mode: a point is internal to the shape if a ray from the point to infinity (in any direction) crosses an odd number of segments.
public static final int WIND_NON_ZERO = 1The non-zero winding mode: a point is internal to the shape if a ray from the point to infinity (in any direction) crosses a different number of segments headed clockwise than those headed counterclockwise.
public static final int SEG_MOVETO = 0Starts a new subpath.
public static final int SEG_LINETO = 1The current segment is a line.
public static final int SEG_QUADTO = 2The current segment is a quadratic parametric curve.
public static final int SEG_CUBICTO = 3The current segment is a cubic parametric curve (more commonly known as a Bezier curve).
public static final int SEG_CLOSE = 4The current segment closes a loop by an implicit line to the previous #SEG_MOVETO coordinate.

Methods

public abstract int getWindingRule()Returns the winding rule to determine which points are inside this path.
public abstract boolean isDone()Tests if the iterator is exhausted.
public abstract void next()Advance to the next segment in the iteration.
public abstract int currentSegment(float[] coords)Returns the coordinates of the next point(s), as well as the type of line segment.
public abstract int currentSegment(double[] coords)Returns the coordinates of the next point(s), as well as the type of line segment.

Field details

WIND_EVEN_ODD

public static final int WIND_EVEN_ODD = 0
The even-odd winding mode: a point is internal to the shape if a ray from the point to infinity (in any direction) crosses an odd number of segments.

WIND_NON_ZERO

public static final int WIND_NON_ZERO = 1
The non-zero winding mode: a point is internal to the shape if a ray from the point to infinity (in any direction) crosses a different number of segments headed clockwise than those headed counterclockwise.

SEG_MOVETO

public static final int SEG_MOVETO = 0
Starts a new subpath. There is no segment from the previous vertex.

SEG_LINETO

public static final int SEG_LINETO = 1
The current segment is a line.

SEG_QUADTO

public static final int SEG_QUADTO = 2

The current segment is a quadratic parametric curve. It is interpolated as t varies from 0 to 1 over the current point (CP), first control point (P1), and final interpolated control point (P2):

`P(t) = B(2,0)*CP + B(2,1)*P1 + B(2,2)*P2
0 <= t <= 1
B(n,m) = mth coefficient of nth degree Bernstein polynomial
= C(n,m) * t^(m) * (1 - t)^(n-m)
C(n,m) = Combinations of n things, taken m at a time
= n! / (m! * (n-m)!)`

SEG_CUBICTO

public static final int SEG_CUBICTO = 3

The current segment is a cubic parametric curve (more commonly known as a Bezier curve). It is interpolated as t varies from 0 to 1 over the current point (CP), first control point (P1), the second control point (P2), and final interpolated control point (P3):

`P(t) = B(3,0)*CP + B(3,1)*P1 + B(3,2)*P2 + B(3,3)*P3
0 <= t <= 1
B(n,m) = mth coefficient of nth degree Bernstein polynomial
= C(n,m) * t^(m) * (1 - t)^(n-m)
C(n,m) = Combinations of n things, taken m at a time
= n! / (m! * (n-m)!)`

SEG_CLOSE

public static final int SEG_CLOSE = 4
The current segment closes a loop by an implicit line to the previous #SEG_MOVETO coordinate.

Method details

getWindingRule

public abstract int getWindingRule()
Returns the winding rule to determine which points are inside this path.

Returns

the winding rule. (#WIND_EVEN_ODD or #WIND_NON_ZERO).

isDone

public abstract boolean isDone()
Tests if the iterator is exhausted. If this returns true, currentSegment and next may throw a RuntimeException (although this is not required).

Returns

true if the iteration is complete

next

public abstract void next()
Advance to the next segment in the iteration. It is not specified what this does if called when #isDone returns true.

currentSegment

public abstract int currentSegment(float[] coords)
Returns the coordinates of the next point(s), as well as the type of line segment. The input array must be at least a float[6], to accommodate up to three (x,y) point pairs (although if you know the iterator is flat, you can probably get by with a float[2]). If the returned type is #SEG_MOVETO or #SEG_LINETO, the first point in the array is modified; if the returned type is #SEG_QUADTO, the first two points are modified; if the returned type is #SEG_CUBICTO, all three points are modified; and if the returned type is #SEG_CLOSE, the array is untouched.

Parameters

coords float[]
the array to place the point coordinates in

Returns

the segment type. One of (#SEG_MOVETO, #SEG_LINETO, #SEG_QUADTO, #SEG_CUBICTO, #SEG_CLOSE).

currentSegment

public abstract int currentSegment(double[] coords)
Returns the coordinates of the next point(s), as well as the type of line segment. The input array must be at least a double[6], to accommodate up to three (x,y) point pairs (although if you know the iterator is flat, you can probably get by with a double[2]). If the returned type is #SEG_MOVETO or #SEG_LINETO, the first point in the array is modified; if the returned type is #SEG_QUADTO, the first two points are modified; if the returned type is #SEG_CUBICTO, all three points are modified; and if the returned type is #SEG_CLOSE, the array is untouched.

Parameters

coords double[]
the array to place the point coordinates in

Returns

the segment type. One of (#SEG_MOVETO, #SEG_LINETO, #SEG_QUADTO, #SEG_CUBICTO, #SEG_CLOSE).