#ifndef _MYTRIG_CPP_
#define  _MYTRIG_CPP_

#include "mytrig.h"
#include <iostream>
#include <math.h>

using namespace std;
//#define DEG_TO_RAD(DEG) (((DEG)*(M_PI))/(180)) // degrees to radians
//#define MAX_ANG 90

////table to keep values of cos from 0 to 90º with a 0.1º resolution
//double table[MAX_ANG * 10 + 1];
double tablemycos[MAX_ANG * 10 + 1];
/*
  <+===================+>
  | My Trig Functions |
<+===================+>
*/

void pop_lookup_table()
{
   for (double i = 0; i <= MAX_ANG * 10; i++)
   {
// 	cout << i << endl;
      // values of cos function are passed in radian angles
          // convertion is needed
     tablemycos[(int)i] = cos(DEG_TO_RAD(i / 10));
// 	cout << tablemycos[(int)i] << endl;
   }
}


double mycos(double deg)
{
	deg = fabs(deg);
	deg = (int)(deg*10) % 3600;
	deg = deg / 10;
// 	cout << deg << endl;
	if(deg <= 90)
		return tablemycos[(int)(deg * 10)];
	if(deg <= 180)
		return -mycos(deg - 90);
	if(deg <= 270)
		return -mycos(deg - 180);
	else
		return mycos(deg - 270);
}

double mysin(double deg)
{
	return mycos(deg - 90);
}


double mytan(double deg)
{
	return mycos(deg - 90)/mycos(deg);
}
#endif
