*
* 1. Get all nodes within a reasonable range. 2. Score the closest
* nodes, adding points for closeness but deducting points for being
* off-axis.
*/
Point base = new Point();
NodeRange cur = getCurRange();
/*
* The LEFT or RIGHT directions should always go IN or OUT of the tree,
* while the up and down will use the score-based search.
*/
if (dir == LEFT || dir == RIGHT)
{
RootedTree t = cur.render.getTree();
PhyloNode curNode = null;
if (dir == LEFT)
{
if (t.getParentOf(cur.node) != null)
{
curNode = (PhyloNode) t.getParentOf(cur.node);
setCurRange(rangeForNode(cur.render, curNode));
return;
}
} else if (dir == RIGHT)
{
if (!t.isLeaf(cur.node))
{
List kids = t.getChildrenOf(cur.node);
curNode = (PhyloNode) kids.get(kids.size() - 1);
setCurRange(rangeForNode(cur.render, curNode));
return;
}
}
}
switch (dir)
{
case (LEFT):
base.setLocation(-1, .1);
break;
case (RIGHT):
base.setLocation(1, -.1);
break;
case (UP):
base.setLocation(0, -1);
break;
case (DOWN):
base.setLocation(0, 1);
break;
}
pt.setLocation(cur.node.getX(), cur.node.getY());
getWithinRange(cur.node.getX(), cur.node.getY(), 200);
Point pt2 = new Point();
float maxScore = -Float.MAX_VALUE;
NodeRange maxRange = null;
for (int i = 0; i < nearNodes.size(); i++)
{
NodeRange r = (NodeRange) nearNodes.get(i);
if (r.type == NodeRange.LABEL)
continue;
if (r.node == cur.node)
continue;
pt2.setLocation(r.node.getX(), r.node.getY());
float score = score(pt, pt2, base);
if (score > maxScore)
{
maxScore = score;
maxRange = r;