home *** CD-ROM | disk | FTP | other *** search
/ gdead.berkeley.edu / gdead.berkeley.edu.tar / gdead.berkeley.edu / pub / cad-tools / m36gen.tar / m36gen_dir / misc.c < prev    next >
C/C++ Source or Header  |  1988-01-28  |  2KB  |  107 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. #define PI 3.141592653589793
  5.  
  6. dir_to_angle(x_int, y_int)
  7. int x_int;
  8. int y_int;
  9. {
  10.     double value;
  11.     double arg;
  12.     int degree_value;
  13.  
  14.     if ( y_int == 0 ) {
  15.     return(0);
  16.     }
  17.  
  18.     if ( x_int == 0 ) {
  19.     return(900);
  20.     }
  21.  
  22.     arg = ( (double) y_int)/ ( (double) x_int);
  23.     value = atan(arg);
  24.  
  25.     /* convert to an integer number of tenths of degrees */
  26.  
  27.     degree_value = (int) (1800*value/PI);
  28.  
  29.     if (degree_value < 0) {
  30.     degree_value += 1800;
  31.     }
  32.  
  33.     return(degree_value);
  34. }
  35.     
  36.  
  37. extern int command_number;
  38.  
  39. error(str)
  40. char *str;
  41. {
  42.     fprintf(stderr,"error at command %d : %s\n",command_number,str);
  43.     exit(1);
  44. }
  45.  
  46. extern FILE *infile;
  47.  
  48. flush_to_semi()
  49. {
  50.     register char c;
  51.  
  52.     while ( (c = getc(infile)) != EOF ) {
  53.     if ( c == ';' ) {
  54.         return;
  55.     }
  56.     }
  57.  
  58.     error("Unexpected end of file");
  59. }
  60.  
  61. flush_comment()
  62. {
  63.     int level = 1;
  64.     char c;
  65.  
  66.     while ( (c = getc(infile)) != EOF ) {
  67.     if ( c == '(' ) {
  68.         level++;
  69.     } else if ( c== ')' ) {
  70.         level--;
  71.     }
  72.  
  73.     if ( level <= 0) {
  74.         flush_to_semi();
  75.         return;
  76.     }
  77.     }
  78.  
  79.     error("Unexpected end of file");
  80. }
  81.  
  82. #define min(x,y) ( (x) < (y) ? (x) : (y) )
  83. #define max(x,y) ( (x) > (y) ? (x) : (y) )
  84.  
  85. extern left, right, bottom, top;
  86.  
  87. int first_bb = 1;
  88.  
  89.     /* compute a bounding box for the masks */
  90.  
  91. update_bb(l,w,x,y)
  92. int l,w,x,y;
  93. {
  94.     if ( first_bb ) {
  95.     left = x - l/2;
  96.     right = x + l/2;
  97.     bottom = y - w/2;
  98.     top = y + w/2;
  99.     first_bb = 0;
  100.     } else {
  101.     left = min(left, x - l/2);
  102.     right = max(right, x + l/2);
  103.     bottom = min(bottom, y - w/2);
  104.     top = max(top, y + w/2);
  105.     }
  106. }
  107.