@Test public void comparePerformance() { final int COUNT = 100000; NetworkNodeAccessor<String> slowWay = new RadiusNetworkNodeAccessor<>(Double.MAX_VALUE); double[] xs = new double[COUNT]; double[] ys = new double[COUNT]; for (int i = 0; i < COUNT; i++) { xs[i] = Math.random() * layoutModel.getWidth(); ys[i] = Math.random() * layoutModel.getHeight(); } long start = System.currentTimeMillis(); for (int i = 0; i < COUNT; i++) { String winnerOne = slowWay.getNode(layoutModel, xs[i], ys[i]); } long end = System.currentTimeMillis(); log.info("radius way took {}", end - start); start = System.currentTimeMillis(); for (int i = 0; i < COUNT; i++) { String winnerTwo = tree.getClosestElement(xs[i], ys[i]); } end = System.currentTimeMillis(); log.info("spatial way took {}", end - start); }
@Override public N getClosestElement(Point2D p) { return getClosestElement(p.getY(), p.getY()); }
SpatialQuadTree extends AbstractSpatial<N, N> implements TreeNode, Spatial<N>, LayoutChangeListener<N> { @Override public N getClosestElement(Point2D p) { return getClosestElement(p.getY(), p.getY()); } }
SpatialQuadTree extends AbstractSpatial<N, N> implements TreeNode, Spatial<N>, LayoutChangeListener<N> { @Override public N getClosestElement(Point2D p) { return getClosestElement(p.getY(), p.getY()); } SpatialQuadTree(LayoutModel<N> layoutModel);  SpatialQuadTree(LayoutModel<N> layoutModel, double width, double height);  SpatialQuadTree(
      LayoutModel<N> layoutModel, int level, double x, double y, double width, double height);  SpatialQuadTree(LayoutModel<N> layoutModel, int pLevel, Rectangle2D area); }
SpatialQuadTree extends AbstractSpatial<N, N> implements TreeNode, Spatial<N>, LayoutChangeListener<N> { @Override public N getClosestElement(Point2D p) { return getClosestElement(p.getY(), p.getY()); } SpatialQuadTree(LayoutModel<N> layoutModel);  SpatialQuadTree(LayoutModel<N> layoutModel, double width, double height);  SpatialQuadTree(
      LayoutModel<N> layoutModel, int level, double x, double y, double width, double height);  SpatialQuadTree(LayoutModel<N> layoutModel, int pLevel, Rectangle2D area); @Override Rectangle2D getBounds(); @Override Collection<? extends TreeNode> getChildren(); SpatialQuadTree<N> setMaxObjects(int o); SpatialQuadTree<N> setMaxLevels(int l); Set<N> getNodes(); @Override void clear(); List<Spatial> getNodes(List<Spatial> list); @Override List<Shape> getGrid(); @Override Set<N> getVisibleElements(Shape shape); Set<N> getVisibleNodes(Rectangle2D r); @Override Rectangle2D getLayoutArea(); @Override void recalculate(); TreeNode getContainingQuadTreeLeaf(N node); Set<SpatialQuadTree<N>> getContainingLeafs(Point2D p); Set<SpatialQuadTree<N>> getContainingLeafs(double x, double y); @Override TreeNode getContainingLeaf(Object element); SpatialQuadTree<N> getContainingQuadTreeLeaf(Point2D p); SpatialQuadTree<N> getContainingQuadTreeLeaf(double x, double y); @Override N getClosestElement(Point2D p); @Override N getClosestElement(double x, double y); @Override void setBounds(Rectangle2D bounds); @Override void update(N node, Point location); @Override void layoutChanged(LayoutEvent<N> evt); @Override void layoutChanged(LayoutNetworkEvent<N> evt); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
SpatialQuadTree extends AbstractSpatial<N, N> implements TreeNode, Spatial<N>, LayoutChangeListener<N> { @Override public N getClosestElement(Point2D p) { return getClosestElement(p.getY(), p.getY()); } SpatialQuadTree(LayoutModel<N> layoutModel);  SpatialQuadTree(LayoutModel<N> layoutModel, double width, double height);  SpatialQuadTree(
      LayoutModel<N> layoutModel, int level, double x, double y, double width, double height);  SpatialQuadTree(LayoutModel<N> layoutModel, int pLevel, Rectangle2D area); @Override Rectangle2D getBounds(); @Override Collection<? extends TreeNode> getChildren(); SpatialQuadTree<N> setMaxObjects(int o); SpatialQuadTree<N> setMaxLevels(int l); Set<N> getNodes(); @Override void clear(); List<Spatial> getNodes(List<Spatial> list); @Override List<Shape> getGrid(); @Override Set<N> getVisibleElements(Shape shape); Set<N> getVisibleNodes(Rectangle2D r); @Override Rectangle2D getLayoutArea(); @Override void recalculate(); TreeNode getContainingQuadTreeLeaf(N node); Set<SpatialQuadTree<N>> getContainingLeafs(Point2D p); Set<SpatialQuadTree<N>> getContainingLeafs(double x, double y); @Override TreeNode getContainingLeaf(Object element); SpatialQuadTree<N> getContainingQuadTreeLeaf(Point2D p); SpatialQuadTree<N> getContainingQuadTreeLeaf(double x, double y); @Override N getClosestElement(Point2D p); @Override N getClosestElement(double x, double y); @Override void setBounds(Rectangle2D bounds); @Override void update(N node, Point location); @Override void layoutChanged(LayoutEvent<N> evt); @Override void layoutChanged(LayoutNetworkEvent<N> evt); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }