Skip to content

Commit

Permalink
Merge pull request #8217 from neilcsmith-net/gh8209
Browse files Browse the repository at this point in the history
Fix infinite loop in FruchtermanReingoldLayout.
  • Loading branch information
ebarboni authored Feb 4, 2025
2 parents 4b3bfa3 + a11dbab commit c5503f0
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void rePerformLayout(int iters) {
// System.out.println("scene bounds are =" + bounds);
temp = bounds.getWidth() / 1000;
// forceConstant = 0.75 * Math.sqrt(bounds.getHeight() * bounds.getWidth() / nds);
forceConstant = 0.25 * Math.sqrt(bounds.getHeight() * bounds.getWidth() / nds);
forceConstant = 1.75 * Math.sqrt(bounds.getHeight() * bounds.getWidth() / nds);
// System.out.println("force constant2=" + forceConstant);
performLayout(false);
}
Expand All @@ -150,7 +150,7 @@ private void init() {
bounds = new Rectangle(magicSizeConstant + (magicSizeMultiplier * nds),
magicSizeConstant + (magicSizeMultiplier * nds)); //g.getMaximumBounds();
temp = bounds.getWidth() / 10;
forceConstant = 0.75 * Math.sqrt(bounds.getHeight() * bounds.getWidth() / nds);
forceConstant = 1.75 * Math.sqrt(bounds.getHeight() * bounds.getWidth() / nds);

GraphNode<I> rn = scene.getRootGraphNode();
NodeWidget rw = getWidget(rn);
Expand Down Expand Up @@ -382,7 +382,8 @@ private void relayoutNonFixed(NodeWidget w) {
r = 30;
theta = 0;
w.setFixed(false);
while (true) {
// 48 - ~3 times round?
for (int i = 0; i < 48; i++) {
AffineTransform tr = AffineTransform.getRotateInstance(theta);
Point2D d2point = tr.transform(new Point2D.Double(0, r), null);
Point point = new Point((int)d2point.getX() + masterPoint.x, (int)d2point.getY() + masterPoint.y);
Expand All @@ -396,10 +397,9 @@ private void relayoutNonFixed(NodeWidget w) {
if (theta > (Math.PI * 2 - Math.PI / 10)) {
r = r + 30;
theta = theta - Math.PI * 2;
thetaStep = thetaStep * 3 / 4;
thetaStep = thetaStep * 3 / 4;
}
}

}

private NodeWidget getWidget(GraphNode n) {
Expand Down

0 comments on commit c5503f0

Please sign in to comment.