From 3d52fc9139a7e230e6fe165224f41dc88805f4ea Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Thu, 22 Jun 2017 10:19:15 +0200 Subject: [PATCH] properly check for undefined --- src/sliceActions/createLines.js | 6 +++--- src/sliceActions/intersectionsToShapes.js | 6 +++--- src/sliceActions/optimizePaths.js | 4 ++-- src/sliceActions/removePrecision.js | 4 ++-- src/sliceActions/slicesToGCode.js | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/sliceActions/createLines.js b/src/sliceActions/createLines.js index 7f0a696..15cd50a 100644 --- a/src/sliceActions/createLines.js +++ b/src/sliceActions/createLines.js @@ -32,9 +32,9 @@ export default function createLines(geometry, settings, openClosed) { // only add unique lines // returns index of said line - const indexA = lookupA !== undefined ? lookupA : addLine(geometry, lineLookup, lines, face.a, face.b); - const indexB = lookupB !== undefined ? lookupB : addLine(geometry, lineLookup, lines, face.b, face.c); - const indexC = lookupC !== undefined ? lookupC : addLine(geometry, lineLookup, lines, face.c, face.a); + const indexA = typeof lookupA !== 'undefined' ? lookupA : addLine(geometry, lineLookup, lines, face.a, face.b); + const indexB = typeof lookupB !== 'undefined' ? lookupB : addLine(geometry, lineLookup, lines, face.b, face.c); + const indexC = typeof lookupC !== 'undefined' ? lookupC : addLine(geometry, lineLookup, lines, face.c, face.a); // set connecting lines (based on face) lines[indexA].connects.push(indexB, indexC); diff --git a/src/sliceActions/intersectionsToShapes.js b/src/sliceActions/intersectionsToShapes.js index 3081dc5..52db98b 100644 --- a/src/sliceActions/intersectionsToShapes.js +++ b/src/sliceActions/intersectionsToShapes.js @@ -17,7 +17,7 @@ export default function intersectionsToShapes(layerIntersectionIndexes, layerInt for (let i = 0; i < intersectionIndexes.length; i ++) { let index = intersectionIndexes[i]; - if (intersectionPoints[index] === undefined) continue; + if (typeof intersectionPoints[index] === 'undefined') continue; const shape = []; @@ -46,7 +46,7 @@ export default function intersectionsToShapes(layerIntersectionIndexes, layerInt } // Check if index has an intersection or is already used - if (intersectionPoints[index] !== undefined) { + if (typeof intersectionPoints[index] !== 'undefined') { const faceNormal = faceNormals[Math.floor(i / 2)]; const a = new THREE.Vector2(intersection.x, intersection.y); @@ -99,7 +99,7 @@ export default function intersectionsToShapes(layerIntersectionIndexes, layerInt for (let i = 0; i < connects.length; i ++) { index = connects[i]; - if (intersectionPoints[index] !== undefined) { + if (typeof intersectionPoints[index] !== 'undefined') { break; } else { index = -1; diff --git a/src/sliceActions/optimizePaths.js b/src/sliceActions/optimizePaths.js index 00b2b41..638ae76 100644 --- a/src/sliceActions/optimizePaths.js +++ b/src/sliceActions/optimizePaths.js @@ -9,7 +9,7 @@ export default function optimizePaths(slices, settings) { for (let layer = 0; layer < slices.length; layer ++) { const slice = slices[layer]; - if (slice.brim !== undefined && slice.brim.paths.length > 0) { + if (typeof slice.brim !== 'undefined' && slice.brim.paths.length > 0) { slice.brim = optimizeShape(slice.brim, start); start.copy(slice.brim.lastPoint(true)); } @@ -73,7 +73,7 @@ export default function optimizePaths(slices, settings) { slice.parts = parts; - if (slice.support !== undefined && slice.support.length > 0) { + if (typeof slice.support !== 'undefined' && slice.support.length > 0) { slice.support = optimizeShape(slice.support, start); start.copy(slice.support.lastPoint(true)); } diff --git a/src/sliceActions/removePrecision.js b/src/sliceActions/removePrecision.js index 9a684db..436eb82 100644 --- a/src/sliceActions/removePrecision.js +++ b/src/sliceActions/removePrecision.js @@ -24,10 +24,10 @@ export default function removePrecision(slices) { } } - if (slice.support !== undefined) { + if (typeof slice.support !== 'undefined') { slice.support.scaleDown(inversePrecision); } - if (slice.brim !== undefined) { + if (typeof slice.brim !== 'undefined') { slice.brim.scaleDown(inversePrecision); } } diff --git a/src/sliceActions/slicesToGCode.js b/src/sliceActions/slicesToGCode.js index c59e162..9d65318 100644 --- a/src/sliceActions/slicesToGCode.js +++ b/src/sliceActions/slicesToGCode.js @@ -13,7 +13,7 @@ export default function slicesToGCode(slices, settings) { gcode.bottom = false; } - if (slice.brim !== undefined) { + if (typeof slice.brim !== 'undefined') { pathToGCode(gcode, slice.brim, true, true, layer, 'brim'); } @@ -30,12 +30,12 @@ export default function slicesToGCode(slices, settings) { pathToGCode(gcode, part.fill, true, false, layer, 'fill'); } else { - const retract = !(slice.parts.length === 1 && slice.support === undefined); + const retract = !(slice.parts.length === 1 && typeof slice.support === 'undefined'); pathToGCode(gcode, part.shape, retract, retract, layer, 'outerLine'); } } - if (slice.support !== undefined) { + if (typeof slice.support !== 'undefined') { pathToGCode(gcode, slice.support, true, true, layer, 'support'); } }