home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / lemming / part02 / lemobjsup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-08-05  |  1.4 KB  |  76 lines

  1. /*
  2.  * lemobjsup.c - superclass for generic object operations
  3.  *
  4.  * copyright (c) by Alan W. Paeth, 1987. All rights reserved.
  5.  */
  6.  
  7. #include <math.h>        /* to define "double floor()" */
  8. #include "lem.h"
  9.  
  10. objsupnearpt(i, x, y)
  11.     {
  12.     if (ptinrect(x, y, Oxl, Oyl, Oxh, Oyh, LINETOL) == 0) return(0);
  13.     return(1);
  14.     }
  15.  
  16. objsupinrect(i, xl, yl, xh, yh)
  17.     {
  18.     return(ptinrect(Oxl, Oyl, xl, yl, xh, yh, LINETOL) &&
  19.     ptinrect(Oxh, Oyh, xl, yl, xh, yh, LINETOL));
  20.     }
  21.  
  22. objsupcantug(i, x, y)
  23.     {
  24.     return(objnearpt(i, x, y));
  25.     }
  26.  
  27. objsuptug(i, xs, ys, xe, ye)
  28.     {
  29.     if (dist(Oxs, Oys, xs, ys) < TUGPROX) objmove(i, xe-xs, ye-ys);
  30.     }
  31.  
  32. objsupalign(i, x, y)
  33.     int *x, *y;
  34.     {
  35.     if (dist(Oxs, Oys, *x, *y) < ENDTOL)
  36.     {
  37.     *x = Oxs;
  38.     *y = Oys;
  39.     }
  40.     }
  41.  
  42. objsupmove(i, x, y)
  43.     {
  44.     Oxs += x;
  45.     Oxe += x;
  46.     Oys += y;
  47.     Oye += y;
  48.     }
  49.  
  50. objsupaffine(i, m11, m12, m21, m22, both)
  51.     float m11, m12, m21, m22;
  52.     {
  53.     float x1, y1;
  54.     if (both)
  55.     {
  56.     x1 = floor((m11*Oxs + m12*Oys) + 0.5);
  57.         y1 = floor((m21*Oxs + m22*Oys) + 0.5);
  58.     Oxs = x1;
  59.     Oys = y1;
  60.     x1 = floor((m11*Oxe + m12*Oye) + 0.5);
  61.         y1 = floor((m21*Oxe + m22*Oye) + 0.5);
  62.     Oxe = x1;
  63.     Oye = y1;
  64.     }
  65.     else
  66.     {
  67.         x1 = floor((m11*Oxcen + m12*Oycen) + 0.5);
  68.         y1 = floor((m21*Oxcen + m22*Oycen) + 0.5);
  69. /*
  70.  *  move only the center point, don't the other endpoint
  71.  * (presumably object dimensions -- this is a text element).
  72.  */
  73.     objmove(i, (int)(x1-Oxcen), (int)(y1-Oycen));
  74.     }
  75.     }
  76.