// JDraw - Oval class
// Written by Jim Calciano, Melanie Lear, and PJ Waskiewicz
// November 18, 1998
// Class to draw an oval from the abstract class DrawObject

import java.awt.*;

public class Oval extends DrawObject{
  private int x1, x2, y1, y2, height, width;
  private Color color;
  // Constructor for when the oval is being drawn
  public Oval(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;
    height = Math.abs(y2-y1);
    width = Math.abs(x2-x1);
  }
  // Constructor for when the oval is created from opening a file
  public Oval(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;
  }
  // Method to return the attributes of the oval to be written to a file
  public String returnString(){
    return (new String("oval" + " " + x1 + " " + y1 + " " + width + " " + 
                       height + " "  + color.getRed() + "," + color.getGreen()
                       + "," + color.getBlue()));
  }
  public void paint (Graphics g){
    g.setColor(color);
    g.drawOval(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;
    answer1 = ((Math.pow(x-center.x,2))/((Math.pow(width,2))));
    answer2 = ((Math.pow(y-center.y,2))/((Math.pow(height,2))));
    answer = answer1+answer2;
    if (answer >= .85 && answer <= 1.15)
      return true;
    return false;
    
  }
}