From 21ee710468bdb3714b4ecba060b7aad7f9f0a6ed Mon Sep 17 00:00:00 2001 From: Pitchaya Boonsarngsuk <2285135b@student.gla.ac.uk> Date: Thu, 22 Mar 2018 16:29:10 +0000 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=20coding=20style=20?= =?UTF-8?q?=E0=B8=A0=E0=B8=B2=E0=B8=84=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc | 1 + src/hybridSimulation.js | 7 ++++--- src/interpolation/interpBruteForce.js | 3 +-- src/interpolation/interpCommon.js | 23 ++++++++++------------- src/interpolation/interpolationPivots.js | 18 ++++++++++-------- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/.eslintrc b/.eslintrc index f0e14f8..73b137e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,6 +9,7 @@ rules: semi: - error - always + no-return-assign: 0 /* no-extra-parens: 1 curly: 0 diff --git a/src/hybridSimulation.js b/src/hybridSimulation.js index bf4881a..57acc73 100644 --- a/src/hybridSimulation.js +++ b/src/hybridSimulation.js @@ -67,11 +67,12 @@ export default function (sim, forceS, forceF) { } // Set default value for interpDistanceFn if not been specified yet - if(interpDistanceFn === undefined) { - if(forceFull.distance == 'function') + if (interpDistanceFn === undefined) { + if (forceFull.distance == 'function') { interpDistanceFn = forceFull.distance(); - else + } else { interpDistanceFn = constant(300); + } } } diff --git a/src/interpolation/interpBruteForce.js b/src/interpolation/interpBruteForce.js index 1591cd8..1584a46 100644 --- a/src/interpolation/interpBruteForce.js +++ b/src/interpolation/interpBruteForce.js @@ -39,8 +39,7 @@ export default function (sampleSet, remainderSet, distanceFn, endingIts) { } index = sampleSubset.indexOf(sample); - if (index !== -1) - sampleSubsetDistanceCache[index] = dist; + if (index !== -1) { sampleSubsetDistanceCache[index] = dist; } } placeNearToNearestNeighbour(node, nearestSample, minDist, sampleSubset, sampleSubsetDistanceCache, endingIts); diff --git a/src/interpolation/interpCommon.js b/src/interpolation/interpCommon.js index 29e2305..30e81d9 100644 --- a/src/interpolation/interpCommon.js +++ b/src/interpolation/interpCommon.js @@ -38,15 +38,11 @@ export function placeNearToNearestNeighbour (node, nearNeighbour, radius, sample // Determine the closest quadrant if (dist0 == dist180) { - if (dist90 > dist270) - lowBound = highBound = 270; - else - lowBound = highBound = 90; + if (dist90 > dist270) { lowBound = highBound = 270; } + else { lowBound = highBound = 90; } } else if (dist90 == dist270) { - if (dist0 > dist180) - lowBound = highBound = 180; - else - lowBound = highBound = 0; + if (dist0 > dist180) { lowBound = highBound = 180; } + else { lowBound = highBound = 0; } } else if (dist0 > dist180) { if (dist90 > dist270) { lowBound = 180; @@ -122,13 +118,14 @@ function binarySearchMin (lb, hb, fn) { valLowerHalf = fn(lb + range / 4), valHigherHalf = fn(lb + range * 3 / 4); - if (valLowerHalf > valHigherHalf) + if (valLowerHalf > valHigherHalf) { lb = Math.floor((lb + hb) / 2); - else if (valLowerHalf < valHigherHalf) + } + else if (valLowerHalf < valHigherHalf) { hb = Math.ceil((lb + hb) / 2); - else { - lb += Math.floor(range/4); - hb -= Math.ceil(range/4); + } else { + lb += Math.floor(range / 4); + hb -= Math.ceil(range / 4); } } return -1; diff --git a/src/interpolation/interpolationPivots.js b/src/interpolation/interpolationPivots.js index 5a7a07a..89f6ba9 100644 --- a/src/interpolation/interpolationPivots.js +++ b/src/interpolation/interpolationPivots.js @@ -44,8 +44,9 @@ export default function (sampleSet, remainderSet, numPivots, distanceFn, endingI let distCache = []; // [ For each non-pivot sample:[For each Pivot: distance] ] let bucketWidths = []; // [ For each Pivot: width of each bucket ] - for (let i = 0; i < nonPivotSamples.length; i++) + for (let i = 0; i < nonPivotSamples.length; i++) { distCache[i] = []; + } for (let j = 0; j < numPivots; j++) { let pivot = pivots[j]; @@ -54,8 +55,9 @@ export default function (sampleSet, remainderSet, numPivots, distanceFn, endingI for (let i = 0; i < numNonPivots; i++) { let sample = nonPivotSamples[i]; distCache[i][j] = distanceFn(pivot, sample); - if (distCache[i][j] > maxDist) + if (distCache[i][j] > maxDist) { maxDist = distCache[i][j]; + } } bucketWidths.push(maxDist / numBuckets); @@ -109,12 +111,11 @@ export default function (sampleSet, remainderSet, numPivots, distanceFn, endingI for (let j = pivotsBuckets[p][bucketNumber].length - 1; j >= 0; j--) { let candidateNode = pivotsBuckets[p][bucketNumber][j]; let index = sampleSubset.indexOf(candidateNode); - if (index !== -1 && sampleSubsetDistanceCache[index] !== undefined) - dist = sampleSubsetDistanceCache[index] - else { + if (index !== -1 && sampleSubsetDistanceCache[index] !== undefined) { + dist = sampleSubsetDistanceCache[index]; + } else { dist = distanceFn(candidateNode, node); - if (index !== -1) - sampleSubsetDistanceCache[index] = dist; + if (index !== -1) { sampleSubsetDistanceCache[index] = dist; } } if (dist < minDist) { @@ -126,8 +127,9 @@ export default function (sampleSet, remainderSet, numPivots, distanceFn, endingI // Fill in holes in cache for (let k = 0; k < sampleSubset.length; k++) { - if (sampleSubsetDistanceCache[k] === undefined) + if (sampleSubsetDistanceCache[k] === undefined) { sampleSubsetDistanceCache[k] = distanceFn(node, sampleSubset[k]); + } } placeNearToNearestNeighbour(node, nearSample, minDist, sampleSubset, sampleSubsetDistanceCache, endingIts); }