public class LineIterator extends java.lang.Object implements java.util.Iterator<java.awt.Point>, ResettableIterator
LineIterator
class may be used to get the set of
(x,y) points required for drawing a line between start and end
points. For convenience, the iterator is resettable and has a
nextPoint()
method to save allocating a new point each
time. The line drawing algorithm was taken from:
http://www.gamedev.net/reference/articles/article1275.asp
Constructor and Description |
---|
LineIterator(java.awt.Point start,
java.awt.Point end)
Creates a new line iterator.
|
Modifier and Type | Method and Description |
---|---|
boolean |
hasNext() |
static void |
main(java.lang.String[] argv)
Tests this class.
|
java.awt.Point |
next() |
java.awt.Point |
nextPoint(java.awt.Point point)
Gets the next point in the line.
|
void |
remove() |
void |
reset()
Resets the iterator to the first element.
|
public LineIterator(java.awt.Point start, java.awt.Point end)
start
- the line starting point.end
- the line ending point.public void reset()
ResettableIterator
reset
in interface ResettableIterator
public java.awt.Point nextPoint(java.awt.Point point)
point
- the point to fill in with coordinates, or null to
allocate a new point.public boolean hasNext()
hasNext
in interface java.util.Iterator<java.awt.Point>
public java.awt.Point next()
next
in interface java.util.Iterator<java.awt.Point>
public void remove()
remove
in interface java.util.Iterator<java.awt.Point>
public static void main(java.lang.String[] argv)
argv
- the array of command line parameters.