Can a GeneralPath be modified?

Posted by Dov on Stack Overflow See other posts from Stack Overflow or by Dov
Published on 2010-03-18T20:38:34Z Indexed on 2010/03/18 20:41 UTC
Read the original article Hit count: 412

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about java

Related posts about java2d