Pass vector to distanceToWeight, remove some useless affinities

This commit is contained in:
Ian Gulliver
2019-07-08 02:40:43 +00:00
parent bb45fba08f
commit df811ec7fa
2 changed files with 12 additions and 1 deletions

View File

@@ -43,7 +43,12 @@ class GraphNode {
setAffinity(nodes) {
const INF = 999999;
for (let node of nodes) {
if (node == this) {
continue;
}
// Weak affinity full mesh
// Keep unassociated subgroups together
this.addAffinity(node, d => d);
@@ -58,14 +63,20 @@ class GraphNode {
node.addAffinity(this, d => d <= 2 ? -INF : 0);
}
}
for (let to of this.links) {
// Stronger affinity for links
// Prefer to move toward the target instance
this.addAffinity(to, d => d <= 2 ? -INF : d * 11);
to.addAffinity(this, d => d <= 2 ? -INF : d * 9);
}
for (let group of this.groups) {
for (let node of group.nodes) {
if (node == this) {
continue;
}
this.addAffinity(node, d => d * 100);
}
}

View File

@@ -35,7 +35,7 @@ class LayoutNode {
};
// Avoid calling sqrt(), since the results are used relatively
let distanceSquared = vec[0] * vec[0] + vec[1] * vec[1];
let weight = aff.distanceToWeight(distanceSquared);
let weight = aff.distanceToWeight(distanceSquared, vec);
for (let i of [0, 1]) {
this.vec[i] += (weight * vec[i]) / vecsum;
}