Skip to main content

[JAVA2D] Area.getPathIterator() question

2 replies [Last post]
Anonymous

Hello,

I have an Area that I want to break down into discrete paths, for
example, if I have an Area that looks like a doughnut, I want to extract
two discrete paths from it.

I do this by getting the PathIterator from the Area as follows:

PathIterator pi = myArea.getPathIterator(new AffineTransform(),
1.0);

Then I look at the segment type, e.g. SEG_LINETO, on each iteration to
determine whether I should add the current point to my current path or
start a new path.

When I iterate over the path iterator, I find many DUPLICATE CONSECUTIVE
POINTS.

So if I build up a GeneralPath from the points given to me by the
PathIterator as follows:

if(segmentType == PathIterator.SEG_LINETO)

{

myGenPath.lineTo((float)coords[0],
(float)coords[1]);

}

I wind up with a GeneralPath that looks fine when drawn on screen,
however, examination shows that it can have many DUPLICATE CONSECUTIVE
POINTS.

Is there some way to get a PathIterator from an Area that will not have
duplicate consecutive points?

Thank you,

Ted Hill

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".
[att1.html]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Knight, Jon

You could only add the first in each set of DUPLICATE CONSECUTIVE POINTS ...

if ( segmentType == PathIterator.SEG_LINETO ) {
if ( prev0 != (float)coords[0] || prev1 != (float)coords[1] ) {
myGenPath.lineTo ( (float)coords[0] ,(float)coords[1] );
}
prev0 = (float)coords[0];
prev1 = (float)coords[1];
}

Jon

-----Original Message-----
From: Discussion list for Java 2D API
[mailto:JAVA2D-INTEREST@JAVA.SUN.COM]On Behalf Of Ted Hill
Sent: Wednesday, June 23, 2004 10:47 AM
To: JAVA2D-INTEREST@JAVA.SUN.COM
Subject: [JAVA2D] Area.getPathIterator() question

Hello,

I have an Area that I want to break down into discrete paths, for example,
if I have an Area that looks like a doughnut, I want to extract two discrete
paths from it.
I do this by getting the PathIterator from the Area as follows:

PathIterator pi = myArea.getPathIterator(new AffineTransform(),
1.0);

Then I look at the segment type, e.g. SEG_LINETO, on each iteration to
determine whether I should add the current point to my current path or start
a new path.

When I iterate over the path iterator, I find many DUPLICATE CONSECUTIVE
POINTS.

So if I build up a GeneralPath from the points given to me by the
PathIterator as follows:

if(segmentType == PathIterator.SEG_LINETO)
{
myGenPath.lineTo((float)coords[0], (float)coords[1]);
}

I wind up with a GeneralPath that looks fine when drawn on screen, however,
examination shows that it can have many DUPLICATE CONSECUTIVE POINTS.

Is there some way to get a PathIterator from an Area that will not have
duplicate consecutive points?

Thank you,

Ted Hill

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".
[att1.html]

Jim Graham

> When I iterate over the path iterator, I find many DUPLICATE
> CONSECUTIVE POINTS.
>
> Is there some way to get a PathIterator from an Area that will not
> have duplicate consecutive points?

One question is whether or not you have discovered any practical
problems from these extra points or is it just that they seem
superflous?

These are most likely due to the fact that Area has no
"setting" for degree of error so it is probably a bit too
exacting on what it considers to be "identical geometry". Are
the points exact duplicates or are they off by the last couple
of decimal places?

The problem is that when you perform intersection calculations
you never really end up with the exact coordinate of the
intersection because floating point doesn't have infinite
precision. When those numbers then come back to try to
interact with each other in later parts of the calculation
the algorithms end up concluding that they are different
coordinates and so what was intersected and sliced cannot
be reconnected in all cases.

If we added some kind of "precision limit" then we could decide
that all coordinates within a certain distance from each other
were the same and then set both to, say, the average of the
two.

This lack of a settable limit on its precision not only leads
to lots of "geometry dirt" in its output, but also can lead to
it taking quadratically longer to work on a path as you perform
more operations.

You might look at:

4818309 - Area on Area ops insert unwanted vertices
4798837 - Area subtrac method duplicates points

They show that the coordinates really are different if that is
the same problem you are seeing. These should probably be turned
into an RFE to add the precision limit since their answer isn't
really "wrong" in the absolute sense of the word, just sub-optimal
for programmers...

...jim

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".