Question

Is there any way to remove a point of a generalpath ? I draw a GeneralPath as follow :

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 for example lineto(10,10) without creating the GeneralPath from new. ( Performance reasons )

A command as follows would be what I like, but this is not available:

GeneralPath.removesegment(1);

Attached a screenshot, that should explain my wish :-) I would like to remove the blue marked point in my GeneralPath.

Thanks and Regads

enter image description here

Was it helpful?

Solution

Path2D.Float, from which GeneralPath is derived, does not provide access to its inner data structures, and does not allow the kind of operation you desire. So unless you are prepared to reimplement GeneralPath or circumvent access restrictions, there simply is no way to achieve this.

On the other hand, I doubt performance should be much of an issue. Id think that in most applications, drawing paths takes more time than manipulating them in memory, so creating a new path from your existing one shouldn't take too long. I'd implement this using a wrapper around the PathIterator, so you can use Path2D.append to move your data to the new path. The wrapper would simply detect the points you want to remove and skip those, delegating everything else to the default iterator of the original path.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top