protected void initialise() {
pathLength = 0f;
FlatteningPathIterator fpi = new FlatteningPathIterator(path.getPathIterator(new AffineTransform()), 0.01f);
segments = new Vector(20);
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));
while (!fpi.isDone()) {
segType = fpi.currentSegment(seg);
switch (segType) {
case PathIterator.SEG_MOVETO:
// System.err.println("== MOVE TO " + seg[0] + " " + seg[1]);
segments.add(new PathSegment(segType, seg[0], seg[1], pathLength));
currentX = seg[0];
currentY = seg[1];
lastMoveX = currentX;
lastMoveY = currentY;
break;
case PathIterator.SEG_LINETO:
// System.err.println("== LINE TO " + seg[0] + " " + seg[1]);
pathLength += Point2D.distance(currentX, currentY, seg[0], seg[1]);
segments.add(new PathSegment(segType, seg[0], seg[1], pathLength));
currentX = seg[0];
currentY = seg[1];
break;
case PathIterator.SEG_CLOSE:
// System.err.println("== CLOSE TO " + lastMoveX + " " + lastMoveY);
pathLength += Point2D.distance(currentX, currentY, lastMoveX, lastMoveY);
segments.add(new PathSegment(PathIterator.SEG_LINETO, lastMoveX, lastMoveY, pathLength));
currentX = lastMoveX;
currentY = lastMoveY;
break;
default:
// ouch, where have these come from
System.out.println("Bad path segment types");
}
fpi.next();
}
initialised = true;