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 { generate as Topo } from './topo3.js';
|
||||||
import { newPoint } from '../../../geo/point.js';
|
import { newPoint } from '../../../geo/point.js';
|
||||||
import { newPolygon } from '../../../geo/polygon.js';
|
import { newPolygon } from '../../../geo/polygon.js';
|
||||||
|
import { newSlice } from '../../core/slice.js';
|
||||||
import { tip2tipEmit } from '../../../geo/paths.js';
|
import { tip2tipEmit } from '../../../geo/paths.js';
|
||||||
|
|
||||||
function createFilter(op, origin, axis) {
|
function createFilter(op, origin, axis) {
|
||||||
|
|
@ -112,6 +113,14 @@ class OpContour extends CamOp {
|
||||||
state
|
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
|
// computed if set to 0
|
||||||
this.tolerance = topo.tolerance;
|
this.tolerance = topo.tolerance;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -190,12 +190,6 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
|
||||||
contouring = bool;
|
contouring = bool;
|
||||||
toolDiamMove = step ?? tool.getStepSize(currentOp.step) * 2;
|
toolDiamMove = step ?? tool.getStepSize(currentOp.step) * 2;
|
||||||
if (bool) setTravelBoundary();
|
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) {
|
function setSpindle(speed) {
|
||||||
|
|
@ -385,6 +379,11 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
|
||||||
.annotate({ slice: p.slice });
|
.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) {
|
function coastlineMove(point) {
|
||||||
let from = toWidgetCoords(printPoint);
|
let from = toWidgetCoords(printPoint);
|
||||||
let to = toWidgetCoords(point);
|
let to = toWidgetCoords(point);
|
||||||
|
|
@ -397,9 +396,6 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
|
||||||
let { points } = poly;
|
let { points } = poly;
|
||||||
for (let i=0; i<points.length; i++) {
|
for (let i=0; i<points.length; i++) {
|
||||||
let pt = points[i];
|
let pt = points[i];
|
||||||
if (!pt) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let dist = from.distTo2D(pt);
|
let dist = from.distTo2D(pt);
|
||||||
if (dist < start.dist) {
|
if (dist < start.dist) {
|
||||||
start.dist = 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) {
|
if (start.poly !== end.poly || start.pos === end.pos) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let pdist = end.pos - start.pos;
|
let { poly } = start;
|
||||||
console.log({ can_route: [ start, end ], pdist });
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -509,7 +530,7 @@ export async function prepare_one(widget, settings, print, firstPoint, update) {
|
||||||
|
|
||||||
// contouring logic
|
// contouring logic
|
||||||
if (isMove && contouring) {
|
if (isMove && contouring) {
|
||||||
if (coastline && deltaXY < toolDiamMove * 5 && coastlineMove(point)) {
|
if (coastline && deltaXY < 5 && coastlineMove(point)) {
|
||||||
// console.log('coastline move');
|
// console.log('coastline move');
|
||||||
} else if (deltaXY > toolDiamMove) {
|
} else if (deltaXY > toolDiamMove) {
|
||||||
upAndOver = true;
|
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 paths = POLY.flatten(clipTo).map(poly => poly.points.map(p => [ p.x, p.y ]).flat().toFloat32());
|
||||||
let coastline = await gpu.generateToolpaths({
|
let coastline = await gpu.generateToolpaths({
|
||||||
paths,
|
paths,
|
||||||
step: toolStep / 2,
|
step: 1,
|
||||||
zFloor: zBottom - 1
|
zFloor: zBottom
|
||||||
});
|
});
|
||||||
this.coastline = coastline.paths.map(arr => newPolygon().fromArray([0,...arr]));
|
this.coastline = coastline.paths.map(arr => newPolygon().fromArray([0,...arr]));
|
||||||
console.log({ coastline: this.coastline, clipTo });
|
|
||||||
gpu.terminate();
|
gpu.terminate();
|
||||||
|
|
||||||
let { numScanlines, pointsPerLine, pathData } = output;
|
let { numScanlines, pointsPerLine, pathData } = output;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue