refactor contouring, curvesonly, latent emit, single threading

This commit is contained in:
Stewart Allen 2023-01-19 11:15:42 -05:00
commit bcfe727765
4 changed files with 50 additions and 36 deletions

View file

@ -1310,7 +1310,7 @@ CAM.init = function(kiri, api) {
spindle: UC.newInput(LANG.cc_spnd_s, {title:LANG.cc_spnd_l, convert:UC.toInt, show:hasSpindle}),
rate: UC.newInput(LANG.cc_feed_s, {title:LANG.cc_feed_l, convert:UC.toInt, units:true}),
sep: UC.newBlank({class:"pop-sep"}),
step: UC.newInput(LANG.cc_sovr_s, {title:LANG.cc_sovr_l, convert:UC.toFloat, bound:UC.bound(0.01,2.0)}),
step: UC.newInput(LANG.cc_sovr_s, {title:LANG.cc_sovr_l, convert:UC.toFloat, bound:UC.bound(0.01,10.0)}),
angle: UC.newInput(LANG.cf_angl_s, {title:LANG.cf_angl_l, convert:UC.toFloat, bound:UC.bound(45,90)}),
leave: UC.newInput(LANG.cf_leav_s, {title:LANG.cf_leav_l, convert:UC.toFloat, bound:UC.bound(0,100)}),
sep: UC.newBlank({class:"pop-sep"}),

View file

@ -356,7 +356,7 @@ CAM.export = function(print, online) {
}
} else if (line.indexOf(';; REWRITE-COMMENTS-PARENS') === 0) {
rewrite_comments = true;
} else if (line.indexOf(';; DECMIALS') === 0) {
} else if (line.indexOf(';; DECIMALS') === 0) {
decimals = parseInt(line.split('=')[1].trim() || 3) || 3;
} else if (line.indexOf(';; COMPACT-OUTPUT') === 0) {
compact_output = true;

View file

@ -163,7 +163,7 @@ function prepEach(widget, settings, print, firstPoint, update) {
tool = new CAM.Tool(settings, toolID);
toolType = tool.getType();
toolDiam = tool.fluteDiameter();
toolDiamMove = toolType === 'endmill' ? toolDiam : tolerance * 2;
toolDiamMove = toolType === 'endmill' ? toolDiam / 4 : tolerance * 2;
lastTool = toolID;
}
feedRate = feed || feedRate;

View file

@ -350,7 +350,7 @@ class Topo {
}
});
let inc = () => { pcount++ };
let dec = () => { if (--pcount === 0) resolver() };
let dec = () => { if (--pcount === 0 && concurrent) resolver() };
if (contourY) {
onupdate(0, stepsTotal, "contour y");
@ -410,6 +410,8 @@ class Topo {
}
}
if (!concurrent) resolver();
await promise;
trace.cleanup();
@ -485,42 +487,15 @@ class Trace {
let trace,
slice,
latent,
lastDZ,
lastP;
const newslice = this.newslice = () => {
this.slice = slice = [];
}
const push_point = this.push_point = function(x, y, z) {
const newP = newPoint(x, y, z);
// todo: merge co-linear, not just co-planar
if (lastP && Math.abs(lastP.z - z) < flatness) {
if (curvesOnly) {
if ((trace.last() || lastP).distTo2D(newP) >= bridge) {
end_poly();
}
} else {
latent = newP;
}
} else {
if (latent) {
trace.push(latent);
latent = null;
}
if (curvesOnly && lastP) {
// maxangle
const dz = Math.abs(lastP.z - z);
const dv = contourX ? Math.abs(lastP.x - x) : Math.abs(lastP.y - y);
const angle = Math.atan2(dz, dv) * RAD2DEG;
// if (lastP.z < 0.1) console.log('pp', {dz, dxy, angle});
if (angle > maxangle) {
lastP = newP;
return;
}
}
trace.push(newP);
}
lastP = newP;
const newtrace = this.newtrace = function() {
trace = newPolygon().setOpen();
}
const end_poly = this.end_poly = function() {
@ -535,11 +510,49 @@ class Trace {
newtrace();
}
latent = undefined;
lastDZ = undefined;
lastP = undefined;
}
const newtrace = this.newtrace = function() {
trace = newPolygon().setOpen();
const push_point = this.push_point = function(x, y, z) {
const newP = newPoint(x, y, z);
if (lastP) {
const dz = z - lastP.z;
if (lastDZ !== undefined && Math.abs(lastDZ - dz) < 0.0001) {
latent = newP;
} else {
if (Math.abs(dz) < flatness) {
if (curvesOnly && (trace.last() || lastP).distTo2D(newP) >= bridge) {
end_poly();
} else {
latent = newP;
}
} else {
if (latent) {
trace.push(latent);
latent = undefined;
}
if (curvesOnly) {
// maxangle
const dv = contourX ? Math.abs(lastP.x - x) : Math.abs(lastP.y - y);
const angle = Math.atan2( Math.abs(dz), dv) * RAD2DEG;
// if (lastP.z < 0.1) console.log('pp', {dz, dxy, angle});
// console.log({ angle, maxangle, dz });
if (angle > maxangle) {
end_poly();
return;
}
}
trace.push(newP);
}
}
lastDZ = dz;
} else {
trace.push(newP);
}
lastP = newP;
}
const object = this.object = this;
@ -615,6 +628,7 @@ class Trace {
const { clipTab, tabHeight, clipTo, box, resolution, leave } = this.cross;
const { toolAtZ } = this.probe;
let { from, to, x, gridx, gridy } = params;
const checkr = newPoint(0,0);
newslice();
newtrace();