Remove point / operation from java.awt.geom.GeneralPath
Is there a way to remove a common path point? I am drawing GeneralPath like this:
GeneralPath gp1=new GeneralPath();
gp1.moveTo(5,5);
gp1.lineTo(10,10);
gp1.lineto(10,30);
gp1.curveTo(2, 2, 7, 7, 5, 5);
gp1.closePath();
Now I would like to remove a specific point / operation like lineto (10,10) without creating a GeneralPath from new. (Performance considerations)
The command is as follows: I like it, but it is not available:
GeneralPath.removesegment(1);
Attached screenshot that should explain my desire :-) I would like to remove the blue marked dot in my GeneralPath.
Thank you and regattas
source to share
Path2D.Float
from which it GeneralPath
is derived does not provide access to its internal data structures and does not allow the desired operation to be performed. Therefore, unless you are willing to override GeneralPath
or bypass access restrictions, it simply cannot be achieved.
On the other hand, I doubt performance should be a big issue. Id think that in most applications, drawing paths take longer than manipulating them in memory, so creating a new path from your existing one shouldn't take too long. I would use this using a wrapper around PathIterator
, so you can use Path2D.append
to move your data to a new path. The wrapper will simply identify the points you want to remove and skip over them, delegating everything else to the default iterator of the original path.
source to share