/*
 * Edge.java
 *
 * Created on December 3, 2003, 12:49 AM
 */

/**
 *
 * @author  linyuan
 */
public class Edge extends Selectable {
    
    Vertex u;
    
    Vertex v;
    
    /** Creates a new instance of Edge */
    public Edge() {
    }
    
    public Edge(Vertex u, Vertex v){
     this.u=u;
     this.v=v;
    }
    double distance(int x, int y) {
        double a, b, c;
        a=(u.x-x)*(u.x-x)+(u.y-y)*(u.y-y)+0.0;
        b=(v.x-x)*(v.x-x)+(v.y-y)*(v.y-y)+0.0;
        c=(u.x-v.x)*(u.x-v.x)+(u.y-v.y)*(u.y-v.y)+0.0;
        if(a>=b+c) return Math.sqrt((double) b);
        if(b>=a+c) return Math.sqrt((double) a);
        return Math.sqrt(b-(c+b-a)*(c+b-a)/4.0/c);
    }
    
    public void draw(java.awt.Graphics g){
        if(isSelected()) g.setColor(selectedColor);
        else g.setColor(color);
        g.drawLine(u.x,u.y,v.x,v.y);
    }
}
