Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
2.4 KiB

  1. /***
  2. **
  3. ** Module: Trig
  4. **
  5. ** Description:
  6. ** This is a module of the T1 to TT font converter. The module
  7. ** contains a look-up table for computing atan2() faster, and
  8. ** with less precision than that of the c run-time library.
  9. **
  10. ** Author: Michael Jansson
  11. **
  12. ** Created: 5/26/93
  13. **
  14. ***/
  15. #include "types.h"
  16. #include "metrics.h"
  17. #include "trig.h"
  18. static const unsigned char atan_tbl[] = {
  19. 0,
  20. 2, 5, 7, 10, 12, 15, 17, 20, 22, 25, 27, 30, 32, 35, 38, 40,
  21. 43, 45, 48, 50, 53, 55, 57, 60, 62, 65, 67, 70, 72, 75, 77, 79,
  22. 82, 84, 87, 89, 91, 94, 96, 98, 101, 103, 105, 107, 110, 112, 114, 116,
  23. 119, 121, 123, 125, 127, 130, 132, 134, 136, 138, 140, 142, 144, 147, 149, 151,
  24. 153, 155, 157, 159, 161, 163, 165, 167, 168, 170, 172, 174, 176, 178, 180, 182,
  25. 183, 185, 187, 189, 191, 192, 194, 196, 198, 199, 201, 203, 204, 206, 208, 209,
  26. 211, 212, 214, 216, 217, 219, 220, 222, 223, 225, 226, 228, 229, 231, 232, 234,
  27. 235, 237, 238, 239, 241, 242, 244, 245, 246, 248, 249, 250, 252, 253, 254, 255
  28. };
  29. /***
  30. ** Function: Atan2
  31. **
  32. ** Description:
  33. ** Compute atan2()
  34. ***/
  35. int FASTCALL Atan2(const funit dy, const funit dx)
  36. {
  37. funit du, dv;
  38. int a = 0;
  39. /* Normalize the sign. */
  40. if (ABS(dx)>ABS(dy)) {
  41. du = ABS(dx);
  42. dv = ABS(dy);
  43. if (du==0) {
  44. a = PI4;
  45. } else {
  46. /* Normalize for the size of the table. */
  47. while (dv>256) {
  48. dv = (dv+1)>>1;
  49. du = (du+1)>>1;
  50. }
  51. dv = ((dv<<7)+(du>>1))/du;
  52. /* Lookup the angle. */
  53. if (dv==1)
  54. a = (int)((long)PI4 * (long)ABS(dx) / (long)ABS(dy));
  55. if (du!=dv)
  56. a = (int)atan_tbl[dv];
  57. }
  58. } else {
  59. du = ABS(dy);
  60. dv = ABS(dx);
  61. if (du==0) {
  62. a = PI4;
  63. } else {
  64. /* Normalize for the size of the table. */
  65. while (dv>256) {
  66. dv = (dv+1)>>1;
  67. du = (du+1)>>1;
  68. }
  69. dv = ((dv<<7)+(du>>1))/du;
  70. /* Lookup the angle. */
  71. if (dv==1)
  72. a = (int)((long)PI4 * (long)ABS(dy) / (long)ABS(dx));
  73. if (du!=dv)
  74. a = PI2 - (int)atan_tbl[dv];
  75. }
  76. }
  77. /* pick the right quadrant. */
  78. if (dx>0) {
  79. if (dy>0) {
  80. /* NOOP */
  81. } else {
  82. a = -a;
  83. }
  84. } else {
  85. if (dy>0) {
  86. a = PI - a;
  87. } else {
  88. a = a - PI;
  89. }
  90. }
  91. return a;
  92. }