home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / lout2.lzh / LOUT2 / z34.c < prev    next >
Text File  |  1994-02-25  |  6KB  |  113 lines

  1. /*@z34.c:Rotation Service:Declarations@***************************************/
  2. /*                                                                           */
  3. /*  LOUT: A HIGH-LEVEL LANGUAGE FOR DOCUMENT FORMATTING (VERSION 2.05)       */
  4. /*  COPYRIGHT (C) 1993 Jeffrey H. Kingston                                   */
  5. /*                                                                           */
  6. /*  Jeffrey H. Kingston (jeff@cs.su.oz.au)                                   */
  7. /*  Basser Department of Computer Science                                    */
  8. /*  The University of Sydney 2006                                            */
  9. /*  AUSTRALIA                                                                */
  10. /*                                                                           */
  11. /*  This program is free software; you can redistribute it and/or modify     */
  12. /*  it under the terms of the GNU General Public License as published by     */
  13. /*  the Free Software Foundation; either version 1, or (at your option)      */
  14. /*  any later version.                                                       */
  15. /*                                                                           */
  16. /*  This program is distributed in the hope that it will be useful,          */
  17. /*  but WITHOUT ANY WARRANTY; without even the implied warranty of           */
  18. /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            */
  19. /*  GNU General Public License for more details.                             */
  20. /*                                                                           */
  21. /*  You should have received a copy of the GNU General Public License        */
  22. /*  along with this program; if not, write to the Free Software              */
  23. /*  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
  24. /*                                                                           */
  25. /*  FILE:         z34.c                                                      */
  26. /*  MODULE:       Rotation Service                                           */
  27. /*  EXTERNS:      RotateSize()                                               */
  28. /*                                                                           */
  29. /*****************************************************************************/
  30. #include <math.h>
  31. #ifndef M_PI
  32. #define M_PI       3.1415926535897931160E0
  33. #endif
  34. #include "externs"
  35. #ifdef OSK
  36. #include "math_bsd.h"
  37. #endif
  38. typedef struct { double x, y;          } rect_coord;
  39. typedef struct { double angle, radius; } polar_coord;
  40.  
  41. #define rect_to_polar(rect, polar)                \
  42. polar.angle = atan2(rect.y, rect.x),                \
  43. polar.radius = sqrt(rect.x*rect.x + rect.y*rect.y)
  44.  
  45. #define polar_to_rect(polar, rect)                \
  46. rect.x = polar.radius * cos(polar.angle),            \
  47. rect.y = polar.radius * sin(polar.angle)
  48.  
  49.  
  50. /*@::RotateSize()@************************************************************/
  51. /*                                                                           */
  52. /*  RotateSize(xcb, xcf, xrb, xrf, y, theta)                                 */
  53. /*                                                                           */
  54. /*  Calculate the size of x, assuming that it is y rotated by theta degrees. */
  55. /*                                                                           */
  56. /*****************************************************************************/
  57.  
  58. RotateSize(xcb, xcf, xrb, xrf, y, theta)
  59. LENGTH *xcb, *xcf, *xrb, *xrf;  OBJECT y;  LENGTH theta;
  60. { rect_coord ycorners[4], xcorner;  polar_coord pol;
  61.   double maxx, maxy, minx, miny, ang;  int i;
  62.   char buff1[20], buff2[20];
  63.  
  64.   /* calculate theta in radians */
  65.   ang = (double) theta * 2 * M_PI / (double) (DG * 360);
  66.   ifdebug(DRS, D, sprintf(buff2, "%.1f", ang));
  67.   debug2(DRS, D, "RotateSize( %s, %s )", EchoObject(y), buff2);
  68.   debug4(DRS, DD, "  ycb %s, ycf %s, yrb %s, yrf %s",
  69.     EchoLength(back(y, COL)), EchoLength(fwd(y, COL)),
  70.     EchoLength(back(y, ROW)), EchoLength(fwd(y, ROW)));
  71.  
  72.   /* set up coordinates of the four corners of y */
  73.   ycorners[0].x =   (float) fwd(y, COL);
  74.   ycorners[0].y =   (float) back(y, ROW);
  75.   ycorners[1].x = - (float) back(y, COL);
  76.   ycorners[1].y =   (float) back(y, ROW);
  77.   ycorners[2].x = - (float) back(y, COL);
  78.   ycorners[2].y = - (float) fwd(y, ROW);
  79.   ycorners[3].x =   (float) fwd(y, COL);
  80.   ycorners[3].y = - (float) fwd(y, ROW);
  81.  
  82.   /* rotate these four corners by theta and store their extremes */
  83.   maxx = maxy = (float) - MAX_LEN;
  84.   minx = miny = (float) MAX_LEN;
  85.   for( i = 0;  i < 4;  i++ )
  86.   {    
  87.     if( ycorners[i].x == 0 && ycorners[i].y == 0 )
  88.     {    pol.radius = 0; pol.angle  = 0; }
  89.     else rect_to_polar(ycorners[i], pol);
  90.     ifdebug(DRS, DD, sprintf(buff1, "%.1f", pol.angle));
  91.     ifdebug(DRS, DD, sprintf(buff2, "%.1f", ang));
  92.     debug5(DRS, DD, "  transforming (%s, %s) -> (%s, %s) + %s",
  93.       EchoLength( (int) ycorners[i].x), EchoLength( (int) ycorners[i].y),
  94.       EchoLength( (int) pol.radius), buff1, buff2);
  95.     pol.angle += ang;
  96.     polar_to_rect(pol, xcorner);
  97.     ifdebug(DRS, DD, sprintf(buff1, "%.1f", pol.angle));
  98.     debug4(DRS, DD, "    transforming (%s, %s) -> (%s, %s)",
  99.       EchoLength( (int) pol.radius), buff1,
  100.       EchoLength( (int) xcorner.x), EchoLength( (int) xcorner.y) );
  101.     maxx = max(maxx, xcorner.x);    minx = min(minx, xcorner.x);
  102.     maxy = max(maxy, xcorner.y);    miny = min(miny, xcorner.y);
  103.   }
  104.  
  105.   /* store sizes back into x and return */
  106.   *xcb = - (int) minx;    *xcf  =   (int) maxx;
  107.   *xrb =   (int) maxy;    *xrf  = - (int) miny;
  108.   debug0(DRS, D, "RotateSize returning.");
  109.   debug4(DRS, DD, "  xcb %s, xcf %s, xrb %s, xrf %s",
  110.     EchoLength(*xcb), EchoLength(*xcf),
  111.     EchoLength(*xrb), EchoLength(*xrf));
  112. } /* end RotateSize */
  113.