I’m new to using iterators and was wondering how one would iterate through each point on a line segment (Line2D.Double, to be precise) — I need to check to see if each point on the line fulfills certain requirements.
Also, given a path object (like GeneralPath), how would you do the same thing (iterate through each point on the outline of the shape)?
Ideally I’d like something like this (with either a line or a path):
Line2D line = new Line2D.Double(p1,p2);
for (Point2D point : line)
{
point.callSomeMethod();
}
There seems to be nothing in the Java API that makes Bresenham’s algorithm user-visible. So I wrote a class that iterates over a line.
You can use it like this: