wood burning stoves*
The moose likes Beginning Java and the fly likes PathIterator returns the last point twice? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "PathIterator returns the last point twice?" Watch "PathIterator returns the last point twice?" New topic
Author

PathIterator returns the last point twice?

Gloria Connors
Greenhorn

Joined: Dec 10, 2007
Posts: 2
I have a polygon, and I'm running through its PathIterator and printing out every point. For some reason, it's printing the last point twice. I would've understood if it printed the FIRST point again at the end (I would've assumed it had "circled back" to the first point), but I don't understand why it's printing the LAST one twice. Here is my code:



(Note: please do not criticize the improper OO design... I am just testing out how Shapes work, I have a homework assignment which I will do with proper OO once I've gotten the hang of these shapes)

[ February 16, 2008: Message edited by: Gloria Connors ]
[ February 16, 2008: Message edited by: Gloria Connors ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I was cringing at the poor OO design of Polygon and PathIterator, that make this so hard to use. Your own program looks fine. To understand what's going on here, you need to look at the return value of the currentSegment() method. Look at the API to understand what the possible return values mean. You may find it useful to write a short method to convert an int return value into a short string which describes what that value means. (In modern Java they would have used an enum type here, but those didn't exist back when this was written.) Use this method to print the type of each path segment, and see what's going on.
[ February 16, 2008: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
 
jQuery in Action, 2nd edition
 
subject: PathIterator returns the last point twice?