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

package rec.core.widgets;

import edu.mit.sketch.geom.Point;
import edu.mit.sketch.geom.Polygon;
import edu.mit.sketch.geom.GeneralPath;
import java.awt.Graphics;
import java.awt.Rectangle;
import rec.geo.GPoint;
import rec.geo.Location;
import rec.geo.GComplex;
import rec.sys.VisibleWidget;
import rec.util.Assert;
import java.awt.geom.AffineTransform;

/**
 * 
 * <p>
 * Created:   Tue Mar 19 12:14:42 2002<br>
 * Copyright: Copyright (C) 2002 by MIT.  All rights reserved.<br>
 * 
 * @author <a href="mailto:moltmans@ai.mit.edu">Michael Oltmans</a>
 * @version $Id: WComplex.java,v 1.2 2003/03/06 00:40:47 moltmans Exp $
 **/

public class WComplex extends VisibleWidget
{
    private GComplex m_complexShape;
    
    public WComplex( GeneralPath generalPath, double length)
    {
	Assert.notNull( generalPath, "Can't have a complex with a null general path" );
	m_complexShape = new GComplex(generalPath, length);
    }

    public GPoint getStartPoint(){
	return m_complexShape.getStartPoint();
    }

    public GPoint getEndPoint(){
	return m_complexShape.getEndPoint();
    }


    /**
     * the length of the diagonal of the bounding box.
     **/
    public double size()
    {
	java.awt.Rectangle bounds = m_complexShape.getBounds();
	return Math.sqrt( (bounds.x * bounds.x) + (bounds.y * bounds.y) );
    }

    /**
     * Unsupported operation.
     **/
    public void resize( double scaleFactor )
    {
	throw( new UnsupportedOperationException( "Unimplimented resize method" ) );
    }

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

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

    /**
     * Check of gp is within offset distance of the path.
     **/
    public boolean includes( GPoint gp, double offset )
    {
	return m_complexShape.includes( gp, (int)offset );
    }

    /**
     * Check if gp is on the given path.
     **/
    public boolean contains( GPoint gp )
    {
	return includes( gp, 3 );
    }

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

	throw( new UnsupportedOperationException( "Unimplimented rotate method" ) );
	//     m_complexShape.translate( -1.0 * gp.getX(), -1.0 * gp.getY() );
	//     m_complexShape.rotateAboutOrigin( angle );
	//     m_complexShape.translate( gp.getX(), gp.getY() );
    }

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

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

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

    public GComplex getComplexShape() 
    {
	return (GComplex) m_complexShape.copy();
    }
  

}// WPolyLine
