Re: [JAVA2D] Expanding a shape

2006-08-22 Thread java2d
I also am trying to find a way of expanding a shape... I still haven't had any luck with anything I've tried, but it sounds like you may have something that works. I've tried two different things. My original solution was to use a flattened path iterator to go over the shape and create

Re: [JAVA2D] Expanding a shape

2006-08-22 Thread Chris Nokleberg
On 8/22/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: After that, I found this thread. I tried the suggested code snippet (using CAP_ROUND and JOIN_ROUND), and it almost works. However, the area I get when I create the stroked shape has holes in it other than the original shape. Can you

Re: [JAVA2D] Expanding a shape

2006-08-22 Thread Jim Graham
This all depends on your definition of expand shape. The code snippet below expands the shape by d distance perpendicular to every point on the outline of the shape without regard to the center of the shape. In other words, the resulting shape includes all points that were within the original

Re: [JAVA2D] Expanding a shape

2006-08-22 Thread Jim Graham
Sorry, that was where the CAP and JOIN settings came into effect with the code. You can choose from among those options you list depending on how you set the CAP and JOIN. And, of course, having said that I just realized one potential bug in the cited code. If the path is not closed then the

Re: [JAVA2D] Expanding a shape

2006-07-17 Thread Jim Graham
You can use the Area class to add in the original Shape: public Shape expandShape(Shape s, float d) { BasicStroke bs = new BasicStroke(d); // or new BasicStroke(d, CAP_ROUND, JOIN_ROUND); Area a = new Area(bs.createStrokedShape(s));

Re: [JAVA2D] Expanding a shape

2006-07-17 Thread Chris Nokleberg
Thanks. Actually I forgot to mention that I previously had used Area but had some issues with performance. It seems like a bit of overkill for this problem, since the path of interest is already calculated as part of stroking. But I doubt there is a better solution unless I reimplement part of

Re: [JAVA2D] Expanding a shape

2006-07-17 Thread Jim Graham
It depends on the performance you are looking for. One situation where Area can take a fairly long time to perform its calculations is when you have curves that are very similar to each other - which would happen here if you had an expand distance that was very small - say much smaller than a

[JAVA2D] Expanding a shape

2006-07-14 Thread Chris Nokleberg
I'd like to expand the boundary of an arbitrary Shape. If I use a BasicStroke createTransformedShape, the result is perfect except for the resulting hole. I currently get rid of the hole by iterating over the path, splitting the shape into multiple subshapes, and then comparing the bounds of each