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

  1. /*
  2.  * lemcut.c - code for chopping against intersecting lines.
  3.  *
  4.  * copyright (c) by Alan W. Paeth, 1987. All rights reserved.
  5.  */
  6.  
  7. #include "lem.h"
  8.  
  9. cutlines()
  10.     {
  11.     int i, x0, x1, y0, y1, x2, y2, x3, y3;
  12.     forobjects
  13.     {
  14.     if (Osel && Otype == LINE)
  15.         {
  16.         x2 = Oxs;
  17.         y2 = Oys;
  18.         x3 = Oxe;
  19.         y3 = Oye;
  20.         {
  21.         int i, j, xs, ys;        /* new "i" variable */
  22.         long det, det2, a, b;
  23.         forobjects
  24.             {
  25.             if (Otype != LINE) continue;
  26.             if (Ostat != UNDEL) continue; /* don't cut sel lines */ 
  27.             x0 = Oxs;
  28.             y0 = Oys;
  29.             x1 = Oxe;
  30.             y1 = Oye;
  31.             if ((x0 == x2) && (y0 == y2)) continue; /* share endpnts */
  32.             if ((x1 == x2) && (y1 == y2)) continue;
  33.             if ((x0 == x3) && (y0 == y3)) continue;
  34.             if ((x1 == x3) && (y1 == y3)) continue;
  35.             det = (x1-x0)*(y3-y2) - (y1-y0)*(x3-x2);
  36.             if (det == 0) continue;
  37.             det2 = det/2;
  38.             a = ((y3-y2)*(x2-x0) + (x2-x3)*(y2-y0));
  39.             b = ((y1-y0)*(x2-x0) + (x0-x1)*(y2-y0));
  40.             if (a == 0) continue;
  41.             if ((a < 0) && (a <= det)) continue;
  42.             if ((a > 0) && (a >= det)) continue;
  43.             if ((b < 0) && (b <= det)) continue;
  44.             if ((b > 0) && (b >= det)) continue;
  45.             xs = x0 + (a*(x1-x0)+det2)/det;
  46.             ys = y0 + (a*(y1-y0)+det2)/det;
  47.             if (dist(x0, y0, xs, ys) <= SPLTTOL) continue;
  48.             if (dist(x1, y1, xs, ys) <= SPLTTOL) continue;
  49.             objectop(i, UNDEL, DEL);
  50.             j = objalloc(LINE);
  51.             copyattr(j, i);
  52.             lineupdate(i, x0, y0, xs, ys);
  53.             lineupdate(j, xs, ys, x1, y1);
  54.             objectop(i, DEL, UNDEL);
  55.             objectop(j, DEL, UNDEL);
  56.             }
  57.         }
  58.         }
  59.     }
  60.     }
  61.