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

////////////////////////////////////////////////////////////////////////////////
//
// FILE:	WMSpring.java
//
// AUTHOR:	Manoj D. Muzumdar
//		archon@ai.mit.edu
//
// DATE:	Mar 99
//
// COPYRIGHT:	Massachusetts Institute of Technology
//		All rights reserved.
//
// PURPOSE:     Mechanical engineering drawing recognition
//
// HISTORY:     Mar 99  archon  created
//
////////////////////////////////////////////////////////////////////////////////

package rec.meche;

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

public class WMSpring extends WPart
{
  public WMSpring( GPoint center, double angle, double size, Cloneable data )
  {
    super( center, angle, size, data );

    //    setColor( Color.cyan );
  }

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

  public Object clone()
  {
    return( new WMSpring( getCenter(), getAngle(), size(), getData() ) );
  }

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

  protected GShape[] create( double size, Cloneable data )
  {
    GShape[] shapes = new GShape[11];

    double unit = size / 10.0;
    // i have no idea why this is like this... it makes the spring too long
    //double inc = size / 8.0;
    double inc = size / 20.0;   // this should be closer
    
    shapes[0] = new GSegment( GPoint.ORIGIN,
			      new GPoint( unit, inc ) );
    shapes[1] = new GSegment( new GPoint( unit, inc ),
			      new GPoint( -1 * unit, inc * 3.0 ) );
    shapes[2] = new GSegment( new GPoint( -1 * unit, inc * 3.0 ),
			      new GPoint( unit, inc * 5.0 ) );
    shapes[3] = new GSegment( new GPoint( unit, inc * 5.0 ),
			      new GPoint( -1 * unit, inc * 7.0 ) );
    shapes[4] = new GSegment( new GPoint( -1 * unit, inc * 7.0 ),
			      new GPoint( unit, inc * 9.0 ) );
    shapes[5] = new GSegment( new GPoint( unit, inc * 9.0 ),
			      new GPoint( -1 * unit, inc * 11.0 ) );
    shapes[6] = new GSegment( new GPoint( -1 * unit, inc * 11.0 ),
			      new GPoint( unit, inc * 13.0 ) );
    shapes[7] = new GSegment( new GPoint( unit, inc * 13.0 ),
			      new GPoint( -1 * unit, inc * 15.0 ) );
    shapes[8] = new GSegment( new GPoint( -1 * unit, inc * 15.0 ),
			      new GPoint( unit, inc * 17.0 ) );
    shapes[9] = new GSegment( new GPoint( unit, inc * 17.0 ),
			      new GPoint( -1 * unit, inc * 19.0 ) );
    shapes[10] = new GSegment( new GPoint( -1 * unit, inc * 19.0 ),
			       new GPoint( 0.0, inc * 20.0 ) );

    return( shapes );
  }

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

  public GPoint getHead()
  {
    return( ((GSegment)getComponents()[0]).getHeadPoint() );
  }

  public GPoint getTail()
  {
    return( ((GSegment)getComponents()[10]).getTailPoint() );
  }
}

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