/**
* This class defines Hilbert curves.  
* @author Frank Ruskey, January 1998.
 * @version 1.0
 * @revised Johannes Martin
 * @version 1.1
 * @revised Bette Bultena, October 2001
 * @version 1.2
 */
public abstract class Hilbert {
  /**
   * Produce the <i>i</i>-th Hilbert curve.
   */

	public void makeCurve( int i ) {
		A( i );
	}   
 
	private void A ( int i ) {
	if (i>0) {
		D( i-1 );  plot( -1, 0 );		
		A( i-1 );  plot( 0, 1 );		
		A( i-1 );  plot( 1, 0 );		
		B( i-1 );  
	} }

	private void B ( int i ) {
	if (i>0) {
		C( i-1 );  plot( 0, -1 );		
		B( i-1 );  plot( 1, 0 );		
		B( i-1 );  plot( 0, 1 );		
		A( i-1 );  
	} }

	private void C ( int i ) {
	if (i>0) {
		B( i-1 );  plot( +1, 0 );		
		C( i-1 );  plot( 0, -1 );		
		C( i-1 );  plot( -1, 0 );		
		D( i-1 );  
	} }

	private void D ( int i ) {
	if (i>0) {
		A( i-1 );  plot( 0, 1 );		
		D( i-1 );  plot( -1, 0 );		
		D( i-1 );  plot( 0, -1 );		
		C( i-1 );  
	} }

	/**
	* Draw a line from the current position to the next position,
	* where the next position is <I>xh</I> horizontal units
	* and <I>xh</I> vertical units.  The user must override this
	* method.
	*/
	protected abstract void plot ( int xh, int yh );
	
}

