import java.awt.*;

public class LineFigure extends Figure {

  int x1,y1,x2,y2;   // the coordinates of the endpoints
  Color c;

  public LineFigure (int x1Val, int y1Val, int x2Val, int y2Val, Color cVal) {
    x1 = x1Val; y1 = y1Val;
    x2 = x2Val; y2 = y2Val;
    c = cVal;
  }

  public void draw (Graphics g) {
    g.setColor(c);
    g.drawLine(x1, y1, x2, y2);
  }

  public boolean inFigure (int a, int b) {
    // is (a,b) inside a long, narrow ellipse around the line?
    return Math.sqrt((x1-a)*(x1-a) + (y1-b)*(y1-b))
         + Math.sqrt((x2-a)*(x2-a) + (y2-b)*(y2-b))
         < Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)) + 5.0;
  }
  
  public void drag (int dx, int dy) {
    x1 += dx; y1 += dy;
    x2 += dx; y2 += dy;
  }
}
