/** * @param layoutModel * @param p the pick point * @return the node associated with location p */ @Override public N getNode(LayoutModel<N> layoutModel, Point p) { return getNode(layoutModel, p.x, p.y); }
@Override public N getClosestElement(double x, double y) { if (!isActive()) { return fallback.getNode(layoutModel, x, y); } Collection<TreeNode> leafs = getContainingLeafs(x, y); if (leafs.size() != 0) { TreeNode leaf = leafs.iterator().next(); Rectangle2D area = leaf.getBounds(); double radius = area.getWidth(); N closest = null; while (closest == null) { double diameter = radius * 2; Ellipse2D searchArea = new Ellipse2D.Double(x - radius, y - radius, diameter, diameter); Collection<N> nodes = getVisibleElements(searchArea); closest = getClosest(nodes, x, y, radius); // if I have already considered all of the nodes in the graph // (in the spatialquadtree) there is no reason to enlarge the // area and try again if (nodes.size() >= layoutModel.getGraph().nodes().size()) { break; } // double the search area size and try again radius *= 2; } return closest; } return null; } /**
public N getClosestElement(double x, double y) { if (!isActive()) { return fallback.getNode(layoutModel, x, y);
if (!isActive() || !rtree.getRoot().isPresent()) { return fallback.getNode(layoutModel, x, y);