Skip to content

Commit

Permalink
reduce calculations on hot path
Browse files Browse the repository at this point in the history
  • Loading branch information
capnmidnight committed Mar 7, 2024
1 parent bee3598 commit bfa3849
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,11 @@ export class ForceDirectedGraph<T> {
const c3 = 1.25;
const c4 = 0.2;
const c5 = 2;
const k = c0 * Math.sqrt(c1 * area / this.displayCount);
const k0 = c0 * Math.sqrt(c1 * area / this.displayCount);
const k1 = c2 / k0;
const k2 = c4 * Math.pow(k0, c5);
this.applyForces(
(connected, len) => connected ? c2 * Math.pow(len, c3) / k : 0,
(_, len) => c4 * Math.pow(k, c5) / len);
(connected, len) => connected ? k1 * Math.pow(len, c3) : 0,
(_, len) => k2 / len);
}
}

0 comments on commit bfa3849

Please sign in to comment.