when healing enabled, warn when non-manifold geometry detected. update release notes

This commit is contained in:
Stewart Allen 2022-09-08 13:26:47 -04:00
commit 059dbced58
8 changed files with 62 additions and 14 deletions

View file

@ -36,6 +36,7 @@ const POLYS = base.polygons = {
expand,
expand_lines,
points,
length,
route,
union,
inset,
@ -52,6 +53,14 @@ const POLYS = base.polygons = {
fingerprint
};
function length(polys) {
let length = 0;
for (let p of polys) {
length += p.deepLength;
}
return length;
}
function setZ(polys, z) {
for (let poly of polys) {
poly.setZ(z);
@ -376,13 +385,16 @@ function subtract(setA, setB, outA, outB, z, minArea, opt = {}) {
*/
function union(polys, minarea, all, opt = {}) {
if (polys.length < 2) return polys;
let lpre = length(polys);
if (opt.wasm && geo.wasm) {
let min = minarea || 0.01;
// let deepLength = polys.map(p => p.deepLength).reduce((a,v) => a+v);
// if (deepLength < 15000)
try {
return geo.wasm.js.union(polys, polys[0].getZ()).filter(p => p.area() > min);
let out = geo.wasm.js.union(polys, polys[0].getZ()).filter(p => p.area() > min);
opt.changes = length(out) - lpre;
return out;
} catch (e) {
console.log({union_fail: polys, minarea, all});
}
@ -419,6 +431,7 @@ function subtract(setA, setB, outA, outB, z, minArea, opt = {}) {
if (out[i]) uset.push(out[i]);
}
opt.changes = length(uset) - lpre;
return uset;
}

View file

@ -385,7 +385,11 @@ async function sliceZ(z, points, options = {}) {
let groups = groupFn(lines, z, options);
if (options.union) {
// simplistic healing of non-manifold meshes
groups = POLY.flatten(POLY.union(POLY.nest(groups), 0.1, true), null, true);
let opt = { x: 1 };
let union = POLY.union(POLY.nest(groups), 0.1, true, opt);
// track total poly length changes to determine if healed
rval.changes = opt.changes;
groups = POLY.flatten(union, null, true);
}
rval.groups = groups;
}