fix dogbones typo for trace. fix first point error

This commit is contained in:
Stewart Allen 2023-02-25 13:07:40 -05:00
commit e0695b1a02
3 changed files with 29 additions and 20 deletions

View file

@ -1366,6 +1366,19 @@ CAM.init = function(kiri, api) {
// filter: UC.newRow([ UC.newButton(LANG.filter, contourFilter) ], {class:"ext-buttons f-row"})
};
function canDogBones() {
if (!poppedRec) return false;
return poppedRec.mode === 'follow';// && poppedRec.offset && poppedRec.offset !== 'none';
}
function canDogBonesRev() {
return canDogBones() && poppedRec.dogbone;
}
function zDogSep() {
return canDogBones() || zBottom();
}
createPopOp('trace', {
mode: 'camTraceType',
offset: 'camTraceOffset',
@ -1395,10 +1408,10 @@ CAM.init = function(kiri, api) {
down: UC.newInput(LANG.cc_sdwn_s, {title:LANG.cc_sdwn_l, convert:UC.toFloat, units:true}),
thru: UC.newInput(LANG.cc_thru_s, {title:LANG.cc_thru_l, convert:UC.toFloat, units:true}),
offover: UC.newInput(LANG.cc_offd_s, {title:LANG.cc_offd_l, convert:UC.toFloat, units:true, show:() => poppedRec.offset !== "none"}),
sep: UC.newBlank({class:"pop-sep", modes:MCAM, poop:true }),
sep: UC.newBlank({class:"pop-sep", modes:MCAM, xshow:zDogSep}),
bottom: UC.newBoolean(LANG.cf_botm_s, undefined, {title:LANG.cf_botm_l, show:(op,conf) => conf.process.camZBottom}),
dogbone: UC.newBoolean(LANG.co_dogb_s, undefined, {title:LANG.co_dogb_l}),
revbone: UC.newBoolean(LANG.co_dogr_s, undefined, {title:LANG.co_dogr_l, show:(op) => poppedRec.dogbone}),
dogbone: UC.newBoolean(LANG.co_dogb_s, undefined, {title:LANG.co_dogb_l, show:canDogBones}),
revbone: UC.newBoolean(LANG.co_dogr_s, undefined, {title:LANG.co_dogr_l, show:canDogBonesRev}),
sep: UC.newBlank({class:"pop-sep"}),
menu: UC.newRow([
UC.newButton(undefined, func.traceAdd, {icon:'<i class="fas fa-plus"></i>'}),

View file

@ -1001,7 +1001,7 @@ class OpTrace extends CamOp {
return slice;
}
function followZ(poly) {
if (op.dogbones) {
if (op.dogbone) {
CAM.addDogbones(poly, toolDiam / 5, !op.revbone);
}
let z = poly.getZ();

View file

@ -292,33 +292,29 @@ CAM.addDogbones = function(poly, dist, reverse) {
if (Array.isArray(poly)) {
return poly.forEach(p => CAM.addDogbones(p, dist));
}
// if (poly.open) return;
let open = poly.open;
let isCW = poly.isClockwise();
if (reverse || poly.parent) isCW = !isCW;
let oldpts = poly.points.slice();
let lastpt = oldpts[oldpts.length - 1];
let lastsl = lastpt.slopeTo(oldpts[0]).toUnit();
let length = oldpts.length + (open ? 0 : 1);
let newpts = [ ];
for (let i=0; i<oldpts.length + (open ? 0 : 1); i++) {
for (let i=0; i<length; i++) {
let nextpt = oldpts[i % oldpts.length];
let nextsl = lastpt.slopeTo(nextpt).toUnit();
let adiff = lastsl.angleDiff(nextsl, true);
let bdiff = ((adiff < 0 ? (180 - adiff) : (180 + adiff)) / 2) + 180;
if (open && i === 0) {
lastsl = nextsl;
lastpt = nextpt;
newpts.push(nextpt);
continue;
}
if (isCW && adiff > 45) {
let newa = base.newSlopeFromAngle(lastsl.angle + bdiff);
newpts.push(lastpt.projectOnSlope(newa, dist));
newpts.push(lastpt.clone());
} else if (!isCW && adiff < -45) {
let newa = base.newSlopeFromAngle(lastsl.angle - bdiff);
newpts.push(lastpt.projectOnSlope(newa, dist));
newpts.push(lastpt.clone());
if (!open || (i > 1 && i < length)) {
if (isCW && adiff > 45) {
let newa = base.newSlopeFromAngle(lastsl.angle + bdiff);
newpts.push(lastpt.projectOnSlope(newa, dist));
newpts.push(lastpt.clone());
} else if (!isCW && adiff < -45) {
let newa = base.newSlopeFromAngle(lastsl.angle - bdiff);
newpts.push(lastpt.projectOnSlope(newa, dist));
newpts.push(lastpt.clone());
}
}
lastsl = nextsl;
lastpt = nextpt;