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

////////////////////////////////////////////////////////////////////////////////
//
// FILE:	CurveParser.java
//
// AUTHOR:	Manoj D. Muzumdar
//		archon@ai.mit.edu
//
// DATE:	Aug 98
//
// COPYRIGHT:	Massachusetts Institute of Technology
//		All rights reserved.
//
// PURPOSE:     Curve recognition library
//
// HISTORY:     Aug 98  archon  created
//
//              Nov 98  archon
//              Now aware of new rec.geo package.
//
//              Feb 99  archon
//              Updated to recognize more varieties of curves.
//
////////////////////////////////////////////////////////////////////////////////

package rec.core.recognizers;

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

public final class CurveParser
{
  public static boolean isCurve( Squiggle st )
  {
    if( st.getNumberOfPoints() < 4 )
      return( false );

    GSegment diam = new GSegment( st.getFirstPoint(), st.getLastPoint() );
    GPoint center = diam.getMidpoint();
    double dist = diam.getLength() / 3.0;

    //Console.writeln( "allowed distance = " + dist );

    // Exclude the ends from the calculation.

    for( int i = 1; i < st.getNumberOfPoints() - 1; ++i ) {

      if( Geometry.distance( st.getPointAt( i ), center ) < dist ) {
	//Console.writeln( "distance = "
	//		 + Geometry.distance( st.getPointAt( i ), center ) );
	return( false );
      }
    }

    return( true );
  }
}

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