แก้ coding style ภาค 7

This commit is contained in:
Pitchaya Boonsarngsuk
2018-03-22 16:35:00 +00:00
parent 684878b1fd
commit 93af0e646a
5 changed files with 18 additions and 18 deletions

View File

@@ -28,7 +28,7 @@ export default function () {
function force (_) { function force (_) {
var i, n = nodes.length, tree = quadtree(nodes, x, y).visitAfter(accumulate); var i, n = nodes.length, tree = quadtree(nodes, x, y).visitAfter(accumulate);
for (alpha = _, i = 0; i < n; ++i) { for (alpha = _, i = 0; i < n; ++i) {
node = nodes[i], tree.visit(apply); node = nodes[i]; tree.visit(apply);
} }
} }
@@ -78,8 +78,8 @@ export default function () {
// Apply the Barnes-Hut approximation if possible. // Apply the Barnes-Hut approximation if possible.
// Limit forces for very close nodes; randomize direction if coincident. // Limit forces for very close nodes; randomize direction if coincident.
if (w / l < theta) { if (w / l < theta) {
if (x === 0) x = jiggle(), l += x * x; if (x === 0) {x = jiggle(); l += x * x;}
if (y === 0) y = jiggle(), l += y * y; if (y === 0) {y = jiggle(); l += y * y;}
if (quad.data) { if (quad.data) {
l = (l - +distance(node, quad.data)) / l * alpha; l = (l - +distance(node, quad.data)) / l * alpha;
x *= l, y *= l; x *= l, y *= l;
@@ -93,14 +93,14 @@ export default function () {
// Limit forces for very close nodes; randomize direction if coincident. // Limit forces for very close nodes; randomize direction if coincident.
if (quad.data !== node || quad.next) { if (quad.data !== node || quad.next) {
if (x === 0) x = jiggle(), l += x * x; if (x === 0) {x = jiggle(); l += x * x;}
if (y === 0) y = jiggle(), l += y * y; if (y === 0) {y = jiggle(); l += y * y;}
} }
do { do {
if (quad.data !== node) { if (quad.data !== node) {
l = (l - +distance(node, quad.data)) / l * alpha; l = (l - +distance(node, quad.data)) / l * alpha;
x *= l, y *= l; x *= l; y *= l;
quad.data.vx -= x; quad.data.vx -= x;
quad.data.vy -= y; quad.data.vy -= y;
node.vx += x; node.vx += x;
@@ -120,7 +120,7 @@ export default function () {
for (var i = 0, source, target, realDist, highDist; i < nodes.length; i++) { for (var i = 0, source, target, realDist, highDist; i < nodes.length; i++) {
for (var j = 0; j < nodes.length; j++) { for (var j = 0; j < nodes.length; j++) {
if (i !== j) { if (i !== j) {
source = nodes[i], target = nodes[j]; source = nodes[i]; target = nodes[j];
realDist = Math.hypot(target.x - source.x, target.y - source.y); realDist = Math.hypot(target.x - source.x, target.y - source.y);
highDist = +distance(nodes[i], nodes[j]); highDist = +distance(nodes[i], nodes[j]);
totalDiffSq += Math.pow(realDist - highDist, 2); totalDiffSq += Math.pow(realDist - highDist, 2);

View File

@@ -42,8 +42,8 @@ export default function (sim, forceS, forceF) {
alreadyRanIterations, alreadyRanIterations,
hybrid; hybrid;
if (simulation != undefined) initSimulation(); if (simulation !== undefined) initSimulation();
if (forceS != undefined || forceF != undefined) initForces(); if (forceS !== undefined || forceF !== undefined) initForces();
// Performed on first run // Performed on first run
function initialize () { function initialize () {
@@ -68,7 +68,7 @@ export default function (sim, forceS, forceF) {
// Set default value for interpDistanceFn if not been specified yet // Set default value for interpDistanceFn if not been specified yet
if (interpDistanceFn === undefined) { if (interpDistanceFn === undefined) {
if (forceFull.distance == 'function') { if (forceFull.distance === 'function') {
interpDistanceFn = forceFull.distance(); interpDistanceFn = forceFull.distance();
} else { } else {
interpDistanceFn = constant(300); interpDistanceFn = constant(300);

View File

@@ -37,9 +37,9 @@ export function placeNearToNearestNeighbour (node, nearNeighbour, radius, sample
highBound = 0.0; highBound = 0.0;
// Determine the closest quadrant // Determine the closest quadrant
if (dist0 == dist180) { 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) { } 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) { } else if (dist0 > dist180) {
if (dist90 > dist270) { if (dist90 > dist270) {
@@ -87,7 +87,7 @@ function sumForcesToSample (node, samples, sampleCache) {
y = node.y - sample.y || jiggle(); y = node.y - sample.y || jiggle();
l = Math.sqrt(x * x + y * y); l = Math.sqrt(x * x + y * y);
l = (l - sampleCache[i]) / l; l = (l - sampleCache[i]) / l;
x *= l, y *= l; x *= l; y *= l;
nodeVx -= x; nodeVx -= x;
nodeVy -= y; nodeVy -= y;
} }
@@ -106,7 +106,7 @@ function binarySearchMin (lb, hb, fn) {
while (lb <= hb) { while (lb <= hb) {
if (lb === hb) return lb; if (lb === hb) return lb;
if (hb - lb == 1) { if (hb - lb === 1) {
if (fn(lb) >= fn(hb)) return hb; if (fn(lb) >= fn(hb)) return hb;
else return lb; else return lb;
} }

View File

@@ -81,7 +81,7 @@ export default function () {
y = target.y + target.vy - source.y - source.vy || jiggle(); y = target.y + target.vy - source.y - source.vy || jiggle();
l = Math.sqrt(x * x + y * y); l = Math.sqrt(x * x + y * y);
l = (l - dist) / l * dataSizeFactor * alpha; l = (l - dist) / l * dataSizeFactor * alpha;
x *= l, y *= l; x *= l; y *= l;
// Set the calculated velocites for both nodes. // Set the calculated velocites for both nodes.
target.vx -= x; target.vx -= x;
target.vy -= y; target.vy -= y;

View File

@@ -53,7 +53,7 @@ export default function () {
let u = 2 * Math.random() - 1; let u = 2 * Math.random() - 1;
let v = 2 * Math.random() - 1; let v = 2 * Math.random() - 1;
let r = u * u + v * v; let r = u * u + v * v;
if (r == 0 || r > 1) { if (r === 0 || r > 1) {
return gaussRandom(); return gaussRandom();
} }
return u * Math.sqrt(-2 * Math.log(r) / r); return u * Math.sqrt(-2 * Math.log(r) / r);
@@ -140,7 +140,7 @@ export default function () {
// Normalize p and compute entropy. // Normalize p and compute entropy.
var Hhere = 0.0; var Hhere = 0.0;
for (j = 0; j < N; j++) { for (j = 0; j < N; j++) {
if (psum == 0) { if (psum === 0) {
pj = 0; pj = 0;
} else { } else {
pj = prow[j] / psum; pj = prow[j] / psum;
@@ -329,7 +329,7 @@ export default function () {
for (var i = 0, source, target, realDist, highDist; i < nodes.length; i++) { for (var i = 0, source, target, realDist, highDist; i < nodes.length; i++) {
for (var j = 0; j < nodes.length; j++) { for (var j = 0; j < nodes.length; j++) {
if (i !== j) { if (i !== j) {
source = nodes[i], target = nodes[j]; source = nodes[i]; target = nodes[j];
realDist = Math.hypot(target.x - source.x, target.y - source.y); realDist = Math.hypot(target.x - source.x, target.y - source.y);
highDist = +distance(nodes[i], nodes[j]); highDist = +distance(nodes[i], nodes[j]);
totalDiffSq += Math.pow(realDist - highDist, 2); totalDiffSq += Math.pow(realDist - highDist, 2);