/project/jni/sdl-1.3/src/video/android/atan2i.h

https://github.com/aichunyu/FFPlayer · C Header · 36 lines · 29 code · 5 blank · 2 comment · 4 complexity · 5863bb864ba08a2d1bb4b13b00e420cf MD5 · raw file

  1. #ifndef __ATAN2I_H__
  2. #define __ATAN2I_H__
  3. #include <math.h>
  4. // Fast arctan2, returns angle in radians as integer, with fractional part in lower 16 bits
  5. // Stolen from http://www.dspguru.com/dsp/tricks/fixed-point-atan2-with-self-normalization , precision is said to be 0.07 rads
  6. #ifndef M_PI
  7. #define M_PI 3.14159265358979323846
  8. #endif
  9. enum { atan2i_coeff_1 = ((int)(M_PI*65536.0/4)), atan2i_coeff_2 = (3*atan2i_coeff_1), atan2i_PI = (int)(M_PI * 65536.0) };
  10. static inline int atan2i(int y, int x)
  11. {
  12. int angle;
  13. int abs_y = abs(y);
  14. if( abs_y == 0 )
  15. abs_y = 1;
  16. if (x>=0)
  17. {
  18. angle = atan2i_coeff_1 - atan2i_coeff_1 * (x - abs_y) / (x + abs_y);
  19. }
  20. else
  21. {
  22. angle = atan2i_coeff_2 - atan2i_coeff_1 * (x + abs_y) / (abs_y - x);
  23. }
  24. if (y < 0)
  25. return(-angle); // negate if in quad III or IV
  26. else
  27. return(angle);
  28. };
  29. #define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
  30. #define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
  31. #endif