Can a GeneralPath be modified?
- by Dov
java2d is fairly expressive, but requires constructing lots of objects.
In contrast, the older API would let you call methods to draw various shapes, but lacks all the new features like transparency, stroke, etc.
Java has fairly high costs associated with object creation. For speed, I would like to create a GeneralPath whose structure does not change, but go in and change the x,y points inside.
path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 10);
path.moveTo(x,y);
path.lineTo(x2, y2);
double len = Math.sqrt((x2-x)*(x2-x) + (y2-y)*(y2-y));
double dx = (x-x2) * headLen / len;
double dy = (y-y2) * headLen / len;
double dx2 = -dy * (headWidth/headLen);
double dy2 = dx * (headWidth/headLen);
path.lineTo(x2 + dx + dx2, y2 + dy + dy2);
path.moveTo(x2 + dx - dx2, y2 + dy - dy2);
path.lineTo(x2,y2);
This one isn't even that long. Imagine a much longer sequence of commands, and only the ones on the end are changing. I just want to be able to overwrite commands, to have an iterator effectively. Does that exist?