// JDraw - FOval class
// Written by Jim Calciano, Melanie Lear, and PJ Waskiewicz
// November 18, 1998
// Class which extends our abstract class DrawObject, and makes a
// filled oval

import java.awt.*;

public class FOval extends DrawObject{
  private int x1, x2, y1, y2, height, width;
  private Color color;
  // Constructor for when the object is being drawn.
  public FOval(int x1, int y1, int x2, int y2, Color color){
    this.x1 = x1;
    this.x2 = x2;
    this.y1 = y1;
    this.y2 = y2;
    this.color = color;
    // Determine what our height and with are properly
    height = Math.abs(y2-y1);
    width = Math.abs(x2-x1);
  }
  // Constructor for when the object is being created from opening a file
  public FOval(int x1, int y1, int x2, int y2, Color color, String s){
    this.x1 = x1;
    this.y1 = y1;
    width = x2;
    height = y2;
    this.color = color;
  }
  // This method returns a string to allow the object to be written to a file
  public String returnString(){
    return (new String("foval" + " " + x1 + " " + y1 + " " + width +
                       " " + height + " "  + color.getRed() + "," +
                       color.getGreen() + "," + color.getBlue()));
  }
  public void paint (Graphics g){
    g.setColor(color);
    g.fillOval(x1-width, y1-height, 2*width, 2*height);
  }
  public Point firstSelPoint(){
    return(new Point(x1,y1));
  }
  public Point secondSelPoint(){
    return(new Point(width,height));
  }
  public Color selColor(){
    return color;
  }
  public void setSelColor(Color c){}
  public boolean areYouSelected(){
    return false;
  }
  public void youAreSelected(boolean b){
  }
  public boolean getIfObjectClicked(){
    return false;
  }
  public boolean getIfHandleClicked(){
    return false;
  }
  public boolean intersects(int x, int y){
    Point center = new Point(x1, y1);
    double answer1, answer2, answer;
    int h,w;
    h = height;
    w = width;
    while (true){
      if (w != 1)
        w--;
      if (h != 1)
        h--;
      if (w == 1 && h == 1)
        break;
      answer1 = ((Math.pow(x-center.x,2))/((Math.pow(w,2))));
      answer2 = ((Math.pow(y-center.y,2))/((Math.pow(h,2))));
      answer = answer1+answer2;
      if (answer >= .85 && answer <= 1.15)
        return true;
    }
    return false;
  }
}