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

// $Id: VeryLooseCircleRecognizer.java,v 1.5 2003/03/06 00:40:47 moltmans Exp $
// Time-stamp: <2000-03-11 18:54:45 moltmans>
package rec.core.recognizers;


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

public class VeryLooseCircleRecognizer extends LooseCircleRecognizer
{

  public static boolean isCircle( rec.sys.Squiggle st )
  {
    if ( isLoop( st ) )
      {
	return true;
      }

    return false;
  }

  public static boolean isLoop( rec.sys.Squiggle st )

  {
    if( !( Geometry.distance( st.getFirstPoint(),
			      st.getLastPoint() )  < 15  ) )
      return( false );

    return( true );
  }


  public VeryLooseCircleRecognizer()
  {
  }


  public boolean recognize( Surface s, Widget w )
  {
    rec.sys.Squiggle st = (rec.sys.Squiggle)w;

    if( isCircle( st ) ) {

      Console.writeln( "circle online" );

      WCircle c = new WCircle( st.getBounds() );
      s.replaceWidget( st, c );

      return( true );
    }

    return( false );
  }

}

///////////////////////////////////////////////////////////////////////////////
