/*
 *  mymath.c
 *  Bmp
 *
 *  Created by Martin Štrympl on 3/26/11.
 *  Copyright 2011 School. All rights reserved.
 *
 */

#include "mymath.h"

#include <math.h>

void PointFromAgle(struct sGerber_Point *ps_point, long double ld_agle)
{
  ld_agle=fmod(((ld_agle/180.0L)*MY_PI), (2.0L*MY_PI));
  
  if (ld_agle<0.0L) ld_agle=-ld_agle;
  
  //sin part
  if (ld_agle<=0.5L*MY_PI)
  {
    ps_point->ld_x=asin(ld_agle);
  }
  else if (ld_agle>=1.5L*MY_PI)
  {
    ps_point->ld_x=asin(2.0*MY_PI-ld_agle);
  }
  else if (ld_agle<=1.0L*MY_PI)
  {
    ps_point->ld_x=asin(1.0*MY_PI-ld_agle);
  }
  else if (ld_agle>=1.0L*MY_PI)
  {
    ps_point->ld_x=asin(1.0*MY_PI-ld_agle);
  }
  
  //cos part
  if (ld_agle<=1.0L*MY_PI)
  {
    ps_point->ld_x=acos(ld_agle);
  }
  else if (ld_agle>=1.0L*MY_PI)
  {
    ps_point->ld_x=asin(2.0*MY_PI-ld_agle);
  }
}
