// (c) MIT 2003.  All rights reserved.

package rec.fun;

import rec.core.widgets.*;
import rec.sys.*;
import rec.util.*;
import rec.geo.*;
import java.util.*;

public class PerpLineMaker extends ParallelLineMaker {

  public PerpLineMaker()
  {
  }

  public boolean recognize( Surface s, Widget w )
  {
    WLine l = (WLine)w;

    Console.writeln( "perp and || line test" );
    if ( ( last == null ) || !s.containsWidget( last ) || w.equals( last ) )
      {
	last = l;
	ang = last.getLine().getAngle();

	return false;
      }

    Console.writeln( "going to compare." );

    double nang = l.getLine().getAngle();
    boolean ret = false;
    
    double df = delta( ang, nang );
    Console.writeln( "angles: del=" + df + "   " + ang + " - " + nang );

    if ( df < Math.PI / 16 )
      {
	Console.writeln( "Making lines parallel." );
	l.rotate( l.getMidpoint(), nang - ang );

	// our new angle for the line
	nang = ang;

	ret = false;
      }
    else if ( df > (7 * Math.PI / 16) )
      {
	Console.writeln( "Making lines perp." );
	l.rotate( l.getMidpoint(), nang - ang - Math.PI / 2 );

	// our new angle for the line
	nang = ang;

	ret = false;
      }

    last = l;
    ang = nang;
	
    return ret;
  }


}
