#include <math.h>
#include <stdlib.h>
#include "types.h"
#include "IOPunct.h"

double grad(double r){ return r*180/M_PI; };
double rad (double g){ return g*M_PI/180; };

/*----------------------------------------------------------------*/
/* Lab 1, Var 1 */
/*----------------------------------------------------------------*/
void calc_coef_rot(double alfa, double &c, double  &s)
{
   alfa = rad(alfa);
   c = cos(alfa); 
   s = sin(alfa);
}

void rot_punct(Punct &r, Punct p, double &c, double &s)
{
   r.x = c * p.x - s * p.y;
   r.y = s * p.x + c * p.y;
}

void rot_set_puncte(PPunct p, int nr, double alfa)
{
   double c, s;
   int i;
   calc_coef_rot(alfa, c, s);
   for(i=0; i<nr; i++){ rot_punct(p[i], p[i], c, s); }
}
/*----------------------------------------------------------------*/
/* Lab 1, Var 2 */
/*----------------------------------------------------------------*/
void depl_punct(Punct &r, Punct p, float a, float b)
{
   r.x = p.x + a;
   r.y = p.y + b;
}

void depl_set_puncte(PPunct p, int nr, float a, float b)
{
   int i;
   for(i=0; i<nr; i++){ depl_punct(p[i], p[i], a, b); }
}
/*----------------------------------------------------------------*/
/* Lab 1, Var 3 */
/*----------------------------------------------------------------*/
void depl_rot_set_puncte(PPunct p, int nr, float a, float b, double alfa)
{
    depl_set_puncte(p, nr, a, b);
    rot_set_puncte (p, nr, alfa);
}
/*----------------------------------------------------------------*/
/* Lab 1, Var 4 */
/*----------------------------------------------------------------*/
void polar_punct(Punct &pol, Punct cart)
{ /* pol.x - ro, pol.y - fi */
   pol.x = sqrt(pow(cart.x, 2)+pow(cart.y, 2));
   if(cart.x != 0) pol.y = atan2(cart.y, cart.x);
   else /* cart.x == 0 */
   {   
      if(cart.y > 0)          pol.y =  M_PI / 2;
      else if(cart.y < 0)     pol.y = -M_PI / 2;
      else                    pol.y =  0;
   }
}

void cartez_punct(Punct &cart, Punct pol)
{  /* pol.x - ro, pol.y - fi */
   cart.x = pol.x * cos(pol.y);
   cart.y = pol.x * sin(pol.y);
}

void polar_set_puncte(PPunct p, int nr)
{
   for(int i=0; i<nr; i++){ polar_punct(p[i], p[i]); }
}

void cartez_set_puncte(PPunct p, int nr)
{
   for(int i=0; i<nr; i++){ cartez_punct(p[i], p[i]); }
}
/*----------------------------------------------------------------*/
