/*
 *		Created on Jan 31, 2007 2:41:33 PM
 *              Modified 5 Feb. 2007 11:15:38 PM
 */


import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;

public interface Shape 
{
   public int getArea();
   public void draw (Graphics g);
   public boolean contains (Point point);
   public String toString ();
}


class Rectangle implements Shape
{
   private Point upperLeft, lowerRight;
   private Color color;
   
   public Rectangle (Point upperLeft, Point lowerRight, Color color) 
   {
       this.upperLeft = upperLeft;
       this.lowerRight = lowerRight;
       this.color = color;
   }
   
    
   public int getArea()
   {
      int width = Math.abs(upperLeft.x - lowerRight.x);
      int height = Math.abs(upperLeft.y - lowerRight.y);
      int area = (width * height);
      return area;
   }
   
   public void draw (Graphics g) 
   {
      int width = Math.abs(upperLeft.x - lowerRight.x);
      int height = Math.abs(upperLeft.y - lowerRight.y);
      g.setColor(color.yellow);
      g.fillRect(upperLeft.x, upperLeft.y,width, height);
       
   }
   
   public boolean contains (Point point) 
   { 
      if(point.x > upperLeft.x && point.x < lowerRight.x)
      {
        if(point.y > upperLeft.y && point.y < lowerRight.y)
        {
            return true;
        }
      }
     else
     {
         return false;
     }
     return false;
   } 
   
   public String toString () 
   {
      return "Rectangle with an area of " + getArea();
   }
}


class Circle implements Shape 
{
   private double radius;
   private Point center;
   private Color color;

   public Circle (double radius, Point center, Color color)
   {
      this.radius = radius;
      this.center = center;
      this.color = color;
   }
   
   public int getArea() 
   {
      double area = Math.PI * (radius * radius);
      return (int)area;
   }

   public void draw (Graphics g) 
   {
      double x = center.getY() - radius;
      double y = center.getY() - radius;
      g.setColor(Color.blue);
      g.fillOval( (int)x,(int)y, (int)radius*2, (int)radius*2);
   }
   
   public boolean contains (Point point) 
   {
      double dist;
      double  x = ((center.x - point.x)*(center.x - point.x));
      double y = ((center.y - point.y) * (center.y - point.y));
      dist = Math.sqrt(x + y);
      if(dist < radius)
      {
          return true;
      }
      else
      {
         return false;
      }
   }

   public String toString () 
   {
      return "Circle with an area of " + getArea();
   }
}


class Triangle implements Shape 
{
   private Point points[];
   private Color color;
   private int area;

   public Triangle (Point p1, Point p2, Point p3, Color color) 
   {
      p1 = p1;
       p2 = p2;
       p3 = p3;
      color = color;
   }      
   
   private void computeArea () {
      double sqDist[] = new double[3];
      for (int i=0; i < 3; ++i) {
         Point a = points[i];
         Point b = points[(i+1)%3];
         double dist = Math.sqrt((b.x-a.x)* (b.x-a.x) + (b.y-a.y) * (b.y-a.y));
         sqDist[i] = dist*dist;
      }
      area = (int)(.25*Math.sqrt(2*sqDist[1]*sqDist[2] + 2*sqDist[2]*sqDist[0]+
                              2*sqDist[0]*sqDist[1] - sqDist[0]*sqDist[0] -
                              sqDist[1]*sqDist[1] - sqDist[2]*sqDist[2]));
   }                              
   
   public int getArea() 
   { 
       return 1;
   }

   public void draw (Graphics g) {
   }
   
   public boolean contains (Point pt) {
      int crossings = 0;
      
      // General polygon inclusion test: if You draw a line from the point
      //    across the x axis, how many lines of the polygon do you cross?
      for (int i=0; i < 3; ++i) {
         Point a = points[i];
         Point b = points[(i+1)%3];
         
         // find the x,y coordinate at which the point's x-axis line
         //    crosses 
         double x = ((a.x*b.y - a.y*b.x) * pt.x - (a.x-b.x)*(pt.x*pt.y))/
                    (-(a.y-b.y)*pt.x);
         double y = ((a.y-b.y)*pt.x*pt.y) / ((a.y-b.y)*pt.x);
         
         // check if the coordinate is inside both line segments
         if (((x <= a.x && x >= b.x) || (x >= a.x && x <= b.x)) &&
             ((y <= a.y && y >= b.y) || (y >= a.y && y <= b.y)) && x < pt.x) {
             ++crossings;
         }
   	}
   	// If the number of lines crossed is odd, the point is in the polygon.
   	return (crossings%2 == 1);
   }

   public String toString ()
   {
      return "Triangle with an are of " + getArea();
   }
}
