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

  1. /*
  2.  * lemline.c - line primities
  3.  *
  4.  * copyright (c) by Alan W. Paeth, 1987. All rights reserved.
  5.  */
  6.  
  7. #include "lem.h"
  8.  
  9. lineadd(x0, y0, x1, y1)
  10.     {
  11.     int i;
  12.     if ((x0 == x1) && (y0 == y1)) return;
  13.     i = objalloc(LINE);
  14.     lineupdate(i, x0, y0, x1, y1);
  15.     objnew(i);
  16.     }
  17.  
  18. lineresize(i)
  19.     {
  20.     }
  21.     
  22. lineupdate(i, x0, y0, x1, y1)
  23.     {
  24.     Oxs = x0;
  25.     Oys = y0;
  26.     Oxe = x1;
  27.     Oye = y1;
  28.     }
  29.  
  30. linenearpt(i, x, y)
  31.     {
  32.     int tol, hy;
  33.     if (ptinrect(x, y, Oxl, Oyl, Oxh, Oyh, LINETOL) == 0) return(0);
  34.     hy = hypot(Ow, Oh);
  35.     if (hy < SHRTTOL) return(1);
  36.     tol = ABS(((x-Ox)*Oh - (y-Oy)*Ow)) / hy;
  37.     return(LINETOL > tol);
  38.     }
  39.  
  40. lineinrect(i, xl, yl, xh, yh)
  41.     {
  42.     return(ptinrect(Oxl, Oyl, xl, yl, xh, yh, LINETOL) &&
  43.     ptinrect(Oxh, Oyh, xl, yl, xh, yh, LINETOL));
  44.     }
  45.  
  46. linecantug(i, x, y)
  47.     {
  48.     return(linenearpt(i, x, y));
  49.     }
  50.     
  51. linetug(i, xs, ys, xe, ye)
  52.     {
  53.     if (dist(Oxs, Oys, xs, ys) < TUGPROX) lineupdate(i, xe, ye, Oxe, Oye);
  54.     else if (dist(Oxe, Oye, xs, ys) < TUGPROX) lineupdate(i, Oxs, Oys, xe, ye);
  55.     else linemove(i, xe-xs, ye-ys);
  56.     }
  57.  
  58. linealign(i, x, y)
  59.     int *x, *y;
  60.     {
  61.     if (dist(Oxs, Oys, *x, *y) < ENDTOL)
  62.     {
  63.     *x = Oxs;
  64.     *y = Oys;
  65.     }
  66.     else if (dist(Oxe, Oye, *x, *y) < ENDTOL)
  67.     {
  68.     *x = Oxe;
  69.     *y = Oye;
  70.     }
  71.     else
  72.     {
  73.     int frac;
  74.     frac = (ABS(Ow) > ABS(Oh)) ? (12*(*x-Oxs)+6)/Ow : (12*(*y-Oys)+6)/Oh;
  75.     *x = ((12-frac)*Oxs + frac*Oxe)/12;
  76.     *y = ((12-frac)*Oys + frac*Oye)/12;
  77.     }
  78.     }
  79.  
  80. linemove(i, x, y)
  81.     {
  82.     objsupmove(i, x, y);
  83.     }
  84.  
  85. lineaffine(i, m11, m12, m21, m22)
  86.     float m11, m12, m21, m22;
  87.     {
  88.     objsupaffine(i, m11, m12, m21, m22, 1);
  89.     }
  90.     
  91. linedraw(i, col)
  92.     {
  93.     int wid;
  94.     wid = lemfont[Osizer].thick;
  95.     drawvec(Oxs, Oys, Oxe, Oye, col, wid, Oemph);
  96.     if (Oalign == ALIGNLEFT)
  97.     {
  98.     int h, x, y, x1, y1;
  99.     h = hypot(Ow, Oh)*13;
  100.     x = Ow*ARROWLEN;
  101.     y = Oh*ARROWLEN;
  102.     x1 = ( x*12-y*5)/h;
  103.     y1 = ( x*5+y*12)/h;
  104.     drawvec(Oxs, Oys, Oxs+x1, Oys+y1, col, wid, EMPHNONE);
  105.     x1 = ( x*12+y*5)/h;
  106.     y1 = (-x*5+y*12)/h;
  107.     drawvec(Oxs, Oys, Oxs+x1, Oys+y1, col, wid, EMPHNONE);
  108.     }
  109.     if (Oalign == ALIGNRGHT)
  110.     {
  111.     int h, x, y, x1, y1;
  112.     h = hypot(Ow, Oh)*13;
  113.     x = Ow*ARROWLEN;
  114.     y = Oh*ARROWLEN;
  115.     x1 = ( x*12-y*5)/h;
  116.     y1 = ( x*5+y*12)/h;
  117.     drawvec(Oxe, Oye, Oxe-x1, Oye-y1, col, wid, EMPHNONE);
  118.     x1 = ( x*12+y*5)/h;
  119.     y1 = (-x*5+y*12)/h;
  120.     drawvec(Oxe, Oye, Oxe-x1, Oye-y1, col, wid, EMPHNONE);
  121.     }
  122.     }
  123.