home *** CD-ROM | disk | FTP | other *** search
- /*
- * lemline.c - line primities
- *
- * copyright (c) by Alan W. Paeth, 1987. All rights reserved.
- */
-
- #include "lem.h"
-
- lineadd(x0, y0, x1, y1)
- {
- int i;
- if ((x0 == x1) && (y0 == y1)) return;
- i = objalloc(LINE);
- lineupdate(i, x0, y0, x1, y1);
- objnew(i);
- }
-
- lineresize(i)
- {
- }
-
- lineupdate(i, x0, y0, x1, y1)
- {
- Oxs = x0;
- Oys = y0;
- Oxe = x1;
- Oye = y1;
- }
-
- linenearpt(i, x, y)
- {
- int tol, hy;
- if (ptinrect(x, y, Oxl, Oyl, Oxh, Oyh, LINETOL) == 0) return(0);
- hy = hypot(Ow, Oh);
- if (hy < SHRTTOL) return(1);
- tol = ABS(((x-Ox)*Oh - (y-Oy)*Ow)) / hy;
- return(LINETOL > tol);
- }
-
- lineinrect(i, xl, yl, xh, yh)
- {
- return(ptinrect(Oxl, Oyl, xl, yl, xh, yh, LINETOL) &&
- ptinrect(Oxh, Oyh, xl, yl, xh, yh, LINETOL));
- }
-
- linecantug(i, x, y)
- {
- return(linenearpt(i, x, y));
- }
-
- linetug(i, xs, ys, xe, ye)
- {
- if (dist(Oxs, Oys, xs, ys) < TUGPROX) lineupdate(i, xe, ye, Oxe, Oye);
- else if (dist(Oxe, Oye, xs, ys) < TUGPROX) lineupdate(i, Oxs, Oys, xe, ye);
- else linemove(i, xe-xs, ye-ys);
- }
-
- linealign(i, x, y)
- int *x, *y;
- {
- if (dist(Oxs, Oys, *x, *y) < ENDTOL)
- {
- *x = Oxs;
- *y = Oys;
- }
- else if (dist(Oxe, Oye, *x, *y) < ENDTOL)
- {
- *x = Oxe;
- *y = Oye;
- }
- else
- {
- int frac;
- frac = (ABS(Ow) > ABS(Oh)) ? (12*(*x-Oxs)+6)/Ow : (12*(*y-Oys)+6)/Oh;
- *x = ((12-frac)*Oxs + frac*Oxe)/12;
- *y = ((12-frac)*Oys + frac*Oye)/12;
- }
- }
-
- linemove(i, x, y)
- {
- objsupmove(i, x, y);
- }
-
- lineaffine(i, m11, m12, m21, m22)
- float m11, m12, m21, m22;
- {
- objsupaffine(i, m11, m12, m21, m22, 1);
- }
-
- linedraw(i, col)
- {
- int wid;
- wid = lemfont[Osizer].thick;
- drawvec(Oxs, Oys, Oxe, Oye, col, wid, Oemph);
- if (Oalign == ALIGNLEFT)
- {
- int h, x, y, x1, y1;
- h = hypot(Ow, Oh)*13;
- x = Ow*ARROWLEN;
- y = Oh*ARROWLEN;
- x1 = ( x*12-y*5)/h;
- y1 = ( x*5+y*12)/h;
- drawvec(Oxs, Oys, Oxs+x1, Oys+y1, col, wid, EMPHNONE);
- x1 = ( x*12+y*5)/h;
- y1 = (-x*5+y*12)/h;
- drawvec(Oxs, Oys, Oxs+x1, Oys+y1, col, wid, EMPHNONE);
- }
- if (Oalign == ALIGNRGHT)
- {
- int h, x, y, x1, y1;
- h = hypot(Ow, Oh)*13;
- x = Ow*ARROWLEN;
- y = Oh*ARROWLEN;
- x1 = ( x*12-y*5)/h;
- y1 = ( x*5+y*12)/h;
- drawvec(Oxe, Oye, Oxe-x1, Oye-y1, col, wid, EMPHNONE);
- x1 = ( x*12+y*5)/h;
- y1 = (-x*5+y*12)/h;
- drawvec(Oxe, Oye, Oxe-x1, Oye-y1, col, wid, EMPHNONE);
- }
- }
-