home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / ui / grutils.cxx < prev    next >
C/C++ Source or Header  |  1995-04-09  |  2KB  |  67 lines

  1.  
  2.  
  3. /*
  4.  *
  5.  *          Copyright (C) 1994, M. A. Sridhar
  6.  *  
  7.  *
  8.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  9.  *     to copy, modify or distribute this software  as you see fit,
  10.  *     and to use  it  for  any  purpose, provided   this copyright
  11.  *     notice and the following   disclaimer are included  with all
  12.  *     copies.
  13.  *
  14.  *                        DISCLAIMER
  15.  *
  16.  *     The author makes no warranties, either expressed or implied,
  17.  *     with respect  to  this  software, its  quality, performance,
  18.  *     merchantability, or fitness for any particular purpose. This
  19.  *     software is distributed  AS IS.  The  user of this  software
  20.  *     assumes all risks  as to its quality  and performance. In no
  21.  *     event shall the author be liable for any direct, indirect or
  22.  *     consequential damages, even if the  author has been  advised
  23.  *     as to the possibility of such damages.
  24.  *
  25.  */
  26.  
  27.  
  28. #include <math.h>
  29.  
  30. #include "base/defs.h"
  31. #include "ui/grutils.h"
  32.  
  33.  
  34. #ifndef M_PI
  35. #define M_PI 3.1415926535897932
  36. #endif
  37.  
  38. double DegToRad (double deg)
  39. {
  40.     bool negative = FALSE;
  41.     if (deg < 0) {
  42.         negative = TRUE;
  43.         deg = -deg;
  44.     }
  45.     // Reduce it modulo 360
  46.     deg = ((long) deg) % 360 + (deg - ((long) deg));
  47.     double rad = M_PI * deg / 180;
  48.     if (negative)
  49.         rad = 2 * M_PI - rad;
  50.     return rad;
  51. }
  52.  
  53. double RadToDeg (double rad)
  54. {
  55.     double deg = rad * 180 / M_PI;
  56.     bool negative = FALSE;
  57.     if (deg < 0) {
  58.         negative = TRUE;
  59.         deg = -deg;
  60.     }
  61.     // Reduce it modulo 360
  62.     deg = ((long) deg) % 360 + (deg - ((long) deg));
  63.     if (negative)
  64.         deg = 360 - deg;
  65.     return deg;
  66. }
  67.