From 208a2f2b0c2c98495c724e57f8beddbf7ca716c5 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Thu, 14 Jan 2021 09:25:58 -0500 Subject: [PATCH] heal polys before tracing --- notes.md | 1 - src/mode/cam/ops.js | 4 +++- src/mode/cam/slice.js | 14 +++++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/notes.md b/notes.md index be40a586..431becf1 100644 --- a/notes.md +++ b/notes.md @@ -54,7 +54,6 @@ # CAM * `B` trace clear and follow need depth-first support -* `B` trace follow open polys should "heal" if ends touch * `B` trace open polys are not wound consistently * `B` path routing with tabs sometimes makes no sense * `B` clicking on a pop-op should pin it until clicked or [esc] diff --git a/src/mode/cam/ops.js b/src/mode/cam/ops.js index 89a9478d..b300493c 100644 --- a/src/mode/cam/ops.js +++ b/src/mode/cam/ops.js @@ -685,7 +685,7 @@ let { op, state } = this; let { tool, rate, down, plunge, offset } = op; let { settings, widget, sliceAll, zMax, tabs } = state; - let { updateToolDiams, cutTabs, cutPolys } = state; + let { updateToolDiams, cutTabs, cutPolys, healPolys } = state; let { process, stock } = settings; // generate tracing offsets from chosen features let sliceOut = this.sliceOut = []; @@ -744,6 +744,8 @@ .setLayer("clear", {line: 0xaa00aa}, false) .addPolys(slice.camLines) } + // connect selected segments if open and touching + polys = healPolys(polys); switch (op.mode) { case "follow": for (let poly of polys) { diff --git a/src/mode/cam/slice.js b/src/mode/cam/slice.js index 2b98f4a1..efc09b8f 100644 --- a/src/mode/cam/slice.js +++ b/src/mode/cam/slice.js @@ -106,6 +106,7 @@ tabs, cutTabs, cutPolys, + healPolys, slicer, sliceAll, updateToolDiams, @@ -273,8 +274,11 @@ function cutPolys(polys, offset, z, inter) { let noff = []; - // tabs = tabs.filter(tab => z < tab.pos.z + tab.dim.z/2).map(tab => tab.off).flat(); offset.forEach(op => noff.appendAll( op.cut(POLY.union(polys, 0, true), inter) )); + return healPolys(noff); + } + + function healPolys(noff) { if (noff.length > 1) { let heal = 0; // heal/rejoin open segments that share endpoints @@ -317,6 +321,14 @@ // cull nulls noff = noff.filter(o => o); } + // close poly if head meets tail + for (let poly of noff) { + if (poly.open && poly.first().isMergable2D(poly.last())) { + poly.points.pop(); + poly.length--; + poly.open = false; + } + } } return noff; }