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

////////////////////////////////////////////////////////////////////////////////
//
// FILE:	WLine.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.sys.*;
import rec.geo.*;

public class WLine extends VisibleWidget
{
  public WLine( GPoint p1, GPoint p2 )
  {
    setEnglishName( "Line" );
    m_Segment = new GSegment( p1, p2 );
  }

  public WLine( rec.sys.Squiggle s )
  {
    this( s.getFirstPoint(), s.getLastPoint() );
  }

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

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

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

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

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

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

  public boolean includes( GPoint gp, double offset )
  {
    return( m_Segment.includes( gp, offset ) );
  }

  public boolean contains( GPoint gp )
  {
    return( m_Segment.contains( gp ) );
  }

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

  public void move( GPoint gp )
  {
    m_Segment.translate( m_Segment.getMidpoint(), gp );
  }

  /**
   * Move by the given amount.  gp is a vector, not absolute position.
   */
  public void translate( GPoint gp )
  {
    m_Segment.translate( gp.x, gp.y );
  }

  public void rotate( GPoint gp, double angle )
  {
    m_Segment.rotate( gp, angle );
  }

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

  public Location getLocation()
  {
    return( new Location( m_Segment.getBounds() ) );
  }

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

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

  public double getLength()
  {
    return( m_Segment.getLength() );
  }

  public GPoint getMidpoint()
  {
    return( m_Segment.getMidpoint() );
  }

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

  public void setHead( GPoint gp )
  {
    GPoint head = m_Segment.getHeadPoint();

    head.x = gp.x;
    head.y = gp.y;
  }

  public GPoint getHead()
  {
    return( m_Segment.getHeadPoint() );
  }

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

  public void setTail( GPoint gp )
  {
    GPoint tail = m_Segment.getTailPoint();

    tail.x = gp.x;
    tail.y = gp.y;
  }

  public GPoint getTail()
  {
    return( m_Segment.getTailPoint() );
  }

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

  public Object clone()
  {
    return( new WLine( getHead(), getTail() ) );
  }


  public GSegment getLine( )
  {
    return (GSegment)m_Segment.copy();
  }

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

  private GSegment m_Segment;
}

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