finish circle prepare

This commit is contained in:
bakedpotatolord 2025-06-03 09:29:48 -06:00
commit 5b6b5fc674

View file

@ -325,7 +325,7 @@ function prepEach(widget, settings, print, firstPoint, update) {
* @param {number} opts.factor speed scale factor * @param {number} opts.factor speed scale factor
*/ */
function camOut(point, cut,opts) { function camOut(point, cut,opts) {
// console.log({camOut: point, cut, opts}) console.trace({camOut: point, cut, opts})
let { let {
center = {}, center = {},
clockwise = true, clockwise = true,
@ -391,13 +391,13 @@ function prepEach(widget, settings, print, firstPoint, update) {
isMove = !(cut || isArc); isMove = !(cut || isArc);
// drop points too close together // drop points too close together
if (!isLathe && deltaXY < 0.001 && point.z === lastPoint.z) { if (!isLathe && !isArc && deltaXY < 0.001 && point.z === lastPoint.z) {
// console.trace(["drop dup",lastPoint,point]); // console.trace(["drop dup",lastPoint,point]);
return; return;
} }
// convert short planar moves to cuts in some cases // convert short planar moves to cuts in some cases
if (!isRough && isMove && deltaXY <= moveLen && deltaZ <= 0 && !lasering) { if (!isRough&& !isArc && isMove && deltaXY <= moveLen && deltaZ <= 0 && !lasering ) {
let iscontour = tolerance > 0; let iscontour = tolerance > 0;
let isflat = absDeltaZ < 0.001; let isflat = absDeltaZ < 0.001;
// restrict this to contouring // restrict this to contouring
@ -742,7 +742,7 @@ function prepEach(widget, settings, print, firstPoint, update) {
// console.log("start",point,lastp) // console.log("start",point,lastp)
let dist = lastp? point.distTo2D(lastp) : 0; let dist = lastp? point.distTo2D(lastp) : 0;
if (lastp) { if (lastp) {
if (dist >arcDist) { if (dist >arcDist && lastp) {
let rec = Object.assign(point,{dist}); let rec = Object.assign(point,{dist});
arcQ.push(rec); arcQ.push(rec);
let desp = false; // do arcQ[0] and rec have differing move speeds? let desp = false; // do arcQ[0] and rec have differing move speeds?
@ -829,8 +829,8 @@ function prepEach(widget, settings, print, firstPoint, update) {
} }
} else { } else {
// if dist to small, output as a cut // if dist to small, output as a cut
console.log('point too small', point); console.log('point too small', point,lastp,dist);
camOut(point, 1); // camOut(point, 1);
} }
} else { } else {
// if first point, emit and set // if first point, emit and set
@ -867,10 +867,20 @@ function prepEach(widget, settings, print, firstPoint, update) {
arcQ.ySum / cl, arcQ.ySum / cl,
) )
// first arc point if(arcQ.length == poly.points.length){
camOut(from,1); //if is a circle
// rest of arc to final point let arcStart = arcQ[0]
camOut(to,1,{ center:center.sub(from), clockwise, arcPoints:[...arcQ]}); camOut(arcStart,1);
camOut(arcStart,1,{ center:center.sub(from), clockwise, arcPoints:[...arcQ]});
}else{
//if a non-circle arc
// first arc point
camOut(from,1);
// rest of arc to final point
camOut(to,1,{ center:center.sub(from), clockwise, arcPoints:[...arcQ]});
}
} else { } else {
//if q too short, emit as lines //if q too short, emit as lines
for (let rec of arcQ) { for (let rec of arcQ) {
@ -881,24 +891,27 @@ function prepEach(widget, settings, print, firstPoint, update) {
arcQ.length = 0; arcQ.length = 0;
arcQ.center = undefined; arcQ.center = undefined;
} }
let last = null; let {point:lastPoint, index:startIdx} = poly.findClosestPointTo(fromPoint);
let last = index;
// scale speed of first cutting poly since it engages the full bit // scale speed of first cutting poly since it engages the full bit
let scale = ((isRough || isPocket) && count === 1) ? engageFactor : 1; let scale = ((isRough || isPocket) && count === 1) ? engageFactor : 1;
if (easeDown && poly.isClosed()) { //if doing ease-down if (easeDown && poly.isClosed()) { //if doing ease-down
last = generateEaseDown((point, )=>{ //generate ease-down points last = generateEaseDown((point, )=>{ //generate ease-down points
camOut(point.clone(), 1, {factor:scale}); // and pass them to camOut camOut(point.clone(), 1, {factor:scale}); // and pass them to camOut
}, poly, fromPoint, easeAngle); }, poly, lastPoint, easeAngle);
} }
poly.forEachPoint(function(point, pidx, points, offset) {
if(offset ==0 ) last = camOut(point.clone(), 0, {factor:scale}); poly.forEachPoint( ( point, pidx, points, offset) => {
else last =arcExport(point,last ?? point); // if(offset == 0) console.log("forEachPoint",point,pidx,points)
}, poly.isClosed(), last); if(offset ==0 ) arcExport(point,lastPoint);
else arcExport(point, lastPoint);
last = pidx;
lastPoint = point;
}, poly.isClosed(), startIdx);
// console.log("at end of arcExport",structuredClone(arcQ)); // console.log("at end of arcExport",structuredClone(arcQ));
if(arcQ.length <= 3){ if(arcQ.length <= 3){
@ -909,6 +922,7 @@ function prepEach(widget, settings, print, firstPoint, update) {
}else{ }else{
console.log("force draining",structuredClone(arcQ)); console.log("force draining",structuredClone(arcQ));
drainQ(); drainQ();
console.log("after draining",structuredClone(arcQ));
// camOut(arcQ.shift(),1); // camOut(arcQ.shift(),1);
} }