package Shapes;
import java.awt.Graphics;
import java.io.PrintStream;

/**
 * Ngon
 * <p><b>History</b> :<ul>
 *   <li>Version 0.1 : Initial version</li>
 * </ul></p>
 * @author Pierrick Calvet & Florian Delclaux
 */
public class Ngon extends OurShape{

  private double angle;
  private double factor;
  private int nSides;
  private int widthSide;

  public Ngon(int x, int y, int nSides, int widthSide){
    super(x, y);
    factor = 1;

    if(nSides > 2){
      this.nSides = nSides;
      this.widthSide = widthSide;
    }
    else
      System.out.println("Number of sides must be equal or more than 3 !");
  }

/**
 * Draw on Graphic g the Polygon
 */
  public void draw(Graphics g){
    angle = ((double)(360 - 360 / nSides) * Math.PI) / 180;
    int pointX[] = new int[nSides];
    int pointY[] = new int[nSides];
    
    pointX[0] = super.x;
    pointY[0] = super.y;

    for(int i = 1; i < nSides; i++){
      pointX[i] = pointX[i - 1] + (int)Math.round(Math.sin(angle * (double)(0 - i)) * (double)widthSide * factor);
      pointY[i] = pointY[i - 1] - (int)Math.round(Math.cos(angle * (double)(0 - i)) * (double)widthSide * factor);
    }
    g.drawPolygon(pointX, pointY, nSides);
  }

  public void scale(double factor){
    this.factor = factor;
  }


/**
 * Compute perimeter of Ngon
 * @return Value of perimeter
 */
  public double perimeter(){
    return (double)(nSides * widthSide) * factor;
  }

/**
 * Compute area of Ngon
 * @return Value of area
 */
  public double area(){
    System.out.println("Doesn't work yet !");
    return 0.0D;
  }
}
