drop redundant or unused index operations

This commit is contained in:
Stewart Allen 2026-01-03 16:28:18 -05:00
commit dda5107810
4 changed files with 54 additions and 11 deletions

View file

@ -13,14 +13,30 @@ export class OpIndex extends CamOp {
async slice() { async slice() {
let { op, state } = this; let { op, state } = this;
if (!state.isIndexed) { if (!state.isIndexed) {
throw 'index op requires indexed stock'; throw 'index op requires indexed stock';
} }
let { widget, updateSlicer, computeShadows, setAxisIndex } = state;
this.degrees = await setAxisIndex(op.degrees, op.absolute); let { lastAxisIndex, widget, updateSlicer, computeShadows, setAxisIndex } = state;
let { degrees, absolute } = op;
if (absolute && lastAxisIndex === degrees) {
return console.log('skip redundant absolute index');
} else if (!absolute && degrees === 0) {
return console.log('skip redundant relative index');
}
this.degrees = await setAxisIndex(degrees, absolute);
state.lastAxisIndex = this.degrees;
// force recompute of topo // force recompute of topo
widget.topo = undefined; widget.topo = undefined;
// update slicer for new widget geometry
updateSlicer(); updateSlicer();
// recompute shadow from new widget geometry
await computeShadows(); await computeShadows();
} }

View file

@ -102,15 +102,24 @@ class OpRough extends CamOp {
})); }));
} }
for (let op of this.ops_list) { let len = ops_list.length;
await op.slice(progress); let per = 1 / len;
let bas = 0;
for (let op of ops_list) {
await op.slice(pct => progress(bas + pct * per));
bas += per;
} }
} }
s
async prepare(ops, progress) { async prepare(ops, progress) {
let { ops_list } = this;
let { setChangeOp } = ops; let { setChangeOp } = ops;
for (let op of this.ops_list) { let len = ops_list.length;
await op.prepare(ops, progress); let per = 1 / len;
let bas = 0;
for (let op of ops_list) {
await op.prepare(ops, pct => progress(bas + pct * per));
bas += per;
setChangeOp(); setChangeOp();
} }
} }

View file

@ -27,6 +27,7 @@ class OpShadow extends CamOp {
async slice(progress) { async slice(progress) {
let state = this.state; let state = this.state;
let { addSlices, settings, shadowAt, unsafe, widget, workarea } = state; let { addSlices, settings, shadowAt, unsafe, widget, workarea } = state;
let { devel } = settings.controller; let { devel } = settings.controller;
@ -36,12 +37,10 @@ class OpShadow extends CamOp {
let skipTerrain = unsafe; let skipTerrain = unsafe;
let terrain = []; let terrain = [];
let tzindex = []; let tzindex = [];
let { bottom_z, top_z } = workarea;
let minZ = Math.floor(bounds.min.z); let minZ = Math.floor(bounds.min.z);
let maxZ = Math.floor(bounds.max.z); let maxZ = Math.floor(bounds.max.z);
for (let z = maxZ; z >= minZ; z--) { for (let z = maxZ; z >= minZ; z--) {
// if (z <= top_z && z >= bottom_z)
tzindex.push(z); tzindex.push(z);
} }

View file

@ -55,7 +55,8 @@ export async function cam_slice(settings, widget, onupdate, ondone) {
let proc = settings.process, let proc = settings.process,
camOps = widget.camops = [], camOps = widget.camops = [],
sliceAll = widget.slices = [], sliceAll = widget.slices = [],
isIndexed = proc.camStockIndexed; isIndexed = proc.camStockIndexed,
lastTime = Date.now();
let axisRotation, axisIndex, let axisRotation, axisIndex,
bounds, dark, color, stock, tabs, track, tool, unsafe, units, workarea, bounds, dark, color, stock, tabs, track, tool, unsafe, units, workarea,
@ -241,6 +242,17 @@ export async function cam_slice(settings, widget, onupdate, ondone) {
} }
} }
function updateProgress(percent, message) {
const mark = Date.now();
if (false) console.log({
time: ((mark - lastTime)/1000).toFixed(2),
pct: ((percent ?? 0) * 100).toFixed(2),
msg: message
});
onupdate(percent, message);
lastTime = mark;
}
function newSlicer(opts) { function newSlicer(opts) {
return new cam_slicer(widget, opts); return new cam_slicer(widget, opts);
} }
@ -250,9 +262,11 @@ export async function cam_slice(settings, widget, onupdate, ondone) {
} }
async function computeShadows() { async function computeShadows() {
console.time('computeShadows');
await new OPS.shadow(state, { type: "shadow", silent: true }).slice(progress => { await new OPS.shadow(state, { type: "shadow", silent: true }).slice(progress => {
// console.log('reshadowing', progress.round(3)); // console.log('reshadowing', progress.round(3));
}); });
console.timeEnd('computeShadows');
} }
function setToolDiam(toolDiam) { function setToolDiam(toolDiam) {
@ -379,6 +393,11 @@ export async function cam_slice(settings, widget, onupdate, ondone) {
} }
} }
// drop last op if it's type index
if (opList.peek().op.op.type === 'index') {
opList.pop();
}
// call slice() function on all ops in order // call slice() function on all ops in order
await setAxisIndex(); await setAxisIndex();
updateSlicer(); updateSlicer();
@ -416,7 +435,7 @@ export async function cam_slice(settings, widget, onupdate, ondone) {
}); });
let operr; let operr;
await op.slice((progress, message) => { await op.slice((progress, message) => {
onupdate((opSum + (progress * weight)) / opTot, message || op.type()); updateProgress((opSum + (progress * weight)) / opTot, message || op.type());
}).catch(e => { }).catch(e => {
operr = e; operr = e;
console.trace(e); console.trace(e);