((Graphics2D) g).translate(tw/2, th/2);
}
PathIterator pi = trajectory.getPathIterator(null);
float[] coords = new float[6];
Float cp = new Point2D.Float();
Point2D.Float sp = new Point2D.Float();
int ret;
float totalDist = 0;
List<float[]> segStack = new ArrayList<float[]>();
do {
try {
ret = pi.currentSegment(coords);
} catch (NoSuchElementException e) {
// invalid object definition - one of the bounds is zero or less
return;
}
if (ret == PathIterator.SEG_LINETO || (ret == PathIterator.SEG_CLOSE && (sp.x != cp.x || sp.y != cp.y))) {
//close by line
float c = calcLine(coords, cp);
totalDist += c;
// move the point to the end (just so it is same for all of them
segStack.add(new float[] { c, 0, 0, 0, 0, coords[0], coords[1], ret });
cp.x = coords[0];
cp.y = coords[1];
}
if (ret == PathIterator.SEG_MOVETO) {
sp.x = cp.x = coords[0];
sp.y = cp.y = coords[1];
}
if (ret == PathIterator.SEG_CUBICTO) {
float c = calcCube(coords, cp);
totalDist += c;
segStack.add(new float[] { c, coords[0], coords[1], coords[2],
coords[3], coords[4], coords[5], ret });
cp.x = coords[4];
cp.y = coords[5];
}
if (ret == PathIterator.SEG_QUADTO) {
float c = calcLengthOfQuad(coords, cp);
totalDist += c;
segStack.add(new float[] { c, coords[0], coords[1], 0 ,0 , coords[2],
coords[3], ret });
cp.x = coords[2];
cp.y = coords[3];
}
// got a starting point, center point on it.
pi.next();
} while (!pi.isDone());
float nxtP = totalDist / getPoints();
List<Point2D.Float> pList = new ArrayList<Point2D.Float>();
pList.add(new Float(sp.x, sp.y));
int sgIdx = 0;
float[] sgmt = segStack.get(sgIdx);
float len = sgmt[0];
float travDist = nxtP;
Float center = new Float(sp.x, sp.y);
for (int i = 1; i < getPoints(); i++) {
while (len < nxtP) {
sgIdx++;
// Be carefull when messing around with points.
sp.x = sgmt[5];
sp.y = sgmt[6];
sgmt = segStack.get(sgIdx);
travDist = nxtP - len;
len += sgmt[0];
}
len -= nxtP;
Float p = calcPoint(travDist, sp, sgmt, width, height);
pList.add(p);
center.x += p.x;
center.y += p.y;
travDist += nxtP;
}