From eb63ebb1d08a6b6032f08683f0d4c1122353904f Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Tue, 9 Sep 2025 22:55:30 -0400 Subject: [PATCH] form chains from radii points --- src/kiri/mode/fdm/post.js | 86 ++++++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 20 deletions(-) diff --git a/src/kiri/mode/fdm/post.js b/src/kiri/mode/fdm/post.js index a2c95565..66c015a7 100644 --- a/src/kiri/mode/fdm/post.js +++ b/src/kiri/mode/fdm/post.js @@ -2,7 +2,7 @@ import '../../../ext/jspoly.js'; import { base } from '../../../geo/base.js'; -import { newPolygon } from '../../../geo/polygon.js'; +import { newPolygon, Polygon } from '../../../geo/polygon.js'; import { polygons as POLY, fillArea } from '../../../geo/polygons.js'; import { getRangeParameters } from './driver.js'; import { slicer } from '../../../geo/slicer.js'; @@ -169,7 +169,7 @@ function thin_type_3(params) { // produce trace from outside of poly inward no more than max inset let { noodle, remain } = top.poly.noodle(offsetN * count); - top.shells = noodle; + // top.shells = noodle; top.gaps = last = remain; let thin = top.thin_fill; @@ -293,9 +293,16 @@ function thin_type_3(params) { } } - let showMid = false; - let showCross = false; - let showRad = true; + let showNoodle = false; + let showMid = false; + let showCross = false; + let showRad = true; + let showShells = true; + + // render inset "noodle" + if (showNoodle) { + top.shells.appendAll(noodle); + } // divide a segment/redius into 1 or more equal subsegments function div(cr) { @@ -315,12 +322,8 @@ function thin_type_3(params) { } } - // add chains to thinwall output for visualization - if (showRad) { - top.shells = []; - } - // ranked points by inset distance - let inset = []; + // gather point offsets into shells + let shells = { count: 0 }; for (let chain of chains.filter(c => c.total >= minR)) { // chain reduction by merging short segments let end = chain[0]; @@ -364,32 +367,75 @@ function thin_type_3(params) { thin.push(new Point(cx + yo, cy - xo)); thin.push(new Point(cx - yo, cy + xo)); } - if (showRad) { + if (showRad || showShells) { let circ = top.shells; let pop = div(cr); let sx = cx + yo; let sy = cy - xo; let m = 1; - let indx = 0; + let index = 0; + let plen = pop.length; + let mid = plen / 2; for (let r of pop) { - indx = Math.min(indx, pop.length - 1 - indx); - let inset_arr = inset[indx]; + let shell = index < mid ? index + 1 : -(pop.length - index); + let inset_arr = shells[shell]; if (!inset_arr) { - inset_arr = inset[indx] = []; + inset_arr = shells[shell] = []; } sx -= (r/cr) * yo * m; sy += (r/cr) * xo * m; - circ.push(newPolygon().centerCircle({ x:sx, y:sy }, r, 10)); m = 2; - inset_arr.push({ x:sx, y:sy, r }); - indx++; + if (showRad) { + circ.push(newPolygon().centerCircle({ x:sx, y:sy }, r, 10)); + } + inset_arr.push(new Point(sx, sy, r)); + index++; + shells.count = Math.max(shells.count, Math.abs(shell)); } } } } } - // console.log({ inset }); + // follow shells and output lines + console.log({ shells }); + if (showShells) + for (let shell = 1; shell <= 1; shell++) { + let poly = new Polygon().setOpen(); + let arr = shells[shell]; + let lp = arr[0]; + poly.push(lp); + let find; + for (;;) { + find = { dist: Infinity }; + // find next closest point + for (let i=1; i 1) { + top.shells.push(poly); + poly = new Polygon().setOpen(); + } + arr[find.pi] = undefined; + poly.push(lp = find.pt); + } else { + break; + } + } + console.log({ poly }); + if (poly.length > 1) { + top.shells.push(poly); + } + } + return { last, gaps }; }