From 91ad27f5401098de16480c2b6846ae8ca51947ba Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sun, 23 Feb 2025 14:50:24 -0500 Subject: [PATCH] add thin type 3 test --- src/geo/polygon.js | 34 ++++++++++++++++++++++++++++++++++ src/geo/polygons.js | 4 ++-- src/kiri-mode/fdm/post.js | 26 ++++++++++++++++++++++++++ src/kiri/consts.js | 3 ++- src/kiri/init.js | 5 +++++ 5 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/geo/polygon.js b/src/geo/polygon.js index 8e722fca..2a3449e0 100644 --- a/src/geo/polygon.js +++ b/src/geo/polygon.js @@ -253,6 +253,40 @@ class Polygon { return ret; } + setInner(inner) { + this.inner = inner; + return this; + } + + // generate a trace path around the inside of a polygon + // including inner polys. return the noodle and the remainder + // of the polygon with the noodle removed (for the next pass) + noodle(width) { + // inset outer polygon + let inner = this.inner; + let inset = this.clone().offset(width); + let noodle = [ this.clone().setInner(inset) ]; + let noodin = []; + // subtract inners from the inset + if (inner) { + noodle = POLY.subtract(noodle, inner, []); + // for each inner, offset and subtract noodle + itself + let nood = []; + for (let innie of inner) { + let inexp = innie.clone().offset(-width); + let intrm = POLY.trimTo(inexp, [ this ]); + let inood = POLY.subtract(intrm, [ ...noodle, innie ], []); + nood.push(...inood); + } + noodin = POLY.union(nood, 0, true); + } + // unify inner noodles and outer noodle + noodle = POLY.union([ ...noodle, ...noodin ], 0, true); + // subtract noodle from poly for next noodle calc + let remain = POLY.subtract([ this ], noodle, []); + return { noodle, remain }; + } + // generate center crossing point cloud centers(step, z, min, max, opt = {}) { let cloud = [], diff --git a/src/geo/polygons.js b/src/geo/polygons.js index cf6c411f..e5333616 100644 --- a/src/geo/polygons.js +++ b/src/geo/polygons.js @@ -348,7 +348,7 @@ function subtract(setA, setB, outA, outB, z, minArea, opt = {}) { let min = numOrDefault(minArea, 0.1), out = []; - function filter(from, to = []) { + function filter(from, to = []) { from.forEach(function(poly) { if (poly.area() >= min) { to.push(poly); @@ -541,7 +541,7 @@ function diff(setA, setB, z) { /** * Slice.doProjectedFills() * - * @param {Polygon[]} setA source set + * @param {Polygon[]} setA target set * @param {Polygon[]} setB mask set * @returns {Polygon[]} */ diff --git a/src/kiri-mode/fdm/post.js b/src/kiri-mode/fdm/post.js index 0621e055..d601cb1d 100644 --- a/src/kiri-mode/fdm/post.js +++ b/src/kiri-mode/fdm/post.js @@ -167,6 +167,28 @@ function thin_type_2(params) { return { last, gaps }; } +function thin_type_3(params) { + let { z, top, count, offsetN, last, gaps } = params; + top.thin_fill = []; + top.fill_sparse = []; + + let { noodle, remain } = top.poly.noodle(offsetN); + top.shells = noodle; + top.gaps = remain; + // top.fill_off = noodle; + + // if (remain.length) { + // top.gaps = []; + // for (let poly of remain) { + // let { noodle } = poly.noodle(offsetN); + // console.log({ next_noodle: noodle }); + // top.gaps.push(...noodle); + // } + // } + + return { last, gaps }; +} + /** * may run in minion or worker context. performs shell offsetting * including thin wall detection when enabled @@ -214,6 +236,10 @@ FDM.doTopShells = function(z, top, count, offset1, offsetN, fillOffset, opt = {} case "type 2": ret = thin_type_2({ z, top, count, top_poly, offset1, offsetN, fillOffset, gaps, wasm }); break; + case "type 3": + ret = thin_type_3({ z, top, count, top_poly, offsetN }); + fillOffset = 0; + break; default: ret = offset_default({ z, top, count, top_poly, offset1, offsetN, wasm }); break; diff --git a/src/kiri/consts.js b/src/kiri/consts.js index aa4c2eaf..2c0a5757 100644 --- a/src/kiri/consts.js +++ b/src/kiri/consts.js @@ -114,7 +114,8 @@ const LISTS = { thin: [ { name: "off" }, { name: "type 1" }, - { name: "type 2" } + { name: "type 2" }, + { name: "type 3" } ] }; diff --git a/src/kiri/init.js b/src/kiri/init.js index e93580f9..6ce1df9f 100644 --- a/src/kiri/init.js +++ b/src/kiri/init.js @@ -1863,6 +1863,11 @@ gapp.register("kiri.init", (root, exports) => { const current = settings(); const control = current.controller; + if (!control.devel) { + // TODO: hide thin type 3 during development + kiri.consts.LISTS.thin.length = 3; + } + platform.deselect(); catalog.addFileListener(updateCatalog); space.view.setZoom(control.reverseZoom, control.zoomSpeed);