diff --git a/src/add/array.js b/src/add/array.js index b9aa099d..8a0202c7 100644 --- a/src/add/array.js +++ b/src/add/array.js @@ -69,6 +69,32 @@ return na; }; + AP.xray = function(arg) { + const na = [], ln = this.length; + for (let i=0; i { + if (el.xout) { + el.xout(null, inset + i + inset); + } else if (el.xray) { + const info = el.xray(); + console.log(inset, info); + Object.values(info).forEach(val => { + if (val.xout) { + val.xout(null, inset + inset); + } + }); + } + }); + }; + /** * remove and return element from array, if present * diff --git a/src/geo/polygon.js b/src/geo/polygon.js index 0d0b56ef..2d5ddad8 100644 --- a/src/geo/polygon.js +++ b/src/geo/polygon.js @@ -122,6 +122,20 @@ } }; + PRO.xray = function(deep) { + const xray = { + id: this.id, + len: this.points.length, + open: this.open, + depth: this.depth, + parent: this.parent ? true : false + }; + if (this.inner) { + xray.inner = deep ? this.inner.xray(deep) : this.inner; + } + return xray; + }; + // return which plane (x,y,z) this polygon is coplanar with PRO.alignment = function() { if (this._aligned) return this._aligned; @@ -886,7 +900,8 @@ */ PRO.isInside = function(poly, tolerance) { // throw new Error("isInside"); - if (!this.bounds.isNested(poly.bounds, tolerance * 3)) { + const neardist = tolerance || CONF.precision_close_to_poly_sq; + if (!this.bounds.isNested(poly.bounds, neardist * 3)) { return false; } @@ -898,12 +913,12 @@ // check midpoint on long lines (TODO: should be distToSq2D()?) if (prev.distTo2D(next) > midcheck) { mid = prev.midPointTo(next); - if (!(mid.inPolygon(poly) || mid.nearPolygon(poly, tolerance || CONF.precision_close_to_poly_sq))) { + if (!(mid.inPolygon(poly) || mid.nearPolygon(poly, neardist))) { exit = false; return true; } } - if (!(next.inPolygon(poly) || next.nearPolygon(poly, tolerance || CONF.precision_close_to_poly_sq))) { + if (!(next.inPolygon(poly) || next.nearPolygon(poly, neardist))) { exit = false; return true; } diff --git a/src/mode/cam/prepare.js b/src/mode/cam/prepare.js index 0e10f124..08aba251 100644 --- a/src/mode/cam/prepare.js +++ b/src/mode/cam/prepare.js @@ -353,9 +353,9 @@ } } let polys = [], t = [], c = []; - POLY.flatten(slice.camLines.clone(true)).forEach(function (poly) { + POLY.flatten(slice.camLines).forEach(function (poly) { let child = poly.parent; - if (depthFirst) poly = poly.clone(true); + if (depthFirst) { poly = poly.clone(); poly.parent = child ? 1 : 0 } if (child) c.push(poly); else t.push(poly); poly.layer = depthData.layer; polys.push(poly); @@ -366,6 +366,7 @@ POLY.setWinding(c, !dir); if (depthFirst) { (slice.camMode === PRO.ROUGH ? depthData.rough : depthData.outline).append(polys); + // polys.xout(`prep ${slice.z}`); } else { printPoint = poly2polyEmit(polys, printPoint, function(poly, index, count) { poly.forEachPoint(function(point, pidx, points, offset) { @@ -440,7 +441,7 @@ fitted.filter(top => !top.level_emit).forEach(top => { top.level_emit = true; let inside = level.filter(poly => poly.isInside(top)); - start = poly2polyEmit(inside, start, emitter); + start = poly2polyEmit(inside, start, emitter, { mark: "emark" }); start = depthRoughPath(start, depth + 1, levels, tops, emitter, top); }); return start; @@ -455,14 +456,20 @@ } if (above) { level = level.filter(lp => { - return above.filter(ap => !ap.level_emit && lp.isNear(ap, radius, true)).length === 0; + const conf = above.filter(ap => !ap.level_emit && lp.isNear(ap, radius, true)); + return conf.length === 0; }); } + const thru = []; // match thru polys level = level.filter(lp => { - if (lp.level_emit) return false; - if (bottm && !clr) { - return bottm.filter(bp => lp.isEquivalent(bp)).length === 0; + if (lp.level_emit) { + return false; } +// if (bottm && !clr) { +// const tm = bottm.filter(bp => lp.isEquivalent(bp)); +// thru.appendAll(tm); +// return tm.length === 0; +// } return true; }); // omit polys that match bottom level polys unless level above is cleared @@ -472,7 +479,6 @@ fromPoint = depthOutlinePath(fromPoint, depth + 1, levels, radius, emitter, clr); return fromPoint; }, {weight: true}); - start = depthOutlinePath(start, depth + 1, levels, radius, emitter, clr); return start; } @@ -490,16 +496,17 @@ } // outline depth first if (depthData.outline.length > 0) { + // depthData.outline.xout('depth'); lastMode = PRO.OUTLINE; setTool(process.camOutlineTool, process.camOutlineSpeed, process.camOutlinePlunge); spindle = Math.min(spindleMax, process.camOutlineSpindle); let flatLevels = depthData.outline.map(level => { return POLY.flatten(level.clone(true), [], true).filter(p => !(p.depth = 0)); - }) + }); + // flatLevels.xout('flat'); // start with the smallest polygon on the top printPoint = flatLevels[0] - .sort((a,b) => { return a.area() - b.area() }) - .shift() + .sort((a,b) => { return a.area() - b.area() })[0] .average(); printPoint = depthOutlinePath(printPoint, 0, flatLevels, toolDiam, polyEmit, false); printPoint = depthOutlinePath(printPoint, 0, flatLevels, toolDiam, polyEmit, true); diff --git a/src/mode/cam/slice.js b/src/mode/cam/slice.js index 593bd6d8..d0fd5a95 100644 --- a/src/mode/cam/slice.js +++ b/src/mode/cam/slice.js @@ -302,7 +302,7 @@ if (addTabsOutline && slice.z <= zMin + tabHeight) { offset = addCutoutTabs(offset, slice.z, outlineToolDiam, tabWidth, proc.camTabsCount, proc.camTabsAngle); } - + // offset.xout(`slice ${slice.z}`); slice.camLines = offset; slice.output() .setLayer("outline", {face: 0, line: 0})