diff --git a/src/geo/polygon.js b/src/geo/polygon.js index 2a2be748..806fbd9b 100644 --- a/src/geo/polygon.js +++ b/src/geo/polygon.js @@ -2326,7 +2326,7 @@ export class Polygon { // split long straight lines into segments no longer than max // and return a new polygon - segment(max = 1, mark) { + segment(max = 1, mark, wrap) { const newp = []; const points = this.points; const length = points.length; @@ -2358,6 +2358,9 @@ export class Polygon { } } if (newp.length > length) { + if (wrap) { + newp.push(newp[0]); + } return newPolygon().addPoints(newp.map(p => p.clone(['segment']))).setOpenValue(this.open); } return this; diff --git a/src/kiri/mode/fdm/post.js b/src/kiri/mode/fdm/post.js index 7a86ea94..8da695bb 100644 --- a/src/kiri/mode/fdm/post.js +++ b/src/kiri/mode/fdm/post.js @@ -70,6 +70,9 @@ export function slicePost(data, options) { function offset_default(params) { let { z, top, count, top_poly, offset1, offsetN, wasm, last, gaps } = params; + + let first; + // standard wall offsetting strategy POLY.offset( top_poly, @@ -81,6 +84,7 @@ function offset_default(params) { outs: top.shells, flat: true, call: (polys, onCount) => { + first = first || polys; last = polys; // mark each poly with depth (offset #) starting at 0 for (let p of polys) { @@ -99,37 +103,87 @@ function offset_default(params) { } } ); - // look for close points on segmented polys + + // look for close points on adjacent segmented polys and merge + let test_polys = first !== last ? [ ...first, ...last ] : last; + let thin_test = POLY.flatten(test_polys).map(poly => { + return { + poly, + points: poly.segment(offset1, true).points + } + }); + if (false) - for (let poly of POLY.flatten(last)) { - let ps = poly.segment(offset1, true); - let pp = ps.points; - let moved = false; - pp.push(pp[0]); - for (let i=0; i