From 0ad8de8c80507c758a6de27ddd8fd5e6b9b89d81 Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Mon, 24 Jul 2017 15:45:18 +0200 Subject: [PATCH] simplify code --- src/Slicer.js | 3 ++- src/sliceActions/addBrim.js | 7 +++---- src/sliceActions/optimizePaths.js | 10 +++------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/Slicer.js b/src/Slicer.js index a3d7196..d100150 100644 --- a/src/Slicer.js +++ b/src/Slicer.js @@ -71,11 +71,12 @@ function sliceAsync(settings, geometry, onProgress) { }); // send geometry and settings to worker to start the slicing progress + geometry = geometry.toJSON(); slicerWorker.postMessage({ message: 'SLICE', data: { settings, - geometry: geometry.toJSON() + geometry } }); }); diff --git a/src/sliceActions/addBrim.js b/src/sliceActions/addBrim.js index 9812598..da66540 100644 --- a/src/sliceActions/addBrim.js +++ b/src/sliceActions/addBrim.js @@ -15,11 +15,10 @@ export default function addBrim(slices, settings) { const [firstLayer] = slices; - firstLayer.brim = firstLayer.parts.reduce((brim, { shape }) => { + firstLayer.brim = firstLayer.parts.reduce((brim, { shape }) => ( brim.join(shape.offset(brimOffset, { ...offsetOptions, endType: shape.closed ? 'etClosedPolygon' : 'etOpenRound' - })); - return brim; - }, new Shape([], true)).simplify('pftNonZero'); + })) + ), new Shape([], true)).simplify('pftNonZero'); } diff --git a/src/sliceActions/optimizePaths.js b/src/sliceActions/optimizePaths.js index cc5fec5..5a478b4 100644 --- a/src/sliceActions/optimizePaths.js +++ b/src/sliceActions/optimizePaths.js @@ -21,12 +21,8 @@ export default function optimizePaths(slices, settings) { for (let i = 0; i < slice.parts.length; i ++) { const part = slice.parts[i]; - let bounds; - if (part.shape.closed) { - bounds = part.outerLine.shapeBounds(); - } else { - bounds = part.shape.shapeBounds(); - } + const shape = part.shape.closed ? part.outerLine : part.shape; + const bounds = shape.shapeBounds(); const top = bounds.top - start.y; const bottom = start.y - bounds.bottom; @@ -41,7 +37,7 @@ export default function optimizePaths(slices, settings) { } } - const part = slice.parts.splice(closestPart, 1)[0]; + const [part] = slice.parts.splice(closestPart, 1); parts.push(part); if (part.shape.closed) {