#include "poly.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

#define MAX_SIZE 100

const char *usage = "-x sx -y sy -R radius -N nvertices FILE";


int main(int argc, char* argv[]) {

  struct Poly P; 
  initPoly(&P);
   
  double x[MAX_SIZE];
  double y[MAX_SIZE];
  int NW;
  
  int opt;
  while((opt = getopt(argc, argv, "x:y:R:N:")) != -1) {
    switch(opt) {
      case 'x' : 
         P.sx =  atof(optarg);
         break;
      case 'y' : 
         P.sy = atof(optarg);
         break;
      case 'R' :
         P.R = atof(optarg);
         break;
      case 'N' :
         P.NV = atoi(optarg);
         break;
      default:
         printf("Nie znam takiej flagi -%c\n", opt);
         printf("USAGE: %s %s\n", argv[0], usage);
         exit(EXIT_FAILURE);
    }
  }

  polyCoords(P, x, y, &NW);

  int i;
  for (i =0; i<P.NV; i++) {
    printf("%g %g\n", x[i], y[i]);
  }
  printf("Ilosc wierzcholkow %d\n", NW);
  
  if (optind >= argc) {
    printf("Podaj nazwe pliku na wyniki\n");
    exit(EXIT_FAILURE);
  }
  poly(P, argv[optind]);
  return 0;
}
