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.

47 lines
1.1 KiB

  1. // mathx.h
  2. #ifndef __INCLUDE_MATHX
  3. #define __INCLUDE_MATHX
  4. #ifdef __cplusplus
  5. extern "C"
  6. {
  7. #endif
  8. int Arctan2(int y, int x);
  9. int Distance(int dX, int dY);
  10. #define DISTANCE_POINT(a,b) Distance((a).x - (b).x, (a).y - (b).y)
  11. #define CROSS_PRODUCT(a,b) (((long) (a).x) * ((long) (b).y) - ((long) (a).y) * ((long) (b).x))
  12. // Calculate difference between two angles and bring into range -180 < angle <= 180.
  13. #define ANGLEDIFF(a,b,c) { \
  14. c = b - a; \
  15. if (c > 180) { \
  16. c -= 360; \
  17. } else if (c <= -180) { \
  18. c += 360; \
  19. } \
  20. }
  21. // Calc d = the angle betw (the extension of rgxy[a]:rgxy[b]) and
  22. // (rgxy[b]:rgxy[c]). The sign of d reflects clockwise vs
  23. // counterclockwise turns.
  24. // LEFT FOR A RAINY DAY: make this more efficient
  25. #define CALCANGLE(a,b,c,d) \
  26. ANGLEDIFF(Arctan2(rgxy[b].y - rgxy[a].y, rgxy[b].x - rgxy[a].x), \
  27. Arctan2(rgxy[c].y - rgxy[b].y, rgxy[c].x - rgxy[b].x), \
  28. d);
  29. #define CALCANGLEPT(a,b,c,d) \
  30. ANGLEDIFF(Arctan2(b.y - a.y, b.x - a.x), \
  31. Arctan2(c.y - b.y, c.x - b.x), \
  32. d);
  33. #ifdef __cplusplus
  34. };
  35. #endif
  36. #endif //__INCLUDE_MATHX