import java.util.Arrays;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * User: Pavel Kunyavskiy
 * Date: 19/10/13
 * Time: 20:47
 */
public class EllipseGenerator implements PolygonGenerator {

    public void generate(int[] x, int[] y, int maxCx, int maxCy, Random rnd) {
        int n = x.length;
        assert x.length == y.length;
        double[] angles = new double[n];
        for (int i = 0; i < n; i++)
            angles[i] = rnd.nextDouble()*Math.PI*2;

        Arrays.sort(angles);
        int shift = rnd.nextInt(n);
        double r1 = rnd.nextDouble()*maxCx / 2;
        double r2 = rnd.nextDouble()*maxCy / 2;
        for (int i = 0; i < n; i++){
            x[(i + shift) % n] = (int)(r1 * Math.sin(angles[i]) + r2 * Math.cos(angles[i]));
            y[(i + shift) % n] = (int)(r1 * Math.cos(angles[i]) + r2 * Math.sin(angles[i]));
        }
        CrossReverseGenerator.fixSegmentIntersection(x, y);
    }

    public String Name(){
        return "Points are close to ellipse";
    }

    public String shortName() {
        return "ellipse";
    }

}
