start to structure tracing code split as client/worker
This commit is contained in:
parent
c2d05ddfd9
commit
563fcb71d0
7 changed files with 116 additions and 147 deletions
|
|
@ -21,77 +21,25 @@
|
|||
DRILL: 7
|
||||
};
|
||||
|
||||
/**
|
||||
* Find top paths to trace when using ball and taper mills
|
||||
* in waterline outlining and tracing modes.
|
||||
*/
|
||||
function findTracingPaths(widget, slice, tool, profile, partial) {
|
||||
// for now, only emit completed polys and not segments
|
||||
// TODO consider limiting to nup path lengths that are >= tool radius
|
||||
let only_whole = !partial;
|
||||
// check for ball and taper mills paths and add to top[0].inner
|
||||
let polys = [];
|
||||
let nups = [];
|
||||
let cull = [];
|
||||
slice.gatherTopPolys([]).forEach(poly => poly.flattenTo(polys));
|
||||
polys.forEach(poly => {
|
||||
let pz = poly.first().z;
|
||||
let mz = -Infinity;
|
||||
let np = newPolygon().setOpen();
|
||||
let mp = 0;
|
||||
// find top poly segments that are not significantly offset
|
||||
// from tool profile and add to new polygons which accumulate
|
||||
// to the top inner array
|
||||
poly.forEachSegment((p1,p2) => {
|
||||
let nz = getTopoZPathMax(widget, profile, p1.x, p1.y, p2.x, p2.y);
|
||||
if (nz > mz) {
|
||||
mz = nz;
|
||||
}
|
||||
// this # should be computed from topo resolution
|
||||
if (nz - pz < 0.01) {
|
||||
mp++
|
||||
if (np.length) {
|
||||
if (!np.first().isEqual(p2)) {
|
||||
np.append(p2);
|
||||
} else {
|
||||
np.setClosed();
|
||||
}
|
||||
} else {
|
||||
np.append(p1).append(p2);
|
||||
}
|
||||
} else if (np.length) {
|
||||
if (!only_whole) {
|
||||
nups.append(np);
|
||||
}
|
||||
np = newPolygon().setOpen();
|
||||
}
|
||||
});
|
||||
if (np.length) {
|
||||
if (np.length === poly.length) {
|
||||
np.setClosed();
|
||||
}
|
||||
// if a trace poly has no interruptions for an endmill
|
||||
// and it's an inner poly, eliminate it from the parent
|
||||
// so it won't be offset.
|
||||
let parent = poly.parent;
|
||||
if (np.isClosed() && parent) {
|
||||
// console.log(slice.z,'cull',poly);
|
||||
if (parent.inner) {
|
||||
parent.inner = parent.inner.filter(p => p !== poly);
|
||||
}
|
||||
if (only_whole) {
|
||||
nups.append(np);
|
||||
}
|
||||
}
|
||||
if (!only_whole) {
|
||||
nups.append(np);
|
||||
}
|
||||
}
|
||||
// defer loading until KIRI.client and KIRI.worker exist
|
||||
KIRI.loader.push(function(API) {
|
||||
|
||||
if (KIRI.client)
|
||||
KIRI.client.traces = function(ondone) {
|
||||
KIRI.client.sync();
|
||||
send("traces", {
|
||||
settings: API.conf.get()
|
||||
}, ondone);
|
||||
};
|
||||
|
||||
if (KIRI.worker)
|
||||
KIRI.worker.traces = function(data, send) {
|
||||
const { settings } = data;
|
||||
const widgets = Object.values(cache);
|
||||
widgets.forEach(widget => CAM.traces(settings, widget));
|
||||
send.done(123);
|
||||
};
|
||||
|
||||
});
|
||||
if (nups.length) {
|
||||
// console.log(slice.z,'nups',nups.length);
|
||||
slice.tops[0].inner = nups;
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
|
|||
Loading…
Reference in a new issue