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

////////////////////////////////////////////////////////////////////////////////
//
// FILE:	PartLibrary.java
//
// AUTHOR:	Manoj D. Muzumdar
//		archon@ai.mit.edu
//
// DATE:	July, 1998
//
// COPYRIGHT:	Massachusetts Institute of Technology
//		All rights reserved.
//
// PURPOSE:     Library for drawing the components of mechanical engineering
//                parts.
//
// HISTORY:     12-10-98 archon
//              integrated new rec.geo changes
//
////////////////////////////////////////////////////////////////////////////////

package rec.meche.util;

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

public final class PartLibrary
{
  public static GShape[] createScrew( double size )
  {
    final double headWidth = size;
    final double headLength = size / 5.0;
    final double tailWidth = size / 5.0;
    final double tailLength = size * 1.5;
    final double threadSeparation = 5.0;

    Assert.check( headWidth >= tailWidth,
      "screw heads much be at least as wide as screw tails" );

    int numberOfThreads = (int)Math.floor( Math.max( 0.0,
      tailLength / threadSeparation ) );

    GShape[] shapes = new GShape[7 + numberOfThreads];

    // Create screw head.

    shapes[0] = new GSegment( new GPoint( 0.0, 0.0 ),
			      new GPoint( headWidth, 0.0 ) );
    shapes[1] = new GSegment( new GPoint( 0.0, 0.0 ),
			      new GPoint( 0.0, headLength ) );
    shapes[2] = new GSegment( new GPoint( 0.0, headLength ),
			      new GPoint( headWidth,
					  headLength ) );
    shapes[3] = new GSegment( new GPoint( headWidth, 0.0 ),
			      new GPoint( headWidth,
					  headLength ) );

    // Create screw tail.

    double firstX = (headWidth - tailWidth) / 2.0;
    double secondX = (headWidth + tailWidth) / 2.0;
    double lowestY = headLength + tailLength;

    shapes[4] = new GSegment( new GPoint( firstX, headLength ),
			      new GPoint( firstX, lowestY ) );
    shapes[5] = new GSegment( new GPoint( secondX, headLength ),
			      new GPoint( secondX, lowestY ) );
    shapes[6] = new GSegment( new GPoint( firstX, lowestY ),
			      new GPoint( secondX, lowestY ) );

    // Create the threads.

    if( numberOfThreads > 0 ) {

      double currentY = headLength + threadSeparation;

      for( int i = 7; i < 7 + numberOfThreads; ++i ) {
	shapes[i] = new GSegment( new GPoint( firstX,
					      currentY ),
				  new GPoint( secondX,
					      currentY ) );
	currentY += threadSeparation;
      }
    }

    return( shapes );
  }

  public static GShape[] createNut( double size )
  {
    GShape[] shapes = new GShape[3];
  }
}

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