Hi! In the addRandomNode routine of today's mainline branch, line 50 of manyBodySampled.js, a value called a distance is calculated not by summing the squared dimension-wise differences, but by subtracting. The resulting value is compared against a distance calculated conventionally on line 29, by summing the squared differences.
This appears to be a bug that would cause the randomly selected new neighbor to replace an element of the current list more often than the algorithm and the code comments suggest it should. In that case, the fix is the one-character change shown below.
Should I make a pull request?
bash$ git diff
diff --git a/src/manyBodySampled.js b/src/manyBodySampled.js
index 9a6220b..65cf91b 100644
--- a/src/manyBodySampled.js
+++ b/src/manyBodySampled.js
@@ -47,7 +47,7 @@ export default function() {
while (++i < node.nearest.length) {
currIdx = node.nearest[i];
currNode = nodes[currIdx];
- currDist = (node.x - currNode.x) * (node.x - currNode.x) - (node.y - currNode.y) * (node.y - currNode.y);
+ currDist = (node.x - currNode.x) * (node.x - currNode.x) + (node.y - currNode.y) * (node.y - currNode.y);
if (currDist > maxDist) {
maxI = i;
maxDist = currDist;
bash$
Hi! In the
addRandomNoderoutine of today's mainline branch, line 50 ofmanyBodySampled.js, a value called a distance is calculated not by summing the squared dimension-wise differences, but by subtracting. The resulting value is compared against a distance calculated conventionally on line 29, by summing the squared differences.This appears to be a bug that would cause the randomly selected new neighbor to replace an element of the current list more often than the algorithm and the code comments suggest it should. In that case, the fix is the one-character change shown below.
Should I make a pull request?