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

////////////////////////////////////////////////////////////////////////////////
//
// FILE:	WCircle.java
//
// AUTHOR:	Manoj D. Muzumdar
//		archon@ai.mit.edu
//
//              Adapted from code written by Luke Weisman
//              luke@ai.mit.edu
//
// DATE:	06-XX-98
//
// COPYRIGHT:	Massachusetts Institute of Technology
//		All rights reserved.
//
// PURPOSE:	Drawing recognition
//
// HISTORY:     11-15-98 archon
//              Now aware of new rec.geo package
//
////////////////////////////////////////////////////////////////////////////////

package rec.core.widgets;

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

public class WCircle extends VisibleWidget
{
  public WCircle( GPoint center, double radius )
  {
    setEnglishName( "Circle" );
    m_Circle = new GCircle( center, radius );
  }

  /**
   * Creates the best fitting circle for the Rectangle.
   */
  public WCircle( Rectangle r )
  {
    setEnglishName( "Circle" );
    double radius = (r.width + r.height) / 4.0;

    m_Circle = new GCircle(
      new GPoint( (double)r.x + ((double)r.width / 2.0),
		  (double)r.y + ((double)r.height / 2.0) ),
      radius );
  }

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

  public double size()
  {
    return( m_Circle.size() );
  }

  public void resize( double scaleFactor )
  {
    m_Circle.resize( scaleFactor );
  }

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

  public void draw( Graphics g )
  {
    m_Circle.display( g );
  }

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

  /**
   * @return Check if gp is on the circle border (within offset)
   **/
  public boolean includes( GPoint gp, double offset )
  {
    return( m_Circle.includes( gp, offset ) );
  }

  /**
   * @return  true if the point is _inside_ the circle (within offset)
   */
  public boolean contains( GPoint gp, double offset )
  {
    return( m_Circle.contains( gp.x, gp.y, offset ) );
  }

  /**
   * @return  true if the point is _inside_ the circle (within offset)
   */
  public boolean contains( GPoint gp )
  {
    return( m_Circle.contains( gp ) );
  }


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

  public void move( GPoint gp )
  {
    m_Circle.translate( m_Circle.getCenter(), gp );
  }

  public void rotate( GPoint gp, double angle )
  {
    // Rotating a circle has no effect.
  }

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

  public Location getLocation()
  {
    return( new Location( m_Circle.getCenter(), m_Circle.getRadius() ) );
  }

  public Rectangle getBounds()
  {
    return( m_Circle.getBounds() );
  }

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

  public void translate( double dx, double dy )
  {
    m_Circle.translate( dx, dy );
  }

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

  public GPoint getCenter()
  {
    return( m_Circle.getCenter() );
  }

  public double getRadius()
  {
    return( m_Circle.getRadius() );
  }

  public GCircle getCircle()
  {
    return( new GCircle( m_Circle ) );
  }

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

  public Object clone()
  {
    return( new WCircle( m_Circle.getCenter(), m_Circle.getRadius() ) );
  }

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

  private GCircle m_Circle;
}

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