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 stroke shape will
not include the last segment back to the start of the path.  Filling a
shape (and executing new Area(Shape)) both implicitly close all
sub-paths, but createStrokedShape does not.

So, the code below only really works correctly for explicitly closed
shapes.  With a slight modification, it could be made to work with
unclosed shapes by writing a "ClosedShape" wrapper - left as an exercise
for the reader... ;-)

                       ...jim

Yinhe Cao wrote:
Jim,

Thanks for the clarification.  Now I know exactly what your "expand
shape" means.  Your definition is crystal clear except at those corners
where the outer normal directions are not well defined.  Are you going
to closed the gap with an arch of radius d, or simply extends the outer
edges?  For small d, there is no much difference, but for a large d, the
difference will be visible.

Thanks,

Yinhe





Jim Graham wrote On 08/22/06 15:44,:

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 shape and also all other points that were
within d distance from the interior of the original shape.

I am not familiar enough with what you are trying to accomplish in
order to suggest a solution.  Are you simply trying to scale the shape
outward from its geometrical center?  I'm not sure what you mean by
"geometrical center", though - is that an average of all of the points
on the outline?  Or is it an average of all of the interior points?
Or an average of the bounds?  Or is it something else?

                ...jim

Yinhe Cao wrote:

I have checked the interface Area, and there is no method to compute the
geometrical center of the area such as:
Point2D center()

The point is if the area interface is extended to incluse the center
method, expandShape method should be very simple and direct to implement
by using AffineTransform.

Yinhe Cao

Jim Graham wrote On 07/17/06 14:39

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));
                a.add(new Area(s);
                return a;
        }

Note that the JOIN setting by default is MITER which may not match your
expectations for what it means to "expand the boundary of a Shape".
ROUND would result in a smoother resulting outline...

                        ...jim

Chris Nokleberg wrote:

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 subshape to find the outermost one. This
is bunch of work just to undo the unnecessary work BasicStroke has
already done, though. Any suggestions on a cleaner solution?

Thanks,
Chris

===========================================================================


To unsubscribe, send email to [EMAIL PROTECTED] and include in
the body
of the message "signoff JAVA2D-INTEREST".  For general help, send
email to
[EMAIL PROTECTED] and include in the body of the message "help".



===========================================================================


To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
of the message "signoff JAVA2D-INTEREST".  For general help, send
email to
[EMAIL PROTECTED] and include in the body of the message "help".


===========================================================================

To unsubscribe, send email to [EMAIL PROTECTED] and include in
the body
of the message "signoff JAVA2D-INTEREST".  For general help, send
email to
[EMAIL PROTECTED] and include in the body of the message "help".


===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to