home *** CD-ROM | disk | FTP | other *** search
- /*
- * lemcut.c - code for chopping against intersecting lines.
- *
- * copyright (c) by Alan W. Paeth, 1987. All rights reserved.
- */
-
- #include "lem.h"
-
- cutlines()
- {
- int i, x0, x1, y0, y1, x2, y2, x3, y3;
- forobjects
- {
- if (Osel && Otype == LINE)
- {
- x2 = Oxs;
- y2 = Oys;
- x3 = Oxe;
- y3 = Oye;
- {
- int i, j, xs, ys; /* new "i" variable */
- long det, det2, a, b;
- forobjects
- {
- if (Otype != LINE) continue;
- if (Ostat != UNDEL) continue; /* don't cut sel lines */
- x0 = Oxs;
- y0 = Oys;
- x1 = Oxe;
- y1 = Oye;
- if ((x0 == x2) && (y0 == y2)) continue; /* share endpnts */
- if ((x1 == x2) && (y1 == y2)) continue;
- if ((x0 == x3) && (y0 == y3)) continue;
- if ((x1 == x3) && (y1 == y3)) continue;
- det = (x1-x0)*(y3-y2) - (y1-y0)*(x3-x2);
- if (det == 0) continue;
- det2 = det/2;
- a = ((y3-y2)*(x2-x0) + (x2-x3)*(y2-y0));
- b = ((y1-y0)*(x2-x0) + (x0-x1)*(y2-y0));
- if (a == 0) continue;
- if ((a < 0) && (a <= det)) continue;
- if ((a > 0) && (a >= det)) continue;
- if ((b < 0) && (b <= det)) continue;
- if ((b > 0) && (b >= det)) continue;
- xs = x0 + (a*(x1-x0)+det2)/det;
- ys = y0 + (a*(y1-y0)+det2)/det;
- if (dist(x0, y0, xs, ys) <= SPLTTOL) continue;
- if (dist(x1, y1, xs, ys) <= SPLTTOL) continue;
- objectop(i, UNDEL, DEL);
- j = objalloc(LINE);
- copyattr(j, i);
- lineupdate(i, x0, y0, xs, ys);
- lineupdate(j, xs, ys, x1, y1);
- objectop(i, DEL, UNDEL);
- objectop(j, DEL, UNDEL);
- }
- }
- }
- }
- }
-