/* Last edited on 2009-09-15 11:42:14 by stolfi */ /* ---------------------------------------------------------------------- */ /* More precisely, whenever an item cannot be added to {state->blk}, either */ /* because it does not fit in the free part of its canvas, or */ /* because there is a change of material or thickness, */ /* the procedure appends the current {state->blk} to the list */ /* {topv.e[0..n-1]}, where {n} is the value of {*ntopP}; */ /* and increments the latter. Then the procedure restarts the {state} with */ /* the same {max_size}, and {cut_wd} parameters, */ /* and continues packing. */ if (state->blk == NULL) { /* Pristine state; accept {it} with no size constraint: */ assert((sh_ht == 0.0) && (sh_px == 0.0) && (sh_py == 0.0)); it_x = 0.0; it_y = 0.0; if ((it_x + it_dx > sh_dx) || (it_y + it_dy > sh_dy)) { /* Piece overflowed the canvas, mark it full: */ state->cur_py = sh_dy + cut_wd; state->cur_ht = state->cur_py; state->cur_px = 0.0; } else { /* Piece fits OK: */ state->cur_ht = it_dy + cut_wd; state->cur_px = it_dx + cut_wd; } } void csc_restart_state(csc_pack_state_t* state); /* Re-initializes the {*state} record to gather a new batch of items. Namely, resets {state.blk} to {NULL} and the used area to empty; that is, {state.cur_ht = state.cur_py = state.cur_px = 0}. However, preserves the current values of {state.max_size}, and {state.cut_wd}. */ void csc_restart_state(csc_pack_state_t* state, csc_options_t *o, int32_t ntop) { state->blk = NULL; state->cur_py = 0.0; state->cur_ht = 0.0; state->cur_px = 0.0; state->cut_wd = o->cutWd; state->max_size = max_size; } void adrw_plot_box ( PSStream *ps, adrw_point_vec_t *P, int vctr, double hwx, double hwy, double R, double G, double B, bool_t dots ); void adrw_plot_pipe ( PSStream *ps, adrw_point_vec_t *P, int va, int vb, double R, double G, double B, bool_t dots ); void adrw_plot_box ( PSStream *ps, adrw_point_vec_t *P, int vctr, double hwx, double hwy, double R, double G, double B, bool_t dots ) { /* Get center coordinates: */ demand((vctr >= 0) && (vctr < P->ne), "invalid point index"); adrw_point_t *apc = &(P->e[vctr]); r3_t *pc = &(apc->p); check_defined(pc, vctr); double xc = pc->c[0]; double yc = pc->c[1]; /* Create corner coordinates {x[0..4], y[0..4]}: */ double x[5], y[5]; x[0] = xc - hwx; y[0] = yc - hwy; x[1] = xc - hwx; y[1] = yc + hwy; x[2] = xc + hwx; y[2] = yc + hwy; x[3] = xc + hwx; y[3] = yc - hwy; x[4] = xc - hwx; y[4] = yc - hwy; /* Plot box: */ pswr_set_fill_color(ps, R,G,B); pswr_polygon(ps, x, y, 5, TRUE, FALSE, TRUE); if (dots) { /* Plot center with label: */ pswr_set_fill_color(ps, 0,0,0); adrw_plot_point(ps, vctr, xc, yc, 0.10); } } void adrw_plot_pipe ( PSStream *ps, adrw_point_vec_t *P, int va, int vb, double R, double G, double B, bool_t dots ) { /* Get endpoint coordinates: */ demand((va >= 0) && (va < P->ne), "invalid point index"); adrw_point_t *apa = &(P->e[va]); r3_t *pa = &(apa->p); double xa = pa->c[0], ya = pa->c[1]; check_defined(pa, va); demand((vb >= 0) && (vb < P->ne), "invalid point index"); adrw_point_t *apb = &(P->e[vb]); r3_t *pb = &(apb->p); double xb = pb->c[0], yb = pb->c[1]; check_defined(pb, vb); /* Plot pipe: */ pswr_set_pen(ps, R,G,B, 0.50, 0,0); pswr_segment(ps, xa, ya, xb, yb); if (dots) { /* Plot endpoints with labels: */ pswr_set_fill_color(ps, 0,0,0); adrw_plot_point(ps, va, xa, ya, 0.5); adrw_plot_point(ps, vb, xb, yb, 0.5); } }