add coastline move routes
This commit is contained in:
parent
debe4fb192
commit
a24c1b6653
3 changed files with 44 additions and 15 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<points.length; i++) {
|
||||
let pt = points[i];
|
||||
if (!pt) {
|
||||
continue;
|
||||
}
|
||||
let dist = from.distTo2D(pt);
|
||||
if (dist < start.dist) {
|
||||
start.dist = dist;
|
||||
|
|
@ -419,8 +415,33 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
|
|||
if (start.poly !== end.poly || start.pos === end.pos) {
|
||||
return false;
|
||||
}
|
||||
let pdist = end.pos - start.pos;
|
||||
console.log({ can_route: [ start, end ], pdist });
|
||||
let { poly } = start;
|
||||
let { points } = poly;
|
||||
let pl = poly.length;
|
||||
let sp = start.pos, ep = end.pos;
|
||||
let adist = Math.abs(ep - sp);
|
||||
let bdist = ep > 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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue