Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix TreeLayoutAlgorithm to not try to use pointModel before visit call #159

Merged
merged 2 commits into from
Nov 29, 2017
Merged

fix TreeLayoutAlgorithm to not try to use pointModel before visit call #159

merged 2 commits into from
Nov 29, 2017

Conversation

tomnelson
Copy link
Contributor

Changes to be committed:
modified: jung-algorithms/src/main/java/edu/uci/ics/jung/layout/algorithms/TreeLayoutAlgorithm.java

 Changes to be committed:
	modified:   jung-algorithms/src/main/java/edu/uci/ics/jung/layout/algorithms/TreeLayoutAlgorithm.java
}

public void visit(LayoutModel<N, P> layoutModel) {
super.visit(layoutModel);
this.m_currentPoint = pointModel.newPoint(0, 0);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm missing something, this assignment never has any effect, because it's immediately overwritten inside the buildTree() call, so we can just remove it.

Pushing this even farther: it's not at all clear to me that we even want a currentPoint instance field. Seems like it would be better to make the following changes:

(1) change the buildTree overload with three arguments so that the last argument is the current point (not just its X coordinate)
(2) add a P argument to setCurrentPositionFor() and pass the current point to it

That way we don't need this piece of class-level state at all, which seems like a better/more robust design.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, TreeLayout. It was one of our contributed Layouts and has always been a little odd. There's probably a ticket out there somewhere to completely redesign it.

 Changes to be committed:
	modified:   jung-algorithms/src/main/java/edu/uci/ics/jung/layout/algorithms/TreeLayoutAlgorithm.java
@tomnelson
Copy link
Contributor Author

All uses of TreeLayoutAlgorithm (several demos) are broken until this is merged. There are no unit tests for TreeLayoutAlgorithm. If there were, they would be broken too.

@jrtom
Copy link
Owner

jrtom commented Nov 29, 2017

Yes, I'm aware that this was broken; I spent as much time as I could on JUNG stuff yesterday. Feel free to add a minimal test for TreeLayout that would have caught the original bug.
I've filed #162 for addressing the issue I brought up in the review.

@jrtom jrtom merged commit f75ba44 into jrtom:master Nov 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants