void line_trim_x(Line * l, double x0, int side) { double y0; double old_y, old_x; if (!l) return; if (side) { if ((l->x1 >= x0) && (l->x2 >= x0)) { line_delete(l); return; } if ((l->x1 <= x0) && (l->x2 <= x0)) return; } else { if ((l->x1 <= x0) && (l->x2 <= x0)) { line_delete(l); return; } if ((l->x1 >= x0) && (l->x2 >= x0)) return; } y0 = (x0 - l->x1) / (l->y2 - l->y1) * (l->x2 - l->x1) + l->y1; if ((side && (l->x1 > l->x2)) || (!side && !(l->x1 > l->x2))) { old_y = l->y1; old_x = l->x1; l->y1 = y0; l->x1 = x0; append_undo_double((void *)(&(l->y1)), old_y, l->y1, CMD_SYNC, OBJ_LINE, l); append_undo_double((void *)(&(l->x1)), old_x, l->x1, 0, 0, NULL); } else { old_y = l->y2; old_x = l->x2; l->y2 = y0; l->x2 = x0; append_undo_double((void *)(&(l->y2)), old_y, l->y2, CMD_SYNC, OBJ_LINE, l); append_undo_double((void *)(&(l->x2)), old_x, l->x2, 0, 0, NULL); } msg_create_and_send(CMD_SYNC, OBJ_LINE, l); }
Ddelline(f, n) { register int s = TRUE; kill_setbuffer(DK_LINE); kill_freebuffer(); while( n-- > 0 && s ) { curwp->w_doto = 0; s &= line_delete(llength(curwp->w_dotp) + 1, TRUE); } kill_setbuffer(DK_CUT); return( s ); }
/* * discard the list of lines associated with a file. this will cause * the file to be re-read next time file_getlinelist is called. */ void file_discardlines(FILEDATA fd) { LINE line; if (fd == NULL) { return; } if (fd->lines != NULL) { /* clear each line to free any memory associated * with them, then discard the entire list */ for( line=(LINE)List_First(fd->lines); line!=NULL; line = (LINE)List_Next((LPVOID)line)) { line_delete(line); } List_Destroy(&fd->lines); } /* this is probably done in List_Destroy, but better do it anyway*/ fd->lines = NULL; }
void line_trim_ab(Line * l, double a0, double b0, int side) { double x0, y0; double a, b; double dx; double tx1, tx2, ty1, ty2; tx1 = l->x1; tx2 = l->x2; ty1 = l->y1; ty2 = l->y2; dx = tx2 - tx1; if (dx == 0.0) { x0 = tx1; y0 = tx1 * a0 + b0; } else { a = (l->y2 - l->y1) / (dx); b = l->y1 - a * l->x1; if ((a == a0) && side) { line_delete(l); return; }; if ((a == a0) && !side) return; x0 = (b0 - b) / (a - a0); y0 = a0 * x0 + b0; } if ((tx1 * a + b > tx1 * a0 + b0) && (tx2 * a + b > tx2 * a0 + b0) && side) { line_delete(l); return; } if ((tx1 * a + b > tx1 * a0 + b0) && (tx2 * a + b > tx2 * a0 + b0) && !side) return; if ((tx1 * a + b <= tx1 * a0 + b0) && (tx2 * a + b <= tx2 * a0 + b0) && !side) { line_delete(l); return; } if ((tx1 * a + b <= tx1 * a0 + b0) && (tx2 * a + b <= tx2 * a0 + b0) && side) return; if (((tx1 * a + b > tx1 * a0 + b0) && side) || ((tx1 * a + b <= tx1 * a0 + b0) && !side)) { append_undo_double((void *)(&(l->x1)), l->x1, x0, CMD_SYNC, OBJ_LINE, l); append_undo_double((void *)(&(l->y1)), l->y1, y0, 0, 0, NULL); l->x1 = x0; l->y1 = y0; } if (((tx2 * a + b > tx2 * a0 + b0) && side) || ((tx2 * a + b <= tx2 * a0 + b0) && !side)) { append_undo_double((void *)(&(l->x2)), l->x2, x0, CMD_SYNC, OBJ_LINE, l); append_undo_double((void *)(&(l->y2)), l->y2, y0, 0, 0, NULL); l->x2 = x0; l->y2 = y0; } msg_create_and_send(CMD_SYNC, OBJ_LINE, l); }