From d982672bb6cb72aef77badcee231e90700d5117e Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Mon, 22 Jul 2024 19:03:27 -0400 Subject: [PATCH] safety checks on mesh points and group array reductions --- src/geo/slicer.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/geo/slicer.js b/src/geo/slicer.js index 6301a042..81509162 100644 --- a/src/geo/slicer.js +++ b/src/geo/slicer.js @@ -173,7 +173,7 @@ async function slice(points, options = {}) { p1 = points[i++]; p2 = points[i++]; p3 = points[i++]; - let zm = Math.min(p1.z, p2.z, p3.z), + let zm = Math.max(0, Math.min(p1.z, p2.z, p3.z)), zM = Math.max(p1.z, p2.z, p3.z), bm = Math.floor(zm * zScale), bM = Math.min(Math.ceil(zM * zScale), bucketCount); @@ -391,7 +391,8 @@ async function sliceZ(z, points, options = {}) { groups = POLY.xor(groups); } if (options.union) { - let points = groups.map(p => p.length).reduce((a,b) => a + b); + let points = groups.map(p => p.length); + if (points.length > 1) points = points.reduce((a,b) => a + b); // simplistic healing of non-manifold meshes let opt = { x: 1 }; let union = POLY.union(POLY.nest(groups), 0.1, true, opt);