Class LineIterator

java.lang.Object
noaa.coastwatch.util.LineIterator
All Implemented Interfaces:
Iterator<Point>, ResettableIterator

public class LineIterator extends Object implements Iterator<Point>, ResettableIterator
The 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
Since:
3.1.7
Author:
Peter Hollemans
  • Constructor Details

    • LineIterator

      public LineIterator(Point start, Point end)
      Creates a new line iterator.
      Parameters:
      start - the line starting point.
      end - the line ending point.
  • Method Details

    • reset

      public void reset()
      Description copied from interface: ResettableIterator
      Resets the iterator to the first element.
      Specified by:
      reset in interface ResettableIterator
    • nextPoint

      public Point nextPoint(Point point)
      Gets the next point in the line.
      Parameters:
      point - the point to fill in with coordinates, or null to allocate a new point.
      Returns:
      the next point. The point is allocated only if the passed point is null, otherwise the same point is returned.
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<Point>
    • next

      public Point next()
      Specified by:
      next in interface Iterator<Point>
    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<Point>
    • main

      public static void main(String[] argv)
      Tests this class.
      Parameters:
      argv - the array of command line parameters.