diff --git a/src/kiri/mode/cam/op-contour.js b/src/kiri/mode/cam/op-contour.js index 5939ef80..b396782d 100644 --- a/src/kiri/mode/cam/op-contour.js +++ b/src/kiri/mode/cam/op-contour.js @@ -5,6 +5,7 @@ import { Tool } from './tool.js'; import { generate as Topo } from './topo3.js'; import { newPoint } from '../../../geo/point.js'; import { newPolygon } from '../../../geo/polygon.js'; +import { newSlice } from '../../core/slice.js'; import { tip2tipEmit } from '../../../geo/paths.js'; function createFilter(op, origin, axis) { @@ -112,6 +113,14 @@ class OpContour extends CamOp { state }); + if (this.debug && topo.coastline) { + console.log('coastline', topo.coastline); + const dbs = newSlice(-1); + const dbo = dbs.output(); + dbo.setLayer("coastline", { line: 0x0000dd }).addPolys(topo.coastline); + addSlices([ dbs ]) + } + // computed if set to 0 this.tolerance = topo.tolerance; } diff --git a/src/kiri/mode/cam/prepare.js b/src/kiri/mode/cam/prepare.js index 8a06ec9a..43a0794e 100644 --- a/src/kiri/mode/cam/prepare.js +++ b/src/kiri/mode/cam/prepare.js @@ -190,12 +190,6 @@ export async function prepare_one(widget, settings, print, firstPoint, update) { contouring = bool; toolDiamMove = step ?? tool.getStepSize(currentOp.step) * 2; if (bool) setTravelBoundary(); - if (coast) { - for (let poly of coast) { - // poly.points = poly.points.map(pt => toWorkCoords(pt)); - } - console.log({ coast_to_work: coast }); - } } function setSpindle(speed) { @@ -385,6 +379,11 @@ export async function prepare_one(widget, settings, print, firstPoint, update) { .annotate({ slice: p.slice }); } + /** + * when moving between contour endpoints, check if we can + * instead route around the bounding area of the contour + * whih we call the coastline. + */ function coastlineMove(point) { let from = toWidgetCoords(printPoint); let to = toWidgetCoords(point); @@ -397,9 +396,6 @@ export async function prepare_one(widget, settings, print, firstPoint, update) { let { points } = poly; for (let i=0; i sp ? + sp + (pl - ep): + ep + (pl - sp); + let dir = 1; + let dist; + if (adist < bdist) { + dist = adist; + if (ep < sp) { + dir = -1; + } + } else { + dist = bdist; + if (ep < sp) { + ep += pl; + } else { + sp += pl; + dir = -1; + } + } + for (let i=sp, d=0; d < dist; i += dir, d++) { + layerPush(toWorkCoords(points[i % pl]), 1, 0, tool); + } return true; } @@ -509,7 +530,7 @@ export async function prepare_one(widget, settings, print, firstPoint, update) { // contouring logic if (isMove && contouring) { - if (coastline && deltaXY < toolDiamMove * 5 && coastlineMove(point)) { + if (coastline && deltaXY < 5 && coastlineMove(point)) { // console.log('coastline move'); } else if (deltaXY > toolDiamMove) { upAndOver = true; diff --git a/src/kiri/mode/cam/topo3.js b/src/kiri/mode/cam/topo3.js index 021e9385..196ddf88 100644 --- a/src/kiri/mode/cam/topo3.js +++ b/src/kiri/mode/cam/topo3.js @@ -172,11 +172,10 @@ export class Topo { let paths = POLY.flatten(clipTo).map(poly => poly.points.map(p => [ p.x, p.y ]).flat().toFloat32()); let coastline = await gpu.generateToolpaths({ paths, - step: toolStep / 2, - zFloor: zBottom - 1 + step: 1, + zFloor: zBottom }); this.coastline = coastline.paths.map(arr => newPolygon().fromArray([0,...arr])); - console.log({ coastline: this.coastline, clipTo }); gpu.terminate(); let { numScanlines, pointsPerLine, pathData } = output;