////////////////////////////////////////////////////////////////////////////////
//																			  //
// AUTHOR:      Tevfik Metin Sezgin	                        				  //
//				Massachusetts Institute of Technology						  //
//				Department of Electrical Engineering and Computer Science	  //
//				Artificial Intelligence Laboratory							  //
//																			  //
// E-MAIL:		mtsezgin@ai.mit.edu, mtsezgin@mit.edu						  //
//																			  //
// COPYRIGHT:   Tevfik Metin Sezgin                    						  //
//              All rights reserved. This code can not be copied, modified,   //
//              or distributed in whole or partially without the written 	  //
//				permission of the author. Also see the COPYRIGHT file.		  //
//																			  //
////////////////////////////////////////////////////////////////////////////////

/** 
  * 
  * See the end of the file for the log of changes.
  * 
  * $Author: mtsezgin $
  * $Date: 2000/06/08 03:14:30 $   
  * $Revision: 1.12 $
  * $Headers$
  * $Id: Point.java,v 1.12 2000/06/08 03:14:30 mtsezgin Exp $     
  * $Name:  $   
  * $Locker:  $
  * $Source: /mit/mtsezgin/CVS/Repository/REC/Point.java,v $
  *  
  **/


import java.io.Serializable;

import java.util.Comparator;
import java.util.Vector;


/**
  *
  * This class represents a Vertex described by a Point and its
  * certainty.
  *
  **/

class      Vertex
extends    Point
implements Serializable,
		   Comparator
{

    /**
    *
    * The index
    *
    **/    
	int index;


    /**
    *
    * The certainty
    *
    **/    
	double certainty;
	

    /**
    *
    * The constructor.
    *
    **/    
    Vertex()
    {
        super();
		certainty = 0.0;
    }


    /**
    *
    * The constructor.
    *
    **/    
    Vertex( java.awt.Point point )
    {
	    super( point );

		if ( point instanceof Vertex ) {
			index     = ((Vertex)point).index;
			certainty = ((Vertex)point).certainty;
		} else {
			certainty = 0.0;
		}
    }


    /**
    *
    * The constructor.
    *
    **/    
    Vertex( int x, int y )
    {
        super( x, y );
		certainty = 0.0;
    }
	

    /**
    *
    * The constructor.
    *
    **/    
    Vertex( double certainty )
    {
        super();
		this.certainty = certainty;
    }


    /**
    *
    * The constructor.
    *
    **/    
    Vertex( java.awt.Point point, double certainty )
    {
        super( point );
		this.certainty = certainty;
		
		if ( point instanceof Vertex ) {
			index     = ((Vertex)point).index;
		}
    }


    /**
    *
    * The constructor.
    *
    **/    
    Vertex( int x, int y, double certainty )
    {
        super( x, y );
		this.certainty = certainty;
    }
    
    
    /**
    *
    * The constructor.
    *
    **/    
    Vertex( Vertex vertex )
    {
        this( vertex.x, vertex.y, vertex.certainty );
		index = vertex.index;
    }
    
    
    /**
    *
    * Set index
    *
    **/    
    public void
    setIndex( int index )
    {
		this.index = index;
    }
    
    
    /**
    *
    * Override toString
    *
    **/    
    public String
    toString()
    {
        return "Vertex ( " + x + ", " + y + " ) with certainty " + 
			( certainty + "              " ).substring( 0, 5 )   +
			", index " + index ;
    }
    
    
    /**
    *
    * Implement Comparator
    *
    **/    
    public int
    compare( Object o1, Object o2 )
    {
		if ( (((Vertex)o1).certainty-((Vertex)o2).certainty) < 0 )
			return -1;
		if ( (((Vertex)o1).certainty-((Vertex)o2).certainty) > 0 )
			return 1;
			return 0;
    }
    
    
    /**
    *
    * Implement Comparator
    *
    **/    
    public boolean
    equals( Object o1, Object o2 )
    {
        return ( ((Vertex)o1).certainty == ((Vertex)o2).certainty );
    }
    
    
    /**
    *
    * For obtaining a complete copy of an array of Vertex objects.
    *
    **/    
    public static Vertex[]
    cloneVertices( Vertex vertices[] )
    {
		Vertex copy[] = new Vertex[vertices.length];
		for ( int i=0; i< vertices.length; i++ ) {
			copy[i] = new Vertex( vertices[i] );
		}
		
   	    return copy;
    }
    
    
    /**
    *
    * Returns an array containing the elements of the Vector.
    *
    **/    
    public static Vertex[]
    vectorToArray( Vector vertices )
    {
		Vertex result[] = new Vertex[vertices.size() ];
		for ( int i=0; i< result.length; i++ ) {
			result[i] = (Vertex)( vertices.elementAt( i ) );
		}
		
   	    return result;
    }
}
/** 
  * 
  * $Log: Point.java,v $
  * Revision 1.12  2000/06/08 03:14:30  mtsezgin
  *
  * Made the class Serializable for supporting saving and loading
  * designs. Both the object attributes, and the original data points
  * are stored and restored.
  *
  * Revision 1.11  2000/06/03 01:52:34  mtsezgin
  * *** empty log message ***
  *
  * Revision 1.10  2000/05/03 23:26:46  mtsezgin
  * *** empty log message ***
  *
  * Revision 1.9  2000/04/28 04:45:04  mtsezgin
  *
  * Now each GeometricObject keeps the mouse input that was previously
  * discarded. User can switch between seeing the recognized mode and
  * the raw mode. setDataPoints( Polygon points ) and getDataPoints()
  * are added to GeometricObject, and all the implementors are modified
  * accordingly.
  *
  * Revision 1.8  2000/04/25 22:18:57  mtsezgin
  *
  * The getBounds changed to getRectangularBounds which returns a Rectangle.
  *
  * Revision 1.7  2000/04/17 07:02:30  mtsezgin
  *
  * Finally made the Rectangle really rotatable.
  *
  * Revision 1.6  2000/04/13 06:24:08  mtsezgin
  *
  * The current version of the program recognized Crosses, and Shades.
  * Implementors of Terminal and their descendants were modified to
  * implement the changes in GeometricObject.
  *
  * Revision 1.5  2000/04/11 01:41:46  mtsezgin
  * *** empty log message ***
  *
  * Revision 1.4  2000/04/11 00:41:47  mtsezgin
  *
  * Now the whole package succesfully parses a motor.
  *
  * Revision 1.3  2000/04/07 04:28:54  mtsezgin
  *
  * Added Rotatable interface. Rectangle and Line are Rotatable for now, but
  * Rectangle should be modified to have an angle field. Also other rotatable
  * classes should also implement Rotatable interface.
  *
  *
  **/
