wyvern.util
Class Bresenham

java.lang.Object
  extended bywyvern.util.Bresenham
All Implemented Interfaces:
java.util.Iterator

public class Bresenham
extends java.lang.Object
implements java.util.Iterator

An object that takes two endpoints and returns all the points on the line between them (including the endpoints).

This class is NOT thread-safe; don't access it from multiple threads.

Version:
1.0, Sep 05, 1997
Author:
Steve Yegge

Constructor Summary
Bresenham(int x1, int y1, int x2, int y2)
          Constructs a new Bresenham iterator between two points.
Bresenham(Point p1, Point p2)
          Constructs a new Bresenham iterator between two points.
 
Method Summary
 boolean hasNext()
          Implements java.util.Iterator.hasNext();
static void main(java.lang.String[] argv)
          Tests the output.
 java.lang.Object next()
          Implements java.util.Iterator.next();
 void remove()
          Removes the element on the line.
 void reset(int x1, int y1, int x2, int y2)
          Resets all the state variables for a new line.
 java.lang.String toString()
          Returns String representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Bresenham

public Bresenham(Point p1,
                 Point p2)
Constructs a new Bresenham iterator between two points.

Parameters:
p1 - the start point
p2 - the end point

Bresenham

public Bresenham(int x1,
                 int y1,
                 int x2,
                 int y2)
Constructs a new Bresenham iterator between two points.

Parameters:
x1 - X coordinate of start point
y1 - Y coordinate of start point
x2 - X coordinate of end point
y2 - Y coordinate of end point
Method Detail

reset

public void reset(int x1,
                  int y1,
                  int x2,
                  int y2)
Resets all the state variables for a new line.

Parameters:
x1 - X coordinate of start point
y1 - Y coordinate of start point
x2 - X coordinate of end point
y2 - Y coordinate of end point

hasNext

public boolean hasNext()
Implements java.util.Iterator.hasNext();

Specified by:
hasNext in interface java.util.Iterator
Returns:
false if we've returned the endpoint, true otherwise

next

public java.lang.Object next()
Implements java.util.Iterator.next();

Specified by:
next in interface java.util.Iterator
Returns:
next Point on the line (needs to be cast from Object)

remove

public void remove()
Removes the element on the line. By default, throws an exception.

Specified by:
remove in interface java.util.Iterator
Throws:
UnsupportedOperationException, - unless a subclass wants to handle this method.

toString

public java.lang.String toString()
Returns String representation.


main

public static void main(java.lang.String[] argv)
Tests the output.