import java.awt.*;

public class OvalFigure extends Figure {

  int x,y;           // the coordinates of the upper-left corner
  int width,height;  // the size of the rectangle holding the oval
  boolean filled;
  Color c;

  public OvalFigure (int x1, int y1, int x2, int y2, boolean f, Color cVal) {
    width = Math.abs(x2-x1);
    height = Math.abs(y2-y1);
    x = Math.min(x1,x2);
    y = Math.min(y1,y2);
    filled = f;
    c = cVal;
  }

  public void draw (Graphics g) {
    g.setColor(c);
    if (filled) g.fillOval(x, y, width, height);
    else        g.drawOval(x, y, width, height);
  }

  public boolean inFigure (int a, int b) {
    if (x>a || a>x+width || y>b || b>y+height) return false;
    double u = 2.0*(a-x)/width - 1.0;
    double v = 2.0*(b-y)/height - 1.0;
    return u*u + v*v <= 1.0;
  }

  public void drag (int dx, int dy) {
    x += dx; y += dy;
  }
}
