/** * Gets all objects inside the specified area. Objects on the border of * the area are not included. * * @param minX The minimum left-right location, longitude * @param minY The minimum up-down location, latitude * @param maxX The maximum left-right location, longitude * @param maxY The maximum up-down location, latitude * @param values1 A collection to store the found objects in. * @return The objects found within the area. */ public Collection<T> getRectangle(final double minX, final double minY, final double maxX, final double maxY, final Collection<T> values1) { return getRectangle(new Rect(minX, minY, maxX, maxY), values1); }
/** * retrieve cells within bounds * * @param bounds bounds * @return all cells which have their centroid withing the given bounds */ public Collection<Cell<T>> getCells(Geometry bounds) { return quadTree.getRectangle( bounds.getEnvelopeInternal().getMinX(), bounds.getEnvelopeInternal().getMinY(), bounds.getEnvelopeInternal().getMaxX(), bounds.getEnvelopeInternal().getMaxY(), new ArrayList<>() ); }
@Test public void testGetRect_flatNetwork() { QuadTree<String> qt = new QuadTree<>(0, 0, 1000, 0); qt.put(0, 0, "node1"); qt.put(100, 0, "node2"); qt.put(500, 0, "node3"); qt.put(900, 0, "node4"); Collection<String> values = new ArrayList<>(); qt.getRectangle(new Rect(90, -10, 600, +10), values); Assert.assertEquals(2, values.size()); Assert.assertTrue(values.contains("node2")); Assert.assertTrue(values.contains("node3")); Collection<String> values2 = new ArrayList<>(); qt.getRectangle(new Rect(90, 0, 600, 0), values2); Assert.assertEquals(2, values2.size()); Assert.assertTrue(values2.contains("node2")); Assert.assertTrue(values2.contains("node3")); }
@Test public void testGetRect() { QuadTree<String> qt = new QuadTree<>(0, 0, 1000, 1000); qt.put(100, 200, "node1"); qt.put(400, 900, "node2"); qt.put(700, 300, "node3"); qt.put(900, 400, "node4"); Collection<String> values = new ArrayList<>(); qt.getRectangle(new Rect(400, 300, 700, 900), values); Assert.assertEquals(2, values.size()); Assert.assertTrue(values.contains("node2")); Assert.assertTrue(values.contains("node3")); }
qt.getRectangle(0.0, 0.0, 20.1, 20.1, values); // test with no object on the boundary assertEquals(4, values.size()); qt.getRectangle(0.0, 0.0, 20.0, 20.0, values); // test with an object exactly on the boundary assertEquals(4, values.size()); qt.getRectangle(0.0, 0.0, 19.9, 19.9, values); // test with no object on the boundary assertEquals(3, values.size());