Example usage for java.awt.geom FlatteningPathIterator isDone

List of usage examples for java.awt.geom FlatteningPathIterator isDone

Introduction

In this page you can find the example usage for java.awt.geom FlatteningPathIterator isDone.

Prototype

public boolean isDone() 

Source Link

Document

Tests if the iteration is complete.

Usage

From source file:PathLength.java

/**
 * Flattens the path and determines the path length.
 *//*from  ww w  . j  a v  a2s .co  m*/
protected void initialise() {
    pathLength = 0f;

    PathIterator pi = path.getPathIterator(new AffineTransform());
    SingleSegmentPathIterator sspi = new SingleSegmentPathIterator();
    segments = new ArrayList(20);
    List indexes = new ArrayList(20);
    int index = 0;
    int origIndex = -1;
    float lastMoveX = 0f;
    float lastMoveY = 0f;
    float currentX = 0f;
    float currentY = 0f;
    float[] seg = new float[6];
    int segType;

    segments.add(new PathSegment(PathIterator.SEG_MOVETO, 0f, 0f, 0f, origIndex));

    while (!pi.isDone()) {
        origIndex++;
        indexes.add(new Integer(index));
        segType = pi.currentSegment(seg);
        switch (segType) {
        case PathIterator.SEG_MOVETO:
            segments.add(new PathSegment(segType, seg[0], seg[1], pathLength, origIndex));
            currentX = seg[0];
            currentY = seg[1];
            lastMoveX = currentX;
            lastMoveY = currentY;
            index++;
            pi.next();
            break;
        case PathIterator.SEG_LINETO:
            pathLength += Point2D.distance(currentX, currentY, seg[0], seg[1]);
            segments.add(new PathSegment(segType, seg[0], seg[1], pathLength, origIndex));
            currentX = seg[0];
            currentY = seg[1];
            index++;
            pi.next();
            break;
        case PathIterator.SEG_CLOSE:
            pathLength += Point2D.distance(currentX, currentY, lastMoveX, lastMoveY);
            segments.add(new PathSegment(PathIterator.SEG_LINETO, lastMoveX, lastMoveY, pathLength, origIndex));
            currentX = lastMoveX;
            currentY = lastMoveY;
            index++;
            pi.next();
            break;
        default:
            sspi.setPathIterator(pi, currentX, currentY);
            FlatteningPathIterator fpi = new FlatteningPathIterator(sspi, 0.01f);
            while (!fpi.isDone()) {
                segType = fpi.currentSegment(seg);
                if (segType == PathIterator.SEG_LINETO) {
                    pathLength += Point2D.distance(currentX, currentY, seg[0], seg[1]);
                    segments.add(new PathSegment(segType, seg[0], seg[1], pathLength, origIndex));
                    currentX = seg[0];
                    currentY = seg[1];
                    index++;
                }
                fpi.next();
            }
        }
    }
    segmentIndexes = new int[indexes.size()];
    for (int i = 0; i < segmentIndexes.length; i++) {
        segmentIndexes[i] = ((Integer) indexes.get(i)).intValue();
    }
    initialised = true;
}